]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.13.1-201402012049.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.1-201402012049.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b89a739..31509cb 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 +randstruct.seed
177 +randstruct.hashed_seed
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 de4cda9..d1183df 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 @@ -417,8 +418,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
306 # Rules shared between *config targets and build targets
307
308 # Basic helpers built in scripts/
309 -PHONY += scripts_basic
310 -scripts_basic:
311 +PHONY += scripts_basic gcc-plugins
312 +scripts_basic: gcc-plugins
313 $(Q)$(MAKE) $(build)=scripts/basic
314 $(Q)rm -f .tmp_quiet_recordmcount
315
316 @@ -579,6 +580,76 @@ else
317 KBUILD_CFLAGS += -O2
318 endif
319
320 +ifndef DISABLE_PAX_PLUGINS
321 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
322 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
323 +else
324 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
325 +endif
326 +ifneq ($(PLUGINCC),)
327 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
328 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
329 +endif
330 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
331 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
332 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
333 +endif
334 +ifdef CONFIG_KALLOCSTAT_PLUGIN
335 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
336 +endif
337 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
338 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
339 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
340 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
341 +endif
342 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
343 +GRKERNSEC_RANDSTRUCT_SEED := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gen-random-seed.sh)
344 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
345 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-seed=$(GRKERNSEC_RANDSTRUCT_SEED)
346 +RANDSTRUCT_HASHED_SEED := $(shell cat "$(srctree)/tools/gcc/randstruct.hashed_seed")
347 +RANDSTRUCT_PLUGIN_CFLAGS += -DRANDSTRUCT_HASHED_SEED="\"$(RANDSTRUCT_HASHED_SEED)\""
348 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
349 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
350 +endif
351 +endif
352 +ifdef CONFIG_CHECKER_PLUGIN
353 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
354 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
355 +endif
356 +endif
357 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
358 +ifdef CONFIG_PAX_SIZE_OVERFLOW
359 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
360 +endif
361 +ifdef CONFIG_PAX_LATENT_ENTROPY
362 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
363 +endif
364 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
365 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
366 +endif
367 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
368 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
369 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
370 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
371 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
372 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
373 +ifeq ($(KBUILD_EXTMOD),)
374 +gcc-plugins:
375 + $(Q)$(MAKE) $(build)=tools/gcc
376 +else
377 +gcc-plugins: ;
378 +endif
379 +else
380 +gcc-plugins:
381 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
382 + $(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.))
383 +else
384 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
385 +endif
386 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
387 +endif
388 +endif
389 +
390 include $(srctree)/arch/$(SRCARCH)/Makefile
391
392 ifdef CONFIG_READABLE_ASM
393 @@ -754,7 +825,7 @@ export mod_sign_cmd
394
395
396 ifeq ($(KBUILD_EXTMOD),)
397 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
398 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
399
400 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
401 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
402 @@ -803,6 +874,8 @@ endif
403
404 # The actual objects are generated when descending,
405 # make sure no implicit rule kicks in
406 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
407 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
408 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
409
410 # Handle descending into subdirectories listed in $(vmlinux-dirs)
411 @@ -812,7 +885,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
412 # Error messages still appears in the original language
413
414 PHONY += $(vmlinux-dirs)
415 -$(vmlinux-dirs): prepare scripts
416 +$(vmlinux-dirs): gcc-plugins prepare scripts
417 $(Q)$(MAKE) $(build)=$@
418
419 define filechk_kernel.release
420 @@ -855,10 +928,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
421
422 archprepare: archheaders archscripts prepare1 scripts_basic
423
424 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
425 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
426 prepare0: archprepare FORCE
427 $(Q)$(MAKE) $(build)=.
428
429 # All the preparing..
430 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
431 prepare: prepare0
432
433 # Generate some files
434 @@ -966,6 +1042,8 @@ all: modules
435 # using awk while concatenating to the final file.
436
437 PHONY += modules
438 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
439 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
440 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
441 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
442 @$(kecho) ' Building modules, stage 2.';
443 @@ -981,7 +1059,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
444
445 # Target to prepare building external modules
446 PHONY += modules_prepare
447 -modules_prepare: prepare scripts
448 +modules_prepare: gcc-plugins prepare scripts
449
450 # Target to install modules
451 PHONY += modules_install
452 @@ -1047,7 +1125,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
453 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
454 signing_key.priv signing_key.x509 x509.genkey \
455 extra_certificates signing_key.x509.keyid \
456 - signing_key.x509.signer
457 + signing_key.x509.signer tools/gcc/size_overflow_hash.h \
458 + tools/gcc/randstruct.seed tools/gcc/randstruct.hashed_seed
459
460 # clean - Delete most, but leave enough to build external modules
461 #
462 @@ -1087,6 +1166,7 @@ distclean: mrproper
463 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
464 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
465 -o -name '.*.rej' \
466 + -o -name '.*.rej' -o -name '*.so' \
467 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
468 -type f -print | xargs rm -f
469
470 @@ -1248,6 +1328,8 @@ PHONY += $(module-dirs) modules
471 $(module-dirs): crmodverdir $(objtree)/Module.symvers
472 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
473
474 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
475 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
476 modules: $(module-dirs)
477 @$(kecho) ' Building modules, stage 2.';
478 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
479 @@ -1387,17 +1469,21 @@ else
480 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
481 endif
482
483 -%.s: %.c prepare scripts FORCE
484 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
485 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
486 +%.s: %.c gcc-plugins prepare scripts FORCE
487 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
488 %.i: %.c prepare scripts FORCE
489 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
490 -%.o: %.c prepare scripts FORCE
491 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
492 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
493 +%.o: %.c gcc-plugins prepare scripts FORCE
494 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
495 %.lst: %.c prepare scripts FORCE
496 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
497 -%.s: %.S prepare scripts FORCE
498 +%.s: %.S gcc-plugins prepare scripts FORCE
499 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
500 -%.o: %.S prepare scripts FORCE
501 +%.o: %.S gcc-plugins prepare scripts FORCE
502 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
503 %.symtypes: %.c prepare scripts FORCE
504 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
505 @@ -1407,11 +1493,15 @@ endif
506 $(cmd_crmodverdir)
507 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
508 $(build)=$(build-dir)
509 -%/: prepare scripts FORCE
510 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
511 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
512 +%/: gcc-plugins prepare scripts FORCE
513 $(cmd_crmodverdir)
514 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
515 $(build)=$(build-dir)
516 -%.ko: prepare scripts FORCE
517 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
518 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
519 +%.ko: gcc-plugins prepare scripts FORCE
520 $(cmd_crmodverdir)
521 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
522 $(build)=$(build-dir) $(@:.ko=.o)
523 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
524 index 78b03ef..da28a51 100644
525 --- a/arch/alpha/include/asm/atomic.h
526 +++ b/arch/alpha/include/asm/atomic.h
527 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
528 #define atomic_dec(v) atomic_sub(1,(v))
529 #define atomic64_dec(v) atomic64_sub(1,(v))
530
531 +#define atomic64_read_unchecked(v) atomic64_read(v)
532 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
533 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
534 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
535 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
536 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
537 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
538 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
539 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
540 +
541 #define smp_mb__before_atomic_dec() smp_mb()
542 #define smp_mb__after_atomic_dec() smp_mb()
543 #define smp_mb__before_atomic_inc() smp_mb()
544 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
545 index ad368a9..fbe0f25 100644
546 --- a/arch/alpha/include/asm/cache.h
547 +++ b/arch/alpha/include/asm/cache.h
548 @@ -4,19 +4,19 @@
549 #ifndef __ARCH_ALPHA_CACHE_H
550 #define __ARCH_ALPHA_CACHE_H
551
552 +#include <linux/const.h>
553
554 /* Bytes per L1 (data) cache line. */
555 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
556 -# define L1_CACHE_BYTES 64
557 # define L1_CACHE_SHIFT 6
558 #else
559 /* Both EV4 and EV5 are write-through, read-allocate,
560 direct-mapped, physical.
561 */
562 -# define L1_CACHE_BYTES 32
563 # define L1_CACHE_SHIFT 5
564 #endif
565
566 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
567 #define SMP_CACHE_BYTES L1_CACHE_BYTES
568
569 #endif
570 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
571 index 968d999..d36b2df 100644
572 --- a/arch/alpha/include/asm/elf.h
573 +++ b/arch/alpha/include/asm/elf.h
574 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
575
576 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
577
578 +#ifdef CONFIG_PAX_ASLR
579 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
580 +
581 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
582 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
583 +#endif
584 +
585 /* $0 is set by ld.so to a pointer to a function which might be
586 registered using atexit. This provides a mean for the dynamic
587 linker to call DT_FINI functions for shared libraries that have
588 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
589 index aab14a0..b4fa3e7 100644
590 --- a/arch/alpha/include/asm/pgalloc.h
591 +++ b/arch/alpha/include/asm/pgalloc.h
592 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
593 pgd_set(pgd, pmd);
594 }
595
596 +static inline void
597 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
598 +{
599 + pgd_populate(mm, pgd, pmd);
600 +}
601 +
602 extern pgd_t *pgd_alloc(struct mm_struct *mm);
603
604 static inline void
605 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
606 index d8f9b7e..f6222fa 100644
607 --- a/arch/alpha/include/asm/pgtable.h
608 +++ b/arch/alpha/include/asm/pgtable.h
609 @@ -102,6 +102,17 @@ struct vm_area_struct;
610 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
611 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
612 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
613 +
614 +#ifdef CONFIG_PAX_PAGEEXEC
615 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
616 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
617 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
618 +#else
619 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
620 +# define PAGE_COPY_NOEXEC PAGE_COPY
621 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
622 +#endif
623 +
624 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
625
626 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
627 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
628 index 2fd00b7..cfd5069 100644
629 --- a/arch/alpha/kernel/module.c
630 +++ b/arch/alpha/kernel/module.c
631 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
632
633 /* The small sections were sorted to the end of the segment.
634 The following should definitely cover them. */
635 - gp = (u64)me->module_core + me->core_size - 0x8000;
636 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
637 got = sechdrs[me->arch.gotsecindex].sh_addr;
638
639 for (i = 0; i < n; i++) {
640 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
641 index 1402fcc..0b1abd2 100644
642 --- a/arch/alpha/kernel/osf_sys.c
643 +++ b/arch/alpha/kernel/osf_sys.c
644 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
645 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
646
647 static unsigned long
648 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
649 - unsigned long limit)
650 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
651 + unsigned long limit, unsigned long flags)
652 {
653 struct vm_unmapped_area_info info;
654 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
655
656 info.flags = 0;
657 info.length = len;
658 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
659 info.high_limit = limit;
660 info.align_mask = 0;
661 info.align_offset = 0;
662 + info.threadstack_offset = offset;
663 return vm_unmapped_area(&info);
664 }
665
666 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
667 merely specific addresses, but regions of memory -- perhaps
668 this feature should be incorporated into all ports? */
669
670 +#ifdef CONFIG_PAX_RANDMMAP
671 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
672 +#endif
673 +
674 if (addr) {
675 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
676 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
677 if (addr != (unsigned long) -ENOMEM)
678 return addr;
679 }
680
681 /* Next, try allocating at TASK_UNMAPPED_BASE. */
682 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
683 - len, limit);
684 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
685 +
686 if (addr != (unsigned long) -ENOMEM)
687 return addr;
688
689 /* Finally, try allocating in low memory. */
690 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
691 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
692
693 return addr;
694 }
695 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
696 index 98838a0..b304fb4 100644
697 --- a/arch/alpha/mm/fault.c
698 +++ b/arch/alpha/mm/fault.c
699 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
700 __reload_thread(pcb);
701 }
702
703 +#ifdef CONFIG_PAX_PAGEEXEC
704 +/*
705 + * PaX: decide what to do with offenders (regs->pc = fault address)
706 + *
707 + * returns 1 when task should be killed
708 + * 2 when patched PLT trampoline was detected
709 + * 3 when unpatched PLT trampoline was detected
710 + */
711 +static int pax_handle_fetch_fault(struct pt_regs *regs)
712 +{
713 +
714 +#ifdef CONFIG_PAX_EMUPLT
715 + int err;
716 +
717 + do { /* PaX: patched PLT emulation #1 */
718 + unsigned int ldah, ldq, jmp;
719 +
720 + err = get_user(ldah, (unsigned int *)regs->pc);
721 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
722 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
723 +
724 + if (err)
725 + break;
726 +
727 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
728 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
729 + jmp == 0x6BFB0000U)
730 + {
731 + unsigned long r27, addr;
732 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
733 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
734 +
735 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
736 + err = get_user(r27, (unsigned long *)addr);
737 + if (err)
738 + break;
739 +
740 + regs->r27 = r27;
741 + regs->pc = r27;
742 + return 2;
743 + }
744 + } while (0);
745 +
746 + do { /* PaX: patched PLT emulation #2 */
747 + unsigned int ldah, lda, br;
748 +
749 + err = get_user(ldah, (unsigned int *)regs->pc);
750 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
751 + err |= get_user(br, (unsigned int *)(regs->pc+8));
752 +
753 + if (err)
754 + break;
755 +
756 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
757 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
758 + (br & 0xFFE00000U) == 0xC3E00000U)
759 + {
760 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
761 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
762 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
763 +
764 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
765 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
766 + return 2;
767 + }
768 + } while (0);
769 +
770 + do { /* PaX: unpatched PLT emulation */
771 + unsigned int br;
772 +
773 + err = get_user(br, (unsigned int *)regs->pc);
774 +
775 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
776 + unsigned int br2, ldq, nop, jmp;
777 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
778 +
779 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
780 + err = get_user(br2, (unsigned int *)addr);
781 + err |= get_user(ldq, (unsigned int *)(addr+4));
782 + err |= get_user(nop, (unsigned int *)(addr+8));
783 + err |= get_user(jmp, (unsigned int *)(addr+12));
784 + err |= get_user(resolver, (unsigned long *)(addr+16));
785 +
786 + if (err)
787 + break;
788 +
789 + if (br2 == 0xC3600000U &&
790 + ldq == 0xA77B000CU &&
791 + nop == 0x47FF041FU &&
792 + jmp == 0x6B7B0000U)
793 + {
794 + regs->r28 = regs->pc+4;
795 + regs->r27 = addr+16;
796 + regs->pc = resolver;
797 + return 3;
798 + }
799 + }
800 + } while (0);
801 +#endif
802 +
803 + return 1;
804 +}
805 +
806 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
807 +{
808 + unsigned long i;
809 +
810 + printk(KERN_ERR "PAX: bytes at PC: ");
811 + for (i = 0; i < 5; i++) {
812 + unsigned int c;
813 + if (get_user(c, (unsigned int *)pc+i))
814 + printk(KERN_CONT "???????? ");
815 + else
816 + printk(KERN_CONT "%08x ", c);
817 + }
818 + printk("\n");
819 +}
820 +#endif
821
822 /*
823 * This routine handles page faults. It determines the address,
824 @@ -133,8 +251,29 @@ retry:
825 good_area:
826 si_code = SEGV_ACCERR;
827 if (cause < 0) {
828 - if (!(vma->vm_flags & VM_EXEC))
829 + if (!(vma->vm_flags & VM_EXEC)) {
830 +
831 +#ifdef CONFIG_PAX_PAGEEXEC
832 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
833 + goto bad_area;
834 +
835 + up_read(&mm->mmap_sem);
836 + switch (pax_handle_fetch_fault(regs)) {
837 +
838 +#ifdef CONFIG_PAX_EMUPLT
839 + case 2:
840 + case 3:
841 + return;
842 +#endif
843 +
844 + }
845 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
846 + do_group_exit(SIGKILL);
847 +#else
848 goto bad_area;
849 +#endif
850 +
851 + }
852 } else if (!cause) {
853 /* Allow reads even for write-only mappings */
854 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
855 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
856 index c1f1a7e..554b0cd 100644
857 --- a/arch/arm/Kconfig
858 +++ b/arch/arm/Kconfig
859 @@ -1828,7 +1828,7 @@ config ALIGNMENT_TRAP
860
861 config UACCESS_WITH_MEMCPY
862 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
863 - depends on MMU
864 + depends on MMU && !PAX_MEMORY_UDEREF
865 default y if CPU_FEROCEON
866 help
867 Implement faster copy_to_user and clear_user methods for CPU
868 @@ -2100,6 +2100,7 @@ config XIP_PHYS_ADDR
869 config KEXEC
870 bool "Kexec system call (EXPERIMENTAL)"
871 depends on (!SMP || PM_SLEEP_SMP)
872 + depends on !GRKERNSEC_KMEM
873 help
874 kexec is a system call that implements the ability to shutdown your
875 current kernel, and to start another kernel. It is like a reboot
876 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
877 index 62d2cb5..7a13651 100644
878 --- a/arch/arm/include/asm/atomic.h
879 +++ b/arch/arm/include/asm/atomic.h
880 @@ -18,17 +18,35 @@
881 #include <asm/barrier.h>
882 #include <asm/cmpxchg.h>
883
884 +#ifdef CONFIG_GENERIC_ATOMIC64
885 +#include <asm-generic/atomic64.h>
886 +#endif
887 +
888 #define ATOMIC_INIT(i) { (i) }
889
890 #ifdef __KERNEL__
891
892 +#define _ASM_EXTABLE(from, to) \
893 +" .pushsection __ex_table,\"a\"\n"\
894 +" .align 3\n" \
895 +" .long " #from ", " #to"\n" \
896 +" .popsection"
897 +
898 /*
899 * On ARM, ordinary assignment (str instruction) doesn't clear the local
900 * strex/ldrex monitor on some implementations. The reason we can use it for
901 * atomic_set() is the clrex or dummy strex done on every exception return.
902 */
903 #define atomic_read(v) (*(volatile int *)&(v)->counter)
904 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
905 +{
906 + return v->counter;
907 +}
908 #define atomic_set(v,i) (((v)->counter) = (i))
909 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
910 +{
911 + v->counter = i;
912 +}
913
914 #if __LINUX_ARM_ARCH__ >= 6
915
916 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
917
918 prefetchw(&v->counter);
919 __asm__ __volatile__("@ atomic_add\n"
920 +"1: ldrex %1, [%3]\n"
921 +" adds %0, %1, %4\n"
922 +
923 +#ifdef CONFIG_PAX_REFCOUNT
924 +" bvc 3f\n"
925 +"2: bkpt 0xf103\n"
926 +"3:\n"
927 +#endif
928 +
929 +" strex %1, %0, [%3]\n"
930 +" teq %1, #0\n"
931 +" bne 1b"
932 +
933 +#ifdef CONFIG_PAX_REFCOUNT
934 +"\n4:\n"
935 + _ASM_EXTABLE(2b, 4b)
936 +#endif
937 +
938 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
939 + : "r" (&v->counter), "Ir" (i)
940 + : "cc");
941 +}
942 +
943 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
944 +{
945 + unsigned long tmp;
946 + int result;
947 +
948 + prefetchw(&v->counter);
949 + __asm__ __volatile__("@ atomic_add_unchecked\n"
950 "1: ldrex %0, [%3]\n"
951 " add %0, %0, %4\n"
952 " strex %1, %0, [%3]\n"
953 @@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
954 smp_mb();
955
956 __asm__ __volatile__("@ atomic_add_return\n"
957 +"1: ldrex %1, [%3]\n"
958 +" adds %0, %1, %4\n"
959 +
960 +#ifdef CONFIG_PAX_REFCOUNT
961 +" bvc 3f\n"
962 +" mov %0, %1\n"
963 +"2: bkpt 0xf103\n"
964 +"3:\n"
965 +#endif
966 +
967 +" strex %1, %0, [%3]\n"
968 +" teq %1, #0\n"
969 +" bne 1b"
970 +
971 +#ifdef CONFIG_PAX_REFCOUNT
972 +"\n4:\n"
973 + _ASM_EXTABLE(2b, 4b)
974 +#endif
975 +
976 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
977 + : "r" (&v->counter), "Ir" (i)
978 + : "cc");
979 +
980 + smp_mb();
981 +
982 + return result;
983 +}
984 +
985 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
986 +{
987 + unsigned long tmp;
988 + int result;
989 +
990 + smp_mb();
991 +
992 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
993 "1: ldrex %0, [%3]\n"
994 " add %0, %0, %4\n"
995 " strex %1, %0, [%3]\n"
996 @@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
997
998 prefetchw(&v->counter);
999 __asm__ __volatile__("@ atomic_sub\n"
1000 +"1: ldrex %1, [%3]\n"
1001 +" subs %0, %1, %4\n"
1002 +
1003 +#ifdef CONFIG_PAX_REFCOUNT
1004 +" bvc 3f\n"
1005 +"2: bkpt 0xf103\n"
1006 +"3:\n"
1007 +#endif
1008 +
1009 +" strex %1, %0, [%3]\n"
1010 +" teq %1, #0\n"
1011 +" bne 1b"
1012 +
1013 +#ifdef CONFIG_PAX_REFCOUNT
1014 +"\n4:\n"
1015 + _ASM_EXTABLE(2b, 4b)
1016 +#endif
1017 +
1018 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1019 + : "r" (&v->counter), "Ir" (i)
1020 + : "cc");
1021 +}
1022 +
1023 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1024 +{
1025 + unsigned long tmp;
1026 + int result;
1027 +
1028 + prefetchw(&v->counter);
1029 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1030 "1: ldrex %0, [%3]\n"
1031 " sub %0, %0, %4\n"
1032 " strex %1, %0, [%3]\n"
1033 @@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1034 smp_mb();
1035
1036 __asm__ __volatile__("@ atomic_sub_return\n"
1037 -"1: ldrex %0, [%3]\n"
1038 -" sub %0, %0, %4\n"
1039 +"1: ldrex %1, [%3]\n"
1040 +" subs %0, %1, %4\n"
1041 +
1042 +#ifdef CONFIG_PAX_REFCOUNT
1043 +" bvc 3f\n"
1044 +" mov %0, %1\n"
1045 +"2: bkpt 0xf103\n"
1046 +"3:\n"
1047 +#endif
1048 +
1049 " strex %1, %0, [%3]\n"
1050 " teq %1, #0\n"
1051 " bne 1b"
1052 +
1053 +#ifdef CONFIG_PAX_REFCOUNT
1054 +"\n4:\n"
1055 + _ASM_EXTABLE(2b, 4b)
1056 +#endif
1057 +
1058 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1059 : "r" (&v->counter), "Ir" (i)
1060 : "cc");
1061 @@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1062 return oldval;
1063 }
1064
1065 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1066 +{
1067 + unsigned long oldval, res;
1068 +
1069 + smp_mb();
1070 +
1071 + do {
1072 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1073 + "ldrex %1, [%3]\n"
1074 + "mov %0, #0\n"
1075 + "teq %1, %4\n"
1076 + "strexeq %0, %5, [%3]\n"
1077 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1078 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1079 + : "cc");
1080 + } while (res);
1081 +
1082 + smp_mb();
1083 +
1084 + return oldval;
1085 +}
1086 +
1087 #else /* ARM_ARCH_6 */
1088
1089 #ifdef CONFIG_SMP
1090 @@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1091
1092 return val;
1093 }
1094 +
1095 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1096 +{
1097 + return atomic_add_return(i, v);
1098 +}
1099 +
1100 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1101 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1102 +{
1103 + (void) atomic_add_return(i, v);
1104 +}
1105
1106 static inline int atomic_sub_return(int i, atomic_t *v)
1107 {
1108 @@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1109 return val;
1110 }
1111 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1112 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1113 +{
1114 + (void) atomic_sub_return(i, v);
1115 +}
1116
1117 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1118 {
1119 @@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1120 return ret;
1121 }
1122
1123 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1124 +{
1125 + return atomic_cmpxchg(v, old, new);
1126 +}
1127 +
1128 #endif /* __LINUX_ARM_ARCH__ */
1129
1130 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1131 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1132 +{
1133 + return xchg(&v->counter, new);
1134 +}
1135
1136 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1137 {
1138 @@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1139 }
1140
1141 #define atomic_inc(v) atomic_add(1, v)
1142 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1143 +{
1144 + atomic_add_unchecked(1, v);
1145 +}
1146 #define atomic_dec(v) atomic_sub(1, v)
1147 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1148 +{
1149 + atomic_sub_unchecked(1, v);
1150 +}
1151
1152 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1153 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1154 +{
1155 + return atomic_add_return_unchecked(1, v) == 0;
1156 +}
1157 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1158 #define atomic_inc_return(v) (atomic_add_return(1, v))
1159 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1160 +{
1161 + return atomic_add_return_unchecked(1, v);
1162 +}
1163 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1164 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1165
1166 @@ -221,6 +410,14 @@ typedef struct {
1167 long long counter;
1168 } atomic64_t;
1169
1170 +#ifdef CONFIG_PAX_REFCOUNT
1171 +typedef struct {
1172 + long long counter;
1173 +} atomic64_unchecked_t;
1174 +#else
1175 +typedef atomic64_t atomic64_unchecked_t;
1176 +#endif
1177 +
1178 #define ATOMIC64_INIT(i) { (i) }
1179
1180 #ifdef CONFIG_ARM_LPAE
1181 @@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1182 return result;
1183 }
1184
1185 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1186 +{
1187 + long long result;
1188 +
1189 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1190 +" ldrd %0, %H0, [%1]"
1191 + : "=&r" (result)
1192 + : "r" (&v->counter), "Qo" (v->counter)
1193 + );
1194 +
1195 + return result;
1196 +}
1197 +
1198 static inline void atomic64_set(atomic64_t *v, long long i)
1199 {
1200 __asm__ __volatile__("@ atomic64_set\n"
1201 @@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1202 : "r" (&v->counter), "r" (i)
1203 );
1204 }
1205 +
1206 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1207 +{
1208 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1209 +" strd %2, %H2, [%1]"
1210 + : "=Qo" (v->counter)
1211 + : "r" (&v->counter), "r" (i)
1212 + );
1213 +}
1214 #else
1215 static inline long long atomic64_read(const atomic64_t *v)
1216 {
1217 @@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1218 return result;
1219 }
1220
1221 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1222 +{
1223 + long long result;
1224 +
1225 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1226 +" ldrexd %0, %H0, [%1]"
1227 + : "=&r" (result)
1228 + : "r" (&v->counter), "Qo" (v->counter)
1229 + );
1230 +
1231 + return result;
1232 +}
1233 +
1234 static inline void atomic64_set(atomic64_t *v, long long i)
1235 {
1236 long long tmp;
1237 @@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1238 : "r" (&v->counter), "r" (i)
1239 : "cc");
1240 }
1241 +
1242 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1243 +{
1244 + long long tmp;
1245 +
1246 + prefetchw(&v->counter);
1247 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1248 +"1: ldrexd %0, %H0, [%2]\n"
1249 +" strexd %0, %3, %H3, [%2]\n"
1250 +" teq %0, #0\n"
1251 +" bne 1b"
1252 + : "=&r" (tmp), "=Qo" (v->counter)
1253 + : "r" (&v->counter), "r" (i)
1254 + : "cc");
1255 +}
1256 #endif
1257
1258 static inline void atomic64_add(long long i, atomic64_t *v)
1259 @@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1260 __asm__ __volatile__("@ atomic64_add\n"
1261 "1: ldrexd %0, %H0, [%3]\n"
1262 " adds %Q0, %Q0, %Q4\n"
1263 +" adcs %R0, %R0, %R4\n"
1264 +
1265 +#ifdef CONFIG_PAX_REFCOUNT
1266 +" bvc 3f\n"
1267 +"2: bkpt 0xf103\n"
1268 +"3:\n"
1269 +#endif
1270 +
1271 +" strexd %1, %0, %H0, [%3]\n"
1272 +" teq %1, #0\n"
1273 +" bne 1b"
1274 +
1275 +#ifdef CONFIG_PAX_REFCOUNT
1276 +"\n4:\n"
1277 + _ASM_EXTABLE(2b, 4b)
1278 +#endif
1279 +
1280 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1281 + : "r" (&v->counter), "r" (i)
1282 + : "cc");
1283 +}
1284 +
1285 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1286 +{
1287 + long long result;
1288 + unsigned long tmp;
1289 +
1290 + prefetchw(&v->counter);
1291 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1292 +"1: ldrexd %0, %H0, [%3]\n"
1293 +" adds %Q0, %Q0, %Q4\n"
1294 " adc %R0, %R0, %R4\n"
1295 " strexd %1, %0, %H0, [%3]\n"
1296 " teq %1, #0\n"
1297 @@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1298 __asm__ __volatile__("@ atomic64_add_return\n"
1299 "1: ldrexd %0, %H0, [%3]\n"
1300 " adds %Q0, %Q0, %Q4\n"
1301 +" adcs %R0, %R0, %R4\n"
1302 +
1303 +#ifdef CONFIG_PAX_REFCOUNT
1304 +" bvc 3f\n"
1305 +" mov %0, %1\n"
1306 +" mov %H0, %H1\n"
1307 +"2: bkpt 0xf103\n"
1308 +"3:\n"
1309 +#endif
1310 +
1311 +" strexd %1, %0, %H0, [%3]\n"
1312 +" teq %1, #0\n"
1313 +" bne 1b"
1314 +
1315 +#ifdef CONFIG_PAX_REFCOUNT
1316 +"\n4:\n"
1317 + _ASM_EXTABLE(2b, 4b)
1318 +#endif
1319 +
1320 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1321 + : "r" (&v->counter), "r" (i)
1322 + : "cc");
1323 +
1324 + smp_mb();
1325 +
1326 + return result;
1327 +}
1328 +
1329 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1330 +{
1331 + long long result;
1332 + unsigned long tmp;
1333 +
1334 + smp_mb();
1335 +
1336 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1337 +"1: ldrexd %0, %H0, [%3]\n"
1338 +" adds %Q0, %Q0, %Q4\n"
1339 " adc %R0, %R0, %R4\n"
1340 " strexd %1, %0, %H0, [%3]\n"
1341 " teq %1, #0\n"
1342 @@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1343 __asm__ __volatile__("@ atomic64_sub\n"
1344 "1: ldrexd %0, %H0, [%3]\n"
1345 " subs %Q0, %Q0, %Q4\n"
1346 +" sbcs %R0, %R0, %R4\n"
1347 +
1348 +#ifdef CONFIG_PAX_REFCOUNT
1349 +" bvc 3f\n"
1350 +"2: bkpt 0xf103\n"
1351 +"3:\n"
1352 +#endif
1353 +
1354 +" strexd %1, %0, %H0, [%3]\n"
1355 +" teq %1, #0\n"
1356 +" bne 1b"
1357 +
1358 +#ifdef CONFIG_PAX_REFCOUNT
1359 +"\n4:\n"
1360 + _ASM_EXTABLE(2b, 4b)
1361 +#endif
1362 +
1363 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1364 + : "r" (&v->counter), "r" (i)
1365 + : "cc");
1366 +}
1367 +
1368 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1369 +{
1370 + long long result;
1371 + unsigned long tmp;
1372 +
1373 + prefetchw(&v->counter);
1374 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1375 +"1: ldrexd %0, %H0, [%3]\n"
1376 +" subs %Q0, %Q0, %Q4\n"
1377 " sbc %R0, %R0, %R4\n"
1378 " strexd %1, %0, %H0, [%3]\n"
1379 " teq %1, #0\n"
1380 @@ -344,17 +691,28 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1381 __asm__ __volatile__("@ atomic64_sub_return\n"
1382 "1: ldrexd %0, %H0, [%3]\n"
1383 " subs %Q0, %Q0, %Q4\n"
1384 -" sbc %R0, %R0, %R4\n"
1385 +" sbcs %R0, %R0, %R4\n"
1386 +
1387 +#ifdef CONFIG_PAX_REFCOUNT
1388 +" bvc 3f\n"
1389 +" mov %0, %1\n"
1390 +" mov %H0, %H1\n"
1391 +"2: bkpt 0xf103\n"
1392 +"3:\n"
1393 +#endif
1394 +
1395 " strexd %1, %0, %H0, [%3]\n"
1396 " teq %1, #0\n"
1397 " bne 1b"
1398 +
1399 +#ifdef CONFIG_PAX_REFCOUNT
1400 +"\n4:\n"
1401 + _ASM_EXTABLE(2b, 4b)
1402 +#endif
1403 +
1404 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1405 : "r" (&v->counter), "r" (i)
1406 : "cc");
1407 -
1408 - smp_mb();
1409 -
1410 - return result;
1411 }
1412
1413 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1414 @@ -382,6 +740,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1415 return oldval;
1416 }
1417
1418 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1419 + long long new)
1420 +{
1421 + long long oldval;
1422 + unsigned long res;
1423 +
1424 + smp_mb();
1425 +
1426 + do {
1427 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1428 + "ldrexd %1, %H1, [%3]\n"
1429 + "mov %0, #0\n"
1430 + "teq %1, %4\n"
1431 + "teqeq %H1, %H4\n"
1432 + "strexdeq %0, %5, %H5, [%3]"
1433 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1434 + : "r" (&ptr->counter), "r" (old), "r" (new)
1435 + : "cc");
1436 + } while (res);
1437 +
1438 + smp_mb();
1439 +
1440 + return oldval;
1441 +}
1442 +
1443 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1444 {
1445 long long result;
1446 @@ -406,20 +789,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1447 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1448 {
1449 long long result;
1450 - unsigned long tmp;
1451 + u64 tmp;
1452
1453 smp_mb();
1454
1455 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1456 -"1: ldrexd %0, %H0, [%3]\n"
1457 -" subs %Q0, %Q0, #1\n"
1458 -" sbc %R0, %R0, #0\n"
1459 +"1: ldrexd %1, %H1, [%3]\n"
1460 +" subs %Q0, %Q1, #1\n"
1461 +" sbcs %R0, %R1, #0\n"
1462 +
1463 +#ifdef CONFIG_PAX_REFCOUNT
1464 +" bvc 3f\n"
1465 +" mov %Q0, %Q1\n"
1466 +" mov %R0, %R1\n"
1467 +"2: bkpt 0xf103\n"
1468 +"3:\n"
1469 +#endif
1470 +
1471 " teq %R0, #0\n"
1472 -" bmi 2f\n"
1473 +" bmi 4f\n"
1474 " strexd %1, %0, %H0, [%3]\n"
1475 " teq %1, #0\n"
1476 " bne 1b\n"
1477 -"2:"
1478 +"4:\n"
1479 +
1480 +#ifdef CONFIG_PAX_REFCOUNT
1481 + _ASM_EXTABLE(2b, 4b)
1482 +#endif
1483 +
1484 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1485 : "r" (&v->counter)
1486 : "cc");
1487 @@ -442,13 +839,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1488 " teq %0, %5\n"
1489 " teqeq %H0, %H5\n"
1490 " moveq %1, #0\n"
1491 -" beq 2f\n"
1492 +" beq 4f\n"
1493 " adds %Q0, %Q0, %Q6\n"
1494 -" adc %R0, %R0, %R6\n"
1495 +" adcs %R0, %R0, %R6\n"
1496 +
1497 +#ifdef CONFIG_PAX_REFCOUNT
1498 +" bvc 3f\n"
1499 +"2: bkpt 0xf103\n"
1500 +"3:\n"
1501 +#endif
1502 +
1503 " strexd %2, %0, %H0, [%4]\n"
1504 " teq %2, #0\n"
1505 " bne 1b\n"
1506 -"2:"
1507 +"4:\n"
1508 +
1509 +#ifdef CONFIG_PAX_REFCOUNT
1510 + _ASM_EXTABLE(2b, 4b)
1511 +#endif
1512 +
1513 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1514 : "r" (&v->counter), "r" (u), "r" (a)
1515 : "cc");
1516 @@ -461,10 +870,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1517
1518 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1519 #define atomic64_inc(v) atomic64_add(1LL, (v))
1520 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1521 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1522 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1523 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1524 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1525 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1526 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1527 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1528 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1529 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1530 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1531 index 75fe66b..ba3dee4 100644
1532 --- a/arch/arm/include/asm/cache.h
1533 +++ b/arch/arm/include/asm/cache.h
1534 @@ -4,8 +4,10 @@
1535 #ifndef __ASMARM_CACHE_H
1536 #define __ASMARM_CACHE_H
1537
1538 +#include <linux/const.h>
1539 +
1540 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1541 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1542 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1543
1544 /*
1545 * Memory returned by kmalloc() may be used for DMA, so we must make
1546 @@ -24,5 +26,6 @@
1547 #endif
1548
1549 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1550 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1551
1552 #endif
1553 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1554 index ee753f1..c9c30a5 100644
1555 --- a/arch/arm/include/asm/cacheflush.h
1556 +++ b/arch/arm/include/asm/cacheflush.h
1557 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1558 void (*dma_unmap_area)(const void *, size_t, int);
1559
1560 void (*dma_flush_range)(const void *, const void *);
1561 -};
1562 +} __no_const;
1563
1564 /*
1565 * Select the calling method
1566 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1567 index 6dcc164..b14d917 100644
1568 --- a/arch/arm/include/asm/checksum.h
1569 +++ b/arch/arm/include/asm/checksum.h
1570 @@ -37,7 +37,19 @@ __wsum
1571 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1572
1573 __wsum
1574 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1575 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1576 +
1577 +static inline __wsum
1578 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1579 +{
1580 + __wsum ret;
1581 + pax_open_userland();
1582 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1583 + pax_close_userland();
1584 + return ret;
1585 +}
1586 +
1587 +
1588
1589 /*
1590 * Fold a partial checksum without adding pseudo headers
1591 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1592 index df2fbba..63fe3e1 100644
1593 --- a/arch/arm/include/asm/cmpxchg.h
1594 +++ b/arch/arm/include/asm/cmpxchg.h
1595 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1596
1597 #define xchg(ptr,x) \
1598 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1599 +#define xchg_unchecked(ptr,x) \
1600 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1601
1602 #include <asm-generic/cmpxchg-local.h>
1603
1604 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1605 index 6ddbe44..b5e38b1 100644
1606 --- a/arch/arm/include/asm/domain.h
1607 +++ b/arch/arm/include/asm/domain.h
1608 @@ -48,18 +48,37 @@
1609 * Domain types
1610 */
1611 #define DOMAIN_NOACCESS 0
1612 -#define DOMAIN_CLIENT 1
1613 #ifdef CONFIG_CPU_USE_DOMAINS
1614 +#define DOMAIN_USERCLIENT 1
1615 +#define DOMAIN_KERNELCLIENT 1
1616 #define DOMAIN_MANAGER 3
1617 +#define DOMAIN_VECTORS DOMAIN_USER
1618 #else
1619 +
1620 +#ifdef CONFIG_PAX_KERNEXEC
1621 #define DOMAIN_MANAGER 1
1622 +#define DOMAIN_KERNEXEC 3
1623 +#else
1624 +#define DOMAIN_MANAGER 1
1625 +#endif
1626 +
1627 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1628 +#define DOMAIN_USERCLIENT 0
1629 +#define DOMAIN_UDEREF 1
1630 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1631 +#else
1632 +#define DOMAIN_USERCLIENT 1
1633 +#define DOMAIN_VECTORS DOMAIN_USER
1634 +#endif
1635 +#define DOMAIN_KERNELCLIENT 1
1636 +
1637 #endif
1638
1639 #define domain_val(dom,type) ((type) << (2*(dom)))
1640
1641 #ifndef __ASSEMBLY__
1642
1643 -#ifdef CONFIG_CPU_USE_DOMAINS
1644 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1645 static inline void set_domain(unsigned val)
1646 {
1647 asm volatile(
1648 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1649 isb();
1650 }
1651
1652 -#define modify_domain(dom,type) \
1653 - do { \
1654 - struct thread_info *thread = current_thread_info(); \
1655 - unsigned int domain = thread->cpu_domain; \
1656 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1657 - thread->cpu_domain = domain | domain_val(dom, type); \
1658 - set_domain(thread->cpu_domain); \
1659 - } while (0)
1660 -
1661 +extern void modify_domain(unsigned int dom, unsigned int type);
1662 #else
1663 static inline void set_domain(unsigned val) { }
1664 static inline void modify_domain(unsigned dom, unsigned type) { }
1665 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1666 index f4b46d3..abc9b2b 100644
1667 --- a/arch/arm/include/asm/elf.h
1668 +++ b/arch/arm/include/asm/elf.h
1669 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1670 the loader. We need to make sure that it is out of the way of the program
1671 that it will "exec", and that there is sufficient room for the brk. */
1672
1673 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1674 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1675 +
1676 +#ifdef CONFIG_PAX_ASLR
1677 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1678 +
1679 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1680 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1681 +#endif
1682
1683 /* When the program starts, a1 contains a pointer to a function to be
1684 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1685 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1686 extern void elf_set_personality(const struct elf32_hdr *);
1687 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1688
1689 -struct mm_struct;
1690 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1691 -#define arch_randomize_brk arch_randomize_brk
1692 -
1693 #ifdef CONFIG_MMU
1694 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1695 struct linux_binprm;
1696 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1697 index de53547..52b9a28 100644
1698 --- a/arch/arm/include/asm/fncpy.h
1699 +++ b/arch/arm/include/asm/fncpy.h
1700 @@ -81,7 +81,9 @@
1701 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1702 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1703 \
1704 + pax_open_kernel(); \
1705 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1706 + pax_close_kernel(); \
1707 flush_icache_range((unsigned long)(dest_buf), \
1708 (unsigned long)(dest_buf) + (size)); \
1709 \
1710 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1711 index e42cf59..7b94b8f 100644
1712 --- a/arch/arm/include/asm/futex.h
1713 +++ b/arch/arm/include/asm/futex.h
1714 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1715 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1716 return -EFAULT;
1717
1718 + pax_open_userland();
1719 +
1720 smp_mb();
1721 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1722 "1: ldrex %1, [%4]\n"
1723 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1724 : "cc", "memory");
1725 smp_mb();
1726
1727 + pax_close_userland();
1728 +
1729 *uval = val;
1730 return ret;
1731 }
1732 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1733 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1734 return -EFAULT;
1735
1736 + pax_open_userland();
1737 +
1738 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1739 "1: " TUSER(ldr) " %1, [%4]\n"
1740 " teq %1, %2\n"
1741 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1742 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1743 : "cc", "memory");
1744
1745 + pax_close_userland();
1746 +
1747 *uval = val;
1748 return ret;
1749 }
1750 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1751 return -EFAULT;
1752
1753 pagefault_disable(); /* implies preempt_disable() */
1754 + pax_open_userland();
1755
1756 switch (op) {
1757 case FUTEX_OP_SET:
1758 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1759 ret = -ENOSYS;
1760 }
1761
1762 + pax_close_userland();
1763 pagefault_enable(); /* subsumes preempt_enable() */
1764
1765 if (!ret) {
1766 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1767 index 83eb2f7..ed77159 100644
1768 --- a/arch/arm/include/asm/kmap_types.h
1769 +++ b/arch/arm/include/asm/kmap_types.h
1770 @@ -4,6 +4,6 @@
1771 /*
1772 * This is the "bare minimum". AIO seems to require this.
1773 */
1774 -#define KM_TYPE_NR 16
1775 +#define KM_TYPE_NR 17
1776
1777 #endif
1778 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1779 index 9e614a1..3302cca 100644
1780 --- a/arch/arm/include/asm/mach/dma.h
1781 +++ b/arch/arm/include/asm/mach/dma.h
1782 @@ -22,7 +22,7 @@ struct dma_ops {
1783 int (*residue)(unsigned int, dma_t *); /* optional */
1784 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1785 const char *type;
1786 -};
1787 +} __do_const;
1788
1789 struct dma_struct {
1790 void *addr; /* single DMA address */
1791 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1792 index 2fe141f..192dc01 100644
1793 --- a/arch/arm/include/asm/mach/map.h
1794 +++ b/arch/arm/include/asm/mach/map.h
1795 @@ -27,13 +27,16 @@ struct map_desc {
1796 #define MT_MINICLEAN 6
1797 #define MT_LOW_VECTORS 7
1798 #define MT_HIGH_VECTORS 8
1799 -#define MT_MEMORY 9
1800 +#define MT_MEMORY_RWX 9
1801 #define MT_ROM 10
1802 -#define MT_MEMORY_NONCACHED 11
1803 +#define MT_MEMORY_NONCACHED_RX 11
1804 #define MT_MEMORY_DTCM 12
1805 #define MT_MEMORY_ITCM 13
1806 #define MT_MEMORY_SO 14
1807 #define MT_MEMORY_DMA_READY 15
1808 +#define MT_MEMORY_RW 16
1809 +#define MT_MEMORY_RX 17
1810 +#define MT_MEMORY_NONCACHED_RW 18
1811
1812 #ifdef CONFIG_MMU
1813 extern void iotable_init(struct map_desc *, int);
1814 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1815 index f94784f..9a09a4a 100644
1816 --- a/arch/arm/include/asm/outercache.h
1817 +++ b/arch/arm/include/asm/outercache.h
1818 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1819 #endif
1820 void (*set_debug)(unsigned long);
1821 void (*resume)(void);
1822 -};
1823 +} __no_const;
1824
1825 extern struct outer_cache_fns outer_cache;
1826
1827 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1828 index 4355f0e..c229913 100644
1829 --- a/arch/arm/include/asm/page.h
1830 +++ b/arch/arm/include/asm/page.h
1831 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1832 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1833 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1834 unsigned long vaddr, struct vm_area_struct *vma);
1835 -};
1836 +} __no_const;
1837
1838 #ifdef MULTI_USER
1839 extern struct cpu_user_fns cpu_user;
1840 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1841 index 78a7793..e3dc06c 100644
1842 --- a/arch/arm/include/asm/pgalloc.h
1843 +++ b/arch/arm/include/asm/pgalloc.h
1844 @@ -17,6 +17,7 @@
1845 #include <asm/processor.h>
1846 #include <asm/cacheflush.h>
1847 #include <asm/tlbflush.h>
1848 +#include <asm/system_info.h>
1849
1850 #define check_pgt_cache() do { } while (0)
1851
1852 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1853 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1854 }
1855
1856 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1857 +{
1858 + pud_populate(mm, pud, pmd);
1859 +}
1860 +
1861 #else /* !CONFIG_ARM_LPAE */
1862
1863 /*
1864 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1865 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1866 #define pmd_free(mm, pmd) do { } while (0)
1867 #define pud_populate(mm,pmd,pte) BUG()
1868 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1869
1870 #endif /* CONFIG_ARM_LPAE */
1871
1872 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1873 __free_page(pte);
1874 }
1875
1876 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1877 +{
1878 +#ifdef CONFIG_ARM_LPAE
1879 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1880 +#else
1881 + if (addr & SECTION_SIZE)
1882 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1883 + else
1884 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1885 +#endif
1886 + flush_pmd_entry(pmdp);
1887 +}
1888 +
1889 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1890 pmdval_t prot)
1891 {
1892 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1893 static inline void
1894 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1895 {
1896 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1897 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1898 }
1899 #define pmd_pgtable(pmd) pmd_page(pmd)
1900
1901 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1902 index 5cfba15..f415e1a 100644
1903 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1904 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1905 @@ -20,12 +20,15 @@
1906 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1907 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1908 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1909 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1910 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1911 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1912 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1913 +
1914 /*
1915 * - section
1916 */
1917 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1918 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1919 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1920 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1921 @@ -37,6 +40,7 @@
1922 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1923 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1924 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1925 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1926
1927 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1928 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1929 @@ -66,6 +70,7 @@
1930 * - extended small page/tiny page
1931 */
1932 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1933 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1934 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1935 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1936 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1937 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1938 index 86a659a..70e0120 100644
1939 --- a/arch/arm/include/asm/pgtable-2level.h
1940 +++ b/arch/arm/include/asm/pgtable-2level.h
1941 @@ -126,6 +126,9 @@
1942 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1943 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1944
1945 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1946 +#define L_PTE_PXN (_AT(pteval_t, 0))
1947 +
1948 /*
1949 * These are the memory types, defined to be compatible with
1950 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1951 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1952 index 626989f..9d67a33 100644
1953 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1954 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1955 @@ -75,6 +75,7 @@
1956 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1957 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1958 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1959 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1961
1962 /*
1963 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1964 index 4f95039..b2dd513 100644
1965 --- a/arch/arm/include/asm/pgtable-3level.h
1966 +++ b/arch/arm/include/asm/pgtable-3level.h
1967 @@ -82,6 +82,7 @@
1968 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1969 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1970 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1971 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1972 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1973 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1974 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1975 @@ -95,6 +96,7 @@
1976 /*
1977 * To be used in assembly code with the upper page attributes.
1978 */
1979 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1980 #define L_PTE_XN_HIGH (1 << (54 - 32))
1981 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1982
1983 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1984 index 1571d12..b8a9b43 100644
1985 --- a/arch/arm/include/asm/pgtable.h
1986 +++ b/arch/arm/include/asm/pgtable.h
1987 @@ -33,6 +33,9 @@
1988 #include <asm/pgtable-2level.h>
1989 #endif
1990
1991 +#define ktla_ktva(addr) (addr)
1992 +#define ktva_ktla(addr) (addr)
1993 +
1994 /*
1995 * Just any arbitrary offset to the start of the vmalloc VM area: the
1996 * current 8MB value just means that there will be a 8MB "hole" after the
1997 @@ -48,6 +51,9 @@
1998 #define LIBRARY_TEXT_START 0x0c000000
1999
2000 #ifndef __ASSEMBLY__
2001 +extern pteval_t __supported_pte_mask;
2002 +extern pmdval_t __supported_pmd_mask;
2003 +
2004 extern void __pte_error(const char *file, int line, pte_t);
2005 extern void __pmd_error(const char *file, int line, pmd_t);
2006 extern void __pgd_error(const char *file, int line, pgd_t);
2007 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2008 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2009 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2010
2011 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2012 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2013 +
2014 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2015 +#include <asm/domain.h>
2016 +#include <linux/thread_info.h>
2017 +#include <linux/preempt.h>
2018 +
2019 +static inline int test_domain(int domain, int domaintype)
2020 +{
2021 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2022 +}
2023 +#endif
2024 +
2025 +#ifdef CONFIG_PAX_KERNEXEC
2026 +static inline unsigned long pax_open_kernel(void) {
2027 +#ifdef CONFIG_ARM_LPAE
2028 + /* TODO */
2029 +#else
2030 + preempt_disable();
2031 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2032 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2033 +#endif
2034 + return 0;
2035 +}
2036 +
2037 +static inline unsigned long pax_close_kernel(void) {
2038 +#ifdef CONFIG_ARM_LPAE
2039 + /* TODO */
2040 +#else
2041 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2042 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2043 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2044 + preempt_enable_no_resched();
2045 +#endif
2046 + return 0;
2047 +}
2048 +#else
2049 +static inline unsigned long pax_open_kernel(void) { return 0; }
2050 +static inline unsigned long pax_close_kernel(void) { return 0; }
2051 +#endif
2052 +
2053 /*
2054 * This is the lowest virtual address we can permit any user space
2055 * mapping to be mapped at. This is particularly important for
2056 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2057 /*
2058 * The pgprot_* and protection_map entries will be fixed up in runtime
2059 * to include the cachable and bufferable bits based on memory policy,
2060 - * as well as any architecture dependent bits like global/ASID and SMP
2061 - * shared mapping bits.
2062 + * as well as any architecture dependent bits like global/ASID, PXN,
2063 + * and SMP shared mapping bits.
2064 */
2065 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2066
2067 @@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2068 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2069 {
2070 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2071 - L_PTE_NONE | L_PTE_VALID;
2072 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2073 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2074 return pte;
2075 }
2076 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2077 index 5324c11..bcae5f0 100644
2078 --- a/arch/arm/include/asm/proc-fns.h
2079 +++ b/arch/arm/include/asm/proc-fns.h
2080 @@ -75,7 +75,7 @@ extern struct processor {
2081 unsigned int suspend_size;
2082 void (*do_suspend)(void *);
2083 void (*do_resume)(void *);
2084 -} processor;
2085 +} __do_const processor;
2086
2087 #ifndef MULTI_CPU
2088 extern void cpu_proc_init(void);
2089 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2090 index c4ae171..ea0c0c2 100644
2091 --- a/arch/arm/include/asm/psci.h
2092 +++ b/arch/arm/include/asm/psci.h
2093 @@ -29,7 +29,7 @@ struct psci_operations {
2094 int (*cpu_off)(struct psci_power_state state);
2095 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2096 int (*migrate)(unsigned long cpuid);
2097 -};
2098 +} __no_const;
2099
2100 extern struct psci_operations psci_ops;
2101 extern struct smp_operations psci_smp_ops;
2102 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2103 index 22a3b9b..7f214ee 100644
2104 --- a/arch/arm/include/asm/smp.h
2105 +++ b/arch/arm/include/asm/smp.h
2106 @@ -112,7 +112,7 @@ struct smp_operations {
2107 int (*cpu_disable)(unsigned int cpu);
2108 #endif
2109 #endif
2110 -};
2111 +} __no_const;
2112
2113 /*
2114 * set platform specific SMP operations
2115 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2116 index 71a06b2..8bb9ae1 100644
2117 --- a/arch/arm/include/asm/thread_info.h
2118 +++ b/arch/arm/include/asm/thread_info.h
2119 @@ -88,9 +88,9 @@ struct thread_info {
2120 .flags = 0, \
2121 .preempt_count = INIT_PREEMPT_COUNT, \
2122 .addr_limit = KERNEL_DS, \
2123 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2124 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2125 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2126 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2127 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2128 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2129 .restart_block = { \
2130 .fn = do_no_restart_syscall, \
2131 }, \
2132 @@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2133 #define TIF_SYSCALL_AUDIT 9
2134 #define TIF_SYSCALL_TRACEPOINT 10
2135 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2136 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2137 +/* within 8 bits of TIF_SYSCALL_TRACE
2138 + * to meet flexible second operand requirements
2139 + */
2140 +#define TIF_GRSEC_SETXID 12
2141 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2142 #define TIF_USING_IWMMXT 17
2143 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2144 #define TIF_RESTORE_SIGMASK 20
2145 @@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2146 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2147 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2148 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2149 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2150
2151 /* Checks for any syscall work in entry-common.S */
2152 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2153 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2154 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2155
2156 /*
2157 * Change these and you break ASM code in entry-common.S
2158 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2159 index 72abdc5..9eba222 100644
2160 --- a/arch/arm/include/asm/uaccess.h
2161 +++ b/arch/arm/include/asm/uaccess.h
2162 @@ -18,6 +18,7 @@
2163 #include <asm/domain.h>
2164 #include <asm/unified.h>
2165 #include <asm/compiler.h>
2166 +#include <asm/pgtable.h>
2167
2168 #if __LINUX_ARM_ARCH__ < 6
2169 #include <asm-generic/uaccess-unaligned.h>
2170 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2171 static inline void set_fs(mm_segment_t fs)
2172 {
2173 current_thread_info()->addr_limit = fs;
2174 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2175 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2176 }
2177
2178 #define segment_eq(a,b) ((a) == (b))
2179
2180 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2181 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2182 +
2183 +static inline void pax_open_userland(void)
2184 +{
2185 +
2186 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2187 + if (segment_eq(get_fs(), USER_DS)) {
2188 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2189 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2190 + }
2191 +#endif
2192 +
2193 +}
2194 +
2195 +static inline void pax_close_userland(void)
2196 +{
2197 +
2198 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2199 + if (segment_eq(get_fs(), USER_DS)) {
2200 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2201 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2202 + }
2203 +#endif
2204 +
2205 +}
2206 +
2207 #define __addr_ok(addr) ({ \
2208 unsigned long flag; \
2209 __asm__("cmp %2, %0; movlo %0, #0" \
2210 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2211
2212 #define get_user(x,p) \
2213 ({ \
2214 + int __e; \
2215 might_fault(); \
2216 - __get_user_check(x,p); \
2217 + pax_open_userland(); \
2218 + __e = __get_user_check(x,p); \
2219 + pax_close_userland(); \
2220 + __e; \
2221 })
2222
2223 extern int __put_user_1(void *, unsigned int);
2224 @@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2225
2226 #define put_user(x,p) \
2227 ({ \
2228 + int __e; \
2229 might_fault(); \
2230 - __put_user_check(x,p); \
2231 + pax_open_userland(); \
2232 + __e = __put_user_check(x,p); \
2233 + pax_close_userland(); \
2234 + __e; \
2235 })
2236
2237 #else /* CONFIG_MMU */
2238 @@ -237,13 +273,17 @@ static inline void set_fs(mm_segment_t fs)
2239 #define __get_user(x,ptr) \
2240 ({ \
2241 long __gu_err = 0; \
2242 + pax_open_userland(); \
2243 __get_user_err((x),(ptr),__gu_err); \
2244 + pax_close_userland(); \
2245 __gu_err; \
2246 })
2247
2248 #define __get_user_error(x,ptr,err) \
2249 ({ \
2250 + pax_open_userland(); \
2251 __get_user_err((x),(ptr),err); \
2252 + pax_close_userland(); \
2253 (void) 0; \
2254 })
2255
2256 @@ -319,13 +359,17 @@ do { \
2257 #define __put_user(x,ptr) \
2258 ({ \
2259 long __pu_err = 0; \
2260 + pax_open_userland(); \
2261 __put_user_err((x),(ptr),__pu_err); \
2262 + pax_close_userland(); \
2263 __pu_err; \
2264 })
2265
2266 #define __put_user_error(x,ptr,err) \
2267 ({ \
2268 + pax_open_userland(); \
2269 __put_user_err((x),(ptr),err); \
2270 + pax_close_userland(); \
2271 (void) 0; \
2272 })
2273
2274 @@ -425,11 +469,44 @@ do { \
2275
2276
2277 #ifdef CONFIG_MMU
2278 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2279 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2280 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2281 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2282 +
2283 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2284 +{
2285 + unsigned long ret;
2286 +
2287 + check_object_size(to, n, false);
2288 + pax_open_userland();
2289 + ret = ___copy_from_user(to, from, n);
2290 + pax_close_userland();
2291 + return ret;
2292 +}
2293 +
2294 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2295 +{
2296 + unsigned long ret;
2297 +
2298 + check_object_size(from, n, true);
2299 + pax_open_userland();
2300 + ret = ___copy_to_user(to, from, n);
2301 + pax_close_userland();
2302 + return ret;
2303 +}
2304 +
2305 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2306 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2307 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2308 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2309 +
2310 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2311 +{
2312 + unsigned long ret;
2313 + pax_open_userland();
2314 + ret = ___clear_user(addr, n);
2315 + pax_close_userland();
2316 + return ret;
2317 +}
2318 +
2319 #else
2320 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2321 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2322 @@ -438,6 +515,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2323
2324 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2325 {
2326 + if ((long)n < 0)
2327 + return n;
2328 +
2329 if (access_ok(VERIFY_READ, from, n))
2330 n = __copy_from_user(to, from, n);
2331 else /* security hole - plug it */
2332 @@ -447,6 +527,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2333
2334 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2335 {
2336 + if ((long)n < 0)
2337 + return n;
2338 +
2339 if (access_ok(VERIFY_WRITE, to, n))
2340 n = __copy_to_user(to, from, n);
2341 return n;
2342 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2343 index 5af0ed1..cea83883 100644
2344 --- a/arch/arm/include/uapi/asm/ptrace.h
2345 +++ b/arch/arm/include/uapi/asm/ptrace.h
2346 @@ -92,7 +92,7 @@
2347 * ARMv7 groups of PSR bits
2348 */
2349 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2350 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2351 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2352 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2353 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2354
2355 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2356 index 1f031dd..d9b5e4a 100644
2357 --- a/arch/arm/kernel/armksyms.c
2358 +++ b/arch/arm/kernel/armksyms.c
2359 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2360
2361 /* networking */
2362 EXPORT_SYMBOL(csum_partial);
2363 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2364 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2365 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2366 EXPORT_SYMBOL(__csum_ipv6_magic);
2367
2368 @@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2369 #ifdef CONFIG_MMU
2370 EXPORT_SYMBOL(copy_page);
2371
2372 -EXPORT_SYMBOL(__copy_from_user);
2373 -EXPORT_SYMBOL(__copy_to_user);
2374 -EXPORT_SYMBOL(__clear_user);
2375 +EXPORT_SYMBOL(___copy_from_user);
2376 +EXPORT_SYMBOL(___copy_to_user);
2377 +EXPORT_SYMBOL(___clear_user);
2378
2379 EXPORT_SYMBOL(__get_user_1);
2380 EXPORT_SYMBOL(__get_user_2);
2381 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2382 index b3fb8c9..59cfab2 100644
2383 --- a/arch/arm/kernel/entry-armv.S
2384 +++ b/arch/arm/kernel/entry-armv.S
2385 @@ -47,6 +47,87 @@
2386 9997:
2387 .endm
2388
2389 + .macro pax_enter_kernel
2390 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2391 + @ make aligned space for saved DACR
2392 + sub sp, sp, #8
2393 + @ save regs
2394 + stmdb sp!, {r1, r2}
2395 + @ read DACR from cpu_domain into r1
2396 + mov r2, sp
2397 + @ assume 8K pages, since we have to split the immediate in two
2398 + bic r2, r2, #(0x1fc0)
2399 + bic r2, r2, #(0x3f)
2400 + ldr r1, [r2, #TI_CPU_DOMAIN]
2401 + @ store old DACR on stack
2402 + str r1, [sp, #8]
2403 +#ifdef CONFIG_PAX_KERNEXEC
2404 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2405 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2406 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2407 +#endif
2408 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2409 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2410 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2411 +#endif
2412 + @ write r1 to current_thread_info()->cpu_domain
2413 + str r1, [r2, #TI_CPU_DOMAIN]
2414 + @ write r1 to DACR
2415 + mcr p15, 0, r1, c3, c0, 0
2416 + @ instruction sync
2417 + instr_sync
2418 + @ restore regs
2419 + ldmia sp!, {r1, r2}
2420 +#endif
2421 + .endm
2422 +
2423 + .macro pax_open_userland
2424 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2425 + @ save regs
2426 + stmdb sp!, {r0, r1}
2427 + @ read DACR from cpu_domain into r1
2428 + mov r0, sp
2429 + @ assume 8K pages, since we have to split the immediate in two
2430 + bic r0, r0, #(0x1fc0)
2431 + bic r0, r0, #(0x3f)
2432 + ldr r1, [r0, #TI_CPU_DOMAIN]
2433 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2434 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2435 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2436 + @ write r1 to current_thread_info()->cpu_domain
2437 + str r1, [r0, #TI_CPU_DOMAIN]
2438 + @ write r1 to DACR
2439 + mcr p15, 0, r1, c3, c0, 0
2440 + @ instruction sync
2441 + instr_sync
2442 + @ restore regs
2443 + ldmia sp!, {r0, r1}
2444 +#endif
2445 + .endm
2446 +
2447 + .macro pax_close_userland
2448 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2449 + @ save regs
2450 + stmdb sp!, {r0, r1}
2451 + @ read DACR from cpu_domain into r1
2452 + mov r0, sp
2453 + @ assume 8K pages, since we have to split the immediate in two
2454 + bic r0, r0, #(0x1fc0)
2455 + bic r0, r0, #(0x3f)
2456 + ldr r1, [r0, #TI_CPU_DOMAIN]
2457 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2458 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
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 pabt_helper
2471 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2472 #ifdef MULTI_PABORT
2473 @@ -89,11 +170,15 @@
2474 * Invalid mode handlers
2475 */
2476 .macro inv_entry, reason
2477 +
2478 + pax_enter_kernel
2479 +
2480 sub sp, sp, #S_FRAME_SIZE
2481 ARM( stmib sp, {r1 - lr} )
2482 THUMB( stmia sp, {r0 - r12} )
2483 THUMB( str sp, [sp, #S_SP] )
2484 THUMB( str lr, [sp, #S_LR] )
2485 +
2486 mov r1, #\reason
2487 .endm
2488
2489 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2490 .macro svc_entry, stack_hole=0
2491 UNWIND(.fnstart )
2492 UNWIND(.save {r0 - pc} )
2493 +
2494 + pax_enter_kernel
2495 +
2496 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2497 +
2498 #ifdef CONFIG_THUMB2_KERNEL
2499 SPFIX( str r0, [sp] ) @ temporarily saved
2500 SPFIX( mov r0, sp )
2501 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2502 ldmia r0, {r3 - r5}
2503 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2504 mov r6, #-1 @ "" "" "" ""
2505 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2506 + @ offset sp by 8 as done in pax_enter_kernel
2507 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2508 +#else
2509 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2510 +#endif
2511 SPFIX( addeq r2, r2, #4 )
2512 str r3, [sp, #-4]! @ save the "real" r0 copied
2513 @ from the exception stack
2514 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2515 .macro usr_entry
2516 UNWIND(.fnstart )
2517 UNWIND(.cantunwind ) @ don't unwind the user space
2518 +
2519 + pax_enter_kernel_user
2520 +
2521 sub sp, sp, #S_FRAME_SIZE
2522 ARM( stmib sp, {r1 - r12} )
2523 THUMB( stmia sp, {r0 - r12} )
2524 @@ -416,7 +513,9 @@ __und_usr:
2525 tst r3, #PSR_T_BIT @ Thumb mode?
2526 bne __und_usr_thumb
2527 sub r4, r2, #4 @ ARM instr at LR - 4
2528 + pax_open_userland
2529 1: ldrt r0, [r4]
2530 + pax_close_userland
2531 ARM_BE8(rev r0, r0) @ little endian instruction
2532
2533 @ r0 = 32-bit ARM instruction which caused the exception
2534 @@ -450,10 +549,14 @@ __und_usr_thumb:
2535 */
2536 .arch armv6t2
2537 #endif
2538 + pax_open_userland
2539 2: ldrht r5, [r4]
2540 + pax_close_userland
2541 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2542 blo __und_usr_fault_16 @ 16bit undefined instruction
2543 + pax_open_userland
2544 3: ldrht r0, [r2]
2545 + pax_close_userland
2546 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2547 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2548 orr r0, r0, r5, lsl #16
2549 @@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2550 */
2551 .pushsection .fixup, "ax"
2552 .align 2
2553 -4: mov pc, r9
2554 +4: pax_close_userland
2555 + mov pc, r9
2556 .popsection
2557 .pushsection __ex_table,"a"
2558 .long 1b, 4b
2559 @@ -692,7 +796,7 @@ ENTRY(__switch_to)
2560 THUMB( str lr, [ip], #4 )
2561 ldr r4, [r2, #TI_TP_VALUE]
2562 ldr r5, [r2, #TI_TP_VALUE + 4]
2563 -#ifdef CONFIG_CPU_USE_DOMAINS
2564 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2565 ldr r6, [r2, #TI_CPU_DOMAIN]
2566 #endif
2567 switch_tls r1, r4, r5, r3, r7
2568 @@ -701,7 +805,7 @@ ENTRY(__switch_to)
2569 ldr r8, =__stack_chk_guard
2570 ldr r7, [r7, #TSK_STACK_CANARY]
2571 #endif
2572 -#ifdef CONFIG_CPU_USE_DOMAINS
2573 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2575 #endif
2576 mov r5, r0
2577 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2578 index a2dcafd..1048b5a 100644
2579 --- a/arch/arm/kernel/entry-common.S
2580 +++ b/arch/arm/kernel/entry-common.S
2581 @@ -10,18 +10,46 @@
2582
2583 #include <asm/unistd.h>
2584 #include <asm/ftrace.h>
2585 +#include <asm/domain.h>
2586 #include <asm/unwind.h>
2587
2588 +#include "entry-header.S"
2589 +
2590 #ifdef CONFIG_NEED_RET_TO_USER
2591 #include <mach/entry-macro.S>
2592 #else
2593 .macro arch_ret_to_user, tmp1, tmp2
2594 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2595 + @ save regs
2596 + stmdb sp!, {r1, r2}
2597 + @ read DACR from cpu_domain into r1
2598 + mov r2, sp
2599 + @ assume 8K pages, since we have to split the immediate in two
2600 + bic r2, r2, #(0x1fc0)
2601 + bic r2, r2, #(0x3f)
2602 + ldr r1, [r2, #TI_CPU_DOMAIN]
2603 +#ifdef CONFIG_PAX_KERNEXEC
2604 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2605 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2606 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2607 +#endif
2608 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2609 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2610 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2611 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2612 +#endif
2613 + @ write r1 to current_thread_info()->cpu_domain
2614 + str r1, [r2, #TI_CPU_DOMAIN]
2615 + @ write r1 to DACR
2616 + mcr p15, 0, r1, c3, c0, 0
2617 + @ instruction sync
2618 + instr_sync
2619 + @ restore regs
2620 + ldmia sp!, {r1, r2}
2621 +#endif
2622 .endm
2623 #endif
2624
2625 -#include "entry-header.S"
2626 -
2627 -
2628 .align 5
2629 /*
2630 * This is the fast syscall return path. We do as little as
2631 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2632 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2633 #endif
2634
2635 + /*
2636 + * do this here to avoid a performance hit of wrapping the code above
2637 + * that directly dereferences userland to parse the SWI instruction
2638 + */
2639 + pax_enter_kernel_user
2640 +
2641 adr tbl, sys_call_table @ load syscall table pointer
2642
2643 #if defined(CONFIG_OABI_COMPAT)
2644 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2645 index 39f89fb..d612bd9 100644
2646 --- a/arch/arm/kernel/entry-header.S
2647 +++ b/arch/arm/kernel/entry-header.S
2648 @@ -184,6 +184,60 @@
2649 msr cpsr_c, \rtemp @ switch back to the SVC mode
2650 .endm
2651
2652 + .macro pax_enter_kernel_user
2653 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2654 + @ save regs
2655 + stmdb sp!, {r0, r1}
2656 + @ read DACR from cpu_domain into r1
2657 + mov r0, sp
2658 + @ assume 8K pages, since we have to split the immediate in two
2659 + bic r0, r0, #(0x1fc0)
2660 + bic r0, r0, #(0x3f)
2661 + ldr r1, [r0, #TI_CPU_DOMAIN]
2662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2663 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2664 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2665 +#endif
2666 +#ifdef CONFIG_PAX_KERNEXEC
2667 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2668 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2669 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2670 +#endif
2671 + @ write r1 to current_thread_info()->cpu_domain
2672 + str r1, [r0, #TI_CPU_DOMAIN]
2673 + @ write r1 to DACR
2674 + mcr p15, 0, r1, c3, c0, 0
2675 + @ instruction sync
2676 + instr_sync
2677 + @ restore regs
2678 + ldmia sp!, {r0, r1}
2679 +#endif
2680 + .endm
2681 +
2682 + .macro pax_exit_kernel
2683 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2684 + @ save regs
2685 + stmdb sp!, {r0, r1}
2686 + @ read old DACR from stack into r1
2687 + ldr r1, [sp, #(8 + S_SP)]
2688 + sub r1, r1, #8
2689 + ldr r1, [r1]
2690 +
2691 + @ write r1 to current_thread_info()->cpu_domain
2692 + mov r0, sp
2693 + @ assume 8K pages, since we have to split the immediate in two
2694 + bic r0, r0, #(0x1fc0)
2695 + bic r0, r0, #(0x3f)
2696 + str r1, [r0, #TI_CPU_DOMAIN]
2697 + @ write r1 to DACR
2698 + mcr p15, 0, r1, c3, c0, 0
2699 + @ instruction sync
2700 + instr_sync
2701 + @ restore regs
2702 + ldmia sp!, {r0, r1}
2703 +#endif
2704 + .endm
2705 +
2706 #ifndef CONFIG_THUMB2_KERNEL
2707 .macro svc_exit, rpsr, irq = 0
2708 .if \irq != 0
2709 @@ -203,6 +257,9 @@
2710 blne trace_hardirqs_off
2711 #endif
2712 .endif
2713 +
2714 + pax_exit_kernel
2715 +
2716 msr spsr_cxsf, \rpsr
2717 #if defined(CONFIG_CPU_V6)
2718 ldr r0, [sp]
2719 @@ -266,6 +323,9 @@
2720 blne trace_hardirqs_off
2721 #endif
2722 .endif
2723 +
2724 + pax_exit_kernel
2725 +
2726 ldr lr, [sp, #S_SP] @ top of the stack
2727 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2728 clrex @ clear the exclusive monitor
2729 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2730 index 918875d..cd5fa27 100644
2731 --- a/arch/arm/kernel/fiq.c
2732 +++ b/arch/arm/kernel/fiq.c
2733 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2734 void *base = vectors_page;
2735 unsigned offset = FIQ_OFFSET;
2736
2737 + pax_open_kernel();
2738 memcpy(base + offset, start, length);
2739 + pax_close_kernel();
2740 +
2741 if (!cache_is_vipt_nonaliasing())
2742 flush_icache_range((unsigned long)base + offset, offset +
2743 length);
2744 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2745 index 32f317e..710ae07 100644
2746 --- a/arch/arm/kernel/head.S
2747 +++ b/arch/arm/kernel/head.S
2748 @@ -52,7 +52,9 @@
2749 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2750
2751 .macro pgtbl, rd, phys
2752 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2753 + mov \rd, #TEXT_OFFSET
2754 + sub \rd, #PG_DIR_SIZE
2755 + add \rd, \rd, \phys
2756 .endm
2757
2758 /*
2759 @@ -436,7 +438,7 @@ __enable_mmu:
2760 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2761 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2762 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2763 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2764 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2765 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2766 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2767 #endif
2768 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2769 index 45e4781..8eac93d 100644
2770 --- a/arch/arm/kernel/module.c
2771 +++ b/arch/arm/kernel/module.c
2772 @@ -38,12 +38,39 @@
2773 #endif
2774
2775 #ifdef CONFIG_MMU
2776 -void *module_alloc(unsigned long size)
2777 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2778 {
2779 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2780 + return NULL;
2781 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2782 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2783 + GFP_KERNEL, prot, NUMA_NO_NODE,
2784 __builtin_return_address(0));
2785 }
2786 +
2787 +void *module_alloc(unsigned long size)
2788 +{
2789 +
2790 +#ifdef CONFIG_PAX_KERNEXEC
2791 + return __module_alloc(size, PAGE_KERNEL);
2792 +#else
2793 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2794 +#endif
2795 +
2796 +}
2797 +
2798 +#ifdef CONFIG_PAX_KERNEXEC
2799 +void module_free_exec(struct module *mod, void *module_region)
2800 +{
2801 + module_free(mod, module_region);
2802 +}
2803 +EXPORT_SYMBOL(module_free_exec);
2804 +
2805 +void *module_alloc_exec(unsigned long size)
2806 +{
2807 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2808 +}
2809 +EXPORT_SYMBOL(module_alloc_exec);
2810 +#endif
2811 #endif
2812
2813 int
2814 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2815 index 07314af..c46655c 100644
2816 --- a/arch/arm/kernel/patch.c
2817 +++ b/arch/arm/kernel/patch.c
2818 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2819 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2820 int size;
2821
2822 + pax_open_kernel();
2823 if (thumb2 && __opcode_is_thumb16(insn)) {
2824 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2825 size = sizeof(u16);
2826 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2827 *(u32 *)addr = insn;
2828 size = sizeof(u32);
2829 }
2830 + pax_close_kernel();
2831
2832 flush_icache_range((uintptr_t)(addr),
2833 (uintptr_t)(addr) + size);
2834 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2835 index 92f7b15..7048500 100644
2836 --- a/arch/arm/kernel/process.c
2837 +++ b/arch/arm/kernel/process.c
2838 @@ -217,6 +217,7 @@ void machine_power_off(void)
2839
2840 if (pm_power_off)
2841 pm_power_off();
2842 + BUG();
2843 }
2844
2845 /*
2846 @@ -230,7 +231,7 @@ void machine_power_off(void)
2847 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2848 * to use. Implementing such co-ordination would be essentially impossible.
2849 */
2850 -void machine_restart(char *cmd)
2851 +__noreturn void machine_restart(char *cmd)
2852 {
2853 local_irq_disable();
2854 smp_send_stop();
2855 @@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2856
2857 show_regs_print_info(KERN_DEFAULT);
2858
2859 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2860 - print_symbol("LR is at %s\n", regs->ARM_lr);
2861 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2862 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2863 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2864 "sp : %08lx ip : %08lx fp : %08lx\n",
2865 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2866 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2867 return 0;
2868 }
2869
2870 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2871 -{
2872 - unsigned long range_end = mm->brk + 0x02000000;
2873 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2874 -}
2875 -
2876 #ifdef CONFIG_MMU
2877 #ifdef CONFIG_KUSER_HELPERS
2878 /*
2879 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2880
2881 static int __init gate_vma_init(void)
2882 {
2883 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2884 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2885 return 0;
2886 }
2887 arch_initcall(gate_vma_init);
2888 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2889
2890 const char *arch_vma_name(struct vm_area_struct *vma)
2891 {
2892 - return is_gate_vma(vma) ? "[vectors]" :
2893 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2894 - "[sigpage]" : NULL;
2895 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2896 }
2897
2898 -static struct page *signal_page;
2899 -extern struct page *get_signal_page(void);
2900 -
2901 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2902 {
2903 struct mm_struct *mm = current->mm;
2904 - unsigned long addr;
2905 - int ret;
2906 -
2907 - if (!signal_page)
2908 - signal_page = get_signal_page();
2909 - if (!signal_page)
2910 - return -ENOMEM;
2911
2912 down_write(&mm->mmap_sem);
2913 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2914 - if (IS_ERR_VALUE(addr)) {
2915 - ret = addr;
2916 - goto up_fail;
2917 - }
2918 -
2919 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2920 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2921 - &signal_page);
2922 -
2923 - if (ret == 0)
2924 - mm->context.sigpage = addr;
2925 -
2926 - up_fail:
2927 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2928 up_write(&mm->mmap_sem);
2929 - return ret;
2930 + return 0;
2931 }
2932 #endif
2933 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2934 index 4693188..4596c5e 100644
2935 --- a/arch/arm/kernel/psci.c
2936 +++ b/arch/arm/kernel/psci.c
2937 @@ -24,7 +24,7 @@
2938 #include <asm/opcodes-virt.h>
2939 #include <asm/psci.h>
2940
2941 -struct psci_operations psci_ops;
2942 +struct psci_operations psci_ops __read_only;
2943
2944 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2945
2946 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2947 index 0dd3b79..e018f64 100644
2948 --- a/arch/arm/kernel/ptrace.c
2949 +++ b/arch/arm/kernel/ptrace.c
2950 @@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2951 return current_thread_info()->syscall;
2952 }
2953
2954 +#ifdef CONFIG_GRKERNSEC_SETXID
2955 +extern void gr_delayed_cred_worker(void);
2956 +#endif
2957 +
2958 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2959 {
2960 current_thread_info()->syscall = scno;
2961
2962 +#ifdef CONFIG_GRKERNSEC_SETXID
2963 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2964 + gr_delayed_cred_worker();
2965 +#endif
2966 +
2967 /* Do the secure computing check first; failures should be fast. */
2968 if (secure_computing(scno) == -1)
2969 return -1;
2970 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2971 index 987a7f5..d9d6071 100644
2972 --- a/arch/arm/kernel/setup.c
2973 +++ b/arch/arm/kernel/setup.c
2974 @@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2975 unsigned int elf_hwcap __read_mostly;
2976 EXPORT_SYMBOL(elf_hwcap);
2977
2978 +pteval_t __supported_pte_mask __read_only;
2979 +pmdval_t __supported_pmd_mask __read_only;
2980
2981 #ifdef MULTI_CPU
2982 -struct processor processor __read_mostly;
2983 +struct processor processor;
2984 #endif
2985 #ifdef MULTI_TLB
2986 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2987 +struct cpu_tlb_fns cpu_tlb __read_only;
2988 #endif
2989 #ifdef MULTI_USER
2990 -struct cpu_user_fns cpu_user __read_mostly;
2991 +struct cpu_user_fns cpu_user __read_only;
2992 #endif
2993 #ifdef MULTI_CACHE
2994 -struct cpu_cache_fns cpu_cache __read_mostly;
2995 +struct cpu_cache_fns cpu_cache __read_only;
2996 #endif
2997 #ifdef CONFIG_OUTER_CACHE
2998 -struct outer_cache_fns outer_cache __read_mostly;
2999 +struct outer_cache_fns outer_cache __read_only;
3000 EXPORT_SYMBOL(outer_cache);
3001 #endif
3002
3003 @@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3004 asm("mrc p15, 0, %0, c0, c1, 4"
3005 : "=r" (mmfr0));
3006 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3007 - (mmfr0 & 0x000000f0) >= 0x00000030)
3008 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3009 cpu_arch = CPU_ARCH_ARMv7;
3010 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3011 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3012 + __supported_pte_mask |= L_PTE_PXN;
3013 + __supported_pmd_mask |= PMD_PXNTABLE;
3014 + }
3015 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3016 (mmfr0 & 0x000000f0) == 0x00000020)
3017 cpu_arch = CPU_ARCH_ARMv6;
3018 else
3019 @@ -573,7 +579,7 @@ static void __init setup_processor(void)
3020 __cpu_architecture = __get_cpu_architecture();
3021
3022 #ifdef MULTI_CPU
3023 - processor = *list->proc;
3024 + memcpy((void *)&processor, list->proc, sizeof processor);
3025 #endif
3026 #ifdef MULTI_TLB
3027 cpu_tlb = *list->tlb;
3028 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3029 index 04d6388..5115238 100644
3030 --- a/arch/arm/kernel/signal.c
3031 +++ b/arch/arm/kernel/signal.c
3032 @@ -23,8 +23,6 @@
3033
3034 extern const unsigned long sigreturn_codes[7];
3035
3036 -static unsigned long signal_return_offset;
3037 -
3038 #ifdef CONFIG_CRUNCH
3039 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3040 {
3041 @@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3042 * except when the MPU has protected the vectors
3043 * page from PL0
3044 */
3045 - retcode = mm->context.sigpage + signal_return_offset +
3046 - (idx << 2) + thumb;
3047 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3048 } else
3049 #endif
3050 {
3051 @@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3052 } while (thread_flags & _TIF_WORK_MASK);
3053 return 0;
3054 }
3055 -
3056 -struct page *get_signal_page(void)
3057 -{
3058 - unsigned long ptr;
3059 - unsigned offset;
3060 - struct page *page;
3061 - void *addr;
3062 -
3063 - page = alloc_pages(GFP_KERNEL, 0);
3064 -
3065 - if (!page)
3066 - return NULL;
3067 -
3068 - addr = page_address(page);
3069 -
3070 - /* Give the signal return code some randomness */
3071 - offset = 0x200 + (get_random_int() & 0x7fc);
3072 - signal_return_offset = offset;
3073 -
3074 - /*
3075 - * Copy signal return handlers into the vector page, and
3076 - * set sigreturn to be a pointer to these.
3077 - */
3078 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3079 -
3080 - ptr = (unsigned long)addr + offset;
3081 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3082 -
3083 - return page;
3084 -}
3085 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3086 index dc894ab..f929a0d 100644
3087 --- a/arch/arm/kernel/smp.c
3088 +++ b/arch/arm/kernel/smp.c
3089 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3090
3091 static DECLARE_COMPLETION(cpu_running);
3092
3093 -static struct smp_operations smp_ops;
3094 +static struct smp_operations smp_ops __read_only;
3095
3096 void __init smp_set_ops(struct smp_operations *ops)
3097 {
3098 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3099 index 4636d56..ce4ec3d 100644
3100 --- a/arch/arm/kernel/traps.c
3101 +++ b/arch/arm/kernel/traps.c
3102 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3103 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3104 {
3105 #ifdef CONFIG_KALLSYMS
3106 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3107 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3108 #else
3109 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3110 #endif
3111 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3112 static int die_owner = -1;
3113 static unsigned int die_nest_count;
3114
3115 +extern void gr_handle_kernel_exploit(void);
3116 +
3117 static unsigned long oops_begin(void)
3118 {
3119 int cpu;
3120 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3121 panic("Fatal exception in interrupt");
3122 if (panic_on_oops)
3123 panic("Fatal exception");
3124 +
3125 + gr_handle_kernel_exploit();
3126 +
3127 if (signr)
3128 do_exit(signr);
3129 }
3130 @@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3131 * The user helper at 0xffff0fe0 must be used instead.
3132 * (see entry-armv.S for details)
3133 */
3134 + pax_open_kernel();
3135 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3136 + pax_close_kernel();
3137 }
3138 return 0;
3139
3140 @@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3141 kuser_init(vectors_base);
3142
3143 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3144 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3145 +
3146 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3147 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3148 +#endif
3149 +
3150 #else /* ifndef CONFIG_CPU_V7M */
3151 /*
3152 * on V7-M there is no need to copy the vector table to a dedicated
3153 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3154 index 7bcee5c..e2f3249 100644
3155 --- a/arch/arm/kernel/vmlinux.lds.S
3156 +++ b/arch/arm/kernel/vmlinux.lds.S
3157 @@ -8,7 +8,11 @@
3158 #include <asm/thread_info.h>
3159 #include <asm/memory.h>
3160 #include <asm/page.h>
3161 -
3162 +
3163 +#ifdef CONFIG_PAX_KERNEXEC
3164 +#include <asm/pgtable.h>
3165 +#endif
3166 +
3167 #define PROC_INFO \
3168 . = ALIGN(4); \
3169 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3170 @@ -34,7 +38,7 @@
3171 #endif
3172
3173 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3174 - defined(CONFIG_GENERIC_BUG)
3175 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3176 #define ARM_EXIT_KEEP(x) x
3177 #define ARM_EXIT_DISCARD(x)
3178 #else
3179 @@ -90,6 +94,11 @@ SECTIONS
3180 _text = .;
3181 HEAD_TEXT
3182 }
3183 +
3184 +#ifdef CONFIG_PAX_KERNEXEC
3185 + . = ALIGN(1<<SECTION_SHIFT);
3186 +#endif
3187 +
3188 .text : { /* Real text segment */
3189 _stext = .; /* Text and read-only data */
3190 __exception_text_start = .;
3191 @@ -112,6 +121,8 @@ SECTIONS
3192 ARM_CPU_KEEP(PROC_INFO)
3193 }
3194
3195 + _etext = .; /* End of text section */
3196 +
3197 RO_DATA(PAGE_SIZE)
3198
3199 . = ALIGN(4);
3200 @@ -142,7 +153,9 @@ SECTIONS
3201
3202 NOTES
3203
3204 - _etext = .; /* End of text and rodata section */
3205 +#ifdef CONFIG_PAX_KERNEXEC
3206 + . = ALIGN(1<<SECTION_SHIFT);
3207 +#endif
3208
3209 #ifndef CONFIG_XIP_KERNEL
3210 . = ALIGN(PAGE_SIZE);
3211 @@ -220,6 +233,11 @@ SECTIONS
3212 . = PAGE_OFFSET + TEXT_OFFSET;
3213 #else
3214 __init_end = .;
3215 +
3216 +#ifdef CONFIG_PAX_KERNEXEC
3217 + . = ALIGN(1<<SECTION_SHIFT);
3218 +#endif
3219 +
3220 . = ALIGN(THREAD_SIZE);
3221 __data_loc = .;
3222 #endif
3223 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3224 index 2a700e0..745b980 100644
3225 --- a/arch/arm/kvm/arm.c
3226 +++ b/arch/arm/kvm/arm.c
3227 @@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3228 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3229
3230 /* The VMID used in the VTTBR */
3231 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3232 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3233 static u8 kvm_next_vmid;
3234 static DEFINE_SPINLOCK(kvm_vmid_lock);
3235
3236 @@ -397,7 +397,7 @@ void force_vm_exit(const cpumask_t *mask)
3237 */
3238 static bool need_new_vmid_gen(struct kvm *kvm)
3239 {
3240 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3241 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3242 }
3243
3244 /**
3245 @@ -430,7 +430,7 @@ static void update_vttbr(struct kvm *kvm)
3246
3247 /* First user of a new VMID generation? */
3248 if (unlikely(kvm_next_vmid == 0)) {
3249 - atomic64_inc(&kvm_vmid_gen);
3250 + atomic64_inc_unchecked(&kvm_vmid_gen);
3251 kvm_next_vmid = 1;
3252
3253 /*
3254 @@ -447,7 +447,7 @@ static void update_vttbr(struct kvm *kvm)
3255 kvm_call_hyp(__kvm_flush_vm_context);
3256 }
3257
3258 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3259 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3260 kvm->arch.vmid = kvm_next_vmid;
3261 kvm_next_vmid++;
3262
3263 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3264 index 14a0d98..7771a7d 100644
3265 --- a/arch/arm/lib/clear_user.S
3266 +++ b/arch/arm/lib/clear_user.S
3267 @@ -12,14 +12,14 @@
3268
3269 .text
3270
3271 -/* Prototype: int __clear_user(void *addr, size_t sz)
3272 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3273 * Purpose : clear some user memory
3274 * Params : addr - user memory address to clear
3275 * : sz - number of bytes to clear
3276 * Returns : number of bytes NOT cleared
3277 */
3278 ENTRY(__clear_user_std)
3279 -WEAK(__clear_user)
3280 +WEAK(___clear_user)
3281 stmfd sp!, {r1, lr}
3282 mov r2, #0
3283 cmp r1, #4
3284 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3285 USER( strnebt r2, [r0])
3286 mov r0, #0
3287 ldmfd sp!, {r1, pc}
3288 -ENDPROC(__clear_user)
3289 +ENDPROC(___clear_user)
3290 ENDPROC(__clear_user_std)
3291
3292 .pushsection .fixup,"ax"
3293 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3294 index 66a477a..bee61d3 100644
3295 --- a/arch/arm/lib/copy_from_user.S
3296 +++ b/arch/arm/lib/copy_from_user.S
3297 @@ -16,7 +16,7 @@
3298 /*
3299 * Prototype:
3300 *
3301 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3302 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3303 *
3304 * Purpose:
3305 *
3306 @@ -84,11 +84,11 @@
3307
3308 .text
3309
3310 -ENTRY(__copy_from_user)
3311 +ENTRY(___copy_from_user)
3312
3313 #include "copy_template.S"
3314
3315 -ENDPROC(__copy_from_user)
3316 +ENDPROC(___copy_from_user)
3317
3318 .pushsection .fixup,"ax"
3319 .align 0
3320 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3321 index 6ee2f67..d1cce76 100644
3322 --- a/arch/arm/lib/copy_page.S
3323 +++ b/arch/arm/lib/copy_page.S
3324 @@ -10,6 +10,7 @@
3325 * ASM optimised string functions
3326 */
3327 #include <linux/linkage.h>
3328 +#include <linux/const.h>
3329 #include <asm/assembler.h>
3330 #include <asm/asm-offsets.h>
3331 #include <asm/cache.h>
3332 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3333 index d066df6..df28194 100644
3334 --- a/arch/arm/lib/copy_to_user.S
3335 +++ b/arch/arm/lib/copy_to_user.S
3336 @@ -16,7 +16,7 @@
3337 /*
3338 * Prototype:
3339 *
3340 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3341 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3342 *
3343 * Purpose:
3344 *
3345 @@ -88,11 +88,11 @@
3346 .text
3347
3348 ENTRY(__copy_to_user_std)
3349 -WEAK(__copy_to_user)
3350 +WEAK(___copy_to_user)
3351
3352 #include "copy_template.S"
3353
3354 -ENDPROC(__copy_to_user)
3355 +ENDPROC(___copy_to_user)
3356 ENDPROC(__copy_to_user_std)
3357
3358 .pushsection .fixup,"ax"
3359 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3360 index 7d08b43..f7ca7ea 100644
3361 --- a/arch/arm/lib/csumpartialcopyuser.S
3362 +++ b/arch/arm/lib/csumpartialcopyuser.S
3363 @@ -57,8 +57,8 @@
3364 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3365 */
3366
3367 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3368 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3369 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3370 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3371
3372 #include "csumpartialcopygeneric.S"
3373
3374 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3375 index 5306de3..aed6d03 100644
3376 --- a/arch/arm/lib/delay.c
3377 +++ b/arch/arm/lib/delay.c
3378 @@ -28,7 +28,7 @@
3379 /*
3380 * Default to the loop-based delay implementation.
3381 */
3382 -struct arm_delay_ops arm_delay_ops = {
3383 +struct arm_delay_ops arm_delay_ops __read_only = {
3384 .delay = __loop_delay,
3385 .const_udelay = __loop_const_udelay,
3386 .udelay = __loop_udelay,
3387 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3388 index 3e58d71..029817c 100644
3389 --- a/arch/arm/lib/uaccess_with_memcpy.c
3390 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3391 @@ -136,7 +136,7 @@ out:
3392 }
3393
3394 unsigned long
3395 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3396 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3397 {
3398 /*
3399 * This test is stubbed out of the main function above to keep
3400 @@ -190,7 +190,7 @@ out:
3401 return n;
3402 }
3403
3404 -unsigned long __clear_user(void __user *addr, unsigned long n)
3405 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3406 {
3407 /* See rational for this in __copy_to_user() above. */
3408 if (n < 64)
3409 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3410 index f3407a5..bd4256f 100644
3411 --- a/arch/arm/mach-kirkwood/common.c
3412 +++ b/arch/arm/mach-kirkwood/common.c
3413 @@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3414 clk_gate_ops.disable(hw);
3415 }
3416
3417 -static struct clk_ops clk_gate_fn_ops;
3418 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3419 +{
3420 + return clk_gate_ops.is_enabled(hw);
3421 +}
3422 +
3423 +static struct clk_ops clk_gate_fn_ops = {
3424 + .enable = clk_gate_fn_enable,
3425 + .disable = clk_gate_fn_disable,
3426 + .is_enabled = clk_gate_fn_is_enabled,
3427 +};
3428
3429 static struct clk __init *clk_register_gate_fn(struct device *dev,
3430 const char *name,
3431 @@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3432 gate_fn->fn_en = fn_en;
3433 gate_fn->fn_dis = fn_dis;
3434
3435 - /* ops is the gate ops, but with our enable/disable functions */
3436 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3437 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3438 - clk_gate_fn_ops = clk_gate_ops;
3439 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3440 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3441 - }
3442 -
3443 clk = clk_register(dev, &gate_fn->gate.hw);
3444
3445 if (IS_ERR(clk))
3446 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3447 index 827d1500..2885dc6 100644
3448 --- a/arch/arm/mach-omap2/board-n8x0.c
3449 +++ b/arch/arm/mach-omap2/board-n8x0.c
3450 @@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3451 }
3452 #endif
3453
3454 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3455 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3456 .late_init = n8x0_menelaus_late_init,
3457 };
3458
3459 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3460 index d24926e..a7645a6 100644
3461 --- a/arch/arm/mach-omap2/gpmc.c
3462 +++ b/arch/arm/mach-omap2/gpmc.c
3463 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3464 };
3465
3466 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3467 -static struct irq_chip gpmc_irq_chip;
3468 static int gpmc_irq_start;
3469
3470 static struct resource gpmc_mem_root;
3471 @@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3472
3473 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3474
3475 +static struct irq_chip gpmc_irq_chip = {
3476 + .name = "gpmc",
3477 + .irq_startup = gpmc_irq_noop_ret,
3478 + .irq_enable = gpmc_irq_enable,
3479 + .irq_disable = gpmc_irq_disable,
3480 + .irq_shutdown = gpmc_irq_noop,
3481 + .irq_ack = gpmc_irq_noop,
3482 + .irq_mask = gpmc_irq_noop,
3483 + .irq_unmask = gpmc_irq_noop,
3484 +
3485 +};
3486 +
3487 static int gpmc_setup_irq(void)
3488 {
3489 int i;
3490 @@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3491 return gpmc_irq_start;
3492 }
3493
3494 - gpmc_irq_chip.name = "gpmc";
3495 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3496 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3497 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3498 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3499 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3500 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3501 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3502 -
3503 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3504 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3505
3506 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3507 index f991016..145ebeb 100644
3508 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3509 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3510 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3511 int (*finish_suspend)(unsigned long cpu_state);
3512 void (*resume)(void);
3513 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3514 -};
3515 +} __no_const;
3516
3517 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3518 static struct powerdomain *mpuss_pd;
3519 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3520 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3521 {}
3522
3523 -struct cpu_pm_ops omap_pm_ops = {
3524 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3525 .finish_suspend = default_finish_suspend,
3526 .resume = dummy_cpu_resume,
3527 .scu_prepare = dummy_scu_prepare,
3528 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3529 index 3664562..72f85c6 100644
3530 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3531 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3532 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3533 return NOTIFY_OK;
3534 }
3535
3536 -static struct notifier_block __refdata irq_hotplug_notifier = {
3537 +static struct notifier_block irq_hotplug_notifier = {
3538 .notifier_call = irq_cpu_hotplug_notify,
3539 };
3540
3541 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3542 index e0a398c..a470fa5 100644
3543 --- a/arch/arm/mach-omap2/omap_device.c
3544 +++ b/arch/arm/mach-omap2/omap_device.c
3545 @@ -508,7 +508,7 @@ void omap_device_delete(struct omap_device *od)
3546 struct platform_device __init *omap_device_build(const char *pdev_name,
3547 int pdev_id,
3548 struct omap_hwmod *oh,
3549 - void *pdata, int pdata_len)
3550 + const void *pdata, int pdata_len)
3551 {
3552 struct omap_hwmod *ohs[] = { oh };
3553
3554 @@ -536,7 +536,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3555 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3556 int pdev_id,
3557 struct omap_hwmod **ohs,
3558 - int oh_cnt, void *pdata,
3559 + int oh_cnt, const void *pdata,
3560 int pdata_len)
3561 {
3562 int ret = -ENOMEM;
3563 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3564 index 78c02b3..c94109a 100644
3565 --- a/arch/arm/mach-omap2/omap_device.h
3566 +++ b/arch/arm/mach-omap2/omap_device.h
3567 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3568 /* Core code interface */
3569
3570 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3571 - struct omap_hwmod *oh, void *pdata,
3572 + struct omap_hwmod *oh, const void *pdata,
3573 int pdata_len);
3574
3575 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3576 struct omap_hwmod **oh, int oh_cnt,
3577 - void *pdata, int pdata_len);
3578 + const void *pdata, int pdata_len);
3579
3580 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3581 struct omap_hwmod **ohs, int oh_cnt);
3582 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3583 index 8a1b5e0..5f30074 100644
3584 --- a/arch/arm/mach-omap2/omap_hwmod.c
3585 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3586 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3587 int (*init_clkdm)(struct omap_hwmod *oh);
3588 void (*update_context_lost)(struct omap_hwmod *oh);
3589 int (*get_context_lost)(struct omap_hwmod *oh);
3590 -};
3591 +} __no_const;
3592
3593 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3594 -static struct omap_hwmod_soc_ops soc_ops;
3595 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3596
3597 /* omap_hwmod_list contains all registered struct omap_hwmods */
3598 static LIST_HEAD(omap_hwmod_list);
3599 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3600 index d15c7bb..b2d1f0c 100644
3601 --- a/arch/arm/mach-omap2/wd_timer.c
3602 +++ b/arch/arm/mach-omap2/wd_timer.c
3603 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3604 struct omap_hwmod *oh;
3605 char *oh_name = "wd_timer2";
3606 char *dev_name = "omap_wdt";
3607 - struct omap_wd_timer_platform_data pdata;
3608 + static struct omap_wd_timer_platform_data pdata = {
3609 + .read_reset_sources = prm_read_reset_sources
3610 + };
3611
3612 if (!cpu_class_is_omap2() || of_have_populated_dt())
3613 return 0;
3614 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3615 return -EINVAL;
3616 }
3617
3618 - pdata.read_reset_sources = prm_read_reset_sources;
3619 -
3620 pdev = omap_device_build(dev_name, id, oh, &pdata,
3621 sizeof(struct omap_wd_timer_platform_data));
3622 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3623 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3624 index b82dcae..44ee5b6 100644
3625 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3626 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3627 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3628 bool entered_lp2 = false;
3629
3630 if (tegra_pending_sgi())
3631 - ACCESS_ONCE(abort_flag) = true;
3632 + ACCESS_ONCE_RW(abort_flag) = true;
3633
3634 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3635
3636 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3637 index bdb3564..cebb96f 100644
3638 --- a/arch/arm/mach-ux500/setup.h
3639 +++ b/arch/arm/mach-ux500/setup.h
3640 @@ -39,13 +39,6 @@ extern void ux500_timer_init(void);
3641 .type = MT_DEVICE, \
3642 }
3643
3644 -#define __MEM_DEV_DESC(x, sz) { \
3645 - .virtual = IO_ADDRESS(x), \
3646 - .pfn = __phys_to_pfn(x), \
3647 - .length = sz, \
3648 - .type = MT_MEMORY, \
3649 -}
3650 -
3651 extern struct smp_operations ux500_smp_ops;
3652 extern void ux500_cpu_die(unsigned int cpu);
3653
3654 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3655 index 1f8fed9..14d7823 100644
3656 --- a/arch/arm/mm/Kconfig
3657 +++ b/arch/arm/mm/Kconfig
3658 @@ -446,7 +446,7 @@ config CPU_32v5
3659
3660 config CPU_32v6
3661 bool
3662 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3663 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3664 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3665
3666 config CPU_32v6K
3667 @@ -601,6 +601,7 @@ config CPU_CP15_MPU
3668
3669 config CPU_USE_DOMAINS
3670 bool
3671 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3672 help
3673 This option enables or disables the use of domain switching
3674 via the set_fs() function.
3675 @@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3676 config KUSER_HELPERS
3677 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3678 default y
3679 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3680 help
3681 Warning: disabling this option may break user programs.
3682
3683 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3684 See Documentation/arm/kernel_user_helpers.txt for details.
3685
3686 However, the fixed address nature of these helpers can be used
3687 - by ROP (return orientated programming) authors when creating
3688 + by ROP (Return Oriented Programming) authors when creating
3689 exploits.
3690
3691 If all of the binaries and libraries which run on your platform
3692 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3693 index 9240364..a2b8cf3 100644
3694 --- a/arch/arm/mm/alignment.c
3695 +++ b/arch/arm/mm/alignment.c
3696 @@ -212,10 +212,12 @@ union offset_union {
3697 #define __get16_unaligned_check(ins,val,addr) \
3698 do { \
3699 unsigned int err = 0, v, a = addr; \
3700 + pax_open_userland(); \
3701 __get8_unaligned_check(ins,v,a,err); \
3702 val = v << ((BE) ? 8 : 0); \
3703 __get8_unaligned_check(ins,v,a,err); \
3704 val |= v << ((BE) ? 0 : 8); \
3705 + pax_close_userland(); \
3706 if (err) \
3707 goto fault; \
3708 } while (0)
3709 @@ -229,6 +231,7 @@ union offset_union {
3710 #define __get32_unaligned_check(ins,val,addr) \
3711 do { \
3712 unsigned int err = 0, v, a = addr; \
3713 + pax_open_userland(); \
3714 __get8_unaligned_check(ins,v,a,err); \
3715 val = v << ((BE) ? 24 : 0); \
3716 __get8_unaligned_check(ins,v,a,err); \
3717 @@ -237,6 +240,7 @@ union offset_union {
3718 val |= v << ((BE) ? 8 : 16); \
3719 __get8_unaligned_check(ins,v,a,err); \
3720 val |= v << ((BE) ? 0 : 24); \
3721 + pax_close_userland(); \
3722 if (err) \
3723 goto fault; \
3724 } while (0)
3725 @@ -250,6 +254,7 @@ union offset_union {
3726 #define __put16_unaligned_check(ins,val,addr) \
3727 do { \
3728 unsigned int err = 0, v = val, a = addr; \
3729 + pax_open_userland(); \
3730 __asm__( FIRST_BYTE_16 \
3731 ARM( "1: "ins" %1, [%2], #1\n" ) \
3732 THUMB( "1: "ins" %1, [%2]\n" ) \
3733 @@ -269,6 +274,7 @@ union offset_union {
3734 " .popsection\n" \
3735 : "=r" (err), "=&r" (v), "=&r" (a) \
3736 : "0" (err), "1" (v), "2" (a)); \
3737 + pax_close_userland(); \
3738 if (err) \
3739 goto fault; \
3740 } while (0)
3741 @@ -282,6 +288,7 @@ union offset_union {
3742 #define __put32_unaligned_check(ins,val,addr) \
3743 do { \
3744 unsigned int err = 0, v = val, a = addr; \
3745 + pax_open_userland(); \
3746 __asm__( FIRST_BYTE_32 \
3747 ARM( "1: "ins" %1, [%2], #1\n" ) \
3748 THUMB( "1: "ins" %1, [%2]\n" ) \
3749 @@ -311,6 +318,7 @@ union offset_union {
3750 " .popsection\n" \
3751 : "=r" (err), "=&r" (v), "=&r" (a) \
3752 : "0" (err), "1" (v), "2" (a)); \
3753 + pax_close_userland(); \
3754 if (err) \
3755 goto fault; \
3756 } while (0)
3757 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3758 index 447da6f..77a5057 100644
3759 --- a/arch/arm/mm/cache-l2x0.c
3760 +++ b/arch/arm/mm/cache-l2x0.c
3761 @@ -45,7 +45,7 @@ struct l2x0_of_data {
3762 void (*setup)(const struct device_node *, u32 *, u32 *);
3763 void (*save)(void);
3764 struct outer_cache_fns outer_cache;
3765 -};
3766 +} __do_const;
3767
3768 static bool of_init = false;
3769
3770 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3771 index 84e6f77..0b52f31 100644
3772 --- a/arch/arm/mm/context.c
3773 +++ b/arch/arm/mm/context.c
3774 @@ -43,7 +43,7 @@
3775 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3776
3777 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3778 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3779 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3780 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3781
3782 static DEFINE_PER_CPU(atomic64_t, active_asids);
3783 @@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3784 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3785 {
3786 u64 asid = atomic64_read(&mm->context.id);
3787 - u64 generation = atomic64_read(&asid_generation);
3788 + u64 generation = atomic64_read_unchecked(&asid_generation);
3789
3790 if (asid != 0 && is_reserved_asid(asid)) {
3791 /*
3792 @@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3793 */
3794 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3795 if (asid == NUM_USER_ASIDS) {
3796 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3797 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3798 &asid_generation);
3799 flush_context(cpu);
3800 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3801 @@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3802 cpu_set_reserved_ttbr0();
3803
3804 asid = atomic64_read(&mm->context.id);
3805 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3806 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3807 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3808 goto switch_mm_fastpath;
3809
3810 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3811 /* Check that our ASID belongs to the current generation. */
3812 asid = atomic64_read(&mm->context.id);
3813 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3814 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3815 asid = new_context(mm, cpu);
3816 atomic64_set(&mm->context.id, asid);
3817 }
3818 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3819 index eb8830a..5360ce7 100644
3820 --- a/arch/arm/mm/fault.c
3821 +++ b/arch/arm/mm/fault.c
3822 @@ -25,6 +25,7 @@
3823 #include <asm/system_misc.h>
3824 #include <asm/system_info.h>
3825 #include <asm/tlbflush.h>
3826 +#include <asm/sections.h>
3827
3828 #include "fault.h"
3829
3830 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3831 if (fixup_exception(regs))
3832 return;
3833
3834 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3835 + if (addr < TASK_SIZE) {
3836 + if (current->signal->curr_ip)
3837 + 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),
3838 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3839 + else
3840 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3841 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3842 + }
3843 +#endif
3844 +
3845 +#ifdef CONFIG_PAX_KERNEXEC
3846 + if ((fsr & FSR_WRITE) &&
3847 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3848 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3849 + {
3850 + if (current->signal->curr_ip)
3851 + 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),
3852 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3853 + else
3854 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3855 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3856 + }
3857 +#endif
3858 +
3859 /*
3860 * No handler, we'll have to terminate things with extreme prejudice.
3861 */
3862 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3863 }
3864 #endif
3865
3866 +#ifdef CONFIG_PAX_PAGEEXEC
3867 + if (fsr & FSR_LNX_PF) {
3868 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3869 + do_group_exit(SIGKILL);
3870 + }
3871 +#endif
3872 +
3873 tsk->thread.address = addr;
3874 tsk->thread.error_code = fsr;
3875 tsk->thread.trap_no = 14;
3876 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3877 }
3878 #endif /* CONFIG_MMU */
3879
3880 +#ifdef CONFIG_PAX_PAGEEXEC
3881 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3882 +{
3883 + long i;
3884 +
3885 + printk(KERN_ERR "PAX: bytes at PC: ");
3886 + for (i = 0; i < 20; i++) {
3887 + unsigned char c;
3888 + if (get_user(c, (__force unsigned char __user *)pc+i))
3889 + printk(KERN_CONT "?? ");
3890 + else
3891 + printk(KERN_CONT "%02x ", c);
3892 + }
3893 + printk("\n");
3894 +
3895 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3896 + for (i = -1; i < 20; i++) {
3897 + unsigned long c;
3898 + if (get_user(c, (__force unsigned long __user *)sp+i))
3899 + printk(KERN_CONT "???????? ");
3900 + else
3901 + printk(KERN_CONT "%08lx ", c);
3902 + }
3903 + printk("\n");
3904 +}
3905 +#endif
3906 +
3907 /*
3908 * First Level Translation Fault Handler
3909 *
3910 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3911 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3912 struct siginfo info;
3913
3914 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3915 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3916 + if (current->signal->curr_ip)
3917 + 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),
3918 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3919 + else
3920 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3921 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3922 + goto die;
3923 + }
3924 +#endif
3925 +
3926 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3927 return;
3928
3929 +die:
3930 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3931 inf->name, fsr, addr);
3932
3933 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3934 ifsr_info[nr].name = name;
3935 }
3936
3937 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
3938 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3939 +
3940 asmlinkage void __exception
3941 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3942 {
3943 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3944 struct siginfo info;
3945 + unsigned long pc = instruction_pointer(regs);
3946 +
3947 + if (user_mode(regs)) {
3948 + unsigned long sigpage = current->mm->context.sigpage;
3949 +
3950 + if (sigpage <= pc && pc < sigpage + 7*4) {
3951 + if (pc < sigpage + 3*4)
3952 + sys_sigreturn(regs);
3953 + else
3954 + sys_rt_sigreturn(regs);
3955 + return;
3956 + }
3957 + if (pc == 0xffff0f60UL) {
3958 + /*
3959 + * PaX: __kuser_cmpxchg64 emulation
3960 + */
3961 + // TODO
3962 + //regs->ARM_pc = regs->ARM_lr;
3963 + //return;
3964 + }
3965 + if (pc == 0xffff0fa0UL) {
3966 + /*
3967 + * PaX: __kuser_memory_barrier emulation
3968 + */
3969 + // dmb(); implied by the exception
3970 + regs->ARM_pc = regs->ARM_lr;
3971 + return;
3972 + }
3973 + if (pc == 0xffff0fc0UL) {
3974 + /*
3975 + * PaX: __kuser_cmpxchg emulation
3976 + */
3977 + // TODO
3978 + //long new;
3979 + //int op;
3980 +
3981 + //op = FUTEX_OP_SET << 28;
3982 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
3983 + //regs->ARM_r0 = old != new;
3984 + //regs->ARM_pc = regs->ARM_lr;
3985 + //return;
3986 + }
3987 + if (pc == 0xffff0fe0UL) {
3988 + /*
3989 + * PaX: __kuser_get_tls emulation
3990 + */
3991 + regs->ARM_r0 = current_thread_info()->tp_value[0];
3992 + regs->ARM_pc = regs->ARM_lr;
3993 + return;
3994 + }
3995 + }
3996 +
3997 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3998 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3999 + if (current->signal->curr_ip)
4000 + 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),
4001 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4002 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4003 + else
4004 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4005 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4006 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4007 + goto die;
4008 + }
4009 +#endif
4010 +
4011 +#ifdef CONFIG_PAX_REFCOUNT
4012 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4013 + unsigned int bkpt;
4014 +
4015 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4016 + current->thread.error_code = ifsr;
4017 + current->thread.trap_no = 0;
4018 + pax_report_refcount_overflow(regs);
4019 + fixup_exception(regs);
4020 + return;
4021 + }
4022 + }
4023 +#endif
4024
4025 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4026 return;
4027
4028 +die:
4029 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4030 inf->name, ifsr, addr);
4031
4032 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4033 index cf08bdf..772656c 100644
4034 --- a/arch/arm/mm/fault.h
4035 +++ b/arch/arm/mm/fault.h
4036 @@ -3,6 +3,7 @@
4037
4038 /*
4039 * Fault status register encodings. We steal bit 31 for our own purposes.
4040 + * Set when the FSR value is from an instruction fault.
4041 */
4042 #define FSR_LNX_PF (1 << 31)
4043 #define FSR_WRITE (1 << 11)
4044 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4045 }
4046 #endif
4047
4048 +/* valid for LPAE and !LPAE */
4049 +static inline int is_xn_fault(unsigned int fsr)
4050 +{
4051 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4052 +}
4053 +
4054 +static inline int is_domain_fault(unsigned int fsr)
4055 +{
4056 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4057 +}
4058 +
4059 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4060 unsigned long search_exception_table(unsigned long addr);
4061
4062 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4063 index 3e8f106..a0a1fe4 100644
4064 --- a/arch/arm/mm/init.c
4065 +++ b/arch/arm/mm/init.c
4066 @@ -30,6 +30,8 @@
4067 #include <asm/setup.h>
4068 #include <asm/tlb.h>
4069 #include <asm/fixmap.h>
4070 +#include <asm/system_info.h>
4071 +#include <asm/cp15.h>
4072
4073 #include <asm/mach/arch.h>
4074 #include <asm/mach/map.h>
4075 @@ -681,7 +683,46 @@ void free_initmem(void)
4076 {
4077 #ifdef CONFIG_HAVE_TCM
4078 extern char __tcm_start, __tcm_end;
4079 +#endif
4080
4081 +#ifdef CONFIG_PAX_KERNEXEC
4082 + unsigned long addr;
4083 + pgd_t *pgd;
4084 + pud_t *pud;
4085 + pmd_t *pmd;
4086 + int cpu_arch = cpu_architecture();
4087 + unsigned int cr = get_cr();
4088 +
4089 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4090 + /* make pages tables, etc before .text NX */
4091 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4092 + pgd = pgd_offset_k(addr);
4093 + pud = pud_offset(pgd, addr);
4094 + pmd = pmd_offset(pud, addr);
4095 + __section_update(pmd, addr, PMD_SECT_XN);
4096 + }
4097 + /* make init NX */
4098 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4099 + pgd = pgd_offset_k(addr);
4100 + pud = pud_offset(pgd, addr);
4101 + pmd = pmd_offset(pud, addr);
4102 + __section_update(pmd, addr, PMD_SECT_XN);
4103 + }
4104 + /* make kernel code/rodata RX */
4105 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4106 + pgd = pgd_offset_k(addr);
4107 + pud = pud_offset(pgd, addr);
4108 + pmd = pmd_offset(pud, addr);
4109 +#ifdef CONFIG_ARM_LPAE
4110 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4111 +#else
4112 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4113 +#endif
4114 + }
4115 + }
4116 +#endif
4117 +
4118 +#ifdef CONFIG_HAVE_TCM
4119 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4120 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4121 #endif
4122 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4123 index f123d6e..04bf569 100644
4124 --- a/arch/arm/mm/ioremap.c
4125 +++ b/arch/arm/mm/ioremap.c
4126 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4127 unsigned int mtype;
4128
4129 if (cached)
4130 - mtype = MT_MEMORY;
4131 + mtype = MT_MEMORY_RX;
4132 else
4133 - mtype = MT_MEMORY_NONCACHED;
4134 + mtype = MT_MEMORY_NONCACHED_RX;
4135
4136 return __arm_ioremap_caller(phys_addr, size, mtype,
4137 __builtin_return_address(0));
4138 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4139 index 5e85ed3..b10a7ed 100644
4140 --- a/arch/arm/mm/mmap.c
4141 +++ b/arch/arm/mm/mmap.c
4142 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4143 struct vm_area_struct *vma;
4144 int do_align = 0;
4145 int aliasing = cache_is_vipt_aliasing();
4146 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4147 struct vm_unmapped_area_info info;
4148
4149 /*
4150 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4151 if (len > TASK_SIZE)
4152 return -ENOMEM;
4153
4154 +#ifdef CONFIG_PAX_RANDMMAP
4155 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4156 +#endif
4157 +
4158 if (addr) {
4159 if (do_align)
4160 addr = COLOUR_ALIGN(addr, pgoff);
4161 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4162 addr = PAGE_ALIGN(addr);
4163
4164 vma = find_vma(mm, addr);
4165 - if (TASK_SIZE - len >= addr &&
4166 - (!vma || addr + len <= vma->vm_start))
4167 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4168 return addr;
4169 }
4170
4171 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4172 info.high_limit = TASK_SIZE;
4173 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4174 info.align_offset = pgoff << PAGE_SHIFT;
4175 + info.threadstack_offset = offset;
4176 return vm_unmapped_area(&info);
4177 }
4178
4179 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4180 unsigned long addr = addr0;
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 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4188 return addr;
4189 }
4190
4191 +#ifdef CONFIG_PAX_RANDMMAP
4192 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4193 +#endif
4194 +
4195 /* requesting a specific address */
4196 if (addr) {
4197 if (do_align)
4198 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4199 else
4200 addr = PAGE_ALIGN(addr);
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 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4209 info.high_limit = mm->mmap_base;
4210 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4211 info.align_offset = pgoff << PAGE_SHIFT;
4212 + info.threadstack_offset = offset;
4213 addr = vm_unmapped_area(&info);
4214
4215 /*
4216 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4217 {
4218 unsigned long random_factor = 0UL;
4219
4220 +#ifdef CONFIG_PAX_RANDMMAP
4221 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4222 +#endif
4223 +
4224 /* 8 bits of randomness in 20 address space bits */
4225 if ((current->flags & PF_RANDOMIZE) &&
4226 !(current->personality & ADDR_NO_RANDOMIZE))
4227 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4228
4229 if (mmap_is_legacy()) {
4230 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4231 +
4232 +#ifdef CONFIG_PAX_RANDMMAP
4233 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4234 + mm->mmap_base += mm->delta_mmap;
4235 +#endif
4236 +
4237 mm->get_unmapped_area = arch_get_unmapped_area;
4238 } else {
4239 mm->mmap_base = mmap_base(random_factor);
4240 +
4241 +#ifdef CONFIG_PAX_RANDMMAP
4242 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4243 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4244 +#endif
4245 +
4246 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4247 }
4248 }
4249 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4250 index 580ef2d..2da06ca 100644
4251 --- a/arch/arm/mm/mmu.c
4252 +++ b/arch/arm/mm/mmu.c
4253 @@ -38,6 +38,22 @@
4254 #include "mm.h"
4255 #include "tcm.h"
4256
4257 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4258 +void modify_domain(unsigned int dom, unsigned int type)
4259 +{
4260 + struct thread_info *thread = current_thread_info();
4261 + unsigned int domain = thread->cpu_domain;
4262 + /*
4263 + * DOMAIN_MANAGER might be defined to some other value,
4264 + * use the arch-defined constant
4265 + */
4266 + domain &= ~domain_val(dom, 3);
4267 + thread->cpu_domain = domain | domain_val(dom, type);
4268 + set_domain(thread->cpu_domain);
4269 +}
4270 +EXPORT_SYMBOL(modify_domain);
4271 +#endif
4272 +
4273 /*
4274 * empty_zero_page is a special page that is used for
4275 * zero-initialized data and COW.
4276 @@ -230,10 +246,18 @@ __setup("noalign", noalign_setup);
4277
4278 #endif /* ifdef CONFIG_CPU_CP15 / else */
4279
4280 -#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4281 +#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4282 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4283
4284 -static struct mem_type mem_types[] = {
4285 +#ifdef CONFIG_PAX_KERNEXEC
4286 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4287 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4288 +#else
4289 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4290 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4291 +#endif
4292 +
4293 +static struct mem_type mem_types[] __read_only = {
4294 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4295 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4296 L_PTE_SHARED,
4297 @@ -262,16 +286,16 @@ static struct mem_type mem_types[] = {
4298 [MT_UNCACHED] = {
4299 .prot_pte = PROT_PTE_DEVICE,
4300 .prot_l1 = PMD_TYPE_TABLE,
4301 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4302 + .prot_sect = PROT_SECT_DEVICE,
4303 .domain = DOMAIN_IO,
4304 },
4305 [MT_CACHECLEAN] = {
4306 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4307 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4308 .domain = DOMAIN_KERNEL,
4309 },
4310 #ifndef CONFIG_ARM_LPAE
4311 [MT_MINICLEAN] = {
4312 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4313 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4314 .domain = DOMAIN_KERNEL,
4315 },
4316 #endif
4317 @@ -279,36 +303,54 @@ static struct mem_type mem_types[] = {
4318 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4319 L_PTE_RDONLY,
4320 .prot_l1 = PMD_TYPE_TABLE,
4321 - .domain = DOMAIN_USER,
4322 + .domain = DOMAIN_VECTORS,
4323 },
4324 [MT_HIGH_VECTORS] = {
4325 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4326 L_PTE_USER | L_PTE_RDONLY,
4327 .prot_l1 = PMD_TYPE_TABLE,
4328 - .domain = DOMAIN_USER,
4329 + .domain = DOMAIN_VECTORS,
4330 },
4331 - [MT_MEMORY] = {
4332 + [MT_MEMORY_RWX] = {
4333 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4334 .prot_l1 = PMD_TYPE_TABLE,
4335 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4336 .domain = DOMAIN_KERNEL,
4337 },
4338 + [MT_MEMORY_RW] = {
4339 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4340 + .prot_l1 = PMD_TYPE_TABLE,
4341 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4342 + .domain = DOMAIN_KERNEL,
4343 + },
4344 + [MT_MEMORY_RX] = {
4345 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4346 + .prot_l1 = PMD_TYPE_TABLE,
4347 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4348 + .domain = DOMAIN_KERNEL,
4349 + },
4350 [MT_ROM] = {
4351 - .prot_sect = PMD_TYPE_SECT,
4352 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4353 .domain = DOMAIN_KERNEL,
4354 },
4355 - [MT_MEMORY_NONCACHED] = {
4356 + [MT_MEMORY_NONCACHED_RW] = {
4357 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4358 L_PTE_MT_BUFFERABLE,
4359 .prot_l1 = PMD_TYPE_TABLE,
4360 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4361 .domain = DOMAIN_KERNEL,
4362 },
4363 + [MT_MEMORY_NONCACHED_RX] = {
4364 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4365 + L_PTE_MT_BUFFERABLE,
4366 + .prot_l1 = PMD_TYPE_TABLE,
4367 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4368 + .domain = DOMAIN_KERNEL,
4369 + },
4370 [MT_MEMORY_DTCM] = {
4371 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4372 - L_PTE_XN,
4373 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4374 .prot_l1 = PMD_TYPE_TABLE,
4375 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4376 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4377 .domain = DOMAIN_KERNEL,
4378 },
4379 [MT_MEMORY_ITCM] = {
4380 @@ -318,10 +360,10 @@ static struct mem_type mem_types[] = {
4381 },
4382 [MT_MEMORY_SO] = {
4383 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4384 - L_PTE_MT_UNCACHED | L_PTE_XN,
4385 + L_PTE_MT_UNCACHED,
4386 .prot_l1 = PMD_TYPE_TABLE,
4387 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4388 - PMD_SECT_UNCACHED | PMD_SECT_XN,
4389 + PMD_SECT_UNCACHED,
4390 .domain = DOMAIN_KERNEL,
4391 },
4392 [MT_MEMORY_DMA_READY] = {
4393 @@ -407,9 +449,35 @@ static void __init build_mem_type_table(void)
4394 * to prevent speculative instruction fetches.
4395 */
4396 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4397 + mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4398 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4399 + mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4400 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4401 + mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4402 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4403 + mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4404 +
4405 + /* Mark other regions on ARMv6+ as execute-never */
4406 +
4407 +#ifdef CONFIG_PAX_KERNEXEC
4408 + mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4409 + mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4410 + mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4411 + mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4412 +#ifndef CONFIG_ARM_LPAE
4413 + mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4414 + mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4415 +#endif
4416 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4417 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4418 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4419 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4420 + mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4421 + mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4422 +#endif
4423 +
4424 + mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4425 + mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4426 }
4427 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4428 /*
4429 @@ -470,6 +538,9 @@ static void __init build_mem_type_table(void)
4430 * from SVC mode and no access from userspace.
4431 */
4432 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4433 +#ifdef CONFIG_PAX_KERNEXEC
4434 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4435 +#endif
4436 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4437 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4438 #endif
4439 @@ -487,11 +558,17 @@ static void __init build_mem_type_table(void)
4440 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4441 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4442 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4443 - mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4444 - mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4445 + mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4446 + mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4447 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4448 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4449 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4450 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4451 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4452 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4453 - mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4454 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4455 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4456 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4457 + mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4458 }
4459 }
4460
4461 @@ -502,15 +579,20 @@ static void __init build_mem_type_table(void)
4462 if (cpu_arch >= CPU_ARCH_ARMv6) {
4463 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4464 /* Non-cacheable Normal is XCB = 001 */
4465 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4466 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4467 + PMD_SECT_BUFFERED;
4468 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4469 PMD_SECT_BUFFERED;
4470 } else {
4471 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4472 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4473 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4474 + PMD_SECT_TEX(1);
4475 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4476 PMD_SECT_TEX(1);
4477 }
4478 } else {
4479 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4480 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4481 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4482 }
4483
4484 #ifdef CONFIG_ARM_LPAE
4485 @@ -526,6 +608,8 @@ static void __init build_mem_type_table(void)
4486 vecs_pgprot |= PTE_EXT_AF;
4487 #endif
4488
4489 + user_pgprot |= __supported_pte_mask;
4490 +
4491 for (i = 0; i < 16; i++) {
4492 pteval_t v = pgprot_val(protection_map[i]);
4493 protection_map[i] = __pgprot(v | user_pgprot);
4494 @@ -543,10 +627,15 @@ static void __init build_mem_type_table(void)
4495
4496 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4497 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4498 - mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4499 - mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4500 + mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4501 + mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4502 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4503 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4504 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4505 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4506 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4507 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4508 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4509 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4510 mem_types[MT_ROM].prot_sect |= cp->pmd;
4511
4512 switch (cp->pmd) {
4513 @@ -1188,18 +1277,15 @@ void __init arm_mm_memblock_reserve(void)
4514 * called function. This means you can't use any function or debugging
4515 * method which may touch any device, otherwise the kernel _will_ crash.
4516 */
4517 +
4518 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4519 +
4520 static void __init devicemaps_init(const struct machine_desc *mdesc)
4521 {
4522 struct map_desc map;
4523 unsigned long addr;
4524 - void *vectors;
4525
4526 - /*
4527 - * Allocate the vector page early.
4528 - */
4529 - vectors = early_alloc(PAGE_SIZE * 2);
4530 -
4531 - early_trap_init(vectors);
4532 + early_trap_init(&vectors);
4533
4534 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4535 pmd_clear(pmd_off_k(addr));
4536 @@ -1239,7 +1325,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4537 * location (0xffff0000). If we aren't using high-vectors, also
4538 * create a mapping at the low-vectors virtual address.
4539 */
4540 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4541 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4542 map.virtual = 0xffff0000;
4543 map.length = PAGE_SIZE;
4544 #ifdef CONFIG_KUSER_HELPERS
4545 @@ -1311,8 +1397,39 @@ static void __init map_lowmem(void)
4546 map.pfn = __phys_to_pfn(start);
4547 map.virtual = __phys_to_virt(start);
4548 map.length = end - start;
4549 - map.type = MT_MEMORY;
4550
4551 +#ifdef CONFIG_PAX_KERNEXEC
4552 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4553 + struct map_desc kernel;
4554 + struct map_desc initmap;
4555 +
4556 + /* when freeing initmem we will make this RW */
4557 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4558 + initmap.virtual = (unsigned long)__init_begin;
4559 + initmap.length = _sdata - __init_begin;
4560 + initmap.type = MT_MEMORY_RWX;
4561 + create_mapping(&initmap);
4562 +
4563 + /* when freeing initmem we will make this RX */
4564 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4565 + kernel.virtual = (unsigned long)_stext;
4566 + kernel.length = __init_begin - _stext;
4567 + kernel.type = MT_MEMORY_RWX;
4568 + create_mapping(&kernel);
4569 +
4570 + if (map.virtual < (unsigned long)_stext) {
4571 + map.length = (unsigned long)_stext - map.virtual;
4572 + map.type = MT_MEMORY_RWX;
4573 + create_mapping(&map);
4574 + }
4575 +
4576 + map.pfn = __phys_to_pfn(__pa(_sdata));
4577 + map.virtual = (unsigned long)_sdata;
4578 + map.length = end - __pa(_sdata);
4579 + }
4580 +#endif
4581 +
4582 + map.type = MT_MEMORY_RW;
4583 create_mapping(&map);
4584 }
4585 }
4586 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4587 index a5bc92d..0bb4730 100644
4588 --- a/arch/arm/plat-omap/sram.c
4589 +++ b/arch/arm/plat-omap/sram.c
4590 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4591 * Looks like we need to preserve some bootloader code at the
4592 * beginning of SRAM for jumping to flash for reboot to work...
4593 */
4594 + pax_open_kernel();
4595 memset_io(omap_sram_base + omap_sram_skip, 0,
4596 omap_sram_size - omap_sram_skip);
4597 + pax_close_kernel();
4598 }
4599 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4600 index ce6d763..cfea917 100644
4601 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4602 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4603 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4604 int (*started)(unsigned ch);
4605 int (*flush)(unsigned ch);
4606 int (*stop)(unsigned ch);
4607 -};
4608 +} __no_const;
4609
4610 extern void *samsung_dmadev_get_ops(void);
4611 extern void *s3c_dma_get_ops(void);
4612 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4613 index c3a58a1..78fbf54 100644
4614 --- a/arch/avr32/include/asm/cache.h
4615 +++ b/arch/avr32/include/asm/cache.h
4616 @@ -1,8 +1,10 @@
4617 #ifndef __ASM_AVR32_CACHE_H
4618 #define __ASM_AVR32_CACHE_H
4619
4620 +#include <linux/const.h>
4621 +
4622 #define L1_CACHE_SHIFT 5
4623 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4624 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4625
4626 /*
4627 * Memory returned by kmalloc() may be used for DMA, so we must make
4628 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4629 index d232888..87c8df1 100644
4630 --- a/arch/avr32/include/asm/elf.h
4631 +++ b/arch/avr32/include/asm/elf.h
4632 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4633 the loader. We need to make sure that it is out of the way of the program
4634 that it will "exec", and that there is sufficient room for the brk. */
4635
4636 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4637 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4638
4639 +#ifdef CONFIG_PAX_ASLR
4640 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4641 +
4642 +#define PAX_DELTA_MMAP_LEN 15
4643 +#define PAX_DELTA_STACK_LEN 15
4644 +#endif
4645
4646 /* This yields a mask that user programs can use to figure out what
4647 instruction set this CPU supports. This could be done in user space,
4648 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4649 index 479330b..53717a8 100644
4650 --- a/arch/avr32/include/asm/kmap_types.h
4651 +++ b/arch/avr32/include/asm/kmap_types.h
4652 @@ -2,9 +2,9 @@
4653 #define __ASM_AVR32_KMAP_TYPES_H
4654
4655 #ifdef CONFIG_DEBUG_HIGHMEM
4656 -# define KM_TYPE_NR 29
4657 +# define KM_TYPE_NR 30
4658 #else
4659 -# define KM_TYPE_NR 14
4660 +# define KM_TYPE_NR 15
4661 #endif
4662
4663 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4664 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4665 index 0eca933..eb78c7b 100644
4666 --- a/arch/avr32/mm/fault.c
4667 +++ b/arch/avr32/mm/fault.c
4668 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4669
4670 int exception_trace = 1;
4671
4672 +#ifdef CONFIG_PAX_PAGEEXEC
4673 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4674 +{
4675 + unsigned long i;
4676 +
4677 + printk(KERN_ERR "PAX: bytes at PC: ");
4678 + for (i = 0; i < 20; i++) {
4679 + unsigned char c;
4680 + if (get_user(c, (unsigned char *)pc+i))
4681 + printk(KERN_CONT "???????? ");
4682 + else
4683 + printk(KERN_CONT "%02x ", c);
4684 + }
4685 + printk("\n");
4686 +}
4687 +#endif
4688 +
4689 /*
4690 * This routine handles page faults. It determines the address and the
4691 * problem, and then passes it off to one of the appropriate routines.
4692 @@ -176,6 +193,16 @@ bad_area:
4693 up_read(&mm->mmap_sem);
4694
4695 if (user_mode(regs)) {
4696 +
4697 +#ifdef CONFIG_PAX_PAGEEXEC
4698 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4699 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4700 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4701 + do_group_exit(SIGKILL);
4702 + }
4703 + }
4704 +#endif
4705 +
4706 if (exception_trace && printk_ratelimit())
4707 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4708 "sp %08lx ecr %lu\n",
4709 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4710 index 568885a..f8008df 100644
4711 --- a/arch/blackfin/include/asm/cache.h
4712 +++ b/arch/blackfin/include/asm/cache.h
4713 @@ -7,6 +7,7 @@
4714 #ifndef __ARCH_BLACKFIN_CACHE_H
4715 #define __ARCH_BLACKFIN_CACHE_H
4716
4717 +#include <linux/const.h>
4718 #include <linux/linkage.h> /* for asmlinkage */
4719
4720 /*
4721 @@ -14,7 +15,7 @@
4722 * Blackfin loads 32 bytes for cache
4723 */
4724 #define L1_CACHE_SHIFT 5
4725 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4726 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4727 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4728
4729 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4730 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4731 index aea2718..3639a60 100644
4732 --- a/arch/cris/include/arch-v10/arch/cache.h
4733 +++ b/arch/cris/include/arch-v10/arch/cache.h
4734 @@ -1,8 +1,9 @@
4735 #ifndef _ASM_ARCH_CACHE_H
4736 #define _ASM_ARCH_CACHE_H
4737
4738 +#include <linux/const.h>
4739 /* Etrax 100LX have 32-byte cache-lines. */
4740 -#define L1_CACHE_BYTES 32
4741 #define L1_CACHE_SHIFT 5
4742 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4743
4744 #endif /* _ASM_ARCH_CACHE_H */
4745 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4746 index 7caf25d..ee65ac5 100644
4747 --- a/arch/cris/include/arch-v32/arch/cache.h
4748 +++ b/arch/cris/include/arch-v32/arch/cache.h
4749 @@ -1,11 +1,12 @@
4750 #ifndef _ASM_CRIS_ARCH_CACHE_H
4751 #define _ASM_CRIS_ARCH_CACHE_H
4752
4753 +#include <linux/const.h>
4754 #include <arch/hwregs/dma.h>
4755
4756 /* A cache-line is 32 bytes. */
4757 -#define L1_CACHE_BYTES 32
4758 #define L1_CACHE_SHIFT 5
4759 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4760
4761 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4762
4763 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4764 index b86329d..6709906 100644
4765 --- a/arch/frv/include/asm/atomic.h
4766 +++ b/arch/frv/include/asm/atomic.h
4767 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4768 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4769 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4770
4771 +#define atomic64_read_unchecked(v) atomic64_read(v)
4772 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4773 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4774 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4775 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4776 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4777 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4778 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4779 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4780 +
4781 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4782 {
4783 int c, old;
4784 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4785 index 2797163..c2a401d 100644
4786 --- a/arch/frv/include/asm/cache.h
4787 +++ b/arch/frv/include/asm/cache.h
4788 @@ -12,10 +12,11 @@
4789 #ifndef __ASM_CACHE_H
4790 #define __ASM_CACHE_H
4791
4792 +#include <linux/const.h>
4793
4794 /* bytes per L1 cache line */
4795 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4796 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4797 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4798
4799 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4800 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4801 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4802 index 43901f2..0d8b865 100644
4803 --- a/arch/frv/include/asm/kmap_types.h
4804 +++ b/arch/frv/include/asm/kmap_types.h
4805 @@ -2,6 +2,6 @@
4806 #ifndef _ASM_KMAP_TYPES_H
4807 #define _ASM_KMAP_TYPES_H
4808
4809 -#define KM_TYPE_NR 17
4810 +#define KM_TYPE_NR 18
4811
4812 #endif
4813 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4814 index 836f147..4cf23f5 100644
4815 --- a/arch/frv/mm/elf-fdpic.c
4816 +++ b/arch/frv/mm/elf-fdpic.c
4817 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4818 {
4819 struct vm_area_struct *vma;
4820 struct vm_unmapped_area_info info;
4821 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4822
4823 if (len > TASK_SIZE)
4824 return -ENOMEM;
4825 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4826 if (addr) {
4827 addr = PAGE_ALIGN(addr);
4828 vma = find_vma(current->mm, addr);
4829 - if (TASK_SIZE - len >= addr &&
4830 - (!vma || addr + len <= vma->vm_start))
4831 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4832 goto success;
4833 }
4834
4835 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4836 info.high_limit = (current->mm->start_stack - 0x00200000);
4837 info.align_mask = 0;
4838 info.align_offset = 0;
4839 + info.threadstack_offset = offset;
4840 addr = vm_unmapped_area(&info);
4841 if (!(addr & ~PAGE_MASK))
4842 goto success;
4843 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4844 index f4ca594..adc72fd6 100644
4845 --- a/arch/hexagon/include/asm/cache.h
4846 +++ b/arch/hexagon/include/asm/cache.h
4847 @@ -21,9 +21,11 @@
4848 #ifndef __ASM_CACHE_H
4849 #define __ASM_CACHE_H
4850
4851 +#include <linux/const.h>
4852 +
4853 /* Bytes per L1 cache line */
4854 -#define L1_CACHE_SHIFT (5)
4855 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4856 +#define L1_CACHE_SHIFT 5
4857 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4858
4859 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4860 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4861 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4862 index 4e4119b..dd7de0a 100644
4863 --- a/arch/ia64/Kconfig
4864 +++ b/arch/ia64/Kconfig
4865 @@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4866 config KEXEC
4867 bool "kexec system call"
4868 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4869 + depends on !GRKERNSEC_KMEM
4870 help
4871 kexec is a system call that implements the ability to shutdown your
4872 current kernel, and to start another kernel. It is like a reboot
4873 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4874 index 6e6fe18..a6ae668 100644
4875 --- a/arch/ia64/include/asm/atomic.h
4876 +++ b/arch/ia64/include/asm/atomic.h
4877 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4878 #define atomic64_inc(v) atomic64_add(1, (v))
4879 #define atomic64_dec(v) atomic64_sub(1, (v))
4880
4881 +#define atomic64_read_unchecked(v) atomic64_read(v)
4882 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4883 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4884 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4885 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4886 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4887 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4888 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4889 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4890 +
4891 /* Atomic operations are already serializing */
4892 #define smp_mb__before_atomic_dec() barrier()
4893 #define smp_mb__after_atomic_dec() barrier()
4894 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4895 index 988254a..e1ee885 100644
4896 --- a/arch/ia64/include/asm/cache.h
4897 +++ b/arch/ia64/include/asm/cache.h
4898 @@ -1,6 +1,7 @@
4899 #ifndef _ASM_IA64_CACHE_H
4900 #define _ASM_IA64_CACHE_H
4901
4902 +#include <linux/const.h>
4903
4904 /*
4905 * Copyright (C) 1998-2000 Hewlett-Packard Co
4906 @@ -9,7 +10,7 @@
4907
4908 /* Bytes per L1 (data) cache line. */
4909 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4910 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4911 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4912
4913 #ifdef CONFIG_SMP
4914 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4915 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4916 index 5a83c5c..4d7f553 100644
4917 --- a/arch/ia64/include/asm/elf.h
4918 +++ b/arch/ia64/include/asm/elf.h
4919 @@ -42,6 +42,13 @@
4920 */
4921 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4922
4923 +#ifdef CONFIG_PAX_ASLR
4924 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4925 +
4926 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4927 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4928 +#endif
4929 +
4930 #define PT_IA_64_UNWIND 0x70000001
4931
4932 /* IA-64 relocations: */
4933 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4934 index 5767cdf..7462574 100644
4935 --- a/arch/ia64/include/asm/pgalloc.h
4936 +++ b/arch/ia64/include/asm/pgalloc.h
4937 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4938 pgd_val(*pgd_entry) = __pa(pud);
4939 }
4940
4941 +static inline void
4942 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4943 +{
4944 + pgd_populate(mm, pgd_entry, pud);
4945 +}
4946 +
4947 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4948 {
4949 return quicklist_alloc(0, GFP_KERNEL, NULL);
4950 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4951 pud_val(*pud_entry) = __pa(pmd);
4952 }
4953
4954 +static inline void
4955 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4956 +{
4957 + pud_populate(mm, pud_entry, pmd);
4958 +}
4959 +
4960 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4961 {
4962 return quicklist_alloc(0, GFP_KERNEL, NULL);
4963 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4964 index 7935115..c0eca6a 100644
4965 --- a/arch/ia64/include/asm/pgtable.h
4966 +++ b/arch/ia64/include/asm/pgtable.h
4967 @@ -12,7 +12,7 @@
4968 * David Mosberger-Tang <davidm@hpl.hp.com>
4969 */
4970
4971 -
4972 +#include <linux/const.h>
4973 #include <asm/mman.h>
4974 #include <asm/page.h>
4975 #include <asm/processor.h>
4976 @@ -142,6 +142,17 @@
4977 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4978 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4979 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4980 +
4981 +#ifdef CONFIG_PAX_PAGEEXEC
4982 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4983 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4984 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4985 +#else
4986 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4987 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4988 +# define PAGE_COPY_NOEXEC PAGE_COPY
4989 +#endif
4990 +
4991 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4992 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4993 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4994 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4995 index 45698cd..e8e2dbc 100644
4996 --- a/arch/ia64/include/asm/spinlock.h
4997 +++ b/arch/ia64/include/asm/spinlock.h
4998 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4999 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5000
5001 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5002 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5003 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5004 }
5005
5006 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5007 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5008 index 449c8c0..18965fb 100644
5009 --- a/arch/ia64/include/asm/uaccess.h
5010 +++ b/arch/ia64/include/asm/uaccess.h
5011 @@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5012 static inline unsigned long
5013 __copy_to_user (void __user *to, const void *from, unsigned long count)
5014 {
5015 + if (count > INT_MAX)
5016 + return count;
5017 +
5018 + if (!__builtin_constant_p(count))
5019 + check_object_size(from, count, true);
5020 +
5021 return __copy_user(to, (__force void __user *) from, count);
5022 }
5023
5024 static inline unsigned long
5025 __copy_from_user (void *to, const void __user *from, unsigned long count)
5026 {
5027 + if (count > INT_MAX)
5028 + return count;
5029 +
5030 + if (!__builtin_constant_p(count))
5031 + check_object_size(to, count, false);
5032 +
5033 return __copy_user((__force void __user *) to, from, count);
5034 }
5035
5036 @@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5037 ({ \
5038 void __user *__cu_to = (to); \
5039 const void *__cu_from = (from); \
5040 - long __cu_len = (n); \
5041 + unsigned long __cu_len = (n); \
5042 \
5043 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5044 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5045 + if (!__builtin_constant_p(n)) \
5046 + check_object_size(__cu_from, __cu_len, true); \
5047 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5048 + } \
5049 __cu_len; \
5050 })
5051
5052 @@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5053 ({ \
5054 void *__cu_to = (to); \
5055 const void __user *__cu_from = (from); \
5056 - long __cu_len = (n); \
5057 + unsigned long __cu_len = (n); \
5058 \
5059 __chk_user_ptr(__cu_from); \
5060 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5061 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5062 + if (!__builtin_constant_p(n)) \
5063 + check_object_size(__cu_to, __cu_len, false); \
5064 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5065 + } \
5066 __cu_len; \
5067 })
5068
5069 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5070 index 24603be..948052d 100644
5071 --- a/arch/ia64/kernel/module.c
5072 +++ b/arch/ia64/kernel/module.c
5073 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5074 void
5075 module_free (struct module *mod, void *module_region)
5076 {
5077 - if (mod && mod->arch.init_unw_table &&
5078 - module_region == mod->module_init) {
5079 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5080 unw_remove_unwind_table(mod->arch.init_unw_table);
5081 mod->arch.init_unw_table = NULL;
5082 }
5083 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5084 }
5085
5086 static inline int
5087 +in_init_rx (const struct module *mod, uint64_t addr)
5088 +{
5089 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5090 +}
5091 +
5092 +static inline int
5093 +in_init_rw (const struct module *mod, uint64_t addr)
5094 +{
5095 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5096 +}
5097 +
5098 +static inline int
5099 in_init (const struct module *mod, uint64_t addr)
5100 {
5101 - return addr - (uint64_t) mod->module_init < mod->init_size;
5102 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5103 +}
5104 +
5105 +static inline int
5106 +in_core_rx (const struct module *mod, uint64_t addr)
5107 +{
5108 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5109 +}
5110 +
5111 +static inline int
5112 +in_core_rw (const struct module *mod, uint64_t addr)
5113 +{
5114 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5115 }
5116
5117 static inline int
5118 in_core (const struct module *mod, uint64_t addr)
5119 {
5120 - return addr - (uint64_t) mod->module_core < mod->core_size;
5121 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5122 }
5123
5124 static inline int
5125 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5126 break;
5127
5128 case RV_BDREL:
5129 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5130 + if (in_init_rx(mod, val))
5131 + val -= (uint64_t) mod->module_init_rx;
5132 + else if (in_init_rw(mod, val))
5133 + val -= (uint64_t) mod->module_init_rw;
5134 + else if (in_core_rx(mod, val))
5135 + val -= (uint64_t) mod->module_core_rx;
5136 + else if (in_core_rw(mod, val))
5137 + val -= (uint64_t) mod->module_core_rw;
5138 break;
5139
5140 case RV_LTV:
5141 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5142 * addresses have been selected...
5143 */
5144 uint64_t gp;
5145 - if (mod->core_size > MAX_LTOFF)
5146 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5147 /*
5148 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5149 * at the end of the module.
5150 */
5151 - gp = mod->core_size - MAX_LTOFF / 2;
5152 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5153 else
5154 - gp = mod->core_size / 2;
5155 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5156 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5157 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5158 mod->arch.gp = gp;
5159 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5160 }
5161 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5162 index ab33328..f39506c 100644
5163 --- a/arch/ia64/kernel/palinfo.c
5164 +++ b/arch/ia64/kernel/palinfo.c
5165 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5166 return NOTIFY_OK;
5167 }
5168
5169 -static struct notifier_block __refdata palinfo_cpu_notifier =
5170 +static struct notifier_block palinfo_cpu_notifier =
5171 {
5172 .notifier_call = palinfo_cpu_callback,
5173 .priority = 0,
5174 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5175 index 41e33f8..65180b2a 100644
5176 --- a/arch/ia64/kernel/sys_ia64.c
5177 +++ b/arch/ia64/kernel/sys_ia64.c
5178 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5179 unsigned long align_mask = 0;
5180 struct mm_struct *mm = current->mm;
5181 struct vm_unmapped_area_info info;
5182 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5183
5184 if (len > RGN_MAP_LIMIT)
5185 return -ENOMEM;
5186 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5187 if (REGION_NUMBER(addr) == RGN_HPAGE)
5188 addr = 0;
5189 #endif
5190 +
5191 +#ifdef CONFIG_PAX_RANDMMAP
5192 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5193 + addr = mm->free_area_cache;
5194 + else
5195 +#endif
5196 +
5197 if (!addr)
5198 addr = TASK_UNMAPPED_BASE;
5199
5200 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5201 info.high_limit = TASK_SIZE;
5202 info.align_mask = align_mask;
5203 info.align_offset = 0;
5204 + info.threadstack_offset = offset;
5205 return vm_unmapped_area(&info);
5206 }
5207
5208 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5209 index 0ccb28f..8992469 100644
5210 --- a/arch/ia64/kernel/vmlinux.lds.S
5211 +++ b/arch/ia64/kernel/vmlinux.lds.S
5212 @@ -198,7 +198,7 @@ SECTIONS {
5213 /* Per-cpu data: */
5214 . = ALIGN(PERCPU_PAGE_SIZE);
5215 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5216 - __phys_per_cpu_start = __per_cpu_load;
5217 + __phys_per_cpu_start = per_cpu_load;
5218 /*
5219 * ensure percpu data fits
5220 * into percpu page size
5221 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5222 index 7225dad..2a7c8256 100644
5223 --- a/arch/ia64/mm/fault.c
5224 +++ b/arch/ia64/mm/fault.c
5225 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5226 return pte_present(pte);
5227 }
5228
5229 +#ifdef CONFIG_PAX_PAGEEXEC
5230 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5231 +{
5232 + unsigned long i;
5233 +
5234 + printk(KERN_ERR "PAX: bytes at PC: ");
5235 + for (i = 0; i < 8; i++) {
5236 + unsigned int c;
5237 + if (get_user(c, (unsigned int *)pc+i))
5238 + printk(KERN_CONT "???????? ");
5239 + else
5240 + printk(KERN_CONT "%08x ", c);
5241 + }
5242 + printk("\n");
5243 +}
5244 +#endif
5245 +
5246 # define VM_READ_BIT 0
5247 # define VM_WRITE_BIT 1
5248 # define VM_EXEC_BIT 2
5249 @@ -151,8 +168,21 @@ retry:
5250 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5251 goto bad_area;
5252
5253 - if ((vma->vm_flags & mask) != mask)
5254 + if ((vma->vm_flags & mask) != mask) {
5255 +
5256 +#ifdef CONFIG_PAX_PAGEEXEC
5257 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5258 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5259 + goto bad_area;
5260 +
5261 + up_read(&mm->mmap_sem);
5262 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5263 + do_group_exit(SIGKILL);
5264 + }
5265 +#endif
5266 +
5267 goto bad_area;
5268 + }
5269
5270 /*
5271 * If for any reason at all we couldn't handle the fault, make
5272 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5273 index 68232db..6ca80af 100644
5274 --- a/arch/ia64/mm/hugetlbpage.c
5275 +++ b/arch/ia64/mm/hugetlbpage.c
5276 @@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5277 unsigned long pgoff, unsigned long flags)
5278 {
5279 struct vm_unmapped_area_info info;
5280 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5281
5282 if (len > RGN_MAP_LIMIT)
5283 return -ENOMEM;
5284 @@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5285 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5286 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5287 info.align_offset = 0;
5288 + info.threadstack_offset = offset;
5289 return vm_unmapped_area(&info);
5290 }
5291
5292 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5293 index 88504ab..cbb6c9f 100644
5294 --- a/arch/ia64/mm/init.c
5295 +++ b/arch/ia64/mm/init.c
5296 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5297 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5298 vma->vm_end = vma->vm_start + PAGE_SIZE;
5299 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5300 +
5301 +#ifdef CONFIG_PAX_PAGEEXEC
5302 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5303 + vma->vm_flags &= ~VM_EXEC;
5304 +
5305 +#ifdef CONFIG_PAX_MPROTECT
5306 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5307 + vma->vm_flags &= ~VM_MAYEXEC;
5308 +#endif
5309 +
5310 + }
5311 +#endif
5312 +
5313 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5314 down_write(&current->mm->mmap_sem);
5315 if (insert_vm_struct(current->mm, vma)) {
5316 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5317 index 40b3ee9..8c2c112 100644
5318 --- a/arch/m32r/include/asm/cache.h
5319 +++ b/arch/m32r/include/asm/cache.h
5320 @@ -1,8 +1,10 @@
5321 #ifndef _ASM_M32R_CACHE_H
5322 #define _ASM_M32R_CACHE_H
5323
5324 +#include <linux/const.h>
5325 +
5326 /* L1 cache line size */
5327 #define L1_CACHE_SHIFT 4
5328 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5329 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5330
5331 #endif /* _ASM_M32R_CACHE_H */
5332 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5333 index 82abd15..d95ae5d 100644
5334 --- a/arch/m32r/lib/usercopy.c
5335 +++ b/arch/m32r/lib/usercopy.c
5336 @@ -14,6 +14,9 @@
5337 unsigned long
5338 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5339 {
5340 + if ((long)n < 0)
5341 + return n;
5342 +
5343 prefetch(from);
5344 if (access_ok(VERIFY_WRITE, to, n))
5345 __copy_user(to,from,n);
5346 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5347 unsigned long
5348 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5349 {
5350 + if ((long)n < 0)
5351 + return n;
5352 +
5353 prefetchw(to);
5354 if (access_ok(VERIFY_READ, from, n))
5355 __copy_user_zeroing(to,from,n);
5356 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5357 index 0395c51..5f26031 100644
5358 --- a/arch/m68k/include/asm/cache.h
5359 +++ b/arch/m68k/include/asm/cache.h
5360 @@ -4,9 +4,11 @@
5361 #ifndef __ARCH_M68K_CACHE_H
5362 #define __ARCH_M68K_CACHE_H
5363
5364 +#include <linux/const.h>
5365 +
5366 /* bytes per L1 cache line */
5367 #define L1_CACHE_SHIFT 4
5368 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5369 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5370
5371 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5372
5373 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5374 index 0424315..defcca9 100644
5375 --- a/arch/metag/mm/hugetlbpage.c
5376 +++ b/arch/metag/mm/hugetlbpage.c
5377 @@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5378 info.high_limit = TASK_SIZE;
5379 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5380 info.align_offset = 0;
5381 + info.threadstack_offset = 0;
5382 return vm_unmapped_area(&info);
5383 }
5384
5385 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5386 index 4efe96a..60e8699 100644
5387 --- a/arch/microblaze/include/asm/cache.h
5388 +++ b/arch/microblaze/include/asm/cache.h
5389 @@ -13,11 +13,12 @@
5390 #ifndef _ASM_MICROBLAZE_CACHE_H
5391 #define _ASM_MICROBLAZE_CACHE_H
5392
5393 +#include <linux/const.h>
5394 #include <asm/registers.h>
5395
5396 #define L1_CACHE_SHIFT 5
5397 /* word-granular cache in microblaze */
5398 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5399 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5400
5401 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5402
5403 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5404 index 650de39..6982b02 100644
5405 --- a/arch/mips/Kconfig
5406 +++ b/arch/mips/Kconfig
5407 @@ -2268,6 +2268,7 @@ source "kernel/Kconfig.preempt"
5408
5409 config KEXEC
5410 bool "Kexec system call"
5411 + depends on !GRKERNSEC_KMEM
5412 help
5413 kexec is a system call that implements the ability to shutdown your
5414 current kernel, and to start another kernel. It is like a reboot
5415 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5416 index 7eed2f2..c4e385d 100644
5417 --- a/arch/mips/include/asm/atomic.h
5418 +++ b/arch/mips/include/asm/atomic.h
5419 @@ -21,15 +21,39 @@
5420 #include <asm/cmpxchg.h>
5421 #include <asm/war.h>
5422
5423 +#ifdef CONFIG_GENERIC_ATOMIC64
5424 +#include <asm-generic/atomic64.h>
5425 +#endif
5426 +
5427 #define ATOMIC_INIT(i) { (i) }
5428
5429 +#ifdef CONFIG_64BIT
5430 +#define _ASM_EXTABLE(from, to) \
5431 +" .section __ex_table,\"a\"\n" \
5432 +" .dword " #from ", " #to"\n" \
5433 +" .previous\n"
5434 +#else
5435 +#define _ASM_EXTABLE(from, to) \
5436 +" .section __ex_table,\"a\"\n" \
5437 +" .word " #from ", " #to"\n" \
5438 +" .previous\n"
5439 +#endif
5440 +
5441 /*
5442 * atomic_read - read atomic variable
5443 * @v: pointer of type atomic_t
5444 *
5445 * Atomically reads the value of @v.
5446 */
5447 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5448 +static inline int atomic_read(const atomic_t *v)
5449 +{
5450 + return (*(volatile const int *) &v->counter);
5451 +}
5452 +
5453 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5454 +{
5455 + return (*(volatile const int *) &v->counter);
5456 +}
5457
5458 /*
5459 * atomic_set - set atomic variable
5460 @@ -38,7 +62,15 @@
5461 *
5462 * Atomically sets the value of @v to @i.
5463 */
5464 -#define atomic_set(v, i) ((v)->counter = (i))
5465 +static inline void atomic_set(atomic_t *v, int i)
5466 +{
5467 + v->counter = i;
5468 +}
5469 +
5470 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5471 +{
5472 + v->counter = i;
5473 +}
5474
5475 /*
5476 * atomic_add - add integer to atomic variable
5477 @@ -47,7 +79,67 @@
5478 *
5479 * Atomically adds @i to @v.
5480 */
5481 -static __inline__ void atomic_add(int i, atomic_t * v)
5482 +static __inline__ void atomic_add(int i, atomic_t *v)
5483 +{
5484 + int temp;
5485 +
5486 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5487 + __asm__ __volatile__(
5488 + " .set mips3 \n"
5489 + "1: ll %0, %1 # atomic_add \n"
5490 +#ifdef CONFIG_PAX_REFCOUNT
5491 + /* Exception on overflow. */
5492 + "2: add %0, %2 \n"
5493 +#else
5494 + " addu %0, %2 \n"
5495 +#endif
5496 + " sc %0, %1 \n"
5497 + " beqzl %0, 1b \n"
5498 +#ifdef CONFIG_PAX_REFCOUNT
5499 + "3: \n"
5500 + _ASM_EXTABLE(2b, 3b)
5501 +#endif
5502 + " .set mips0 \n"
5503 + : "=&r" (temp), "+m" (v->counter)
5504 + : "Ir" (i));
5505 + } else if (kernel_uses_llsc) {
5506 + __asm__ __volatile__(
5507 + " .set mips3 \n"
5508 + "1: ll %0, %1 # atomic_add \n"
5509 +#ifdef CONFIG_PAX_REFCOUNT
5510 + /* Exception on overflow. */
5511 + "2: add %0, %2 \n"
5512 +#else
5513 + " addu %0, %2 \n"
5514 +#endif
5515 + " sc %0, %1 \n"
5516 + " beqz %0, 1b \n"
5517 +#ifdef CONFIG_PAX_REFCOUNT
5518 + "3: \n"
5519 + _ASM_EXTABLE(2b, 3b)
5520 +#endif
5521 + " .set mips0 \n"
5522 + : "=&r" (temp), "+m" (v->counter)
5523 + : "Ir" (i));
5524 + } else {
5525 + unsigned long flags;
5526 +
5527 + raw_local_irq_save(flags);
5528 + __asm__ __volatile__(
5529 +#ifdef CONFIG_PAX_REFCOUNT
5530 + /* Exception on overflow. */
5531 + "1: add %0, %1 \n"
5532 + "2: \n"
5533 + _ASM_EXTABLE(1b, 2b)
5534 +#else
5535 + " addu %0, %1 \n"
5536 +#endif
5537 + : "+r" (v->counter) : "Ir" (i));
5538 + raw_local_irq_restore(flags);
5539 + }
5540 +}
5541 +
5542 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5543 {
5544 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5545 int temp;
5546 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5547 *
5548 * Atomically subtracts @i from @v.
5549 */
5550 -static __inline__ void atomic_sub(int i, atomic_t * v)
5551 +static __inline__ void atomic_sub(int i, atomic_t *v)
5552 +{
5553 + int temp;
5554 +
5555 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5556 + __asm__ __volatile__(
5557 + " .set mips3 \n"
5558 + "1: ll %0, %1 # atomic64_sub \n"
5559 +#ifdef CONFIG_PAX_REFCOUNT
5560 + /* Exception on overflow. */
5561 + "2: sub %0, %2 \n"
5562 +#else
5563 + " subu %0, %2 \n"
5564 +#endif
5565 + " sc %0, %1 \n"
5566 + " beqzl %0, 1b \n"
5567 +#ifdef CONFIG_PAX_REFCOUNT
5568 + "3: \n"
5569 + _ASM_EXTABLE(2b, 3b)
5570 +#endif
5571 + " .set mips0 \n"
5572 + : "=&r" (temp), "+m" (v->counter)
5573 + : "Ir" (i));
5574 + } else if (kernel_uses_llsc) {
5575 + __asm__ __volatile__(
5576 + " .set mips3 \n"
5577 + "1: ll %0, %1 # atomic64_sub \n"
5578 +#ifdef CONFIG_PAX_REFCOUNT
5579 + /* Exception on overflow. */
5580 + "2: sub %0, %2 \n"
5581 +#else
5582 + " subu %0, %2 \n"
5583 +#endif
5584 + " sc %0, %1 \n"
5585 + " beqz %0, 1b \n"
5586 +#ifdef CONFIG_PAX_REFCOUNT
5587 + "3: \n"
5588 + _ASM_EXTABLE(2b, 3b)
5589 +#endif
5590 + " .set mips0 \n"
5591 + : "=&r" (temp), "+m" (v->counter)
5592 + : "Ir" (i));
5593 + } else {
5594 + unsigned long flags;
5595 +
5596 + raw_local_irq_save(flags);
5597 + __asm__ __volatile__(
5598 +#ifdef CONFIG_PAX_REFCOUNT
5599 + /* Exception on overflow. */
5600 + "1: sub %0, %1 \n"
5601 + "2: \n"
5602 + _ASM_EXTABLE(1b, 2b)
5603 +#else
5604 + " subu %0, %1 \n"
5605 +#endif
5606 + : "+r" (v->counter) : "Ir" (i));
5607 + raw_local_irq_restore(flags);
5608 + }
5609 +}
5610 +
5611 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5612 {
5613 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5614 int temp;
5615 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5616 /*
5617 * Same as above, but return the result value
5618 */
5619 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5620 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5621 +{
5622 + int result;
5623 + int temp;
5624 +
5625 + smp_mb__before_llsc();
5626 +
5627 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5628 + __asm__ __volatile__(
5629 + " .set mips3 \n"
5630 + "1: ll %1, %2 # atomic_add_return \n"
5631 +#ifdef CONFIG_PAX_REFCOUNT
5632 + "2: add %0, %1, %3 \n"
5633 +#else
5634 + " addu %0, %1, %3 \n"
5635 +#endif
5636 + " sc %0, %2 \n"
5637 + " beqzl %0, 1b \n"
5638 +#ifdef CONFIG_PAX_REFCOUNT
5639 + " b 4f \n"
5640 + " .set noreorder \n"
5641 + "3: b 5f \n"
5642 + " move %0, %1 \n"
5643 + " .set reorder \n"
5644 + _ASM_EXTABLE(2b, 3b)
5645 +#endif
5646 + "4: addu %0, %1, %3 \n"
5647 +#ifdef CONFIG_PAX_REFCOUNT
5648 + "5: \n"
5649 +#endif
5650 + " .set mips0 \n"
5651 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5652 + : "Ir" (i));
5653 + } else if (kernel_uses_llsc) {
5654 + __asm__ __volatile__(
5655 + " .set mips3 \n"
5656 + "1: ll %1, %2 # atomic_add_return \n"
5657 +#ifdef CONFIG_PAX_REFCOUNT
5658 + "2: add %0, %1, %3 \n"
5659 +#else
5660 + " addu %0, %1, %3 \n"
5661 +#endif
5662 + " sc %0, %2 \n"
5663 + " bnez %0, 4f \n"
5664 + " b 1b \n"
5665 +#ifdef CONFIG_PAX_REFCOUNT
5666 + " .set noreorder \n"
5667 + "3: b 5f \n"
5668 + " move %0, %1 \n"
5669 + " .set reorder \n"
5670 + _ASM_EXTABLE(2b, 3b)
5671 +#endif
5672 + "4: addu %0, %1, %3 \n"
5673 +#ifdef CONFIG_PAX_REFCOUNT
5674 + "5: \n"
5675 +#endif
5676 + " .set mips0 \n"
5677 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5678 + : "Ir" (i));
5679 + } else {
5680 + unsigned long flags;
5681 +
5682 + raw_local_irq_save(flags);
5683 + __asm__ __volatile__(
5684 + " lw %0, %1 \n"
5685 +#ifdef CONFIG_PAX_REFCOUNT
5686 + /* Exception on overflow. */
5687 + "1: add %0, %2 \n"
5688 +#else
5689 + " addu %0, %2 \n"
5690 +#endif
5691 + " sw %0, %1 \n"
5692 +#ifdef CONFIG_PAX_REFCOUNT
5693 + /* Note: Dest reg is not modified on overflow */
5694 + "2: \n"
5695 + _ASM_EXTABLE(1b, 2b)
5696 +#endif
5697 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5698 + raw_local_irq_restore(flags);
5699 + }
5700 +
5701 + smp_llsc_mb();
5702 +
5703 + return result;
5704 +}
5705 +
5706 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5707 {
5708 int result;
5709
5710 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5711 return result;
5712 }
5713
5714 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5715 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5716 +{
5717 + int result;
5718 + int temp;
5719 +
5720 + smp_mb__before_llsc();
5721 +
5722 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5723 + __asm__ __volatile__(
5724 + " .set mips3 \n"
5725 + "1: ll %1, %2 # atomic_sub_return \n"
5726 +#ifdef CONFIG_PAX_REFCOUNT
5727 + "2: sub %0, %1, %3 \n"
5728 +#else
5729 + " subu %0, %1, %3 \n"
5730 +#endif
5731 + " sc %0, %2 \n"
5732 + " beqzl %0, 1b \n"
5733 +#ifdef CONFIG_PAX_REFCOUNT
5734 + " b 4f \n"
5735 + " .set noreorder \n"
5736 + "3: b 5f \n"
5737 + " move %0, %1 \n"
5738 + " .set reorder \n"
5739 + _ASM_EXTABLE(2b, 3b)
5740 +#endif
5741 + "4: subu %0, %1, %3 \n"
5742 +#ifdef CONFIG_PAX_REFCOUNT
5743 + "5: \n"
5744 +#endif
5745 + " .set mips0 \n"
5746 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5747 + : "Ir" (i), "m" (v->counter)
5748 + : "memory");
5749 + } else if (kernel_uses_llsc) {
5750 + __asm__ __volatile__(
5751 + " .set mips3 \n"
5752 + "1: ll %1, %2 # atomic_sub_return \n"
5753 +#ifdef CONFIG_PAX_REFCOUNT
5754 + "2: sub %0, %1, %3 \n"
5755 +#else
5756 + " subu %0, %1, %3 \n"
5757 +#endif
5758 + " sc %0, %2 \n"
5759 + " bnez %0, 4f \n"
5760 + " b 1b \n"
5761 +#ifdef CONFIG_PAX_REFCOUNT
5762 + " .set noreorder \n"
5763 + "3: b 5f \n"
5764 + " move %0, %1 \n"
5765 + " .set reorder \n"
5766 + _ASM_EXTABLE(2b, 3b)
5767 +#endif
5768 + "4: subu %0, %1, %3 \n"
5769 +#ifdef CONFIG_PAX_REFCOUNT
5770 + "5: \n"
5771 +#endif
5772 + " .set mips0 \n"
5773 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5774 + : "Ir" (i));
5775 + } else {
5776 + unsigned long flags;
5777 +
5778 + raw_local_irq_save(flags);
5779 + __asm__ __volatile__(
5780 + " lw %0, %1 \n"
5781 +#ifdef CONFIG_PAX_REFCOUNT
5782 + /* Exception on overflow. */
5783 + "1: sub %0, %2 \n"
5784 +#else
5785 + " subu %0, %2 \n"
5786 +#endif
5787 + " sw %0, %1 \n"
5788 +#ifdef CONFIG_PAX_REFCOUNT
5789 + /* Note: Dest reg is not modified on overflow */
5790 + "2: \n"
5791 + _ASM_EXTABLE(1b, 2b)
5792 +#endif
5793 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5794 + raw_local_irq_restore(flags);
5795 + }
5796 +
5797 + smp_llsc_mb();
5798 +
5799 + return result;
5800 +}
5801 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5802 {
5803 int result;
5804
5805 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5806 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5807 * The function returns the old value of @v minus @i.
5808 */
5809 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5810 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5811 {
5812 int result;
5813
5814 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5815 return result;
5816 }
5817
5818 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5819 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5820 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5821 +{
5822 + return cmpxchg(&v->counter, old, new);
5823 +}
5824 +
5825 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5826 + int new)
5827 +{
5828 + return cmpxchg(&(v->counter), old, new);
5829 +}
5830 +
5831 +static inline int atomic_xchg(atomic_t *v, int new)
5832 +{
5833 + return xchg(&v->counter, new);
5834 +}
5835 +
5836 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5837 +{
5838 + return xchg(&(v->counter), new);
5839 +}
5840
5841 /**
5842 * __atomic_add_unless - add unless the number is a given value
5843 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5844
5845 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5846 #define atomic_inc_return(v) atomic_add_return(1, (v))
5847 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5848 +{
5849 + return atomic_add_return_unchecked(1, v);
5850 +}
5851
5852 /*
5853 * atomic_sub_and_test - subtract value from variable and test result
5854 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5855 * other cases.
5856 */
5857 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5858 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5859 +{
5860 + return atomic_add_return_unchecked(1, v) == 0;
5861 +}
5862
5863 /*
5864 * atomic_dec_and_test - decrement by 1 and test
5865 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5866 * Atomically increments @v by 1.
5867 */
5868 #define atomic_inc(v) atomic_add(1, (v))
5869 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5870 +{
5871 + atomic_add_unchecked(1, v);
5872 +}
5873
5874 /*
5875 * atomic_dec - decrement and test
5876 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5877 * Atomically decrements @v by 1.
5878 */
5879 #define atomic_dec(v) atomic_sub(1, (v))
5880 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5881 +{
5882 + atomic_sub_unchecked(1, v);
5883 +}
5884
5885 /*
5886 * atomic_add_negative - add and test if negative
5887 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5888 * @v: pointer of type atomic64_t
5889 *
5890 */
5891 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5892 +static inline long atomic64_read(const atomic64_t *v)
5893 +{
5894 + return (*(volatile const long *) &v->counter);
5895 +}
5896 +
5897 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5898 +{
5899 + return (*(volatile const long *) &v->counter);
5900 +}
5901
5902 /*
5903 * atomic64_set - set atomic variable
5904 * @v: pointer of type atomic64_t
5905 * @i: required value
5906 */
5907 -#define atomic64_set(v, i) ((v)->counter = (i))
5908 +static inline void atomic64_set(atomic64_t *v, long i)
5909 +{
5910 + v->counter = i;
5911 +}
5912 +
5913 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5914 +{
5915 + v->counter = i;
5916 +}
5917
5918 /*
5919 * atomic64_add - add integer to atomic variable
5920 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5921 *
5922 * Atomically adds @i to @v.
5923 */
5924 -static __inline__ void atomic64_add(long i, atomic64_t * v)
5925 +static __inline__ void atomic64_add(long i, atomic64_t *v)
5926 +{
5927 + long temp;
5928 +
5929 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5930 + __asm__ __volatile__(
5931 + " .set mips3 \n"
5932 + "1: lld %0, %1 # atomic64_add \n"
5933 +#ifdef CONFIG_PAX_REFCOUNT
5934 + /* Exception on overflow. */
5935 + "2: dadd %0, %2 \n"
5936 +#else
5937 + " daddu %0, %2 \n"
5938 +#endif
5939 + " scd %0, %1 \n"
5940 + " beqzl %0, 1b \n"
5941 +#ifdef CONFIG_PAX_REFCOUNT
5942 + "3: \n"
5943 + _ASM_EXTABLE(2b, 3b)
5944 +#endif
5945 + " .set mips0 \n"
5946 + : "=&r" (temp), "+m" (v->counter)
5947 + : "Ir" (i));
5948 + } else if (kernel_uses_llsc) {
5949 + __asm__ __volatile__(
5950 + " .set mips3 \n"
5951 + "1: lld %0, %1 # atomic64_add \n"
5952 +#ifdef CONFIG_PAX_REFCOUNT
5953 + /* Exception on overflow. */
5954 + "2: dadd %0, %2 \n"
5955 +#else
5956 + " daddu %0, %2 \n"
5957 +#endif
5958 + " scd %0, %1 \n"
5959 + " beqz %0, 1b \n"
5960 +#ifdef CONFIG_PAX_REFCOUNT
5961 + "3: \n"
5962 + _ASM_EXTABLE(2b, 3b)
5963 +#endif
5964 + " .set mips0 \n"
5965 + : "=&r" (temp), "+m" (v->counter)
5966 + : "Ir" (i));
5967 + } else {
5968 + unsigned long flags;
5969 +
5970 + raw_local_irq_save(flags);
5971 + __asm__ __volatile__(
5972 +#ifdef CONFIG_PAX_REFCOUNT
5973 + /* Exception on overflow. */
5974 + "1: dadd %0, %1 \n"
5975 + "2: \n"
5976 + _ASM_EXTABLE(1b, 2b)
5977 +#else
5978 + " daddu %0, %1 \n"
5979 +#endif
5980 + : "+r" (v->counter) : "Ir" (i));
5981 + raw_local_irq_restore(flags);
5982 + }
5983 +}
5984 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5985 {
5986 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5987 long temp;
5988 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5989 *
5990 * Atomically subtracts @i from @v.
5991 */
5992 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
5993 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
5994 +{
5995 + long temp;
5996 +
5997 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5998 + __asm__ __volatile__(
5999 + " .set mips3 \n"
6000 + "1: lld %0, %1 # atomic64_sub \n"
6001 +#ifdef CONFIG_PAX_REFCOUNT
6002 + /* Exception on overflow. */
6003 + "2: dsub %0, %2 \n"
6004 +#else
6005 + " dsubu %0, %2 \n"
6006 +#endif
6007 + " scd %0, %1 \n"
6008 + " beqzl %0, 1b \n"
6009 +#ifdef CONFIG_PAX_REFCOUNT
6010 + "3: \n"
6011 + _ASM_EXTABLE(2b, 3b)
6012 +#endif
6013 + " .set mips0 \n"
6014 + : "=&r" (temp), "+m" (v->counter)
6015 + : "Ir" (i));
6016 + } else if (kernel_uses_llsc) {
6017 + __asm__ __volatile__(
6018 + " .set mips3 \n"
6019 + "1: lld %0, %1 # atomic64_sub \n"
6020 +#ifdef CONFIG_PAX_REFCOUNT
6021 + /* Exception on overflow. */
6022 + "2: dsub %0, %2 \n"
6023 +#else
6024 + " dsubu %0, %2 \n"
6025 +#endif
6026 + " scd %0, %1 \n"
6027 + " beqz %0, 1b \n"
6028 +#ifdef CONFIG_PAX_REFCOUNT
6029 + "3: \n"
6030 + _ASM_EXTABLE(2b, 3b)
6031 +#endif
6032 + " .set mips0 \n"
6033 + : "=&r" (temp), "+m" (v->counter)
6034 + : "Ir" (i));
6035 + } else {
6036 + unsigned long flags;
6037 +
6038 + raw_local_irq_save(flags);
6039 + __asm__ __volatile__(
6040 +#ifdef CONFIG_PAX_REFCOUNT
6041 + /* Exception on overflow. */
6042 + "1: dsub %0, %1 \n"
6043 + "2: \n"
6044 + _ASM_EXTABLE(1b, 2b)
6045 +#else
6046 + " dsubu %0, %1 \n"
6047 +#endif
6048 + : "+r" (v->counter) : "Ir" (i));
6049 + raw_local_irq_restore(flags);
6050 + }
6051 +}
6052 +
6053 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6054 {
6055 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6056 long temp;
6057 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6058 /*
6059 * Same as above, but return the result value
6060 */
6061 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6062 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6063 +{
6064 + long result;
6065 + long temp;
6066 +
6067 + smp_mb__before_llsc();
6068 +
6069 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6070 + __asm__ __volatile__(
6071 + " .set mips3 \n"
6072 + "1: lld %1, %2 # atomic64_add_return \n"
6073 +#ifdef CONFIG_PAX_REFCOUNT
6074 + "2: dadd %0, %1, %3 \n"
6075 +#else
6076 + " daddu %0, %1, %3 \n"
6077 +#endif
6078 + " scd %0, %2 \n"
6079 + " beqzl %0, 1b \n"
6080 +#ifdef CONFIG_PAX_REFCOUNT
6081 + " b 4f \n"
6082 + " .set noreorder \n"
6083 + "3: b 5f \n"
6084 + " move %0, %1 \n"
6085 + " .set reorder \n"
6086 + _ASM_EXTABLE(2b, 3b)
6087 +#endif
6088 + "4: daddu %0, %1, %3 \n"
6089 +#ifdef CONFIG_PAX_REFCOUNT
6090 + "5: \n"
6091 +#endif
6092 + " .set mips0 \n"
6093 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6094 + : "Ir" (i));
6095 + } else if (kernel_uses_llsc) {
6096 + __asm__ __volatile__(
6097 + " .set mips3 \n"
6098 + "1: lld %1, %2 # atomic64_add_return \n"
6099 +#ifdef CONFIG_PAX_REFCOUNT
6100 + "2: dadd %0, %1, %3 \n"
6101 +#else
6102 + " daddu %0, %1, %3 \n"
6103 +#endif
6104 + " scd %0, %2 \n"
6105 + " bnez %0, 4f \n"
6106 + " b 1b \n"
6107 +#ifdef CONFIG_PAX_REFCOUNT
6108 + " .set noreorder \n"
6109 + "3: b 5f \n"
6110 + " move %0, %1 \n"
6111 + " .set reorder \n"
6112 + _ASM_EXTABLE(2b, 3b)
6113 +#endif
6114 + "4: daddu %0, %1, %3 \n"
6115 +#ifdef CONFIG_PAX_REFCOUNT
6116 + "5: \n"
6117 +#endif
6118 + " .set mips0 \n"
6119 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6120 + : "Ir" (i), "m" (v->counter)
6121 + : "memory");
6122 + } else {
6123 + unsigned long flags;
6124 +
6125 + raw_local_irq_save(flags);
6126 + __asm__ __volatile__(
6127 + " ld %0, %1 \n"
6128 +#ifdef CONFIG_PAX_REFCOUNT
6129 + /* Exception on overflow. */
6130 + "1: dadd %0, %2 \n"
6131 +#else
6132 + " daddu %0, %2 \n"
6133 +#endif
6134 + " sd %0, %1 \n"
6135 +#ifdef CONFIG_PAX_REFCOUNT
6136 + /* Note: Dest reg is not modified on overflow */
6137 + "2: \n"
6138 + _ASM_EXTABLE(1b, 2b)
6139 +#endif
6140 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6141 + raw_local_irq_restore(flags);
6142 + }
6143 +
6144 + smp_llsc_mb();
6145 +
6146 + return result;
6147 +}
6148 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6149 {
6150 long result;
6151
6152 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6153 return result;
6154 }
6155
6156 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6157 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6158 +{
6159 + long result;
6160 + long temp;
6161 +
6162 + smp_mb__before_llsc();
6163 +
6164 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6165 + long temp;
6166 +
6167 + __asm__ __volatile__(
6168 + " .set mips3 \n"
6169 + "1: lld %1, %2 # atomic64_sub_return \n"
6170 +#ifdef CONFIG_PAX_REFCOUNT
6171 + "2: dsub %0, %1, %3 \n"
6172 +#else
6173 + " dsubu %0, %1, %3 \n"
6174 +#endif
6175 + " scd %0, %2 \n"
6176 + " beqzl %0, 1b \n"
6177 +#ifdef CONFIG_PAX_REFCOUNT
6178 + " b 4f \n"
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: dsubu %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 if (kernel_uses_llsc) {
6194 + __asm__ __volatile__(
6195 + " .set mips3 \n"
6196 + "1: lld %1, %2 # atomic64_sub_return \n"
6197 +#ifdef CONFIG_PAX_REFCOUNT
6198 + "2: dsub %0, %1, %3 \n"
6199 +#else
6200 + " dsubu %0, %1, %3 \n"
6201 +#endif
6202 + " scd %0, %2 \n"
6203 + " bnez %0, 4f \n"
6204 + " b 1b \n"
6205 +#ifdef CONFIG_PAX_REFCOUNT
6206 + " .set noreorder \n"
6207 + "3: b 5f \n"
6208 + " move %0, %1 \n"
6209 + " .set reorder \n"
6210 + _ASM_EXTABLE(2b, 3b)
6211 +#endif
6212 + "4: dsubu %0, %1, %3 \n"
6213 +#ifdef CONFIG_PAX_REFCOUNT
6214 + "5: \n"
6215 +#endif
6216 + " .set mips0 \n"
6217 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6218 + : "Ir" (i), "m" (v->counter)
6219 + : "memory");
6220 + } else {
6221 + unsigned long flags;
6222 +
6223 + raw_local_irq_save(flags);
6224 + __asm__ __volatile__(
6225 + " ld %0, %1 \n"
6226 +#ifdef CONFIG_PAX_REFCOUNT
6227 + /* Exception on overflow. */
6228 + "1: dsub %0, %2 \n"
6229 +#else
6230 + " dsubu %0, %2 \n"
6231 +#endif
6232 + " sd %0, %1 \n"
6233 +#ifdef CONFIG_PAX_REFCOUNT
6234 + /* Note: Dest reg is not modified on overflow */
6235 + "2: \n"
6236 + _ASM_EXTABLE(1b, 2b)
6237 +#endif
6238 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6239 + raw_local_irq_restore(flags);
6240 + }
6241 +
6242 + smp_llsc_mb();
6243 +
6244 + return result;
6245 +}
6246 +
6247 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6248 {
6249 long result;
6250
6251 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6252 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6253 * The function returns the old value of @v minus @i.
6254 */
6255 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6256 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6257 {
6258 long result;
6259
6260 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6261 return result;
6262 }
6263
6264 -#define atomic64_cmpxchg(v, o, n) \
6265 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6266 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6267 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6268 +{
6269 + return cmpxchg(&v->counter, old, new);
6270 +}
6271 +
6272 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6273 + long new)
6274 +{
6275 + return cmpxchg(&(v->counter), old, new);
6276 +}
6277 +
6278 +static inline long atomic64_xchg(atomic64_t *v, long new)
6279 +{
6280 + return xchg(&v->counter, new);
6281 +}
6282 +
6283 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6284 +{
6285 + return xchg(&(v->counter), new);
6286 +}
6287
6288 /**
6289 * atomic64_add_unless - add unless the number is a given value
6290 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6291
6292 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6293 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6294 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6295
6296 /*
6297 * atomic64_sub_and_test - subtract value from variable and test result
6298 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6299 * other cases.
6300 */
6301 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6302 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6303
6304 /*
6305 * atomic64_dec_and_test - decrement by 1 and test
6306 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6307 * Atomically increments @v by 1.
6308 */
6309 #define atomic64_inc(v) atomic64_add(1, (v))
6310 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6311
6312 /*
6313 * atomic64_dec - decrement and test
6314 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6315 * Atomically decrements @v by 1.
6316 */
6317 #define atomic64_dec(v) atomic64_sub(1, (v))
6318 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6319
6320 /*
6321 * atomic64_add_negative - add and test if negative
6322 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6323 index b4db69f..8f3b093 100644
6324 --- a/arch/mips/include/asm/cache.h
6325 +++ b/arch/mips/include/asm/cache.h
6326 @@ -9,10 +9,11 @@
6327 #ifndef _ASM_CACHE_H
6328 #define _ASM_CACHE_H
6329
6330 +#include <linux/const.h>
6331 #include <kmalloc.h>
6332
6333 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6334 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6335 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6336
6337 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6338 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6339 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6340 index a66359e..d3d474a 100644
6341 --- a/arch/mips/include/asm/elf.h
6342 +++ b/arch/mips/include/asm/elf.h
6343 @@ -373,13 +373,16 @@ extern const char *__elf_platform;
6344 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6345 #endif
6346
6347 +#ifdef CONFIG_PAX_ASLR
6348 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6349 +
6350 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6351 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6352 +#endif
6353 +
6354 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6355 struct linux_binprm;
6356 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6357 int uses_interp);
6358
6359 -struct mm_struct;
6360 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6361 -#define arch_randomize_brk arch_randomize_brk
6362 -
6363 #endif /* _ASM_ELF_H */
6364 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6365 index c1f6afa..38cc6e9 100644
6366 --- a/arch/mips/include/asm/exec.h
6367 +++ b/arch/mips/include/asm/exec.h
6368 @@ -12,6 +12,6 @@
6369 #ifndef _ASM_EXEC_H
6370 #define _ASM_EXEC_H
6371
6372 -extern unsigned long arch_align_stack(unsigned long sp);
6373 +#define arch_align_stack(x) ((x) & ~0xfUL)
6374
6375 #endif /* _ASM_EXEC_H */
6376 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6377 index d44622c..64990d2 100644
6378 --- a/arch/mips/include/asm/local.h
6379 +++ b/arch/mips/include/asm/local.h
6380 @@ -12,15 +12,25 @@ typedef struct
6381 atomic_long_t a;
6382 } local_t;
6383
6384 +typedef struct {
6385 + atomic_long_unchecked_t a;
6386 +} local_unchecked_t;
6387 +
6388 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6389
6390 #define local_read(l) atomic_long_read(&(l)->a)
6391 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6392 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6393 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6394
6395 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6396 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6397 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6398 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6399 #define local_inc(l) atomic_long_inc(&(l)->a)
6400 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6401 #define local_dec(l) atomic_long_dec(&(l)->a)
6402 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6403
6404 /*
6405 * Same as above, but return the result value
6406 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6407 return result;
6408 }
6409
6410 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6411 +{
6412 + unsigned long result;
6413 +
6414 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6415 + unsigned long temp;
6416 +
6417 + __asm__ __volatile__(
6418 + " .set mips3 \n"
6419 + "1:" __LL "%1, %2 # local_add_return \n"
6420 + " addu %0, %1, %3 \n"
6421 + __SC "%0, %2 \n"
6422 + " beqzl %0, 1b \n"
6423 + " addu %0, %1, %3 \n"
6424 + " .set mips0 \n"
6425 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6426 + : "Ir" (i), "m" (l->a.counter)
6427 + : "memory");
6428 + } else if (kernel_uses_llsc) {
6429 + unsigned long temp;
6430 +
6431 + __asm__ __volatile__(
6432 + " .set mips3 \n"
6433 + "1:" __LL "%1, %2 # local_add_return \n"
6434 + " addu %0, %1, %3 \n"
6435 + __SC "%0, %2 \n"
6436 + " beqz %0, 1b \n"
6437 + " addu %0, %1, %3 \n"
6438 + " .set mips0 \n"
6439 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6440 + : "Ir" (i), "m" (l->a.counter)
6441 + : "memory");
6442 + } else {
6443 + unsigned long flags;
6444 +
6445 + local_irq_save(flags);
6446 + result = l->a.counter;
6447 + result += i;
6448 + l->a.counter = result;
6449 + local_irq_restore(flags);
6450 + }
6451 +
6452 + return result;
6453 +}
6454 +
6455 static __inline__ long local_sub_return(long i, local_t * l)
6456 {
6457 unsigned long result;
6458 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6459
6460 #define local_cmpxchg(l, o, n) \
6461 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6462 +#define local_cmpxchg_unchecked(l, o, n) \
6463 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6464 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6465
6466 /**
6467 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6468 index f6be474..12ad554 100644
6469 --- a/arch/mips/include/asm/page.h
6470 +++ b/arch/mips/include/asm/page.h
6471 @@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6472 #ifdef CONFIG_CPU_MIPS32
6473 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6474 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6475 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6476 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6477 #else
6478 typedef struct { unsigned long long pte; } pte_t;
6479 #define pte_val(x) ((x).pte)
6480 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6481 index b336037..5b874cc 100644
6482 --- a/arch/mips/include/asm/pgalloc.h
6483 +++ b/arch/mips/include/asm/pgalloc.h
6484 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6485 {
6486 set_pud(pud, __pud((unsigned long)pmd));
6487 }
6488 +
6489 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6490 +{
6491 + pud_populate(mm, pud, pmd);
6492 +}
6493 #endif
6494
6495 /*
6496 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6497 index 25da651..ae2a259 100644
6498 --- a/arch/mips/include/asm/smtc_proc.h
6499 +++ b/arch/mips/include/asm/smtc_proc.h
6500 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6501
6502 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6503
6504 -extern atomic_t smtc_fpu_recoveries;
6505 +extern atomic_unchecked_t smtc_fpu_recoveries;
6506
6507 #endif /* __ASM_SMTC_PROC_H */
6508 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6509 index 4f58ef6..5e7081b 100644
6510 --- a/arch/mips/include/asm/thread_info.h
6511 +++ b/arch/mips/include/asm/thread_info.h
6512 @@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6513 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6514 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6515 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6516 +/* li takes a 32bit immediate */
6517 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6518 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6519
6520 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6521 @@ -132,13 +134,14 @@ static inline struct thread_info *current_thread_info(void)
6522 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6523 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6524 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6525 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6526
6527 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6528 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6529 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6530
6531 /* work to do in syscall_trace_leave() */
6532 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6533 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6534 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6535
6536 /* work to do on interrupt/exception return */
6537 #define _TIF_WORK_MASK \
6538 @@ -146,7 +149,7 @@ static inline struct thread_info *current_thread_info(void)
6539 /* work to do on any return to u-space */
6540 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6541 _TIF_WORK_SYSCALL_EXIT | \
6542 - _TIF_SYSCALL_TRACEPOINT)
6543 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6544
6545 /*
6546 * We stash processor id into a COP0 register to retrieve it fast
6547 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6548 index 1188e00..41cf144 100644
6549 --- a/arch/mips/kernel/binfmt_elfn32.c
6550 +++ b/arch/mips/kernel/binfmt_elfn32.c
6551 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6552 #undef ELF_ET_DYN_BASE
6553 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6554
6555 +#ifdef CONFIG_PAX_ASLR
6556 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6557 +
6558 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6559 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6560 +#endif
6561 +
6562 #include <asm/processor.h>
6563 #include <linux/module.h>
6564 #include <linux/elfcore.h>
6565 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6566 index 202e581..689ca79 100644
6567 --- a/arch/mips/kernel/binfmt_elfo32.c
6568 +++ b/arch/mips/kernel/binfmt_elfo32.c
6569 @@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6570 #undef ELF_ET_DYN_BASE
6571 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6572
6573 +#ifdef CONFIG_PAX_ASLR
6574 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6575 +
6576 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6577 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6578 +#endif
6579 +
6580 #include <asm/processor.h>
6581
6582 /*
6583 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6584 index d1fea7a..45602ea 100644
6585 --- a/arch/mips/kernel/irq.c
6586 +++ b/arch/mips/kernel/irq.c
6587 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6588 printk("unexpected IRQ # %d\n", irq);
6589 }
6590
6591 -atomic_t irq_err_count;
6592 +atomic_unchecked_t irq_err_count;
6593
6594 int arch_show_interrupts(struct seq_file *p, int prec)
6595 {
6596 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6597 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6598 return 0;
6599 }
6600
6601 asmlinkage void spurious_interrupt(void)
6602 {
6603 - atomic_inc(&irq_err_count);
6604 + atomic_inc_unchecked(&irq_err_count);
6605 }
6606
6607 void __init init_IRQ(void)
6608 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6609 index ddc7610..8c58f17 100644
6610 --- a/arch/mips/kernel/process.c
6611 +++ b/arch/mips/kernel/process.c
6612 @@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6613 out:
6614 return pc;
6615 }
6616 -
6617 -/*
6618 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6619 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6620 - */
6621 -unsigned long arch_align_stack(unsigned long sp)
6622 -{
6623 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6624 - sp -= get_random_int() & ~PAGE_MASK;
6625 -
6626 - return sp & ALMASK;
6627 -}
6628 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6629 index b52e1d2..1a3ca09 100644
6630 --- a/arch/mips/kernel/ptrace.c
6631 +++ b/arch/mips/kernel/ptrace.c
6632 @@ -652,6 +652,10 @@ long arch_ptrace(struct task_struct *child, long request,
6633 return ret;
6634 }
6635
6636 +#ifdef CONFIG_GRKERNSEC_SETXID
6637 +extern void gr_delayed_cred_worker(void);
6638 +#endif
6639 +
6640 /*
6641 * Notification of system call entry/exit
6642 * - triggered by current->work.syscall_trace
6643 @@ -668,6 +672,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6644 tracehook_report_syscall_entry(regs))
6645 ret = -1;
6646
6647 +#ifdef CONFIG_GRKERNSEC_SETXID
6648 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6649 + gr_delayed_cred_worker();
6650 +#endif
6651 +
6652 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6653 trace_sys_enter(regs, regs->regs[2]);
6654
6655 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6656 index c10aa84..9ec2e60 100644
6657 --- a/arch/mips/kernel/smtc-proc.c
6658 +++ b/arch/mips/kernel/smtc-proc.c
6659 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6660
6661 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6662
6663 -atomic_t smtc_fpu_recoveries;
6664 +atomic_unchecked_t smtc_fpu_recoveries;
6665
6666 static int smtc_proc_show(struct seq_file *m, void *v)
6667 {
6668 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6669 for(i = 0; i < NR_CPUS; i++)
6670 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6671 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6672 - atomic_read(&smtc_fpu_recoveries));
6673 + atomic_read_unchecked(&smtc_fpu_recoveries));
6674 return 0;
6675 }
6676
6677 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
6678 smtc_cpu_stats[i].selfipis = 0;
6679 }
6680
6681 - atomic_set(&smtc_fpu_recoveries, 0);
6682 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6683
6684 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6685 }
6686 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6687 index dfc1b91..11a2c07 100644
6688 --- a/arch/mips/kernel/smtc.c
6689 +++ b/arch/mips/kernel/smtc.c
6690 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6691 }
6692 smtc_ipi_qdump();
6693 printk("%d Recoveries of \"stolen\" FPU\n",
6694 - atomic_read(&smtc_fpu_recoveries));
6695 + atomic_read_unchecked(&smtc_fpu_recoveries));
6696 }
6697
6698
6699 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6700 index 84536bf..79caa4d 100644
6701 --- a/arch/mips/kernel/sync-r4k.c
6702 +++ b/arch/mips/kernel/sync-r4k.c
6703 @@ -21,8 +21,8 @@
6704 #include <asm/mipsregs.h>
6705
6706 static atomic_t count_start_flag = ATOMIC_INIT(0);
6707 -static atomic_t count_count_start = ATOMIC_INIT(0);
6708 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6709 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6710 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6711 static atomic_t count_reference = ATOMIC_INIT(0);
6712
6713 #define COUNTON 100
6714 @@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6715
6716 for (i = 0; i < NR_LOOPS; i++) {
6717 /* slaves loop on '!= 2' */
6718 - while (atomic_read(&count_count_start) != 1)
6719 + while (atomic_read_unchecked(&count_count_start) != 1)
6720 mb();
6721 - atomic_set(&count_count_stop, 0);
6722 + atomic_set_unchecked(&count_count_stop, 0);
6723 smp_wmb();
6724
6725 /* this lets the slaves write their count register */
6726 - atomic_inc(&count_count_start);
6727 + atomic_inc_unchecked(&count_count_start);
6728
6729 /*
6730 * Everyone initialises count in the last loop:
6731 @@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6732 /*
6733 * Wait for all slaves to leave the synchronization point:
6734 */
6735 - while (atomic_read(&count_count_stop) != 1)
6736 + while (atomic_read_unchecked(&count_count_stop) != 1)
6737 mb();
6738 - atomic_set(&count_count_start, 0);
6739 + atomic_set_unchecked(&count_count_start, 0);
6740 smp_wmb();
6741 - atomic_inc(&count_count_stop);
6742 + atomic_inc_unchecked(&count_count_stop);
6743 }
6744 /* Arrange for an interrupt in a short while */
6745 write_c0_compare(read_c0_count() + COUNTON);
6746 @@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6747 initcount = atomic_read(&count_reference);
6748
6749 for (i = 0; i < NR_LOOPS; i++) {
6750 - atomic_inc(&count_count_start);
6751 - while (atomic_read(&count_count_start) != 2)
6752 + atomic_inc_unchecked(&count_count_start);
6753 + while (atomic_read_unchecked(&count_count_start) != 2)
6754 mb();
6755
6756 /*
6757 @@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6758 if (i == NR_LOOPS-1)
6759 write_c0_count(initcount);
6760
6761 - atomic_inc(&count_count_stop);
6762 - while (atomic_read(&count_count_stop) != 2)
6763 + atomic_inc_unchecked(&count_count_stop);
6764 + while (atomic_read_unchecked(&count_count_stop) != 2)
6765 mb();
6766 }
6767 /* Arrange for an interrupt in a short while */
6768 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6769 index f9c8746..78b64e3 100644
6770 --- a/arch/mips/kernel/traps.c
6771 +++ b/arch/mips/kernel/traps.c
6772 @@ -690,7 +690,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6773 siginfo_t info;
6774
6775 prev_state = exception_enter();
6776 - die_if_kernel("Integer overflow", regs);
6777 + if (unlikely(!user_mode(regs))) {
6778 +
6779 +#ifdef CONFIG_PAX_REFCOUNT
6780 + if (fixup_exception(regs)) {
6781 + pax_report_refcount_overflow(regs);
6782 + exception_exit(prev_state);
6783 + return;
6784 + }
6785 +#endif
6786 +
6787 + die("Integer overflow", regs);
6788 + }
6789
6790 info.si_code = FPE_INTOVF;
6791 info.si_signo = SIGFPE;
6792 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6793 index becc42b..9e43d4b 100644
6794 --- a/arch/mips/mm/fault.c
6795 +++ b/arch/mips/mm/fault.c
6796 @@ -28,6 +28,23 @@
6797 #include <asm/highmem.h> /* For VMALLOC_END */
6798 #include <linux/kdebug.h>
6799
6800 +#ifdef CONFIG_PAX_PAGEEXEC
6801 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6802 +{
6803 + unsigned long i;
6804 +
6805 + printk(KERN_ERR "PAX: bytes at PC: ");
6806 + for (i = 0; i < 5; i++) {
6807 + unsigned int c;
6808 + if (get_user(c, (unsigned int *)pc+i))
6809 + printk(KERN_CONT "???????? ");
6810 + else
6811 + printk(KERN_CONT "%08x ", c);
6812 + }
6813 + printk("\n");
6814 +}
6815 +#endif
6816 +
6817 /*
6818 * This routine handles page faults. It determines the address,
6819 * and the problem, and then passes it off to one of the appropriate
6820 @@ -199,6 +216,14 @@ bad_area:
6821 bad_area_nosemaphore:
6822 /* User mode accesses just cause a SIGSEGV */
6823 if (user_mode(regs)) {
6824 +
6825 +#ifdef CONFIG_PAX_PAGEEXEC
6826 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6827 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6828 + do_group_exit(SIGKILL);
6829 + }
6830 +#endif
6831 +
6832 tsk->thread.cp0_badvaddr = address;
6833 tsk->thread.error_code = write;
6834 #if 0
6835 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6836 index f1baadd..8537544 100644
6837 --- a/arch/mips/mm/mmap.c
6838 +++ b/arch/mips/mm/mmap.c
6839 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6840 struct vm_area_struct *vma;
6841 unsigned long addr = addr0;
6842 int do_color_align;
6843 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6844 struct vm_unmapped_area_info info;
6845
6846 if (unlikely(len > TASK_SIZE))
6847 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6848 do_color_align = 1;
6849
6850 /* requesting a specific address */
6851 +
6852 +#ifdef CONFIG_PAX_RANDMMAP
6853 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6854 +#endif
6855 +
6856 if (addr) {
6857 if (do_color_align)
6858 addr = COLOUR_ALIGN(addr, pgoff);
6859 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6860 addr = PAGE_ALIGN(addr);
6861
6862 vma = find_vma(mm, addr);
6863 - if (TASK_SIZE - len >= addr &&
6864 - (!vma || addr + len <= vma->vm_start))
6865 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6866 return addr;
6867 }
6868
6869 info.length = len;
6870 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6871 info.align_offset = pgoff << PAGE_SHIFT;
6872 + info.threadstack_offset = offset;
6873
6874 if (dir == DOWN) {
6875 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6876 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6877 {
6878 unsigned long random_factor = 0UL;
6879
6880 +#ifdef CONFIG_PAX_RANDMMAP
6881 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6882 +#endif
6883 +
6884 if (current->flags & PF_RANDOMIZE) {
6885 random_factor = get_random_int();
6886 random_factor = random_factor << PAGE_SHIFT;
6887 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6888
6889 if (mmap_is_legacy()) {
6890 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6891 +
6892 +#ifdef CONFIG_PAX_RANDMMAP
6893 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6894 + mm->mmap_base += mm->delta_mmap;
6895 +#endif
6896 +
6897 mm->get_unmapped_area = arch_get_unmapped_area;
6898 } else {
6899 mm->mmap_base = mmap_base(random_factor);
6900 +
6901 +#ifdef CONFIG_PAX_RANDMMAP
6902 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6903 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6904 +#endif
6905 +
6906 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6907 }
6908 }
6909
6910 -static inline unsigned long brk_rnd(void)
6911 -{
6912 - unsigned long rnd = get_random_int();
6913 -
6914 - rnd = rnd << PAGE_SHIFT;
6915 - /* 8MB for 32bit, 256MB for 64bit */
6916 - if (TASK_IS_32BIT_ADDR)
6917 - rnd = rnd & 0x7ffffful;
6918 - else
6919 - rnd = rnd & 0xffffffful;
6920 -
6921 - return rnd;
6922 -}
6923 -
6924 -unsigned long arch_randomize_brk(struct mm_struct *mm)
6925 -{
6926 - unsigned long base = mm->brk;
6927 - unsigned long ret;
6928 -
6929 - ret = PAGE_ALIGN(base + brk_rnd());
6930 -
6931 - if (ret < mm->brk)
6932 - return mm->brk;
6933 -
6934 - return ret;
6935 -}
6936 -
6937 int __virt_addr_valid(const volatile void *kaddr)
6938 {
6939 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6940 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6941 index a2358b4..7cead4f 100644
6942 --- a/arch/mips/sgi-ip27/ip27-nmi.c
6943 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
6944 @@ -187,9 +187,9 @@ void
6945 cont_nmi_dump(void)
6946 {
6947 #ifndef REAL_NMI_SIGNAL
6948 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
6949 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6950
6951 - atomic_inc(&nmied_cpus);
6952 + atomic_inc_unchecked(&nmied_cpus);
6953 #endif
6954 /*
6955 * Only allow 1 cpu to proceed
6956 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
6957 udelay(10000);
6958 }
6959 #else
6960 - while (atomic_read(&nmied_cpus) != num_online_cpus());
6961 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6962 #endif
6963
6964 /*
6965 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6966 index 967d144..db12197 100644
6967 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6968 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6969 @@ -11,12 +11,14 @@
6970 #ifndef _ASM_PROC_CACHE_H
6971 #define _ASM_PROC_CACHE_H
6972
6973 +#include <linux/const.h>
6974 +
6975 /* L1 cache */
6976
6977 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6978 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6979 -#define L1_CACHE_BYTES 16 /* bytes per entry */
6980 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6981 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6982 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6983
6984 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6985 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6986 index bcb5df2..84fabd2 100644
6987 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6988 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6989 @@ -16,13 +16,15 @@
6990 #ifndef _ASM_PROC_CACHE_H
6991 #define _ASM_PROC_CACHE_H
6992
6993 +#include <linux/const.h>
6994 +
6995 /*
6996 * L1 cache
6997 */
6998 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6999 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7000 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7001 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7002 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7003 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7004
7005 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7006 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7007 index 4ce7a01..449202a 100644
7008 --- a/arch/openrisc/include/asm/cache.h
7009 +++ b/arch/openrisc/include/asm/cache.h
7010 @@ -19,11 +19,13 @@
7011 #ifndef __ASM_OPENRISC_CACHE_H
7012 #define __ASM_OPENRISC_CACHE_H
7013
7014 +#include <linux/const.h>
7015 +
7016 /* FIXME: How can we replace these with values from the CPU...
7017 * they shouldn't be hard-coded!
7018 */
7019
7020 -#define L1_CACHE_BYTES 16
7021 #define L1_CACHE_SHIFT 4
7022 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7023
7024 #endif /* __ASM_OPENRISC_CACHE_H */
7025 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7026 index 472886c..00e7df9 100644
7027 --- a/arch/parisc/include/asm/atomic.h
7028 +++ b/arch/parisc/include/asm/atomic.h
7029 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7030 return dec;
7031 }
7032
7033 +#define atomic64_read_unchecked(v) atomic64_read(v)
7034 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7035 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7036 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7037 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7038 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7039 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7040 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7041 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7042 +
7043 #endif /* !CONFIG_64BIT */
7044
7045
7046 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7047 index 47f11c7..3420df2 100644
7048 --- a/arch/parisc/include/asm/cache.h
7049 +++ b/arch/parisc/include/asm/cache.h
7050 @@ -5,6 +5,7 @@
7051 #ifndef __ARCH_PARISC_CACHE_H
7052 #define __ARCH_PARISC_CACHE_H
7053
7054 +#include <linux/const.h>
7055
7056 /*
7057 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7058 @@ -15,13 +16,13 @@
7059 * just ruin performance.
7060 */
7061 #ifdef CONFIG_PA20
7062 -#define L1_CACHE_BYTES 64
7063 #define L1_CACHE_SHIFT 6
7064 #else
7065 -#define L1_CACHE_BYTES 32
7066 #define L1_CACHE_SHIFT 5
7067 #endif
7068
7069 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7070 +
7071 #ifndef __ASSEMBLY__
7072
7073 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7074 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7075 index ad2b503..bdf1651 100644
7076 --- a/arch/parisc/include/asm/elf.h
7077 +++ b/arch/parisc/include/asm/elf.h
7078 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7079
7080 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7081
7082 +#ifdef CONFIG_PAX_ASLR
7083 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7084 +
7085 +#define PAX_DELTA_MMAP_LEN 16
7086 +#define PAX_DELTA_STACK_LEN 16
7087 +#endif
7088 +
7089 /* This yields a mask that user programs can use to figure out what
7090 instruction set this CPU supports. This could be done in user space,
7091 but it's not easy, and we've already done it here. */
7092 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7093 index f213f5b..0af3e8e 100644
7094 --- a/arch/parisc/include/asm/pgalloc.h
7095 +++ b/arch/parisc/include/asm/pgalloc.h
7096 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7097 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7098 }
7099
7100 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7101 +{
7102 + pgd_populate(mm, pgd, pmd);
7103 +}
7104 +
7105 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7106 {
7107 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7108 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7109 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7110 #define pmd_free(mm, x) do { } while (0)
7111 #define pgd_populate(mm, pmd, pte) BUG()
7112 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7113
7114 #endif
7115
7116 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7117 index 34899b5..02dd060 100644
7118 --- a/arch/parisc/include/asm/pgtable.h
7119 +++ b/arch/parisc/include/asm/pgtable.h
7120 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7121 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7122 #define PAGE_COPY PAGE_EXECREAD
7123 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7124 +
7125 +#ifdef CONFIG_PAX_PAGEEXEC
7126 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7127 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7128 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7129 +#else
7130 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7131 +# define PAGE_COPY_NOEXEC PAGE_COPY
7132 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7133 +#endif
7134 +
7135 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7136 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7137 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7138 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7139 index 4006964..fcb3cc2 100644
7140 --- a/arch/parisc/include/asm/uaccess.h
7141 +++ b/arch/parisc/include/asm/uaccess.h
7142 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7143 const void __user *from,
7144 unsigned long n)
7145 {
7146 - int sz = __compiletime_object_size(to);
7147 + size_t sz = __compiletime_object_size(to);
7148 int ret = -EFAULT;
7149
7150 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7151 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7152 ret = __copy_from_user(to, from, n);
7153 else
7154 copy_from_user_overflow();
7155 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7156 index 50dfafc..b9fc230 100644
7157 --- a/arch/parisc/kernel/module.c
7158 +++ b/arch/parisc/kernel/module.c
7159 @@ -98,16 +98,38 @@
7160
7161 /* three functions to determine where in the module core
7162 * or init pieces the location is */
7163 +static inline int in_init_rx(struct module *me, void *loc)
7164 +{
7165 + return (loc >= me->module_init_rx &&
7166 + loc < (me->module_init_rx + me->init_size_rx));
7167 +}
7168 +
7169 +static inline int in_init_rw(struct module *me, void *loc)
7170 +{
7171 + return (loc >= me->module_init_rw &&
7172 + loc < (me->module_init_rw + me->init_size_rw));
7173 +}
7174 +
7175 static inline int in_init(struct module *me, void *loc)
7176 {
7177 - return (loc >= me->module_init &&
7178 - loc <= (me->module_init + me->init_size));
7179 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7180 +}
7181 +
7182 +static inline int in_core_rx(struct module *me, void *loc)
7183 +{
7184 + return (loc >= me->module_core_rx &&
7185 + loc < (me->module_core_rx + me->core_size_rx));
7186 +}
7187 +
7188 +static inline int in_core_rw(struct module *me, void *loc)
7189 +{
7190 + return (loc >= me->module_core_rw &&
7191 + loc < (me->module_core_rw + me->core_size_rw));
7192 }
7193
7194 static inline int in_core(struct module *me, void *loc)
7195 {
7196 - return (loc >= me->module_core &&
7197 - loc <= (me->module_core + me->core_size));
7198 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7199 }
7200
7201 static inline int in_local(struct module *me, void *loc)
7202 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7203 }
7204
7205 /* align things a bit */
7206 - me->core_size = ALIGN(me->core_size, 16);
7207 - me->arch.got_offset = me->core_size;
7208 - me->core_size += gots * sizeof(struct got_entry);
7209 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7210 + me->arch.got_offset = me->core_size_rw;
7211 + me->core_size_rw += gots * sizeof(struct got_entry);
7212
7213 - me->core_size = ALIGN(me->core_size, 16);
7214 - me->arch.fdesc_offset = me->core_size;
7215 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7216 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7217 + me->arch.fdesc_offset = me->core_size_rw;
7218 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7219
7220 me->arch.got_max = gots;
7221 me->arch.fdesc_max = fdescs;
7222 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7223
7224 BUG_ON(value == 0);
7225
7226 - got = me->module_core + me->arch.got_offset;
7227 + got = me->module_core_rw + me->arch.got_offset;
7228 for (i = 0; got[i].addr; i++)
7229 if (got[i].addr == value)
7230 goto out;
7231 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7232 #ifdef CONFIG_64BIT
7233 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7234 {
7235 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7236 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7237
7238 if (!value) {
7239 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7240 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7241
7242 /* Create new one */
7243 fdesc->addr = value;
7244 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7245 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7246 return (Elf_Addr)fdesc;
7247 }
7248 #endif /* CONFIG_64BIT */
7249 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7250
7251 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7252 end = table + sechdrs[me->arch.unwind_section].sh_size;
7253 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7254 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7255
7256 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7257 me->arch.unwind_section, table, end, gp);
7258 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7259 index 0d3a9d4..20a99b0 100644
7260 --- a/arch/parisc/kernel/sys_parisc.c
7261 +++ b/arch/parisc/kernel/sys_parisc.c
7262 @@ -33,9 +33,11 @@
7263 #include <linux/utsname.h>
7264 #include <linux/personality.h>
7265
7266 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7267 +static unsigned long get_unshared_area(unsigned long addr, unsigned long len,
7268 + unsigned long flags)
7269 {
7270 struct vm_unmapped_area_info info;
7271 + unsigned long offset = gr_rand_threadstack_offset(current->mm, NULL, flags);
7272
7273 info.flags = 0;
7274 info.length = len;
7275 @@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7276 info.high_limit = TASK_SIZE;
7277 info.align_mask = 0;
7278 info.align_offset = 0;
7279 + info.threadstack_offset = offset;
7280 return vm_unmapped_area(&info);
7281 }
7282
7283 @@ -69,9 +72,10 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7284 }
7285
7286 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7287 - unsigned long len, unsigned long pgoff)
7288 + unsigned long len, unsigned long pgoff, unsigned long flags)
7289 {
7290 struct vm_unmapped_area_info info;
7291 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7292
7293 info.flags = 0;
7294 info.length = len;
7295 @@ -79,6 +83,7 @@ static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7296 info.high_limit = TASK_SIZE;
7297 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7298 info.align_offset = shared_align_offset(filp, pgoff);
7299 + info.threadstack_offset = offset;
7300 return vm_unmapped_area(&info);
7301 }
7302
7303 @@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7304 return -EINVAL;
7305 return addr;
7306 }
7307 - if (!addr)
7308 + if (!addr) {
7309 addr = TASK_UNMAPPED_BASE;
7310
7311 +#ifdef CONFIG_PAX_RANDMMAP
7312 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7313 + addr += current->mm->delta_mmap;
7314 +#endif
7315 +
7316 + }
7317 +
7318 if (filp || (flags & MAP_SHARED))
7319 - addr = get_shared_area(filp, addr, len, pgoff);
7320 + addr = get_shared_area(filp, addr, len, pgoff, flags);
7321 else
7322 - addr = get_unshared_area(addr, len);
7323 + addr = get_unshared_area(addr, len, flags);
7324
7325 return addr;
7326 }
7327 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7328 index 1cd1d0c..44ec918 100644
7329 --- a/arch/parisc/kernel/traps.c
7330 +++ b/arch/parisc/kernel/traps.c
7331 @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7332
7333 down_read(&current->mm->mmap_sem);
7334 vma = find_vma(current->mm,regs->iaoq[0]);
7335 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7336 - && (vma->vm_flags & VM_EXEC)) {
7337 -
7338 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7339 fault_address = regs->iaoq[0];
7340 fault_space = regs->iasq[0];
7341
7342 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7343 index 9d08c71..e2b4d20 100644
7344 --- a/arch/parisc/mm/fault.c
7345 +++ b/arch/parisc/mm/fault.c
7346 @@ -15,6 +15,7 @@
7347 #include <linux/sched.h>
7348 #include <linux/interrupt.h>
7349 #include <linux/module.h>
7350 +#include <linux/unistd.h>
7351
7352 #include <asm/uaccess.h>
7353 #include <asm/traps.h>
7354 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7355 static unsigned long
7356 parisc_acctyp(unsigned long code, unsigned int inst)
7357 {
7358 - if (code == 6 || code == 16)
7359 + if (code == 6 || code == 7 || code == 16)
7360 return VM_EXEC;
7361
7362 switch (inst & 0xf0000000) {
7363 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7364 }
7365 #endif
7366
7367 +#ifdef CONFIG_PAX_PAGEEXEC
7368 +/*
7369 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7370 + *
7371 + * returns 1 when task should be killed
7372 + * 2 when rt_sigreturn trampoline was detected
7373 + * 3 when unpatched PLT trampoline was detected
7374 + */
7375 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7376 +{
7377 +
7378 +#ifdef CONFIG_PAX_EMUPLT
7379 + int err;
7380 +
7381 + do { /* PaX: unpatched PLT emulation */
7382 + unsigned int bl, depwi;
7383 +
7384 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7385 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7386 +
7387 + if (err)
7388 + break;
7389 +
7390 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7391 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7392 +
7393 + err = get_user(ldw, (unsigned int *)addr);
7394 + err |= get_user(bv, (unsigned int *)(addr+4));
7395 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7396 +
7397 + if (err)
7398 + break;
7399 +
7400 + if (ldw == 0x0E801096U &&
7401 + bv == 0xEAC0C000U &&
7402 + ldw2 == 0x0E881095U)
7403 + {
7404 + unsigned int resolver, map;
7405 +
7406 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7407 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7408 + if (err)
7409 + break;
7410 +
7411 + regs->gr[20] = instruction_pointer(regs)+8;
7412 + regs->gr[21] = map;
7413 + regs->gr[22] = resolver;
7414 + regs->iaoq[0] = resolver | 3UL;
7415 + regs->iaoq[1] = regs->iaoq[0] + 4;
7416 + return 3;
7417 + }
7418 + }
7419 + } while (0);
7420 +#endif
7421 +
7422 +#ifdef CONFIG_PAX_EMUTRAMP
7423 +
7424 +#ifndef CONFIG_PAX_EMUSIGRT
7425 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7426 + return 1;
7427 +#endif
7428 +
7429 + do { /* PaX: rt_sigreturn emulation */
7430 + unsigned int ldi1, ldi2, bel, nop;
7431 +
7432 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7433 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7434 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7435 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7436 +
7437 + if (err)
7438 + break;
7439 +
7440 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7441 + ldi2 == 0x3414015AU &&
7442 + bel == 0xE4008200U &&
7443 + nop == 0x08000240U)
7444 + {
7445 + regs->gr[25] = (ldi1 & 2) >> 1;
7446 + regs->gr[20] = __NR_rt_sigreturn;
7447 + regs->gr[31] = regs->iaoq[1] + 16;
7448 + regs->sr[0] = regs->iasq[1];
7449 + regs->iaoq[0] = 0x100UL;
7450 + regs->iaoq[1] = regs->iaoq[0] + 4;
7451 + regs->iasq[0] = regs->sr[2];
7452 + regs->iasq[1] = regs->sr[2];
7453 + return 2;
7454 + }
7455 + } while (0);
7456 +#endif
7457 +
7458 + return 1;
7459 +}
7460 +
7461 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7462 +{
7463 + unsigned long i;
7464 +
7465 + printk(KERN_ERR "PAX: bytes at PC: ");
7466 + for (i = 0; i < 5; i++) {
7467 + unsigned int c;
7468 + if (get_user(c, (unsigned int *)pc+i))
7469 + printk(KERN_CONT "???????? ");
7470 + else
7471 + printk(KERN_CONT "%08x ", c);
7472 + }
7473 + printk("\n");
7474 +}
7475 +#endif
7476 +
7477 int fixup_exception(struct pt_regs *regs)
7478 {
7479 const struct exception_table_entry *fix;
7480 @@ -210,8 +321,33 @@ retry:
7481
7482 good_area:
7483
7484 - if ((vma->vm_flags & acc_type) != acc_type)
7485 + if ((vma->vm_flags & acc_type) != acc_type) {
7486 +
7487 +#ifdef CONFIG_PAX_PAGEEXEC
7488 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7489 + (address & ~3UL) == instruction_pointer(regs))
7490 + {
7491 + up_read(&mm->mmap_sem);
7492 + switch (pax_handle_fetch_fault(regs)) {
7493 +
7494 +#ifdef CONFIG_PAX_EMUPLT
7495 + case 3:
7496 + return;
7497 +#endif
7498 +
7499 +#ifdef CONFIG_PAX_EMUTRAMP
7500 + case 2:
7501 + return;
7502 +#endif
7503 +
7504 + }
7505 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7506 + do_group_exit(SIGKILL);
7507 + }
7508 +#endif
7509 +
7510 goto bad_area;
7511 + }
7512
7513 /*
7514 * If for any reason at all we couldn't handle the fault, make
7515 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7516 index b44b52c..4cd253c 100644
7517 --- a/arch/powerpc/Kconfig
7518 +++ b/arch/powerpc/Kconfig
7519 @@ -382,6 +382,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7520 config KEXEC
7521 bool "kexec system call"
7522 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7523 + depends on !GRKERNSEC_KMEM
7524 help
7525 kexec is a system call that implements the ability to shutdown your
7526 current kernel, and to start another kernel. It is like a reboot
7527 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7528 index e3b1d41..8e81edf 100644
7529 --- a/arch/powerpc/include/asm/atomic.h
7530 +++ b/arch/powerpc/include/asm/atomic.h
7531 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7532 return t1;
7533 }
7534
7535 +#define atomic64_read_unchecked(v) atomic64_read(v)
7536 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7537 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7538 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7539 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7540 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7541 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7542 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7543 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7544 +
7545 #endif /* __powerpc64__ */
7546
7547 #endif /* __KERNEL__ */
7548 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7549 index 9e495c9..b6878e5 100644
7550 --- a/arch/powerpc/include/asm/cache.h
7551 +++ b/arch/powerpc/include/asm/cache.h
7552 @@ -3,6 +3,7 @@
7553
7554 #ifdef __KERNEL__
7555
7556 +#include <linux/const.h>
7557
7558 /* bytes per L1 cache line */
7559 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7560 @@ -22,7 +23,7 @@
7561 #define L1_CACHE_SHIFT 7
7562 #endif
7563
7564 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7565 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7566
7567 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7568
7569 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7570 index 935b5e7..7001d2d 100644
7571 --- a/arch/powerpc/include/asm/elf.h
7572 +++ b/arch/powerpc/include/asm/elf.h
7573 @@ -28,8 +28,19 @@
7574 the loader. We need to make sure that it is out of the way of the program
7575 that it will "exec", and that there is sufficient room for the brk. */
7576
7577 -extern unsigned long randomize_et_dyn(unsigned long base);
7578 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7579 +#define ELF_ET_DYN_BASE (0x20000000)
7580 +
7581 +#ifdef CONFIG_PAX_ASLR
7582 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7583 +
7584 +#ifdef __powerpc64__
7585 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7586 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7587 +#else
7588 +#define PAX_DELTA_MMAP_LEN 15
7589 +#define PAX_DELTA_STACK_LEN 15
7590 +#endif
7591 +#endif
7592
7593 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7594
7595 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7596 (0x7ff >> (PAGE_SHIFT - 12)) : \
7597 (0x3ffff >> (PAGE_SHIFT - 12)))
7598
7599 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7600 -#define arch_randomize_brk arch_randomize_brk
7601 -
7602 -
7603 #ifdef CONFIG_SPU_BASE
7604 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7605 #define NT_SPU 1
7606 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7607 index 8196e9c..d83a9f3 100644
7608 --- a/arch/powerpc/include/asm/exec.h
7609 +++ b/arch/powerpc/include/asm/exec.h
7610 @@ -4,6 +4,6 @@
7611 #ifndef _ASM_POWERPC_EXEC_H
7612 #define _ASM_POWERPC_EXEC_H
7613
7614 -extern unsigned long arch_align_stack(unsigned long sp);
7615 +#define arch_align_stack(x) ((x) & ~0xfUL)
7616
7617 #endif /* _ASM_POWERPC_EXEC_H */
7618 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7619 index 5acabbd..7ea14fa 100644
7620 --- a/arch/powerpc/include/asm/kmap_types.h
7621 +++ b/arch/powerpc/include/asm/kmap_types.h
7622 @@ -10,7 +10,7 @@
7623 * 2 of the License, or (at your option) any later version.
7624 */
7625
7626 -#define KM_TYPE_NR 16
7627 +#define KM_TYPE_NR 17
7628
7629 #endif /* __KERNEL__ */
7630 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7631 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7632 index 8565c25..2865190 100644
7633 --- a/arch/powerpc/include/asm/mman.h
7634 +++ b/arch/powerpc/include/asm/mman.h
7635 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7636 }
7637 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7638
7639 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7640 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7641 {
7642 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7643 }
7644 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7645 index 32e4e21..62afb12 100644
7646 --- a/arch/powerpc/include/asm/page.h
7647 +++ b/arch/powerpc/include/asm/page.h
7648 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7649 * and needs to be executable. This means the whole heap ends
7650 * up being executable.
7651 */
7652 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7653 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7654 +#define VM_DATA_DEFAULT_FLAGS32 \
7655 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7656 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7657
7658 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7659 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7660 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7661 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7662 #endif
7663
7664 +#define ktla_ktva(addr) (addr)
7665 +#define ktva_ktla(addr) (addr)
7666 +
7667 #ifndef CONFIG_PPC_BOOK3S_64
7668 /*
7669 * Use the top bit of the higher-level page table entries to indicate whether
7670 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7671 index 88693ce..ac6f9ab 100644
7672 --- a/arch/powerpc/include/asm/page_64.h
7673 +++ b/arch/powerpc/include/asm/page_64.h
7674 @@ -153,15 +153,18 @@ do { \
7675 * stack by default, so in the absence of a PT_GNU_STACK program header
7676 * we turn execute permission off.
7677 */
7678 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7679 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7680 +#define VM_STACK_DEFAULT_FLAGS32 \
7681 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7682 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7683
7684 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7685 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7686
7687 +#ifndef CONFIG_PAX_PAGEEXEC
7688 #define VM_STACK_DEFAULT_FLAGS \
7689 (is_32bit_task() ? \
7690 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7691 +#endif
7692
7693 #include <asm-generic/getorder.h>
7694
7695 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7696 index 4b0be20..c15a27d 100644
7697 --- a/arch/powerpc/include/asm/pgalloc-64.h
7698 +++ b/arch/powerpc/include/asm/pgalloc-64.h
7699 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7700 #ifndef CONFIG_PPC_64K_PAGES
7701
7702 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7703 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7704
7705 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7706 {
7707 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7708 pud_set(pud, (unsigned long)pmd);
7709 }
7710
7711 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7712 +{
7713 + pud_populate(mm, pud, pmd);
7714 +}
7715 +
7716 #define pmd_populate(mm, pmd, pte_page) \
7717 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7718 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7719 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
7720 #endif
7721
7722 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7723 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7724
7725 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7726 pte_t *pte)
7727 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7728 index 7d6eacf..14c0240 100644
7729 --- a/arch/powerpc/include/asm/pgtable.h
7730 +++ b/arch/powerpc/include/asm/pgtable.h
7731 @@ -2,6 +2,7 @@
7732 #define _ASM_POWERPC_PGTABLE_H
7733 #ifdef __KERNEL__
7734
7735 +#include <linux/const.h>
7736 #ifndef __ASSEMBLY__
7737 #include <asm/processor.h> /* For TASK_SIZE */
7738 #include <asm/mmu.h>
7739 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7740 index 4aad413..85d86bf 100644
7741 --- a/arch/powerpc/include/asm/pte-hash32.h
7742 +++ b/arch/powerpc/include/asm/pte-hash32.h
7743 @@ -21,6 +21,7 @@
7744 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7745 #define _PAGE_USER 0x004 /* usermode access allowed */
7746 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7747 +#define _PAGE_EXEC _PAGE_GUARDED
7748 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7749 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7750 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7751 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7752 index fa8388e..f985549 100644
7753 --- a/arch/powerpc/include/asm/reg.h
7754 +++ b/arch/powerpc/include/asm/reg.h
7755 @@ -239,6 +239,7 @@
7756 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7757 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7758 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7759 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7760 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7761 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7762 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7763 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7764 index 084e080..9415a3d 100644
7765 --- a/arch/powerpc/include/asm/smp.h
7766 +++ b/arch/powerpc/include/asm/smp.h
7767 @@ -51,7 +51,7 @@ struct smp_ops_t {
7768 int (*cpu_disable)(void);
7769 void (*cpu_die)(unsigned int nr);
7770 int (*cpu_bootable)(unsigned int nr);
7771 -};
7772 +} __no_const;
7773
7774 extern void smp_send_debugger_break(void);
7775 extern void start_secondary_resume(void);
7776 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7777 index 9854c56..7517190 100644
7778 --- a/arch/powerpc/include/asm/thread_info.h
7779 +++ b/arch/powerpc/include/asm/thread_info.h
7780 @@ -91,7 +91,6 @@ static inline struct thread_info *current_thread_info(void)
7781 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7782 TIF_NEED_RESCHED */
7783 #define TIF_32BIT 4 /* 32 bit binary */
7784 -#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7785 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7786 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7787 #define TIF_SINGLESTEP 8 /* singlestepping active */
7788 @@ -108,6 +107,9 @@ static inline struct thread_info *current_thread_info(void)
7789 #if defined(CONFIG_PPC64)
7790 #define TIF_ELF2ABI 18 /* function descriptors must die! */
7791 #endif
7792 +#define TIF_PERFMON_WORK 19 /* work for pfm_handle_work() */
7793 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7794 +#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7795
7796 /* as above, but as bit values */
7797 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7798 @@ -127,9 +129,10 @@ static inline struct thread_info *current_thread_info(void)
7799 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7800 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7801 #define _TIF_NOHZ (1<<TIF_NOHZ)
7802 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7803 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7804 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7805 - _TIF_NOHZ)
7806 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
7807
7808 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7809 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7810 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7811 index 9485b43..4718d50 100644
7812 --- a/arch/powerpc/include/asm/uaccess.h
7813 +++ b/arch/powerpc/include/asm/uaccess.h
7814 @@ -318,52 +318,6 @@ do { \
7815 extern unsigned long __copy_tofrom_user(void __user *to,
7816 const void __user *from, unsigned long size);
7817
7818 -#ifndef __powerpc64__
7819 -
7820 -static inline unsigned long copy_from_user(void *to,
7821 - const void __user *from, unsigned long n)
7822 -{
7823 - unsigned long over;
7824 -
7825 - if (access_ok(VERIFY_READ, from, n))
7826 - return __copy_tofrom_user((__force void __user *)to, from, n);
7827 - if ((unsigned long)from < TASK_SIZE) {
7828 - over = (unsigned long)from + n - TASK_SIZE;
7829 - return __copy_tofrom_user((__force void __user *)to, from,
7830 - n - over) + over;
7831 - }
7832 - return n;
7833 -}
7834 -
7835 -static inline unsigned long copy_to_user(void __user *to,
7836 - const void *from, unsigned long n)
7837 -{
7838 - unsigned long over;
7839 -
7840 - if (access_ok(VERIFY_WRITE, to, n))
7841 - return __copy_tofrom_user(to, (__force void __user *)from, n);
7842 - if ((unsigned long)to < TASK_SIZE) {
7843 - over = (unsigned long)to + n - TASK_SIZE;
7844 - return __copy_tofrom_user(to, (__force void __user *)from,
7845 - n - over) + over;
7846 - }
7847 - return n;
7848 -}
7849 -
7850 -#else /* __powerpc64__ */
7851 -
7852 -#define __copy_in_user(to, from, size) \
7853 - __copy_tofrom_user((to), (from), (size))
7854 -
7855 -extern unsigned long copy_from_user(void *to, const void __user *from,
7856 - unsigned long n);
7857 -extern unsigned long copy_to_user(void __user *to, const void *from,
7858 - unsigned long n);
7859 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
7860 - unsigned long n);
7861 -
7862 -#endif /* __powerpc64__ */
7863 -
7864 static inline unsigned long __copy_from_user_inatomic(void *to,
7865 const void __user *from, unsigned long n)
7866 {
7867 @@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7868 if (ret == 0)
7869 return 0;
7870 }
7871 +
7872 + if (!__builtin_constant_p(n))
7873 + check_object_size(to, n, false);
7874 +
7875 return __copy_tofrom_user((__force void __user *)to, from, n);
7876 }
7877
7878 @@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7879 if (ret == 0)
7880 return 0;
7881 }
7882 +
7883 + if (!__builtin_constant_p(n))
7884 + check_object_size(from, n, true);
7885 +
7886 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7887 }
7888
7889 @@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7890 return __copy_to_user_inatomic(to, from, size);
7891 }
7892
7893 +#ifndef __powerpc64__
7894 +
7895 +static inline unsigned long __must_check copy_from_user(void *to,
7896 + const void __user *from, unsigned long n)
7897 +{
7898 + unsigned long over;
7899 +
7900 + if ((long)n < 0)
7901 + return n;
7902 +
7903 + if (access_ok(VERIFY_READ, from, n)) {
7904 + if (!__builtin_constant_p(n))
7905 + check_object_size(to, n, false);
7906 + return __copy_tofrom_user((__force void __user *)to, from, n);
7907 + }
7908 + if ((unsigned long)from < TASK_SIZE) {
7909 + over = (unsigned long)from + n - TASK_SIZE;
7910 + if (!__builtin_constant_p(n - over))
7911 + check_object_size(to, n - over, false);
7912 + return __copy_tofrom_user((__force void __user *)to, from,
7913 + n - over) + over;
7914 + }
7915 + return n;
7916 +}
7917 +
7918 +static inline unsigned long __must_check copy_to_user(void __user *to,
7919 + const void *from, unsigned long n)
7920 +{
7921 + unsigned long over;
7922 +
7923 + if ((long)n < 0)
7924 + return n;
7925 +
7926 + if (access_ok(VERIFY_WRITE, to, n)) {
7927 + if (!__builtin_constant_p(n))
7928 + check_object_size(from, n, true);
7929 + return __copy_tofrom_user(to, (__force void __user *)from, n);
7930 + }
7931 + if ((unsigned long)to < TASK_SIZE) {
7932 + over = (unsigned long)to + n - TASK_SIZE;
7933 + if (!__builtin_constant_p(n))
7934 + check_object_size(from, n - over, true);
7935 + return __copy_tofrom_user(to, (__force void __user *)from,
7936 + n - over) + over;
7937 + }
7938 + return n;
7939 +}
7940 +
7941 +#else /* __powerpc64__ */
7942 +
7943 +#define __copy_in_user(to, from, size) \
7944 + __copy_tofrom_user((to), (from), (size))
7945 +
7946 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7947 +{
7948 + if ((long)n < 0 || n > INT_MAX)
7949 + return n;
7950 +
7951 + if (!__builtin_constant_p(n))
7952 + check_object_size(to, n, false);
7953 +
7954 + if (likely(access_ok(VERIFY_READ, from, n)))
7955 + n = __copy_from_user(to, from, n);
7956 + else
7957 + memset(to, 0, n);
7958 + return n;
7959 +}
7960 +
7961 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7962 +{
7963 + if ((long)n < 0 || n > INT_MAX)
7964 + return n;
7965 +
7966 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
7967 + if (!__builtin_constant_p(n))
7968 + check_object_size(from, n, true);
7969 + n = __copy_to_user(to, from, n);
7970 + }
7971 + return n;
7972 +}
7973 +
7974 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
7975 + unsigned long n);
7976 +
7977 +#endif /* __powerpc64__ */
7978 +
7979 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7980
7981 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7982 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7983 index e775156..af2d1c0 100644
7984 --- a/arch/powerpc/kernel/exceptions-64e.S
7985 +++ b/arch/powerpc/kernel/exceptions-64e.S
7986 @@ -759,6 +759,7 @@ storage_fault_common:
7987 std r14,_DAR(r1)
7988 std r15,_DSISR(r1)
7989 addi r3,r1,STACK_FRAME_OVERHEAD
7990 + bl .save_nvgprs
7991 mr r4,r14
7992 mr r5,r15
7993 ld r14,PACA_EXGEN+EX_R14(r13)
7994 @@ -767,8 +768,7 @@ storage_fault_common:
7995 cmpdi r3,0
7996 bne- 1f
7997 b .ret_from_except_lite
7998 -1: bl .save_nvgprs
7999 - mr r5,r3
8000 +1: mr r5,r3
8001 addi r3,r1,STACK_FRAME_OVERHEAD
8002 ld r4,_DAR(r1)
8003 bl .bad_page_fault
8004 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8005 index 9f905e4..1d6b3d2 100644
8006 --- a/arch/powerpc/kernel/exceptions-64s.S
8007 +++ b/arch/powerpc/kernel/exceptions-64s.S
8008 @@ -1390,10 +1390,10 @@ handle_page_fault:
8009 11: ld r4,_DAR(r1)
8010 ld r5,_DSISR(r1)
8011 addi r3,r1,STACK_FRAME_OVERHEAD
8012 + bl .save_nvgprs
8013 bl .do_page_fault
8014 cmpdi r3,0
8015 beq+ 12f
8016 - bl .save_nvgprs
8017 mr r5,r3
8018 addi r3,r1,STACK_FRAME_OVERHEAD
8019 lwz r4,_DAR(r1)
8020 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8021 index 6cff040..74ac5d1 100644
8022 --- a/arch/powerpc/kernel/module_32.c
8023 +++ b/arch/powerpc/kernel/module_32.c
8024 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8025 me->arch.core_plt_section = i;
8026 }
8027 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8028 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8029 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8030 return -ENOEXEC;
8031 }
8032
8033 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8034
8035 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8036 /* Init, or core PLT? */
8037 - if (location >= mod->module_core
8038 - && location < mod->module_core + mod->core_size)
8039 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8040 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8041 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8042 - else
8043 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8044 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8045 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8046 + else {
8047 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8048 + return ~0UL;
8049 + }
8050
8051 /* Find this entry, or if that fails, the next avail. entry */
8052 while (entry->jump[0]) {
8053 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8054 }
8055 #ifdef CONFIG_DYNAMIC_FTRACE
8056 module->arch.tramp =
8057 - do_plt_call(module->module_core,
8058 + do_plt_call(module->module_core_rx,
8059 (unsigned long)ftrace_caller,
8060 sechdrs, module);
8061 #endif
8062 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8063 index 4a96556..dd95f6c 100644
8064 --- a/arch/powerpc/kernel/process.c
8065 +++ b/arch/powerpc/kernel/process.c
8066 @@ -888,8 +888,8 @@ void show_regs(struct pt_regs * regs)
8067 * Lookup NIP late so we have the best change of getting the
8068 * above info out without failing
8069 */
8070 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8071 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8072 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8073 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8074 #endif
8075 show_stack(current, (unsigned long *) regs->gpr[1]);
8076 if (!user_mode(regs))
8077 @@ -1376,10 +1376,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8078 newsp = stack[0];
8079 ip = stack[STACK_FRAME_LR_SAVE];
8080 if (!firstframe || ip != lr) {
8081 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8082 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8083 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8084 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8085 - printk(" (%pS)",
8086 + printk(" (%pA)",
8087 (void *)current->ret_stack[curr_frame].ret);
8088 curr_frame--;
8089 }
8090 @@ -1399,7 +1399,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8091 struct pt_regs *regs = (struct pt_regs *)
8092 (sp + STACK_FRAME_OVERHEAD);
8093 lr = regs->link;
8094 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8095 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8096 regs->trap, (void *)regs->nip, (void *)lr);
8097 firstframe = 1;
8098 }
8099 @@ -1435,58 +1435,3 @@ void notrace __ppc64_runlatch_off(void)
8100 mtspr(SPRN_CTRLT, ctrl);
8101 }
8102 #endif /* CONFIG_PPC64 */
8103 -
8104 -unsigned long arch_align_stack(unsigned long sp)
8105 -{
8106 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8107 - sp -= get_random_int() & ~PAGE_MASK;
8108 - return sp & ~0xf;
8109 -}
8110 -
8111 -static inline unsigned long brk_rnd(void)
8112 -{
8113 - unsigned long rnd = 0;
8114 -
8115 - /* 8MB for 32bit, 1GB for 64bit */
8116 - if (is_32bit_task())
8117 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8118 - else
8119 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8120 -
8121 - return rnd << PAGE_SHIFT;
8122 -}
8123 -
8124 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8125 -{
8126 - unsigned long base = mm->brk;
8127 - unsigned long ret;
8128 -
8129 -#ifdef CONFIG_PPC_STD_MMU_64
8130 - /*
8131 - * If we are using 1TB segments and we are allowed to randomise
8132 - * the heap, we can put it above 1TB so it is backed by a 1TB
8133 - * segment. Otherwise the heap will be in the bottom 1TB
8134 - * which always uses 256MB segments and this may result in a
8135 - * performance penalty.
8136 - */
8137 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8138 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8139 -#endif
8140 -
8141 - ret = PAGE_ALIGN(base + brk_rnd());
8142 -
8143 - if (ret < mm->brk)
8144 - return mm->brk;
8145 -
8146 - return ret;
8147 -}
8148 -
8149 -unsigned long randomize_et_dyn(unsigned long base)
8150 -{
8151 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8152 -
8153 - if (ret < base)
8154 - return base;
8155 -
8156 - return ret;
8157 -}
8158 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8159 index 2e3d2bf..35df241 100644
8160 --- a/arch/powerpc/kernel/ptrace.c
8161 +++ b/arch/powerpc/kernel/ptrace.c
8162 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8163 return ret;
8164 }
8165
8166 +#ifdef CONFIG_GRKERNSEC_SETXID
8167 +extern void gr_delayed_cred_worker(void);
8168 +#endif
8169 +
8170 /*
8171 * We must return the syscall number to actually look up in the table.
8172 * This can be -1L to skip running any syscall at all.
8173 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8174
8175 secure_computing_strict(regs->gpr[0]);
8176
8177 +#ifdef CONFIG_GRKERNSEC_SETXID
8178 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8179 + gr_delayed_cred_worker();
8180 +#endif
8181 +
8182 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8183 tracehook_report_syscall_entry(regs))
8184 /*
8185 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8186 {
8187 int step;
8188
8189 +#ifdef CONFIG_GRKERNSEC_SETXID
8190 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8191 + gr_delayed_cred_worker();
8192 +#endif
8193 +
8194 audit_syscall_exit(regs);
8195
8196 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8197 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8198 index 68027bf..b26fd31 100644
8199 --- a/arch/powerpc/kernel/signal_32.c
8200 +++ b/arch/powerpc/kernel/signal_32.c
8201 @@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8202 /* Save user registers on the stack */
8203 frame = &rt_sf->uc.uc_mcontext;
8204 addr = frame;
8205 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8206 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8207 sigret = 0;
8208 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8209 } else {
8210 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8211 index 4299104..29e2c51 100644
8212 --- a/arch/powerpc/kernel/signal_64.c
8213 +++ b/arch/powerpc/kernel/signal_64.c
8214 @@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8215 #endif
8216
8217 /* Set up to return from userspace. */
8218 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8219 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8220 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8221 } else {
8222 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8223 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8224 index 907a472..4ba206f 100644
8225 --- a/arch/powerpc/kernel/traps.c
8226 +++ b/arch/powerpc/kernel/traps.c
8227 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8228 return flags;
8229 }
8230
8231 +extern void gr_handle_kernel_exploit(void);
8232 +
8233 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8234 int signr)
8235 {
8236 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8237 panic("Fatal exception in interrupt");
8238 if (panic_on_oops)
8239 panic("Fatal exception");
8240 +
8241 + gr_handle_kernel_exploit();
8242 +
8243 do_exit(signr);
8244 }
8245
8246 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8247 index 094e45c..d82b848 100644
8248 --- a/arch/powerpc/kernel/vdso.c
8249 +++ b/arch/powerpc/kernel/vdso.c
8250 @@ -35,6 +35,7 @@
8251 #include <asm/vdso.h>
8252 #include <asm/vdso_datapage.h>
8253 #include <asm/setup.h>
8254 +#include <asm/mman.h>
8255
8256 #undef DEBUG
8257
8258 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8259 vdso_base = VDSO32_MBASE;
8260 #endif
8261
8262 - current->mm->context.vdso_base = 0;
8263 + current->mm->context.vdso_base = ~0UL;
8264
8265 /* vDSO has a problem and was disabled, just don't "enable" it for the
8266 * process
8267 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8268 vdso_base = get_unmapped_area(NULL, vdso_base,
8269 (vdso_pages << PAGE_SHIFT) +
8270 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8271 - 0, 0);
8272 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8273 if (IS_ERR_VALUE(vdso_base)) {
8274 rc = vdso_base;
8275 goto fail_mmapsem;
8276 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8277 index 5eea6f3..5d10396 100644
8278 --- a/arch/powerpc/lib/usercopy_64.c
8279 +++ b/arch/powerpc/lib/usercopy_64.c
8280 @@ -9,22 +9,6 @@
8281 #include <linux/module.h>
8282 #include <asm/uaccess.h>
8283
8284 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8285 -{
8286 - if (likely(access_ok(VERIFY_READ, from, n)))
8287 - n = __copy_from_user(to, from, n);
8288 - else
8289 - memset(to, 0, n);
8290 - return n;
8291 -}
8292 -
8293 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8294 -{
8295 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8296 - n = __copy_to_user(to, from, n);
8297 - return n;
8298 -}
8299 -
8300 unsigned long copy_in_user(void __user *to, const void __user *from,
8301 unsigned long n)
8302 {
8303 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8304 return n;
8305 }
8306
8307 -EXPORT_SYMBOL(copy_from_user);
8308 -EXPORT_SYMBOL(copy_to_user);
8309 EXPORT_SYMBOL(copy_in_user);
8310
8311 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8312 index 51ab9e7..7d3c78b 100644
8313 --- a/arch/powerpc/mm/fault.c
8314 +++ b/arch/powerpc/mm/fault.c
8315 @@ -33,6 +33,10 @@
8316 #include <linux/magic.h>
8317 #include <linux/ratelimit.h>
8318 #include <linux/context_tracking.h>
8319 +#include <linux/slab.h>
8320 +#include <linux/pagemap.h>
8321 +#include <linux/compiler.h>
8322 +#include <linux/unistd.h>
8323
8324 #include <asm/firmware.h>
8325 #include <asm/page.h>
8326 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8327 }
8328 #endif
8329
8330 +#ifdef CONFIG_PAX_PAGEEXEC
8331 +/*
8332 + * PaX: decide what to do with offenders (regs->nip = fault address)
8333 + *
8334 + * returns 1 when task should be killed
8335 + */
8336 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8337 +{
8338 + return 1;
8339 +}
8340 +
8341 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8342 +{
8343 + unsigned long i;
8344 +
8345 + printk(KERN_ERR "PAX: bytes at PC: ");
8346 + for (i = 0; i < 5; i++) {
8347 + unsigned int c;
8348 + if (get_user(c, (unsigned int __user *)pc+i))
8349 + printk(KERN_CONT "???????? ");
8350 + else
8351 + printk(KERN_CONT "%08x ", c);
8352 + }
8353 + printk("\n");
8354 +}
8355 +#endif
8356 +
8357 /*
8358 * Check whether the instruction at regs->nip is a store using
8359 * an update addressing form which will update r1.
8360 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8361 * indicate errors in DSISR but can validly be set in SRR1.
8362 */
8363 if (trap == 0x400)
8364 - error_code &= 0x48200000;
8365 + error_code &= 0x58200000;
8366 else
8367 is_write = error_code & DSISR_ISSTORE;
8368 #else
8369 @@ -378,7 +409,7 @@ good_area:
8370 * "undefined". Of those that can be set, this is the only
8371 * one which seems bad.
8372 */
8373 - if (error_code & 0x10000000)
8374 + if (error_code & DSISR_GUARDED)
8375 /* Guarded storage error. */
8376 goto bad_area;
8377 #endif /* CONFIG_8xx */
8378 @@ -393,7 +424,7 @@ good_area:
8379 * processors use the same I/D cache coherency mechanism
8380 * as embedded.
8381 */
8382 - if (error_code & DSISR_PROTFAULT)
8383 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8384 goto bad_area;
8385 #endif /* CONFIG_PPC_STD_MMU */
8386
8387 @@ -483,6 +514,23 @@ bad_area:
8388 bad_area_nosemaphore:
8389 /* User mode accesses cause a SIGSEGV */
8390 if (user_mode(regs)) {
8391 +
8392 +#ifdef CONFIG_PAX_PAGEEXEC
8393 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8394 +#ifdef CONFIG_PPC_STD_MMU
8395 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8396 +#else
8397 + if (is_exec && regs->nip == address) {
8398 +#endif
8399 + switch (pax_handle_fetch_fault(regs)) {
8400 + }
8401 +
8402 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8403 + do_group_exit(SIGKILL);
8404 + }
8405 + }
8406 +#endif
8407 +
8408 _exception(SIGSEGV, regs, code, address);
8409 goto bail;
8410 }
8411 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8412 index cb8bdbe..d770680 100644
8413 --- a/arch/powerpc/mm/mmap.c
8414 +++ b/arch/powerpc/mm/mmap.c
8415 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8416 {
8417 unsigned long rnd = 0;
8418
8419 +#ifdef CONFIG_PAX_RANDMMAP
8420 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8421 +#endif
8422 +
8423 if (current->flags & PF_RANDOMIZE) {
8424 /* 8MB for 32bit, 1GB for 64bit */
8425 if (is_32bit_task())
8426 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8427 */
8428 if (mmap_is_legacy()) {
8429 mm->mmap_base = TASK_UNMAPPED_BASE;
8430 +
8431 +#ifdef CONFIG_PAX_RANDMMAP
8432 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8433 + mm->mmap_base += mm->delta_mmap;
8434 +#endif
8435 +
8436 mm->get_unmapped_area = arch_get_unmapped_area;
8437 } else {
8438 mm->mmap_base = mmap_base();
8439 +
8440 +#ifdef CONFIG_PAX_RANDMMAP
8441 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8442 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8443 +#endif
8444 +
8445 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8446 }
8447 }
8448 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8449 index 7ce9cf3..a964087 100644
8450 --- a/arch/powerpc/mm/slice.c
8451 +++ b/arch/powerpc/mm/slice.c
8452 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8453 if ((mm->task_size - len) < addr)
8454 return 0;
8455 vma = find_vma(mm, addr);
8456 - return (!vma || (addr + len) <= vma->vm_start);
8457 + return check_heap_stack_gap(vma, addr, len, 0);
8458 }
8459
8460 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8461 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8462 info.align_offset = 0;
8463
8464 addr = TASK_UNMAPPED_BASE;
8465 +
8466 +#ifdef CONFIG_PAX_RANDMMAP
8467 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8468 + addr += mm->delta_mmap;
8469 +#endif
8470 +
8471 while (addr < TASK_SIZE) {
8472 info.low_limit = addr;
8473 if (!slice_scan_available(addr, available, 1, &addr))
8474 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8475 if (fixed && addr > (mm->task_size - len))
8476 return -EINVAL;
8477
8478 +#ifdef CONFIG_PAX_RANDMMAP
8479 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8480 + addr = 0;
8481 +#endif
8482 +
8483 /* If hint, make sure it matches our alignment restrictions */
8484 if (!fixed && addr) {
8485 addr = _ALIGN_UP(addr, 1ul << pshift);
8486 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8487 index 9098692..3d54cd1 100644
8488 --- a/arch/powerpc/platforms/cell/spufs/file.c
8489 +++ b/arch/powerpc/platforms/cell/spufs/file.c
8490 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8491 return VM_FAULT_NOPAGE;
8492 }
8493
8494 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8495 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8496 unsigned long address,
8497 - void *buf, int len, int write)
8498 + void *buf, size_t len, int write)
8499 {
8500 struct spu_context *ctx = vma->vm_file->private_data;
8501 unsigned long offset = address - vma->vm_start;
8502 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8503 index fa9aaf7..3f5d836 100644
8504 --- a/arch/s390/include/asm/atomic.h
8505 +++ b/arch/s390/include/asm/atomic.h
8506 @@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8507 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8508 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8509
8510 +#define atomic64_read_unchecked(v) atomic64_read(v)
8511 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8512 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8513 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8514 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8515 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8516 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8517 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8518 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8519 +
8520 #define smp_mb__before_atomic_dec() smp_mb()
8521 #define smp_mb__after_atomic_dec() smp_mb()
8522 #define smp_mb__before_atomic_inc() smp_mb()
8523 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8524 index 4d7ccac..d03d0ad 100644
8525 --- a/arch/s390/include/asm/cache.h
8526 +++ b/arch/s390/include/asm/cache.h
8527 @@ -9,8 +9,10 @@
8528 #ifndef __ARCH_S390_CACHE_H
8529 #define __ARCH_S390_CACHE_H
8530
8531 -#define L1_CACHE_BYTES 256
8532 +#include <linux/const.h>
8533 +
8534 #define L1_CACHE_SHIFT 8
8535 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8536 #define NET_SKB_PAD 32
8537
8538 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8539 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8540 index 78f4f87..598ce39 100644
8541 --- a/arch/s390/include/asm/elf.h
8542 +++ b/arch/s390/include/asm/elf.h
8543 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8544 the loader. We need to make sure that it is out of the way of the program
8545 that it will "exec", and that there is sufficient room for the brk. */
8546
8547 -extern unsigned long randomize_et_dyn(unsigned long base);
8548 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8549 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8550 +
8551 +#ifdef CONFIG_PAX_ASLR
8552 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8553 +
8554 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8555 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8556 +#endif
8557
8558 /* This yields a mask that user programs can use to figure out what
8559 instruction set this CPU supports. */
8560 @@ -222,9 +228,6 @@ struct linux_binprm;
8561 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8562 int arch_setup_additional_pages(struct linux_binprm *, int);
8563
8564 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8565 -#define arch_randomize_brk arch_randomize_brk
8566 -
8567 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8568
8569 #endif
8570 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8571 index c4a93d6..4d2a9b4 100644
8572 --- a/arch/s390/include/asm/exec.h
8573 +++ b/arch/s390/include/asm/exec.h
8574 @@ -7,6 +7,6 @@
8575 #ifndef __ASM_EXEC_H
8576 #define __ASM_EXEC_H
8577
8578 -extern unsigned long arch_align_stack(unsigned long sp);
8579 +#define arch_align_stack(x) ((x) & ~0xfUL)
8580
8581 #endif /* __ASM_EXEC_H */
8582 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8583 index 79330af..a3a7b06 100644
8584 --- a/arch/s390/include/asm/uaccess.h
8585 +++ b/arch/s390/include/asm/uaccess.h
8586 @@ -245,6 +245,10 @@ static inline unsigned long __must_check
8587 copy_to_user(void __user *to, const void *from, unsigned long n)
8588 {
8589 might_fault();
8590 +
8591 + if ((long)n < 0)
8592 + return n;
8593 +
8594 return __copy_to_user(to, from, n);
8595 }
8596
8597 @@ -268,6 +272,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8598 static inline unsigned long __must_check
8599 __copy_from_user(void *to, const void __user *from, unsigned long n)
8600 {
8601 + if ((long)n < 0)
8602 + return n;
8603 +
8604 return uaccess.copy_from_user(n, from, to);
8605 }
8606
8607 @@ -296,10 +303,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8608 static inline unsigned long __must_check
8609 copy_from_user(void *to, const void __user *from, unsigned long n)
8610 {
8611 - unsigned int sz = __compiletime_object_size(to);
8612 + size_t sz = __compiletime_object_size(to);
8613
8614 might_fault();
8615 - if (unlikely(sz != -1 && sz < n)) {
8616 +
8617 + if ((long)n < 0)
8618 + return n;
8619 +
8620 + if (unlikely(sz != (size_t)-1 && sz < n)) {
8621 copy_from_user_overflow();
8622 return n;
8623 }
8624 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8625 index b89b591..fd9609d 100644
8626 --- a/arch/s390/kernel/module.c
8627 +++ b/arch/s390/kernel/module.c
8628 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8629
8630 /* Increase core size by size of got & plt and set start
8631 offsets for got and plt. */
8632 - me->core_size = ALIGN(me->core_size, 4);
8633 - me->arch.got_offset = me->core_size;
8634 - me->core_size += me->arch.got_size;
8635 - me->arch.plt_offset = me->core_size;
8636 - me->core_size += me->arch.plt_size;
8637 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
8638 + me->arch.got_offset = me->core_size_rw;
8639 + me->core_size_rw += me->arch.got_size;
8640 + me->arch.plt_offset = me->core_size_rx;
8641 + me->core_size_rx += me->arch.plt_size;
8642 return 0;
8643 }
8644
8645 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8646 if (info->got_initialized == 0) {
8647 Elf_Addr *gotent;
8648
8649 - gotent = me->module_core + me->arch.got_offset +
8650 + gotent = me->module_core_rw + me->arch.got_offset +
8651 info->got_offset;
8652 *gotent = val;
8653 info->got_initialized = 1;
8654 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8655 rc = apply_rela_bits(loc, val, 0, 64, 0);
8656 else if (r_type == R_390_GOTENT ||
8657 r_type == R_390_GOTPLTENT) {
8658 - val += (Elf_Addr) me->module_core - loc;
8659 + val += (Elf_Addr) me->module_core_rw - loc;
8660 rc = apply_rela_bits(loc, val, 1, 32, 1);
8661 }
8662 break;
8663 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8664 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8665 if (info->plt_initialized == 0) {
8666 unsigned int *ip;
8667 - ip = me->module_core + me->arch.plt_offset +
8668 + ip = me->module_core_rx + me->arch.plt_offset +
8669 info->plt_offset;
8670 #ifndef CONFIG_64BIT
8671 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8672 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8673 val - loc + 0xffffUL < 0x1ffffeUL) ||
8674 (r_type == R_390_PLT32DBL &&
8675 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8676 - val = (Elf_Addr) me->module_core +
8677 + val = (Elf_Addr) me->module_core_rx +
8678 me->arch.plt_offset +
8679 info->plt_offset;
8680 val += rela->r_addend - loc;
8681 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8682 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8683 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8684 val = val + rela->r_addend -
8685 - ((Elf_Addr) me->module_core + me->arch.got_offset);
8686 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8687 if (r_type == R_390_GOTOFF16)
8688 rc = apply_rela_bits(loc, val, 0, 16, 0);
8689 else if (r_type == R_390_GOTOFF32)
8690 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8691 break;
8692 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8693 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8694 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
8695 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8696 rela->r_addend - loc;
8697 if (r_type == R_390_GOTPC)
8698 rc = apply_rela_bits(loc, val, 1, 32, 0);
8699 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8700 index 7ed0d4e..1dfc145 100644
8701 --- a/arch/s390/kernel/process.c
8702 +++ b/arch/s390/kernel/process.c
8703 @@ -242,39 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
8704 }
8705 return 0;
8706 }
8707 -
8708 -unsigned long arch_align_stack(unsigned long sp)
8709 -{
8710 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8711 - sp -= get_random_int() & ~PAGE_MASK;
8712 - return sp & ~0xf;
8713 -}
8714 -
8715 -static inline unsigned long brk_rnd(void)
8716 -{
8717 - /* 8MB for 32bit, 1GB for 64bit */
8718 - if (is_32bit_task())
8719 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8720 - else
8721 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8722 -}
8723 -
8724 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8725 -{
8726 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8727 -
8728 - if (ret < mm->brk)
8729 - return mm->brk;
8730 - return ret;
8731 -}
8732 -
8733 -unsigned long randomize_et_dyn(unsigned long base)
8734 -{
8735 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8736 -
8737 - if (!(current->flags & PF_RANDOMIZE))
8738 - return base;
8739 - if (ret < base)
8740 - return base;
8741 - return ret;
8742 -}
8743 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8744 index 9b436c2..54fbf0a 100644
8745 --- a/arch/s390/mm/mmap.c
8746 +++ b/arch/s390/mm/mmap.c
8747 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8748 */
8749 if (mmap_is_legacy()) {
8750 mm->mmap_base = mmap_base_legacy();
8751 +
8752 +#ifdef CONFIG_PAX_RANDMMAP
8753 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8754 + mm->mmap_base += mm->delta_mmap;
8755 +#endif
8756 +
8757 mm->get_unmapped_area = arch_get_unmapped_area;
8758 } else {
8759 mm->mmap_base = mmap_base();
8760 +
8761 +#ifdef CONFIG_PAX_RANDMMAP
8762 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8763 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8764 +#endif
8765 +
8766 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8767 }
8768 }
8769 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8770 */
8771 if (mmap_is_legacy()) {
8772 mm->mmap_base = mmap_base_legacy();
8773 +
8774 +#ifdef CONFIG_PAX_RANDMMAP
8775 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8776 + mm->mmap_base += mm->delta_mmap;
8777 +#endif
8778 +
8779 mm->get_unmapped_area = s390_get_unmapped_area;
8780 } else {
8781 mm->mmap_base = mmap_base();
8782 +
8783 +#ifdef CONFIG_PAX_RANDMMAP
8784 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8785 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8786 +#endif
8787 +
8788 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8789 }
8790 }
8791 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8792 index ae3d59f..f65f075 100644
8793 --- a/arch/score/include/asm/cache.h
8794 +++ b/arch/score/include/asm/cache.h
8795 @@ -1,7 +1,9 @@
8796 #ifndef _ASM_SCORE_CACHE_H
8797 #define _ASM_SCORE_CACHE_H
8798
8799 +#include <linux/const.h>
8800 +
8801 #define L1_CACHE_SHIFT 4
8802 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8803 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8804
8805 #endif /* _ASM_SCORE_CACHE_H */
8806 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8807 index f9f3cd5..58ff438 100644
8808 --- a/arch/score/include/asm/exec.h
8809 +++ b/arch/score/include/asm/exec.h
8810 @@ -1,6 +1,6 @@
8811 #ifndef _ASM_SCORE_EXEC_H
8812 #define _ASM_SCORE_EXEC_H
8813
8814 -extern unsigned long arch_align_stack(unsigned long sp);
8815 +#define arch_align_stack(x) (x)
8816
8817 #endif /* _ASM_SCORE_EXEC_H */
8818 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8819 index a1519ad3..e8ac1ff 100644
8820 --- a/arch/score/kernel/process.c
8821 +++ b/arch/score/kernel/process.c
8822 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8823
8824 return task_pt_regs(task)->cp0_epc;
8825 }
8826 -
8827 -unsigned long arch_align_stack(unsigned long sp)
8828 -{
8829 - return sp;
8830 -}
8831 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8832 index ef9e555..331bd29 100644
8833 --- a/arch/sh/include/asm/cache.h
8834 +++ b/arch/sh/include/asm/cache.h
8835 @@ -9,10 +9,11 @@
8836 #define __ASM_SH_CACHE_H
8837 #ifdef __KERNEL__
8838
8839 +#include <linux/const.h>
8840 #include <linux/init.h>
8841 #include <cpu/cache.h>
8842
8843 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8844 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8845
8846 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8847
8848 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8849 index 6777177..cb5e44f 100644
8850 --- a/arch/sh/mm/mmap.c
8851 +++ b/arch/sh/mm/mmap.c
8852 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8853 struct mm_struct *mm = current->mm;
8854 struct vm_area_struct *vma;
8855 int do_colour_align;
8856 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8857 struct vm_unmapped_area_info info;
8858
8859 if (flags & MAP_FIXED) {
8860 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8861 if (filp || (flags & MAP_SHARED))
8862 do_colour_align = 1;
8863
8864 +#ifdef CONFIG_PAX_RANDMMAP
8865 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8866 +#endif
8867 +
8868 if (addr) {
8869 if (do_colour_align)
8870 addr = COLOUR_ALIGN(addr, pgoff);
8871 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8872 addr = PAGE_ALIGN(addr);
8873
8874 vma = find_vma(mm, addr);
8875 - if (TASK_SIZE - len >= addr &&
8876 - (!vma || addr + len <= vma->vm_start))
8877 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8878 return addr;
8879 }
8880
8881 info.flags = 0;
8882 info.length = len;
8883 - info.low_limit = TASK_UNMAPPED_BASE;
8884 + info.low_limit = mm->mmap_base;
8885 info.high_limit = TASK_SIZE;
8886 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8887 info.align_offset = pgoff << PAGE_SHIFT;
8888 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8889 struct mm_struct *mm = current->mm;
8890 unsigned long addr = addr0;
8891 int do_colour_align;
8892 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8893 struct vm_unmapped_area_info info;
8894
8895 if (flags & MAP_FIXED) {
8896 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8897 if (filp || (flags & MAP_SHARED))
8898 do_colour_align = 1;
8899
8900 +#ifdef CONFIG_PAX_RANDMMAP
8901 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8902 +#endif
8903 +
8904 /* requesting a specific address */
8905 if (addr) {
8906 if (do_colour_align)
8907 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8908 addr = PAGE_ALIGN(addr);
8909
8910 vma = find_vma(mm, addr);
8911 - if (TASK_SIZE - len >= addr &&
8912 - (!vma || addr + len <= vma->vm_start))
8913 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8914 return addr;
8915 }
8916
8917 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8918 VM_BUG_ON(addr != -ENOMEM);
8919 info.flags = 0;
8920 info.low_limit = TASK_UNMAPPED_BASE;
8921 +
8922 +#ifdef CONFIG_PAX_RANDMMAP
8923 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8924 + info.low_limit += mm->delta_mmap;
8925 +#endif
8926 +
8927 info.high_limit = TASK_SIZE;
8928 addr = vm_unmapped_area(&info);
8929 }
8930 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8931 index be56a24..443328f 100644
8932 --- a/arch/sparc/include/asm/atomic_64.h
8933 +++ b/arch/sparc/include/asm/atomic_64.h
8934 @@ -14,18 +14,40 @@
8935 #define ATOMIC64_INIT(i) { (i) }
8936
8937 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8938 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8939 +{
8940 + return v->counter;
8941 +}
8942 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8943 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8944 +{
8945 + return v->counter;
8946 +}
8947
8948 #define atomic_set(v, i) (((v)->counter) = i)
8949 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8950 +{
8951 + v->counter = i;
8952 +}
8953 #define atomic64_set(v, i) (((v)->counter) = i)
8954 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8955 +{
8956 + v->counter = i;
8957 +}
8958
8959 extern void atomic_add(int, atomic_t *);
8960 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8961 extern void atomic64_add(long, atomic64_t *);
8962 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8963 extern void atomic_sub(int, atomic_t *);
8964 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8965 extern void atomic64_sub(long, atomic64_t *);
8966 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8967
8968 extern int atomic_add_ret(int, atomic_t *);
8969 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8970 extern long atomic64_add_ret(long, atomic64_t *);
8971 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8972 extern int atomic_sub_ret(int, atomic_t *);
8973 extern long atomic64_sub_ret(long, atomic64_t *);
8974
8975 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8976 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8977
8978 #define atomic_inc_return(v) atomic_add_ret(1, v)
8979 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8980 +{
8981 + return atomic_add_ret_unchecked(1, v);
8982 +}
8983 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8984 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8985 +{
8986 + return atomic64_add_ret_unchecked(1, v);
8987 +}
8988
8989 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8990 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8991
8992 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8993 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8994 +{
8995 + return atomic_add_ret_unchecked(i, v);
8996 +}
8997 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8998 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8999 +{
9000 + return atomic64_add_ret_unchecked(i, v);
9001 +}
9002
9003 /*
9004 * atomic_inc_and_test - increment and test
9005 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9006 * other cases.
9007 */
9008 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9009 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9010 +{
9011 + return atomic_inc_return_unchecked(v) == 0;
9012 +}
9013 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9014
9015 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9016 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9017 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9018
9019 #define atomic_inc(v) atomic_add(1, v)
9020 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9021 +{
9022 + atomic_add_unchecked(1, v);
9023 +}
9024 #define atomic64_inc(v) atomic64_add(1, v)
9025 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9026 +{
9027 + atomic64_add_unchecked(1, v);
9028 +}
9029
9030 #define atomic_dec(v) atomic_sub(1, v)
9031 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9032 +{
9033 + atomic_sub_unchecked(1, v);
9034 +}
9035 #define atomic64_dec(v) atomic64_sub(1, v)
9036 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9037 +{
9038 + atomic64_sub_unchecked(1, v);
9039 +}
9040
9041 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9042 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9043
9044 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9045 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9046 +{
9047 + return cmpxchg(&v->counter, old, new);
9048 +}
9049 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9050 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9051 +{
9052 + return xchg(&v->counter, new);
9053 +}
9054
9055 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9056 {
9057 - int c, old;
9058 + int c, old, new;
9059 c = atomic_read(v);
9060 for (;;) {
9061 - if (unlikely(c == (u)))
9062 + if (unlikely(c == u))
9063 break;
9064 - old = atomic_cmpxchg((v), c, c + (a));
9065 +
9066 + asm volatile("addcc %2, %0, %0\n"
9067 +
9068 +#ifdef CONFIG_PAX_REFCOUNT
9069 + "tvs %%icc, 6\n"
9070 +#endif
9071 +
9072 + : "=r" (new)
9073 + : "0" (c), "ir" (a)
9074 + : "cc");
9075 +
9076 + old = atomic_cmpxchg(v, c, new);
9077 if (likely(old == c))
9078 break;
9079 c = old;
9080 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9081 #define atomic64_cmpxchg(v, o, n) \
9082 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9083 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9084 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9085 +{
9086 + return xchg(&v->counter, new);
9087 +}
9088
9089 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9090 {
9091 - long c, old;
9092 + long c, old, new;
9093 c = atomic64_read(v);
9094 for (;;) {
9095 - if (unlikely(c == (u)))
9096 + if (unlikely(c == u))
9097 break;
9098 - old = atomic64_cmpxchg((v), c, c + (a));
9099 +
9100 + asm volatile("addcc %2, %0, %0\n"
9101 +
9102 +#ifdef CONFIG_PAX_REFCOUNT
9103 + "tvs %%xcc, 6\n"
9104 +#endif
9105 +
9106 + : "=r" (new)
9107 + : "0" (c), "ir" (a)
9108 + : "cc");
9109 +
9110 + old = atomic64_cmpxchg(v, c, new);
9111 if (likely(old == c))
9112 break;
9113 c = old;
9114 }
9115 - return c != (u);
9116 + return c != u;
9117 }
9118
9119 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9120 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9121 index 5bb6991..5c2132e 100644
9122 --- a/arch/sparc/include/asm/cache.h
9123 +++ b/arch/sparc/include/asm/cache.h
9124 @@ -7,10 +7,12 @@
9125 #ifndef _SPARC_CACHE_H
9126 #define _SPARC_CACHE_H
9127
9128 +#include <linux/const.h>
9129 +
9130 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9131
9132 #define L1_CACHE_SHIFT 5
9133 -#define L1_CACHE_BYTES 32
9134 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9135
9136 #ifdef CONFIG_SPARC32
9137 #define SMP_CACHE_BYTES_SHIFT 5
9138 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9139 index a24e41f..47677ff 100644
9140 --- a/arch/sparc/include/asm/elf_32.h
9141 +++ b/arch/sparc/include/asm/elf_32.h
9142 @@ -114,6 +114,13 @@ typedef struct {
9143
9144 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9145
9146 +#ifdef CONFIG_PAX_ASLR
9147 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9148 +
9149 +#define PAX_DELTA_MMAP_LEN 16
9150 +#define PAX_DELTA_STACK_LEN 16
9151 +#endif
9152 +
9153 /* This yields a mask that user programs can use to figure out what
9154 instruction set this cpu supports. This can NOT be done in userspace
9155 on Sparc. */
9156 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9157 index 370ca1e..d4f4a98 100644
9158 --- a/arch/sparc/include/asm/elf_64.h
9159 +++ b/arch/sparc/include/asm/elf_64.h
9160 @@ -189,6 +189,13 @@ typedef struct {
9161 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9162 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9163
9164 +#ifdef CONFIG_PAX_ASLR
9165 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9166 +
9167 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9168 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9169 +#endif
9170 +
9171 extern unsigned long sparc64_elf_hwcap;
9172 #define ELF_HWCAP sparc64_elf_hwcap
9173
9174 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9175 index 9b1c36d..209298b 100644
9176 --- a/arch/sparc/include/asm/pgalloc_32.h
9177 +++ b/arch/sparc/include/asm/pgalloc_32.h
9178 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9179 }
9180
9181 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9182 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9183
9184 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9185 unsigned long address)
9186 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9187 index bcfe063..b333142 100644
9188 --- a/arch/sparc/include/asm/pgalloc_64.h
9189 +++ b/arch/sparc/include/asm/pgalloc_64.h
9190 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9191 }
9192
9193 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9194 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9195
9196 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9197 {
9198 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9199 index 502f632..da1917f 100644
9200 --- a/arch/sparc/include/asm/pgtable_32.h
9201 +++ b/arch/sparc/include/asm/pgtable_32.h
9202 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9203 #define PAGE_SHARED SRMMU_PAGE_SHARED
9204 #define PAGE_COPY SRMMU_PAGE_COPY
9205 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9206 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9207 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9208 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9209 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9210
9211 /* Top-level page directory - dummy used by init-mm.
9212 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9213
9214 /* xwr */
9215 #define __P000 PAGE_NONE
9216 -#define __P001 PAGE_READONLY
9217 -#define __P010 PAGE_COPY
9218 -#define __P011 PAGE_COPY
9219 +#define __P001 PAGE_READONLY_NOEXEC
9220 +#define __P010 PAGE_COPY_NOEXEC
9221 +#define __P011 PAGE_COPY_NOEXEC
9222 #define __P100 PAGE_READONLY
9223 #define __P101 PAGE_READONLY
9224 #define __P110 PAGE_COPY
9225 #define __P111 PAGE_COPY
9226
9227 #define __S000 PAGE_NONE
9228 -#define __S001 PAGE_READONLY
9229 -#define __S010 PAGE_SHARED
9230 -#define __S011 PAGE_SHARED
9231 +#define __S001 PAGE_READONLY_NOEXEC
9232 +#define __S010 PAGE_SHARED_NOEXEC
9233 +#define __S011 PAGE_SHARED_NOEXEC
9234 #define __S100 PAGE_READONLY
9235 #define __S101 PAGE_READONLY
9236 #define __S110 PAGE_SHARED
9237 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9238 index 79da178..c2eede8 100644
9239 --- a/arch/sparc/include/asm/pgtsrmmu.h
9240 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9241 @@ -115,6 +115,11 @@
9242 SRMMU_EXEC | SRMMU_REF)
9243 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9244 SRMMU_EXEC | SRMMU_REF)
9245 +
9246 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9247 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9248 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9249 +
9250 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9251 SRMMU_DIRTY | SRMMU_REF)
9252
9253 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9254 index 9689176..63c18ea 100644
9255 --- a/arch/sparc/include/asm/spinlock_64.h
9256 +++ b/arch/sparc/include/asm/spinlock_64.h
9257 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9258
9259 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9260
9261 -static void inline arch_read_lock(arch_rwlock_t *lock)
9262 +static inline void arch_read_lock(arch_rwlock_t *lock)
9263 {
9264 unsigned long tmp1, tmp2;
9265
9266 __asm__ __volatile__ (
9267 "1: ldsw [%2], %0\n"
9268 " brlz,pn %0, 2f\n"
9269 -"4: add %0, 1, %1\n"
9270 +"4: addcc %0, 1, %1\n"
9271 +
9272 +#ifdef CONFIG_PAX_REFCOUNT
9273 +" tvs %%icc, 6\n"
9274 +#endif
9275 +
9276 " cas [%2], %0, %1\n"
9277 " cmp %0, %1\n"
9278 " bne,pn %%icc, 1b\n"
9279 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9280 " .previous"
9281 : "=&r" (tmp1), "=&r" (tmp2)
9282 : "r" (lock)
9283 - : "memory");
9284 + : "memory", "cc");
9285 }
9286
9287 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9288 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9289 {
9290 int tmp1, tmp2;
9291
9292 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9293 "1: ldsw [%2], %0\n"
9294 " brlz,a,pn %0, 2f\n"
9295 " mov 0, %0\n"
9296 -" add %0, 1, %1\n"
9297 +" addcc %0, 1, %1\n"
9298 +
9299 +#ifdef CONFIG_PAX_REFCOUNT
9300 +" tvs %%icc, 6\n"
9301 +#endif
9302 +
9303 " cas [%2], %0, %1\n"
9304 " cmp %0, %1\n"
9305 " bne,pn %%icc, 1b\n"
9306 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9307 return tmp1;
9308 }
9309
9310 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9311 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9312 {
9313 unsigned long tmp1, tmp2;
9314
9315 __asm__ __volatile__(
9316 "1: lduw [%2], %0\n"
9317 -" sub %0, 1, %1\n"
9318 +" subcc %0, 1, %1\n"
9319 +
9320 +#ifdef CONFIG_PAX_REFCOUNT
9321 +" tvs %%icc, 6\n"
9322 +#endif
9323 +
9324 " cas [%2], %0, %1\n"
9325 " cmp %0, %1\n"
9326 " bne,pn %%xcc, 1b\n"
9327 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9328 : "memory");
9329 }
9330
9331 -static void inline arch_write_lock(arch_rwlock_t *lock)
9332 +static inline void arch_write_lock(arch_rwlock_t *lock)
9333 {
9334 unsigned long mask, tmp1, tmp2;
9335
9336 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9337 : "memory");
9338 }
9339
9340 -static void inline arch_write_unlock(arch_rwlock_t *lock)
9341 +static inline void arch_write_unlock(arch_rwlock_t *lock)
9342 {
9343 __asm__ __volatile__(
9344 " stw %%g0, [%0]"
9345 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9346 : "memory");
9347 }
9348
9349 -static int inline arch_write_trylock(arch_rwlock_t *lock)
9350 +static inline int arch_write_trylock(arch_rwlock_t *lock)
9351 {
9352 unsigned long mask, tmp1, tmp2, result;
9353
9354 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9355 index 96efa7a..16858bf 100644
9356 --- a/arch/sparc/include/asm/thread_info_32.h
9357 +++ b/arch/sparc/include/asm/thread_info_32.h
9358 @@ -49,6 +49,8 @@ struct thread_info {
9359 unsigned long w_saved;
9360
9361 struct restart_block restart_block;
9362 +
9363 + unsigned long lowest_stack;
9364 };
9365
9366 /*
9367 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9368 index a5f01ac..703b554 100644
9369 --- a/arch/sparc/include/asm/thread_info_64.h
9370 +++ b/arch/sparc/include/asm/thread_info_64.h
9371 @@ -63,6 +63,8 @@ struct thread_info {
9372 struct pt_regs *kern_una_regs;
9373 unsigned int kern_una_insn;
9374
9375 + unsigned long lowest_stack;
9376 +
9377 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9378 };
9379
9380 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9381 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9382 /* flag bit 4 is available */
9383 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9384 -/* flag bit 6 is available */
9385 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9386 #define TIF_32BIT 7 /* 32-bit binary */
9387 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9388 #define TIF_SECCOMP 9 /* secure computing */
9389 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9390 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9391 +
9392 /* NOTE: Thread flags >= 12 should be ones we have no interest
9393 * in using in assembly, else we can't use the mask as
9394 * an immediate value in instructions such as andcc.
9395 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9396 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9397 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9398 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9399 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9400
9401 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9402 _TIF_DO_NOTIFY_RESUME_MASK | \
9403 _TIF_NEED_RESCHED)
9404 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9405
9406 +#define _TIF_WORK_SYSCALL \
9407 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9408 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9409 +
9410 +
9411 /*
9412 * Thread-synchronous status.
9413 *
9414 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9415 index 0167d26..767bb0c 100644
9416 --- a/arch/sparc/include/asm/uaccess.h
9417 +++ b/arch/sparc/include/asm/uaccess.h
9418 @@ -1,5 +1,6 @@
9419 #ifndef ___ASM_SPARC_UACCESS_H
9420 #define ___ASM_SPARC_UACCESS_H
9421 +
9422 #if defined(__sparc__) && defined(__arch64__)
9423 #include <asm/uaccess_64.h>
9424 #else
9425 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9426 index 53a28dd..50c38c3 100644
9427 --- a/arch/sparc/include/asm/uaccess_32.h
9428 +++ b/arch/sparc/include/asm/uaccess_32.h
9429 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9430
9431 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9432 {
9433 - if (n && __access_ok((unsigned long) to, n))
9434 + if ((long)n < 0)
9435 + return n;
9436 +
9437 + if (n && __access_ok((unsigned long) to, n)) {
9438 + if (!__builtin_constant_p(n))
9439 + check_object_size(from, n, true);
9440 return __copy_user(to, (__force void __user *) from, n);
9441 - else
9442 + } else
9443 return n;
9444 }
9445
9446 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9447 {
9448 + if ((long)n < 0)
9449 + return n;
9450 +
9451 + if (!__builtin_constant_p(n))
9452 + check_object_size(from, n, true);
9453 +
9454 return __copy_user(to, (__force void __user *) from, n);
9455 }
9456
9457 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9458 {
9459 - if (n && __access_ok((unsigned long) from, n))
9460 + if ((long)n < 0)
9461 + return n;
9462 +
9463 + if (n && __access_ok((unsigned long) from, n)) {
9464 + if (!__builtin_constant_p(n))
9465 + check_object_size(to, n, false);
9466 return __copy_user((__force void __user *) to, from, n);
9467 - else
9468 + } else
9469 return n;
9470 }
9471
9472 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9473 {
9474 + if ((long)n < 0)
9475 + return n;
9476 +
9477 return __copy_user((__force void __user *) to, from, n);
9478 }
9479
9480 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9481 index ad7e178..c9e7423 100644
9482 --- a/arch/sparc/include/asm/uaccess_64.h
9483 +++ b/arch/sparc/include/asm/uaccess_64.h
9484 @@ -10,6 +10,7 @@
9485 #include <linux/compiler.h>
9486 #include <linux/string.h>
9487 #include <linux/thread_info.h>
9488 +#include <linux/kernel.h>
9489 #include <asm/asi.h>
9490 #include <asm/spitfire.h>
9491 #include <asm-generic/uaccess-unaligned.h>
9492 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9493 static inline unsigned long __must_check
9494 copy_from_user(void *to, const void __user *from, unsigned long size)
9495 {
9496 - unsigned long ret = ___copy_from_user(to, from, size);
9497 + unsigned long ret;
9498
9499 + if ((long)size < 0 || size > INT_MAX)
9500 + return size;
9501 +
9502 + if (!__builtin_constant_p(size))
9503 + check_object_size(to, size, false);
9504 +
9505 + ret = ___copy_from_user(to, from, size);
9506 if (unlikely(ret))
9507 ret = copy_from_user_fixup(to, from, size);
9508
9509 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9510 static inline unsigned long __must_check
9511 copy_to_user(void __user *to, const void *from, unsigned long size)
9512 {
9513 - unsigned long ret = ___copy_to_user(to, from, size);
9514 + unsigned long ret;
9515
9516 + if ((long)size < 0 || size > INT_MAX)
9517 + return size;
9518 +
9519 + if (!__builtin_constant_p(size))
9520 + check_object_size(from, size, true);
9521 +
9522 + ret = ___copy_to_user(to, from, size);
9523 if (unlikely(ret))
9524 ret = copy_to_user_fixup(to, from, size);
9525 return ret;
9526 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9527 index d15cc17..d0ae796 100644
9528 --- a/arch/sparc/kernel/Makefile
9529 +++ b/arch/sparc/kernel/Makefile
9530 @@ -4,7 +4,7 @@
9531 #
9532
9533 asflags-y := -ansi
9534 -ccflags-y := -Werror
9535 +#ccflags-y := -Werror
9536
9537 extra-y := head_$(BITS).o
9538
9539 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9540 index fdd819d..5af08c8 100644
9541 --- a/arch/sparc/kernel/process_32.c
9542 +++ b/arch/sparc/kernel/process_32.c
9543 @@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9544
9545 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9546 r->psr, r->pc, r->npc, r->y, print_tainted());
9547 - printk("PC: <%pS>\n", (void *) r->pc);
9548 + printk("PC: <%pA>\n", (void *) r->pc);
9549 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9550 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9551 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9552 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9553 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9554 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9555 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9556 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9557
9558 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9559 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9560 @@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9561 rw = (struct reg_window32 *) fp;
9562 pc = rw->ins[7];
9563 printk("[%08lx : ", pc);
9564 - printk("%pS ] ", (void *) pc);
9565 + printk("%pA ] ", (void *) pc);
9566 fp = rw->ins[6];
9567 } while (++count < 16);
9568 printk("\n");
9569 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9570 index 32a280e..84fc6a9 100644
9571 --- a/arch/sparc/kernel/process_64.c
9572 +++ b/arch/sparc/kernel/process_64.c
9573 @@ -159,7 +159,7 @@ static void show_regwindow(struct pt_regs *regs)
9574 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9575 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9576 if (regs->tstate & TSTATE_PRIV)
9577 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9578 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9579 }
9580
9581 void show_regs(struct pt_regs *regs)
9582 @@ -168,7 +168,7 @@ void show_regs(struct pt_regs *regs)
9583
9584 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9585 regs->tpc, regs->tnpc, regs->y, print_tainted());
9586 - printk("TPC: <%pS>\n", (void *) regs->tpc);
9587 + printk("TPC: <%pA>\n", (void *) regs->tpc);
9588 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9589 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9590 regs->u_regs[3]);
9591 @@ -181,7 +181,7 @@ void show_regs(struct pt_regs *regs)
9592 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9593 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9594 regs->u_regs[15]);
9595 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9596 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9597 show_regwindow(regs);
9598 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9599 }
9600 @@ -270,7 +270,7 @@ void arch_trigger_all_cpu_backtrace(void)
9601 ((tp && tp->task) ? tp->task->pid : -1));
9602
9603 if (gp->tstate & TSTATE_PRIV) {
9604 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9605 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9606 (void *) gp->tpc,
9607 (void *) gp->o7,
9608 (void *) gp->i7,
9609 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9610 index 79cc0d1..ec62734 100644
9611 --- a/arch/sparc/kernel/prom_common.c
9612 +++ b/arch/sparc/kernel/prom_common.c
9613 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9614
9615 unsigned int prom_early_allocated __initdata;
9616
9617 -static struct of_pdt_ops prom_sparc_ops __initdata = {
9618 +static struct of_pdt_ops prom_sparc_ops __initconst = {
9619 .nextprop = prom_common_nextprop,
9620 .getproplen = prom_getproplen,
9621 .getproperty = prom_getproperty,
9622 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9623 index c13c9f2..d572c34 100644
9624 --- a/arch/sparc/kernel/ptrace_64.c
9625 +++ b/arch/sparc/kernel/ptrace_64.c
9626 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
9627 return ret;
9628 }
9629
9630 +#ifdef CONFIG_GRKERNSEC_SETXID
9631 +extern void gr_delayed_cred_worker(void);
9632 +#endif
9633 +
9634 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9635 {
9636 int ret = 0;
9637 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9638 if (test_thread_flag(TIF_NOHZ))
9639 user_exit();
9640
9641 +#ifdef CONFIG_GRKERNSEC_SETXID
9642 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9643 + gr_delayed_cred_worker();
9644 +#endif
9645 +
9646 if (test_thread_flag(TIF_SYSCALL_TRACE))
9647 ret = tracehook_report_syscall_entry(regs);
9648
9649 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9650 if (test_thread_flag(TIF_NOHZ))
9651 user_exit();
9652
9653 +#ifdef CONFIG_GRKERNSEC_SETXID
9654 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9655 + gr_delayed_cred_worker();
9656 +#endif
9657 +
9658 audit_syscall_exit(regs);
9659
9660 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9661 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9662 index b085311..6f885f7 100644
9663 --- a/arch/sparc/kernel/smp_64.c
9664 +++ b/arch/sparc/kernel/smp_64.c
9665 @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9666 extern unsigned long xcall_flush_dcache_page_spitfire;
9667
9668 #ifdef CONFIG_DEBUG_DCFLUSH
9669 -extern atomic_t dcpage_flushes;
9670 -extern atomic_t dcpage_flushes_xcall;
9671 +extern atomic_unchecked_t dcpage_flushes;
9672 +extern atomic_unchecked_t dcpage_flushes_xcall;
9673 #endif
9674
9675 static inline void __local_flush_dcache_page(struct page *page)
9676 @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9677 return;
9678
9679 #ifdef CONFIG_DEBUG_DCFLUSH
9680 - atomic_inc(&dcpage_flushes);
9681 + atomic_inc_unchecked(&dcpage_flushes);
9682 #endif
9683
9684 this_cpu = get_cpu();
9685 @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9686 xcall_deliver(data0, __pa(pg_addr),
9687 (u64) pg_addr, cpumask_of(cpu));
9688 #ifdef CONFIG_DEBUG_DCFLUSH
9689 - atomic_inc(&dcpage_flushes_xcall);
9690 + atomic_inc_unchecked(&dcpage_flushes_xcall);
9691 #endif
9692 }
9693 }
9694 @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9695 preempt_disable();
9696
9697 #ifdef CONFIG_DEBUG_DCFLUSH
9698 - atomic_inc(&dcpage_flushes);
9699 + atomic_inc_unchecked(&dcpage_flushes);
9700 #endif
9701 data0 = 0;
9702 pg_addr = page_address(page);
9703 @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9704 xcall_deliver(data0, __pa(pg_addr),
9705 (u64) pg_addr, cpu_online_mask);
9706 #ifdef CONFIG_DEBUG_DCFLUSH
9707 - atomic_inc(&dcpage_flushes_xcall);
9708 + atomic_inc_unchecked(&dcpage_flushes_xcall);
9709 #endif
9710 }
9711 __local_flush_dcache_page(page);
9712 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9713 index 3a8d184..49498a8 100644
9714 --- a/arch/sparc/kernel/sys_sparc_32.c
9715 +++ b/arch/sparc/kernel/sys_sparc_32.c
9716 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9717 if (len > TASK_SIZE - PAGE_SIZE)
9718 return -ENOMEM;
9719 if (!addr)
9720 - addr = TASK_UNMAPPED_BASE;
9721 + addr = current->mm->mmap_base;
9722
9723 info.flags = 0;
9724 info.length = len;
9725 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9726 index beb0b5a..5a153f7 100644
9727 --- a/arch/sparc/kernel/sys_sparc_64.c
9728 +++ b/arch/sparc/kernel/sys_sparc_64.c
9729 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9730 struct vm_area_struct * vma;
9731 unsigned long task_size = TASK_SIZE;
9732 int do_color_align;
9733 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9734 struct vm_unmapped_area_info info;
9735
9736 if (flags & MAP_FIXED) {
9737 /* We do not accept a shared mapping if it would violate
9738 * cache aliasing constraints.
9739 */
9740 - if ((flags & MAP_SHARED) &&
9741 + if ((filp || (flags & MAP_SHARED)) &&
9742 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9743 return -EINVAL;
9744 return addr;
9745 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9746 if (filp || (flags & MAP_SHARED))
9747 do_color_align = 1;
9748
9749 +#ifdef CONFIG_PAX_RANDMMAP
9750 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9751 +#endif
9752 +
9753 if (addr) {
9754 if (do_color_align)
9755 addr = COLOR_ALIGN(addr, pgoff);
9756 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9757 addr = PAGE_ALIGN(addr);
9758
9759 vma = find_vma(mm, addr);
9760 - if (task_size - len >= addr &&
9761 - (!vma || addr + len <= vma->vm_start))
9762 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9763 return addr;
9764 }
9765
9766 info.flags = 0;
9767 info.length = len;
9768 - info.low_limit = TASK_UNMAPPED_BASE;
9769 + info.low_limit = mm->mmap_base;
9770 info.high_limit = min(task_size, VA_EXCLUDE_START);
9771 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9772 info.align_offset = pgoff << PAGE_SHIFT;
9773 + info.threadstack_offset = offset;
9774 addr = vm_unmapped_area(&info);
9775
9776 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9777 VM_BUG_ON(addr != -ENOMEM);
9778 info.low_limit = VA_EXCLUDE_END;
9779 +
9780 +#ifdef CONFIG_PAX_RANDMMAP
9781 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9782 + info.low_limit += mm->delta_mmap;
9783 +#endif
9784 +
9785 info.high_limit = task_size;
9786 addr = vm_unmapped_area(&info);
9787 }
9788 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9789 unsigned long task_size = STACK_TOP32;
9790 unsigned long addr = addr0;
9791 int do_color_align;
9792 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9793 struct vm_unmapped_area_info info;
9794
9795 /* This should only ever run for 32-bit processes. */
9796 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9797 /* We do not accept a shared mapping if it would violate
9798 * cache aliasing constraints.
9799 */
9800 - if ((flags & MAP_SHARED) &&
9801 + if ((filp || (flags & MAP_SHARED)) &&
9802 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9803 return -EINVAL;
9804 return addr;
9805 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9806 if (filp || (flags & MAP_SHARED))
9807 do_color_align = 1;
9808
9809 +#ifdef CONFIG_PAX_RANDMMAP
9810 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9811 +#endif
9812 +
9813 /* requesting a specific address */
9814 if (addr) {
9815 if (do_color_align)
9816 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9817 addr = PAGE_ALIGN(addr);
9818
9819 vma = find_vma(mm, addr);
9820 - if (task_size - len >= addr &&
9821 - (!vma || addr + len <= vma->vm_start))
9822 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9823 return addr;
9824 }
9825
9826 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9827 info.high_limit = mm->mmap_base;
9828 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9829 info.align_offset = pgoff << PAGE_SHIFT;
9830 + info.threadstack_offset = offset;
9831 addr = vm_unmapped_area(&info);
9832
9833 /*
9834 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9835 VM_BUG_ON(addr != -ENOMEM);
9836 info.flags = 0;
9837 info.low_limit = TASK_UNMAPPED_BASE;
9838 +
9839 +#ifdef CONFIG_PAX_RANDMMAP
9840 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9841 + info.low_limit += mm->delta_mmap;
9842 +#endif
9843 +
9844 info.high_limit = STACK_TOP32;
9845 addr = vm_unmapped_area(&info);
9846 }
9847 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9848 EXPORT_SYMBOL(get_fb_unmapped_area);
9849
9850 /* Essentially the same as PowerPC. */
9851 -static unsigned long mmap_rnd(void)
9852 +static unsigned long mmap_rnd(struct mm_struct *mm)
9853 {
9854 unsigned long rnd = 0UL;
9855
9856 +#ifdef CONFIG_PAX_RANDMMAP
9857 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9858 +#endif
9859 +
9860 if (current->flags & PF_RANDOMIZE) {
9861 unsigned long val = get_random_int();
9862 if (test_thread_flag(TIF_32BIT))
9863 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
9864
9865 void arch_pick_mmap_layout(struct mm_struct *mm)
9866 {
9867 - unsigned long random_factor = mmap_rnd();
9868 + unsigned long random_factor = mmap_rnd(mm);
9869 unsigned long gap;
9870
9871 /*
9872 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9873 gap == RLIM_INFINITY ||
9874 sysctl_legacy_va_layout) {
9875 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9876 +
9877 +#ifdef CONFIG_PAX_RANDMMAP
9878 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9879 + mm->mmap_base += mm->delta_mmap;
9880 +#endif
9881 +
9882 mm->get_unmapped_area = arch_get_unmapped_area;
9883 } else {
9884 /* We know it's 32-bit */
9885 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9886 gap = (task_size / 6 * 5);
9887
9888 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9889 +
9890 +#ifdef CONFIG_PAX_RANDMMAP
9891 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9892 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9893 +#endif
9894 +
9895 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9896 }
9897 }
9898 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9899 index 87729ff..192f9d8 100644
9900 --- a/arch/sparc/kernel/syscalls.S
9901 +++ b/arch/sparc/kernel/syscalls.S
9902 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9903 #endif
9904 .align 32
9905 1: ldx [%g6 + TI_FLAGS], %l5
9906 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9907 + andcc %l5, _TIF_WORK_SYSCALL, %g0
9908 be,pt %icc, rtrap
9909 nop
9910 call syscall_trace_leave
9911 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
9912
9913 srl %i3, 0, %o3 ! IEU0
9914 srl %i2, 0, %o2 ! IEU0 Group
9915 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9916 + andcc %l0, _TIF_WORK_SYSCALL, %g0
9917 bne,pn %icc, linux_syscall_trace32 ! CTI
9918 mov %i0, %l5 ! IEU1
9919 5: call %l7 ! CTI Group brk forced
9920 @@ -207,7 +207,7 @@ linux_sparc_syscall:
9921
9922 mov %i3, %o3 ! IEU1
9923 mov %i4, %o4 ! IEU0 Group
9924 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9925 + andcc %l0, _TIF_WORK_SYSCALL, %g0
9926 bne,pn %icc, linux_syscall_trace ! CTI Group
9927 mov %i0, %l5 ! IEU0
9928 2: call %l7 ! CTI Group brk forced
9929 @@ -223,7 +223,7 @@ ret_sys_call:
9930
9931 cmp %o0, -ERESTART_RESTARTBLOCK
9932 bgeu,pn %xcc, 1f
9933 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9934 + andcc %l0, _TIF_WORK_SYSCALL, %g0
9935 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9936
9937 2:
9938 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9939 index 6629829..036032d 100644
9940 --- a/arch/sparc/kernel/traps_32.c
9941 +++ b/arch/sparc/kernel/traps_32.c
9942 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9943 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9944 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9945
9946 +extern void gr_handle_kernel_exploit(void);
9947 +
9948 void die_if_kernel(char *str, struct pt_regs *regs)
9949 {
9950 static int die_counter;
9951 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9952 count++ < 30 &&
9953 (((unsigned long) rw) >= PAGE_OFFSET) &&
9954 !(((unsigned long) rw) & 0x7)) {
9955 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
9956 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
9957 (void *) rw->ins[7]);
9958 rw = (struct reg_window32 *)rw->ins[6];
9959 }
9960 }
9961 printk("Instruction DUMP:");
9962 instruction_dump ((unsigned long *) regs->pc);
9963 - if(regs->psr & PSR_PS)
9964 + if(regs->psr & PSR_PS) {
9965 + gr_handle_kernel_exploit();
9966 do_exit(SIGKILL);
9967 + }
9968 do_exit(SIGSEGV);
9969 }
9970
9971 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9972 index 4ced92f..965eeed 100644
9973 --- a/arch/sparc/kernel/traps_64.c
9974 +++ b/arch/sparc/kernel/traps_64.c
9975 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9976 i + 1,
9977 p->trapstack[i].tstate, p->trapstack[i].tpc,
9978 p->trapstack[i].tnpc, p->trapstack[i].tt);
9979 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9980 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9981 }
9982 }
9983
9984 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9985
9986 lvl -= 0x100;
9987 if (regs->tstate & TSTATE_PRIV) {
9988 +
9989 +#ifdef CONFIG_PAX_REFCOUNT
9990 + if (lvl == 6)
9991 + pax_report_refcount_overflow(regs);
9992 +#endif
9993 +
9994 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9995 die_if_kernel(buffer, regs);
9996 }
9997 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9998 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9999 {
10000 char buffer[32];
10001 -
10002 +
10003 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10004 0, lvl, SIGTRAP) == NOTIFY_STOP)
10005 return;
10006
10007 +#ifdef CONFIG_PAX_REFCOUNT
10008 + if (lvl == 6)
10009 + pax_report_refcount_overflow(regs);
10010 +#endif
10011 +
10012 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10013
10014 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10015 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10016 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10017 printk("%s" "ERROR(%d): ",
10018 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10019 - printk("TPC<%pS>\n", (void *) regs->tpc);
10020 + printk("TPC<%pA>\n", (void *) regs->tpc);
10021 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10022 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10023 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10024 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10025 smp_processor_id(),
10026 (type & 0x1) ? 'I' : 'D',
10027 regs->tpc);
10028 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10029 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10030 panic("Irrecoverable Cheetah+ parity error.");
10031 }
10032
10033 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10034 smp_processor_id(),
10035 (type & 0x1) ? 'I' : 'D',
10036 regs->tpc);
10037 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10038 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10039 }
10040
10041 struct sun4v_error_entry {
10042 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10043 /*0x38*/u64 reserved_5;
10044 };
10045
10046 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10047 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10048 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10049 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10050
10051 static const char *sun4v_err_type_to_str(u8 type)
10052 {
10053 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10054 }
10055
10056 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10057 - int cpu, const char *pfx, atomic_t *ocnt)
10058 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10059 {
10060 u64 *raw_ptr = (u64 *) ent;
10061 u32 attrs;
10062 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10063
10064 show_regs(regs);
10065
10066 - if ((cnt = atomic_read(ocnt)) != 0) {
10067 - atomic_set(ocnt, 0);
10068 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10069 + atomic_set_unchecked(ocnt, 0);
10070 wmb();
10071 printk("%s: Queue overflowed %d times.\n",
10072 pfx, cnt);
10073 @@ -2046,7 +2057,7 @@ out:
10074 */
10075 void sun4v_resum_overflow(struct pt_regs *regs)
10076 {
10077 - atomic_inc(&sun4v_resum_oflow_cnt);
10078 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10079 }
10080
10081 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10082 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10083 /* XXX Actually even this can make not that much sense. Perhaps
10084 * XXX we should just pull the plug and panic directly from here?
10085 */
10086 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10087 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10088 }
10089
10090 unsigned long sun4v_err_itlb_vaddr;
10091 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10092
10093 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10094 regs->tpc, tl);
10095 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10096 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10097 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10098 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10099 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10100 (void *) regs->u_regs[UREG_I7]);
10101 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10102 "pte[%lx] error[%lx]\n",
10103 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10104
10105 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10106 regs->tpc, tl);
10107 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10108 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10109 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10110 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10111 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10112 (void *) regs->u_regs[UREG_I7]);
10113 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10114 "pte[%lx] error[%lx]\n",
10115 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10116 fp = (unsigned long)sf->fp + STACK_BIAS;
10117 }
10118
10119 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10120 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10121 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10122 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10123 int index = tsk->curr_ret_stack;
10124 if (tsk->ret_stack && index >= graph) {
10125 pc = tsk->ret_stack[index - graph].ret;
10126 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10127 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10128 graph++;
10129 }
10130 }
10131 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10132 return (struct reg_window *) (fp + STACK_BIAS);
10133 }
10134
10135 +extern void gr_handle_kernel_exploit(void);
10136 +
10137 void die_if_kernel(char *str, struct pt_regs *regs)
10138 {
10139 static int die_counter;
10140 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10141 while (rw &&
10142 count++ < 30 &&
10143 kstack_valid(tp, (unsigned long) rw)) {
10144 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10145 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10146 (void *) rw->ins[7]);
10147
10148 rw = kernel_stack_up(rw);
10149 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10150 }
10151 user_instruction_dump ((unsigned int __user *) regs->tpc);
10152 }
10153 - if (regs->tstate & TSTATE_PRIV)
10154 + if (regs->tstate & TSTATE_PRIV) {
10155 + gr_handle_kernel_exploit();
10156 do_exit(SIGKILL);
10157 + }
10158 do_exit(SIGSEGV);
10159 }
10160 EXPORT_SYMBOL(die_if_kernel);
10161 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10162 index 3c1a7cb..73e1923 100644
10163 --- a/arch/sparc/kernel/unaligned_64.c
10164 +++ b/arch/sparc/kernel/unaligned_64.c
10165 @@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10166 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10167
10168 if (__ratelimit(&ratelimit)) {
10169 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10170 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10171 regs->tpc, (void *) regs->tpc);
10172 }
10173 }
10174 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10175 index dbe119b..089c7c1 100644
10176 --- a/arch/sparc/lib/Makefile
10177 +++ b/arch/sparc/lib/Makefile
10178 @@ -2,7 +2,7 @@
10179 #
10180
10181 asflags-y := -ansi -DST_DIV0=0x02
10182 -ccflags-y := -Werror
10183 +#ccflags-y := -Werror
10184
10185 lib-$(CONFIG_SPARC32) += ashrdi3.o
10186 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10187 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10188 index 85c233d..68500e0 100644
10189 --- a/arch/sparc/lib/atomic_64.S
10190 +++ b/arch/sparc/lib/atomic_64.S
10191 @@ -17,7 +17,12 @@
10192 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10193 BACKOFF_SETUP(%o2)
10194 1: lduw [%o1], %g1
10195 - add %g1, %o0, %g7
10196 + addcc %g1, %o0, %g7
10197 +
10198 +#ifdef CONFIG_PAX_REFCOUNT
10199 + tvs %icc, 6
10200 +#endif
10201 +
10202 cas [%o1], %g1, %g7
10203 cmp %g1, %g7
10204 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10205 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10206 2: BACKOFF_SPIN(%o2, %o3, 1b)
10207 ENDPROC(atomic_add)
10208
10209 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10210 + BACKOFF_SETUP(%o2)
10211 +1: lduw [%o1], %g1
10212 + add %g1, %o0, %g7
10213 + cas [%o1], %g1, %g7
10214 + cmp %g1, %g7
10215 + bne,pn %icc, 2f
10216 + nop
10217 + retl
10218 + nop
10219 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10220 +ENDPROC(atomic_add_unchecked)
10221 +
10222 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10223 BACKOFF_SETUP(%o2)
10224 1: lduw [%o1], %g1
10225 - sub %g1, %o0, %g7
10226 + subcc %g1, %o0, %g7
10227 +
10228 +#ifdef CONFIG_PAX_REFCOUNT
10229 + tvs %icc, 6
10230 +#endif
10231 +
10232 cas [%o1], %g1, %g7
10233 cmp %g1, %g7
10234 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10235 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10236 2: BACKOFF_SPIN(%o2, %o3, 1b)
10237 ENDPROC(atomic_sub)
10238
10239 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10240 + BACKOFF_SETUP(%o2)
10241 +1: lduw [%o1], %g1
10242 + sub %g1, %o0, %g7
10243 + cas [%o1], %g1, %g7
10244 + cmp %g1, %g7
10245 + bne,pn %icc, 2f
10246 + nop
10247 + retl
10248 + nop
10249 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10250 +ENDPROC(atomic_sub_unchecked)
10251 +
10252 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10253 BACKOFF_SETUP(%o2)
10254 1: lduw [%o1], %g1
10255 - add %g1, %o0, %g7
10256 + addcc %g1, %o0, %g7
10257 +
10258 +#ifdef CONFIG_PAX_REFCOUNT
10259 + tvs %icc, 6
10260 +#endif
10261 +
10262 cas [%o1], %g1, %g7
10263 cmp %g1, %g7
10264 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10265 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10266 2: BACKOFF_SPIN(%o2, %o3, 1b)
10267 ENDPROC(atomic_add_ret)
10268
10269 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10270 + BACKOFF_SETUP(%o2)
10271 +1: lduw [%o1], %g1
10272 + addcc %g1, %o0, %g7
10273 + cas [%o1], %g1, %g7
10274 + cmp %g1, %g7
10275 + bne,pn %icc, 2f
10276 + add %g7, %o0, %g7
10277 + sra %g7, 0, %o0
10278 + retl
10279 + nop
10280 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10281 +ENDPROC(atomic_add_ret_unchecked)
10282 +
10283 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10284 BACKOFF_SETUP(%o2)
10285 1: lduw [%o1], %g1
10286 - sub %g1, %o0, %g7
10287 + subcc %g1, %o0, %g7
10288 +
10289 +#ifdef CONFIG_PAX_REFCOUNT
10290 + tvs %icc, 6
10291 +#endif
10292 +
10293 cas [%o1], %g1, %g7
10294 cmp %g1, %g7
10295 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10296 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10297 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10298 BACKOFF_SETUP(%o2)
10299 1: ldx [%o1], %g1
10300 - add %g1, %o0, %g7
10301 + addcc %g1, %o0, %g7
10302 +
10303 +#ifdef CONFIG_PAX_REFCOUNT
10304 + tvs %xcc, 6
10305 +#endif
10306 +
10307 casx [%o1], %g1, %g7
10308 cmp %g1, %g7
10309 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10310 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10311 2: BACKOFF_SPIN(%o2, %o3, 1b)
10312 ENDPROC(atomic64_add)
10313
10314 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10315 + BACKOFF_SETUP(%o2)
10316 +1: ldx [%o1], %g1
10317 + addcc %g1, %o0, %g7
10318 + casx [%o1], %g1, %g7
10319 + cmp %g1, %g7
10320 + bne,pn %xcc, 2f
10321 + nop
10322 + retl
10323 + nop
10324 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10325 +ENDPROC(atomic64_add_unchecked)
10326 +
10327 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10328 BACKOFF_SETUP(%o2)
10329 1: ldx [%o1], %g1
10330 - sub %g1, %o0, %g7
10331 + subcc %g1, %o0, %g7
10332 +
10333 +#ifdef CONFIG_PAX_REFCOUNT
10334 + tvs %xcc, 6
10335 +#endif
10336 +
10337 casx [%o1], %g1, %g7
10338 cmp %g1, %g7
10339 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10340 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10341 2: BACKOFF_SPIN(%o2, %o3, 1b)
10342 ENDPROC(atomic64_sub)
10343
10344 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10345 + BACKOFF_SETUP(%o2)
10346 +1: ldx [%o1], %g1
10347 + subcc %g1, %o0, %g7
10348 + casx [%o1], %g1, %g7
10349 + cmp %g1, %g7
10350 + bne,pn %xcc, 2f
10351 + nop
10352 + retl
10353 + nop
10354 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10355 +ENDPROC(atomic64_sub_unchecked)
10356 +
10357 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10358 BACKOFF_SETUP(%o2)
10359 1: ldx [%o1], %g1
10360 - add %g1, %o0, %g7
10361 + addcc %g1, %o0, %g7
10362 +
10363 +#ifdef CONFIG_PAX_REFCOUNT
10364 + tvs %xcc, 6
10365 +#endif
10366 +
10367 casx [%o1], %g1, %g7
10368 cmp %g1, %g7
10369 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10370 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10371 2: BACKOFF_SPIN(%o2, %o3, 1b)
10372 ENDPROC(atomic64_add_ret)
10373
10374 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10375 + BACKOFF_SETUP(%o2)
10376 +1: ldx [%o1], %g1
10377 + addcc %g1, %o0, %g7
10378 + casx [%o1], %g1, %g7
10379 + cmp %g1, %g7
10380 + bne,pn %xcc, 2f
10381 + add %g7, %o0, %g7
10382 + mov %g7, %o0
10383 + retl
10384 + nop
10385 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10386 +ENDPROC(atomic64_add_ret_unchecked)
10387 +
10388 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10389 BACKOFF_SETUP(%o2)
10390 1: ldx [%o1], %g1
10391 - sub %g1, %o0, %g7
10392 + subcc %g1, %o0, %g7
10393 +
10394 +#ifdef CONFIG_PAX_REFCOUNT
10395 + tvs %xcc, 6
10396 +#endif
10397 +
10398 casx [%o1], %g1, %g7
10399 cmp %g1, %g7
10400 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10401 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10402 index 323335b..ed85ea2 100644
10403 --- a/arch/sparc/lib/ksyms.c
10404 +++ b/arch/sparc/lib/ksyms.c
10405 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10406
10407 /* Atomic counter implementation. */
10408 EXPORT_SYMBOL(atomic_add);
10409 +EXPORT_SYMBOL(atomic_add_unchecked);
10410 EXPORT_SYMBOL(atomic_add_ret);
10411 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
10412 EXPORT_SYMBOL(atomic_sub);
10413 +EXPORT_SYMBOL(atomic_sub_unchecked);
10414 EXPORT_SYMBOL(atomic_sub_ret);
10415 EXPORT_SYMBOL(atomic64_add);
10416 +EXPORT_SYMBOL(atomic64_add_unchecked);
10417 EXPORT_SYMBOL(atomic64_add_ret);
10418 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10419 EXPORT_SYMBOL(atomic64_sub);
10420 +EXPORT_SYMBOL(atomic64_sub_unchecked);
10421 EXPORT_SYMBOL(atomic64_sub_ret);
10422 EXPORT_SYMBOL(atomic64_dec_if_positive);
10423
10424 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10425 index 30c3ecc..736f015 100644
10426 --- a/arch/sparc/mm/Makefile
10427 +++ b/arch/sparc/mm/Makefile
10428 @@ -2,7 +2,7 @@
10429 #
10430
10431 asflags-y := -ansi
10432 -ccflags-y := -Werror
10433 +#ccflags-y := -Werror
10434
10435 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10436 obj-y += fault_$(BITS).o
10437 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10438 index 59dbd46..1dd7f5e 100644
10439 --- a/arch/sparc/mm/fault_32.c
10440 +++ b/arch/sparc/mm/fault_32.c
10441 @@ -21,6 +21,9 @@
10442 #include <linux/perf_event.h>
10443 #include <linux/interrupt.h>
10444 #include <linux/kdebug.h>
10445 +#include <linux/slab.h>
10446 +#include <linux/pagemap.h>
10447 +#include <linux/compiler.h>
10448
10449 #include <asm/page.h>
10450 #include <asm/pgtable.h>
10451 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10452 return safe_compute_effective_address(regs, insn);
10453 }
10454
10455 +#ifdef CONFIG_PAX_PAGEEXEC
10456 +#ifdef CONFIG_PAX_DLRESOLVE
10457 +static void pax_emuplt_close(struct vm_area_struct *vma)
10458 +{
10459 + vma->vm_mm->call_dl_resolve = 0UL;
10460 +}
10461 +
10462 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10463 +{
10464 + unsigned int *kaddr;
10465 +
10466 + vmf->page = alloc_page(GFP_HIGHUSER);
10467 + if (!vmf->page)
10468 + return VM_FAULT_OOM;
10469 +
10470 + kaddr = kmap(vmf->page);
10471 + memset(kaddr, 0, PAGE_SIZE);
10472 + kaddr[0] = 0x9DE3BFA8U; /* save */
10473 + flush_dcache_page(vmf->page);
10474 + kunmap(vmf->page);
10475 + return VM_FAULT_MAJOR;
10476 +}
10477 +
10478 +static const struct vm_operations_struct pax_vm_ops = {
10479 + .close = pax_emuplt_close,
10480 + .fault = pax_emuplt_fault
10481 +};
10482 +
10483 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10484 +{
10485 + int ret;
10486 +
10487 + INIT_LIST_HEAD(&vma->anon_vma_chain);
10488 + vma->vm_mm = current->mm;
10489 + vma->vm_start = addr;
10490 + vma->vm_end = addr + PAGE_SIZE;
10491 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10492 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10493 + vma->vm_ops = &pax_vm_ops;
10494 +
10495 + ret = insert_vm_struct(current->mm, vma);
10496 + if (ret)
10497 + return ret;
10498 +
10499 + ++current->mm->total_vm;
10500 + return 0;
10501 +}
10502 +#endif
10503 +
10504 +/*
10505 + * PaX: decide what to do with offenders (regs->pc = fault address)
10506 + *
10507 + * returns 1 when task should be killed
10508 + * 2 when patched PLT trampoline was detected
10509 + * 3 when unpatched PLT trampoline was detected
10510 + */
10511 +static int pax_handle_fetch_fault(struct pt_regs *regs)
10512 +{
10513 +
10514 +#ifdef CONFIG_PAX_EMUPLT
10515 + int err;
10516 +
10517 + do { /* PaX: patched PLT emulation #1 */
10518 + unsigned int sethi1, sethi2, jmpl;
10519 +
10520 + err = get_user(sethi1, (unsigned int *)regs->pc);
10521 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10522 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10523 +
10524 + if (err)
10525 + break;
10526 +
10527 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10528 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
10529 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
10530 + {
10531 + unsigned int addr;
10532 +
10533 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10534 + addr = regs->u_regs[UREG_G1];
10535 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10536 + regs->pc = addr;
10537 + regs->npc = addr+4;
10538 + return 2;
10539 + }
10540 + } while (0);
10541 +
10542 + do { /* PaX: patched PLT emulation #2 */
10543 + unsigned int ba;
10544 +
10545 + err = get_user(ba, (unsigned int *)regs->pc);
10546 +
10547 + if (err)
10548 + break;
10549 +
10550 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10551 + unsigned int addr;
10552 +
10553 + if ((ba & 0xFFC00000U) == 0x30800000U)
10554 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10555 + else
10556 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10557 + regs->pc = addr;
10558 + regs->npc = addr+4;
10559 + return 2;
10560 + }
10561 + } while (0);
10562 +
10563 + do { /* PaX: patched PLT emulation #3 */
10564 + unsigned int sethi, bajmpl, nop;
10565 +
10566 + err = get_user(sethi, (unsigned int *)regs->pc);
10567 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10568 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
10569 +
10570 + if (err)
10571 + break;
10572 +
10573 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10574 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10575 + nop == 0x01000000U)
10576 + {
10577 + unsigned int addr;
10578 +
10579 + addr = (sethi & 0x003FFFFFU) << 10;
10580 + regs->u_regs[UREG_G1] = addr;
10581 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10582 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10583 + else
10584 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10585 + regs->pc = addr;
10586 + regs->npc = addr+4;
10587 + return 2;
10588 + }
10589 + } while (0);
10590 +
10591 + do { /* PaX: unpatched PLT emulation step 1 */
10592 + unsigned int sethi, ba, nop;
10593 +
10594 + err = get_user(sethi, (unsigned int *)regs->pc);
10595 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
10596 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
10597 +
10598 + if (err)
10599 + break;
10600 +
10601 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10602 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10603 + nop == 0x01000000U)
10604 + {
10605 + unsigned int addr, save, call;
10606 +
10607 + if ((ba & 0xFFC00000U) == 0x30800000U)
10608 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10609 + else
10610 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10611 +
10612 + err = get_user(save, (unsigned int *)addr);
10613 + err |= get_user(call, (unsigned int *)(addr+4));
10614 + err |= get_user(nop, (unsigned int *)(addr+8));
10615 + if (err)
10616 + break;
10617 +
10618 +#ifdef CONFIG_PAX_DLRESOLVE
10619 + if (save == 0x9DE3BFA8U &&
10620 + (call & 0xC0000000U) == 0x40000000U &&
10621 + nop == 0x01000000U)
10622 + {
10623 + struct vm_area_struct *vma;
10624 + unsigned long call_dl_resolve;
10625 +
10626 + down_read(&current->mm->mmap_sem);
10627 + call_dl_resolve = current->mm->call_dl_resolve;
10628 + up_read(&current->mm->mmap_sem);
10629 + if (likely(call_dl_resolve))
10630 + goto emulate;
10631 +
10632 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10633 +
10634 + down_write(&current->mm->mmap_sem);
10635 + if (current->mm->call_dl_resolve) {
10636 + call_dl_resolve = current->mm->call_dl_resolve;
10637 + up_write(&current->mm->mmap_sem);
10638 + if (vma)
10639 + kmem_cache_free(vm_area_cachep, vma);
10640 + goto emulate;
10641 + }
10642 +
10643 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10644 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10645 + up_write(&current->mm->mmap_sem);
10646 + if (vma)
10647 + kmem_cache_free(vm_area_cachep, vma);
10648 + return 1;
10649 + }
10650 +
10651 + if (pax_insert_vma(vma, call_dl_resolve)) {
10652 + up_write(&current->mm->mmap_sem);
10653 + kmem_cache_free(vm_area_cachep, vma);
10654 + return 1;
10655 + }
10656 +
10657 + current->mm->call_dl_resolve = call_dl_resolve;
10658 + up_write(&current->mm->mmap_sem);
10659 +
10660 +emulate:
10661 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10662 + regs->pc = call_dl_resolve;
10663 + regs->npc = addr+4;
10664 + return 3;
10665 + }
10666 +#endif
10667 +
10668 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10669 + if ((save & 0xFFC00000U) == 0x05000000U &&
10670 + (call & 0xFFFFE000U) == 0x85C0A000U &&
10671 + nop == 0x01000000U)
10672 + {
10673 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10674 + regs->u_regs[UREG_G2] = addr + 4;
10675 + addr = (save & 0x003FFFFFU) << 10;
10676 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10677 + regs->pc = addr;
10678 + regs->npc = addr+4;
10679 + return 3;
10680 + }
10681 + }
10682 + } while (0);
10683 +
10684 + do { /* PaX: unpatched PLT emulation step 2 */
10685 + unsigned int save, call, nop;
10686 +
10687 + err = get_user(save, (unsigned int *)(regs->pc-4));
10688 + err |= get_user(call, (unsigned int *)regs->pc);
10689 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
10690 + if (err)
10691 + break;
10692 +
10693 + if (save == 0x9DE3BFA8U &&
10694 + (call & 0xC0000000U) == 0x40000000U &&
10695 + nop == 0x01000000U)
10696 + {
10697 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10698 +
10699 + regs->u_regs[UREG_RETPC] = regs->pc;
10700 + regs->pc = dl_resolve;
10701 + regs->npc = dl_resolve+4;
10702 + return 3;
10703 + }
10704 + } while (0);
10705 +#endif
10706 +
10707 + return 1;
10708 +}
10709 +
10710 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10711 +{
10712 + unsigned long i;
10713 +
10714 + printk(KERN_ERR "PAX: bytes at PC: ");
10715 + for (i = 0; i < 8; i++) {
10716 + unsigned int c;
10717 + if (get_user(c, (unsigned int *)pc+i))
10718 + printk(KERN_CONT "???????? ");
10719 + else
10720 + printk(KERN_CONT "%08x ", c);
10721 + }
10722 + printk("\n");
10723 +}
10724 +#endif
10725 +
10726 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10727 int text_fault)
10728 {
10729 @@ -229,6 +503,24 @@ good_area:
10730 if (!(vma->vm_flags & VM_WRITE))
10731 goto bad_area;
10732 } else {
10733 +
10734 +#ifdef CONFIG_PAX_PAGEEXEC
10735 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10736 + up_read(&mm->mmap_sem);
10737 + switch (pax_handle_fetch_fault(regs)) {
10738 +
10739 +#ifdef CONFIG_PAX_EMUPLT
10740 + case 2:
10741 + case 3:
10742 + return;
10743 +#endif
10744 +
10745 + }
10746 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10747 + do_group_exit(SIGKILL);
10748 + }
10749 +#endif
10750 +
10751 /* Allow reads even for write-only mappings */
10752 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10753 goto bad_area;
10754 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10755 index 69bb818..6ca35c8 100644
10756 --- a/arch/sparc/mm/fault_64.c
10757 +++ b/arch/sparc/mm/fault_64.c
10758 @@ -22,6 +22,9 @@
10759 #include <linux/kdebug.h>
10760 #include <linux/percpu.h>
10761 #include <linux/context_tracking.h>
10762 +#include <linux/slab.h>
10763 +#include <linux/pagemap.h>
10764 +#include <linux/compiler.h>
10765
10766 #include <asm/page.h>
10767 #include <asm/pgtable.h>
10768 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10769 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10770 regs->tpc);
10771 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10772 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10773 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10774 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10775 dump_stack();
10776 unhandled_fault(regs->tpc, current, regs);
10777 @@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10778 show_regs(regs);
10779 }
10780
10781 +#ifdef CONFIG_PAX_PAGEEXEC
10782 +#ifdef CONFIG_PAX_DLRESOLVE
10783 +static void pax_emuplt_close(struct vm_area_struct *vma)
10784 +{
10785 + vma->vm_mm->call_dl_resolve = 0UL;
10786 +}
10787 +
10788 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10789 +{
10790 + unsigned int *kaddr;
10791 +
10792 + vmf->page = alloc_page(GFP_HIGHUSER);
10793 + if (!vmf->page)
10794 + return VM_FAULT_OOM;
10795 +
10796 + kaddr = kmap(vmf->page);
10797 + memset(kaddr, 0, PAGE_SIZE);
10798 + kaddr[0] = 0x9DE3BFA8U; /* save */
10799 + flush_dcache_page(vmf->page);
10800 + kunmap(vmf->page);
10801 + return VM_FAULT_MAJOR;
10802 +}
10803 +
10804 +static const struct vm_operations_struct pax_vm_ops = {
10805 + .close = pax_emuplt_close,
10806 + .fault = pax_emuplt_fault
10807 +};
10808 +
10809 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10810 +{
10811 + int ret;
10812 +
10813 + INIT_LIST_HEAD(&vma->anon_vma_chain);
10814 + vma->vm_mm = current->mm;
10815 + vma->vm_start = addr;
10816 + vma->vm_end = addr + PAGE_SIZE;
10817 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10818 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10819 + vma->vm_ops = &pax_vm_ops;
10820 +
10821 + ret = insert_vm_struct(current->mm, vma);
10822 + if (ret)
10823 + return ret;
10824 +
10825 + ++current->mm->total_vm;
10826 + return 0;
10827 +}
10828 +#endif
10829 +
10830 +/*
10831 + * PaX: decide what to do with offenders (regs->tpc = fault address)
10832 + *
10833 + * returns 1 when task should be killed
10834 + * 2 when patched PLT trampoline was detected
10835 + * 3 when unpatched PLT trampoline was detected
10836 + */
10837 +static int pax_handle_fetch_fault(struct pt_regs *regs)
10838 +{
10839 +
10840 +#ifdef CONFIG_PAX_EMUPLT
10841 + int err;
10842 +
10843 + do { /* PaX: patched PLT emulation #1 */
10844 + unsigned int sethi1, sethi2, jmpl;
10845 +
10846 + err = get_user(sethi1, (unsigned int *)regs->tpc);
10847 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10848 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10849 +
10850 + if (err)
10851 + break;
10852 +
10853 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10854 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
10855 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
10856 + {
10857 + unsigned long addr;
10858 +
10859 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10860 + addr = regs->u_regs[UREG_G1];
10861 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10862 +
10863 + if (test_thread_flag(TIF_32BIT))
10864 + addr &= 0xFFFFFFFFUL;
10865 +
10866 + regs->tpc = addr;
10867 + regs->tnpc = addr+4;
10868 + return 2;
10869 + }
10870 + } while (0);
10871 +
10872 + do { /* PaX: patched PLT emulation #2 */
10873 + unsigned int ba;
10874 +
10875 + err = get_user(ba, (unsigned int *)regs->tpc);
10876 +
10877 + if (err)
10878 + break;
10879 +
10880 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10881 + unsigned long addr;
10882 +
10883 + if ((ba & 0xFFC00000U) == 0x30800000U)
10884 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10885 + else
10886 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10887 +
10888 + if (test_thread_flag(TIF_32BIT))
10889 + addr &= 0xFFFFFFFFUL;
10890 +
10891 + regs->tpc = addr;
10892 + regs->tnpc = addr+4;
10893 + return 2;
10894 + }
10895 + } while (0);
10896 +
10897 + do { /* PaX: patched PLT emulation #3 */
10898 + unsigned int sethi, bajmpl, nop;
10899 +
10900 + err = get_user(sethi, (unsigned int *)regs->tpc);
10901 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10902 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10903 +
10904 + if (err)
10905 + break;
10906 +
10907 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10908 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10909 + nop == 0x01000000U)
10910 + {
10911 + unsigned long addr;
10912 +
10913 + addr = (sethi & 0x003FFFFFU) << 10;
10914 + regs->u_regs[UREG_G1] = addr;
10915 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10916 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10917 + else
10918 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10919 +
10920 + if (test_thread_flag(TIF_32BIT))
10921 + addr &= 0xFFFFFFFFUL;
10922 +
10923 + regs->tpc = addr;
10924 + regs->tnpc = addr+4;
10925 + return 2;
10926 + }
10927 + } while (0);
10928 +
10929 + do { /* PaX: patched PLT emulation #4 */
10930 + unsigned int sethi, mov1, call, mov2;
10931 +
10932 + err = get_user(sethi, (unsigned int *)regs->tpc);
10933 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10934 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
10935 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10936 +
10937 + if (err)
10938 + break;
10939 +
10940 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10941 + mov1 == 0x8210000FU &&
10942 + (call & 0xC0000000U) == 0x40000000U &&
10943 + mov2 == 0x9E100001U)
10944 + {
10945 + unsigned long addr;
10946 +
10947 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10948 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10949 +
10950 + if (test_thread_flag(TIF_32BIT))
10951 + addr &= 0xFFFFFFFFUL;
10952 +
10953 + regs->tpc = addr;
10954 + regs->tnpc = addr+4;
10955 + return 2;
10956 + }
10957 + } while (0);
10958 +
10959 + do { /* PaX: patched PLT emulation #5 */
10960 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10961 +
10962 + err = get_user(sethi, (unsigned int *)regs->tpc);
10963 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10964 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10965 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10966 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10967 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10968 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10969 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10970 +
10971 + if (err)
10972 + break;
10973 +
10974 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10975 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
10976 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10977 + (or1 & 0xFFFFE000U) == 0x82106000U &&
10978 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
10979 + sllx == 0x83287020U &&
10980 + jmpl == 0x81C04005U &&
10981 + nop == 0x01000000U)
10982 + {
10983 + unsigned long addr;
10984 +
10985 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10986 + regs->u_regs[UREG_G1] <<= 32;
10987 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10988 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10989 + regs->tpc = addr;
10990 + regs->tnpc = addr+4;
10991 + return 2;
10992 + }
10993 + } while (0);
10994 +
10995 + do { /* PaX: patched PLT emulation #6 */
10996 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10997 +
10998 + err = get_user(sethi, (unsigned int *)regs->tpc);
10999 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11000 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11001 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11002 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11003 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11004 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11005 +
11006 + if (err)
11007 + break;
11008 +
11009 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11010 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11011 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11012 + sllx == 0x83287020U &&
11013 + (or & 0xFFFFE000U) == 0x8A116000U &&
11014 + jmpl == 0x81C04005U &&
11015 + nop == 0x01000000U)
11016 + {
11017 + unsigned long addr;
11018 +
11019 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11020 + regs->u_regs[UREG_G1] <<= 32;
11021 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11022 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11023 + regs->tpc = addr;
11024 + regs->tnpc = addr+4;
11025 + return 2;
11026 + }
11027 + } while (0);
11028 +
11029 + do { /* PaX: unpatched PLT emulation step 1 */
11030 + unsigned int sethi, ba, nop;
11031 +
11032 + err = get_user(sethi, (unsigned int *)regs->tpc);
11033 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11034 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11035 +
11036 + if (err)
11037 + break;
11038 +
11039 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11040 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11041 + nop == 0x01000000U)
11042 + {
11043 + unsigned long addr;
11044 + unsigned int save, call;
11045 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11046 +
11047 + if ((ba & 0xFFC00000U) == 0x30800000U)
11048 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11049 + else
11050 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11051 +
11052 + if (test_thread_flag(TIF_32BIT))
11053 + addr &= 0xFFFFFFFFUL;
11054 +
11055 + err = get_user(save, (unsigned int *)addr);
11056 + err |= get_user(call, (unsigned int *)(addr+4));
11057 + err |= get_user(nop, (unsigned int *)(addr+8));
11058 + if (err)
11059 + break;
11060 +
11061 +#ifdef CONFIG_PAX_DLRESOLVE
11062 + if (save == 0x9DE3BFA8U &&
11063 + (call & 0xC0000000U) == 0x40000000U &&
11064 + nop == 0x01000000U)
11065 + {
11066 + struct vm_area_struct *vma;
11067 + unsigned long call_dl_resolve;
11068 +
11069 + down_read(&current->mm->mmap_sem);
11070 + call_dl_resolve = current->mm->call_dl_resolve;
11071 + up_read(&current->mm->mmap_sem);
11072 + if (likely(call_dl_resolve))
11073 + goto emulate;
11074 +
11075 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11076 +
11077 + down_write(&current->mm->mmap_sem);
11078 + if (current->mm->call_dl_resolve) {
11079 + call_dl_resolve = current->mm->call_dl_resolve;
11080 + up_write(&current->mm->mmap_sem);
11081 + if (vma)
11082 + kmem_cache_free(vm_area_cachep, vma);
11083 + goto emulate;
11084 + }
11085 +
11086 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11087 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11088 + up_write(&current->mm->mmap_sem);
11089 + if (vma)
11090 + kmem_cache_free(vm_area_cachep, vma);
11091 + return 1;
11092 + }
11093 +
11094 + if (pax_insert_vma(vma, call_dl_resolve)) {
11095 + up_write(&current->mm->mmap_sem);
11096 + kmem_cache_free(vm_area_cachep, vma);
11097 + return 1;
11098 + }
11099 +
11100 + current->mm->call_dl_resolve = call_dl_resolve;
11101 + up_write(&current->mm->mmap_sem);
11102 +
11103 +emulate:
11104 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11105 + regs->tpc = call_dl_resolve;
11106 + regs->tnpc = addr+4;
11107 + return 3;
11108 + }
11109 +#endif
11110 +
11111 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11112 + if ((save & 0xFFC00000U) == 0x05000000U &&
11113 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11114 + nop == 0x01000000U)
11115 + {
11116 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11117 + regs->u_regs[UREG_G2] = addr + 4;
11118 + addr = (save & 0x003FFFFFU) << 10;
11119 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11120 +
11121 + if (test_thread_flag(TIF_32BIT))
11122 + addr &= 0xFFFFFFFFUL;
11123 +
11124 + regs->tpc = addr;
11125 + regs->tnpc = addr+4;
11126 + return 3;
11127 + }
11128 +
11129 + /* PaX: 64-bit PLT stub */
11130 + err = get_user(sethi1, (unsigned int *)addr);
11131 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11132 + err |= get_user(or1, (unsigned int *)(addr+8));
11133 + err |= get_user(or2, (unsigned int *)(addr+12));
11134 + err |= get_user(sllx, (unsigned int *)(addr+16));
11135 + err |= get_user(add, (unsigned int *)(addr+20));
11136 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11137 + err |= get_user(nop, (unsigned int *)(addr+28));
11138 + if (err)
11139 + break;
11140 +
11141 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11142 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11143 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11144 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11145 + sllx == 0x89293020U &&
11146 + add == 0x8A010005U &&
11147 + jmpl == 0x89C14000U &&
11148 + nop == 0x01000000U)
11149 + {
11150 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11151 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11152 + regs->u_regs[UREG_G4] <<= 32;
11153 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11154 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11155 + regs->u_regs[UREG_G4] = addr + 24;
11156 + addr = regs->u_regs[UREG_G5];
11157 + regs->tpc = addr;
11158 + regs->tnpc = addr+4;
11159 + return 3;
11160 + }
11161 + }
11162 + } while (0);
11163 +
11164 +#ifdef CONFIG_PAX_DLRESOLVE
11165 + do { /* PaX: unpatched PLT emulation step 2 */
11166 + unsigned int save, call, nop;
11167 +
11168 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11169 + err |= get_user(call, (unsigned int *)regs->tpc);
11170 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11171 + if (err)
11172 + break;
11173 +
11174 + if (save == 0x9DE3BFA8U &&
11175 + (call & 0xC0000000U) == 0x40000000U &&
11176 + nop == 0x01000000U)
11177 + {
11178 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11179 +
11180 + if (test_thread_flag(TIF_32BIT))
11181 + dl_resolve &= 0xFFFFFFFFUL;
11182 +
11183 + regs->u_regs[UREG_RETPC] = regs->tpc;
11184 + regs->tpc = dl_resolve;
11185 + regs->tnpc = dl_resolve+4;
11186 + return 3;
11187 + }
11188 + } while (0);
11189 +#endif
11190 +
11191 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11192 + unsigned int sethi, ba, nop;
11193 +
11194 + err = get_user(sethi, (unsigned int *)regs->tpc);
11195 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11196 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11197 +
11198 + if (err)
11199 + break;
11200 +
11201 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11202 + (ba & 0xFFF00000U) == 0x30600000U &&
11203 + nop == 0x01000000U)
11204 + {
11205 + unsigned long addr;
11206 +
11207 + addr = (sethi & 0x003FFFFFU) << 10;
11208 + regs->u_regs[UREG_G1] = addr;
11209 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11210 +
11211 + if (test_thread_flag(TIF_32BIT))
11212 + addr &= 0xFFFFFFFFUL;
11213 +
11214 + regs->tpc = addr;
11215 + regs->tnpc = addr+4;
11216 + return 2;
11217 + }
11218 + } while (0);
11219 +
11220 +#endif
11221 +
11222 + return 1;
11223 +}
11224 +
11225 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11226 +{
11227 + unsigned long i;
11228 +
11229 + printk(KERN_ERR "PAX: bytes at PC: ");
11230 + for (i = 0; i < 8; i++) {
11231 + unsigned int c;
11232 + if (get_user(c, (unsigned int *)pc+i))
11233 + printk(KERN_CONT "???????? ");
11234 + else
11235 + printk(KERN_CONT "%08x ", c);
11236 + }
11237 + printk("\n");
11238 +}
11239 +#endif
11240 +
11241 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11242 {
11243 enum ctx_state prev_state = exception_enter();
11244 @@ -344,6 +807,29 @@ retry:
11245 if (!vma)
11246 goto bad_area;
11247
11248 +#ifdef CONFIG_PAX_PAGEEXEC
11249 + /* PaX: detect ITLB misses on non-exec pages */
11250 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11251 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11252 + {
11253 + if (address != regs->tpc)
11254 + goto good_area;
11255 +
11256 + up_read(&mm->mmap_sem);
11257 + switch (pax_handle_fetch_fault(regs)) {
11258 +
11259 +#ifdef CONFIG_PAX_EMUPLT
11260 + case 2:
11261 + case 3:
11262 + return;
11263 +#endif
11264 +
11265 + }
11266 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11267 + do_group_exit(SIGKILL);
11268 + }
11269 +#endif
11270 +
11271 /* Pure DTLB misses do not tell us whether the fault causing
11272 * load/store/atomic was a write or not, it only says that there
11273 * was no match. So in such a case we (carefully) read the
11274 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11275 index 3096317..a7b7654 100644
11276 --- a/arch/sparc/mm/hugetlbpage.c
11277 +++ b/arch/sparc/mm/hugetlbpage.c
11278 @@ -26,7 +26,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11279 unsigned long addr,
11280 unsigned long len,
11281 unsigned long pgoff,
11282 - unsigned long flags)
11283 + unsigned long flags,
11284 + unsigned long offset)
11285 {
11286 unsigned long task_size = TASK_SIZE;
11287 struct vm_unmapped_area_info info;
11288 @@ -36,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11289
11290 info.flags = 0;
11291 info.length = len;
11292 - info.low_limit = TASK_UNMAPPED_BASE;
11293 + info.low_limit = mm->mmap_base;
11294 info.high_limit = min(task_size, VA_EXCLUDE_START);
11295 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11296 info.align_offset = 0;
11297 + info.threadstack_offset = offset;
11298 addr = vm_unmapped_area(&info);
11299
11300 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11301 VM_BUG_ON(addr != -ENOMEM);
11302 info.low_limit = VA_EXCLUDE_END;
11303 +
11304 +#ifdef CONFIG_PAX_RANDMMAP
11305 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11306 + info.low_limit += mm->delta_mmap;
11307 +#endif
11308 +
11309 info.high_limit = task_size;
11310 addr = vm_unmapped_area(&info);
11311 }
11312 @@ -56,7 +64,8 @@ static unsigned long
11313 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11314 const unsigned long len,
11315 const unsigned long pgoff,
11316 - const unsigned long flags)
11317 + const unsigned long flags,
11318 + const unsigned long offset)
11319 {
11320 struct mm_struct *mm = current->mm;
11321 unsigned long addr = addr0;
11322 @@ -71,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11323 info.high_limit = mm->mmap_base;
11324 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11325 info.align_offset = 0;
11326 + info.threadstack_offset = offset;
11327 addr = vm_unmapped_area(&info);
11328
11329 /*
11330 @@ -83,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11331 VM_BUG_ON(addr != -ENOMEM);
11332 info.flags = 0;
11333 info.low_limit = TASK_UNMAPPED_BASE;
11334 +
11335 +#ifdef CONFIG_PAX_RANDMMAP
11336 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11337 + info.low_limit += mm->delta_mmap;
11338 +#endif
11339 +
11340 info.high_limit = STACK_TOP32;
11341 addr = vm_unmapped_area(&info);
11342 }
11343 @@ -97,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11344 struct mm_struct *mm = current->mm;
11345 struct vm_area_struct *vma;
11346 unsigned long task_size = TASK_SIZE;
11347 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11348
11349 if (test_thread_flag(TIF_32BIT))
11350 task_size = STACK_TOP32;
11351 @@ -112,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11352 return addr;
11353 }
11354
11355 +#ifdef CONFIG_PAX_RANDMMAP
11356 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11357 +#endif
11358 +
11359 if (addr) {
11360 addr = ALIGN(addr, HPAGE_SIZE);
11361 vma = find_vma(mm, addr);
11362 - if (task_size - len >= addr &&
11363 - (!vma || addr + len <= vma->vm_start))
11364 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11365 return addr;
11366 }
11367 if (mm->get_unmapped_area == arch_get_unmapped_area)
11368 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11369 - pgoff, flags);
11370 + pgoff, flags, offset);
11371 else
11372 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11373 - pgoff, flags);
11374 + pgoff, flags, offset);
11375 }
11376
11377 pte_t *huge_pte_alloc(struct mm_struct *mm,
11378 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11379 index 5322e53..f820c5e 100644
11380 --- a/arch/sparc/mm/init_64.c
11381 +++ b/arch/sparc/mm/init_64.c
11382 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11383 int num_kernel_image_mappings;
11384
11385 #ifdef CONFIG_DEBUG_DCFLUSH
11386 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
11387 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11388 #ifdef CONFIG_SMP
11389 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11390 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11391 #endif
11392 #endif
11393
11394 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11395 {
11396 BUG_ON(tlb_type == hypervisor);
11397 #ifdef CONFIG_DEBUG_DCFLUSH
11398 - atomic_inc(&dcpage_flushes);
11399 + atomic_inc_unchecked(&dcpage_flushes);
11400 #endif
11401
11402 #ifdef DCACHE_ALIASING_POSSIBLE
11403 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11404
11405 #ifdef CONFIG_DEBUG_DCFLUSH
11406 seq_printf(m, "DCPageFlushes\t: %d\n",
11407 - atomic_read(&dcpage_flushes));
11408 + atomic_read_unchecked(&dcpage_flushes));
11409 #ifdef CONFIG_SMP
11410 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11411 - atomic_read(&dcpage_flushes_xcall));
11412 + atomic_read_unchecked(&dcpage_flushes_xcall));
11413 #endif /* CONFIG_SMP */
11414 #endif /* CONFIG_DEBUG_DCFLUSH */
11415 }
11416 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11417 index b3692ce..e4517c9 100644
11418 --- a/arch/tile/Kconfig
11419 +++ b/arch/tile/Kconfig
11420 @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11421
11422 config KEXEC
11423 bool "kexec system call"
11424 + depends on !GRKERNSEC_KMEM
11425 ---help---
11426 kexec is a system call that implements the ability to shutdown your
11427 current kernel, and to start another kernel. It is like a reboot
11428 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11429 index ad220ee..2f537b3 100644
11430 --- a/arch/tile/include/asm/atomic_64.h
11431 +++ b/arch/tile/include/asm/atomic_64.h
11432 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11433
11434 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11435
11436 +#define atomic64_read_unchecked(v) atomic64_read(v)
11437 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11438 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11439 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11440 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11441 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
11442 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11443 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
11444 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11445 +
11446 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11447 #define smp_mb__before_atomic_dec() smp_mb()
11448 #define smp_mb__after_atomic_dec() smp_mb()
11449 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11450 index 6160761..00cac88 100644
11451 --- a/arch/tile/include/asm/cache.h
11452 +++ b/arch/tile/include/asm/cache.h
11453 @@ -15,11 +15,12 @@
11454 #ifndef _ASM_TILE_CACHE_H
11455 #define _ASM_TILE_CACHE_H
11456
11457 +#include <linux/const.h>
11458 #include <arch/chip.h>
11459
11460 /* bytes per L1 data cache line */
11461 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11462 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11463 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11464
11465 /* bytes per L2 cache line */
11466 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11467 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11468 index b6cde32..c0cb736 100644
11469 --- a/arch/tile/include/asm/uaccess.h
11470 +++ b/arch/tile/include/asm/uaccess.h
11471 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11472 const void __user *from,
11473 unsigned long n)
11474 {
11475 - int sz = __compiletime_object_size(to);
11476 + size_t sz = __compiletime_object_size(to);
11477
11478 - if (likely(sz == -1 || sz >= n))
11479 + if (likely(sz == (size_t)-1 || sz >= n))
11480 n = _copy_from_user(to, from, n);
11481 else
11482 copy_from_user_overflow();
11483 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11484 index 0cb3bba..7338b2d 100644
11485 --- a/arch/tile/mm/hugetlbpage.c
11486 +++ b/arch/tile/mm/hugetlbpage.c
11487 @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11488 info.high_limit = TASK_SIZE;
11489 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11490 info.align_offset = 0;
11491 + info.threadstack_offset = 0;
11492 return vm_unmapped_area(&info);
11493 }
11494
11495 @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11496 info.high_limit = current->mm->mmap_base;
11497 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11498 info.align_offset = 0;
11499 + info.threadstack_offset = 0;
11500 addr = vm_unmapped_area(&info);
11501
11502 /*
11503 diff --git a/arch/um/Makefile b/arch/um/Makefile
11504 index 36e658a..71a5c5a 100644
11505 --- a/arch/um/Makefile
11506 +++ b/arch/um/Makefile
11507 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11508 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11509 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11510
11511 +ifdef CONSTIFY_PLUGIN
11512 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11513 +endif
11514 +
11515 #This will adjust *FLAGS accordingly to the platform.
11516 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11517
11518 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11519 index 19e1bdd..3665b77 100644
11520 --- a/arch/um/include/asm/cache.h
11521 +++ b/arch/um/include/asm/cache.h
11522 @@ -1,6 +1,7 @@
11523 #ifndef __UM_CACHE_H
11524 #define __UM_CACHE_H
11525
11526 +#include <linux/const.h>
11527
11528 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11529 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11530 @@ -12,6 +13,6 @@
11531 # define L1_CACHE_SHIFT 5
11532 #endif
11533
11534 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11535 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11536
11537 #endif
11538 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11539 index 2e0a6b1..a64d0f5 100644
11540 --- a/arch/um/include/asm/kmap_types.h
11541 +++ b/arch/um/include/asm/kmap_types.h
11542 @@ -8,6 +8,6 @@
11543
11544 /* No more #include "asm/arch/kmap_types.h" ! */
11545
11546 -#define KM_TYPE_NR 14
11547 +#define KM_TYPE_NR 15
11548
11549 #endif
11550 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11551 index 5ff53d9..5850cdf 100644
11552 --- a/arch/um/include/asm/page.h
11553 +++ b/arch/um/include/asm/page.h
11554 @@ -14,6 +14,9 @@
11555 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11556 #define PAGE_MASK (~(PAGE_SIZE-1))
11557
11558 +#define ktla_ktva(addr) (addr)
11559 +#define ktva_ktla(addr) (addr)
11560 +
11561 #ifndef __ASSEMBLY__
11562
11563 struct page;
11564 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11565 index 0032f92..cd151e0 100644
11566 --- a/arch/um/include/asm/pgtable-3level.h
11567 +++ b/arch/um/include/asm/pgtable-3level.h
11568 @@ -58,6 +58,7 @@
11569 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11570 #define pud_populate(mm, pud, pmd) \
11571 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11572 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11573
11574 #ifdef CONFIG_64BIT
11575 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11576 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11577 index eecc414..48adb87 100644
11578 --- a/arch/um/kernel/process.c
11579 +++ b/arch/um/kernel/process.c
11580 @@ -356,22 +356,6 @@ int singlestepping(void * t)
11581 return 2;
11582 }
11583
11584 -/*
11585 - * Only x86 and x86_64 have an arch_align_stack().
11586 - * All other arches have "#define arch_align_stack(x) (x)"
11587 - * in their asm/system.h
11588 - * As this is included in UML from asm-um/system-generic.h,
11589 - * we can use it to behave as the subarch does.
11590 - */
11591 -#ifndef arch_align_stack
11592 -unsigned long arch_align_stack(unsigned long sp)
11593 -{
11594 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11595 - sp -= get_random_int() % 8192;
11596 - return sp & ~0xf;
11597 -}
11598 -#endif
11599 -
11600 unsigned long get_wchan(struct task_struct *p)
11601 {
11602 unsigned long stack_page, sp, ip;
11603 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11604 index ad8f795..2c7eec6 100644
11605 --- a/arch/unicore32/include/asm/cache.h
11606 +++ b/arch/unicore32/include/asm/cache.h
11607 @@ -12,8 +12,10 @@
11608 #ifndef __UNICORE_CACHE_H__
11609 #define __UNICORE_CACHE_H__
11610
11611 -#define L1_CACHE_SHIFT (5)
11612 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11613 +#include <linux/const.h>
11614 +
11615 +#define L1_CACHE_SHIFT 5
11616 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11617
11618 /*
11619 * Memory returned by kmalloc() may be used for DMA, so we must make
11620 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11621 index 0952ecd..75e0e8a 100644
11622 --- a/arch/x86/Kconfig
11623 +++ b/arch/x86/Kconfig
11624 @@ -249,7 +249,7 @@ config X86_HT
11625
11626 config X86_32_LAZY_GS
11627 def_bool y
11628 - depends on X86_32 && !CC_STACKPROTECTOR
11629 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11630
11631 config ARCH_HWEIGHT_CFLAGS
11632 string
11633 @@ -1104,6 +1104,7 @@ config MICROCODE_EARLY
11634
11635 config X86_MSR
11636 tristate "/dev/cpu/*/msr - Model-specific register support"
11637 + depends on !GRKERNSEC_KMEM
11638 ---help---
11639 This device gives privileged processes access to the x86
11640 Model-Specific Registers (MSRs). It is a character device with
11641 @@ -1127,7 +1128,7 @@ choice
11642
11643 config NOHIGHMEM
11644 bool "off"
11645 - depends on !X86_NUMAQ
11646 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11647 ---help---
11648 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11649 However, the address space of 32-bit x86 processors is only 4
11650 @@ -1164,7 +1165,7 @@ config NOHIGHMEM
11651
11652 config HIGHMEM4G
11653 bool "4GB"
11654 - depends on !X86_NUMAQ
11655 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11656 ---help---
11657 Select this if you have a 32-bit processor and between 1 and 4
11658 gigabytes of physical RAM.
11659 @@ -1217,7 +1218,7 @@ config PAGE_OFFSET
11660 hex
11661 default 0xB0000000 if VMSPLIT_3G_OPT
11662 default 0x80000000 if VMSPLIT_2G
11663 - default 0x78000000 if VMSPLIT_2G_OPT
11664 + default 0x70000000 if VMSPLIT_2G_OPT
11665 default 0x40000000 if VMSPLIT_1G
11666 default 0xC0000000
11667 depends on X86_32
11668 @@ -1619,6 +1620,7 @@ config SECCOMP
11669
11670 config CC_STACKPROTECTOR
11671 bool "Enable -fstack-protector buffer overflow detection"
11672 + depends on X86_64 || !PAX_MEMORY_UDEREF
11673 ---help---
11674 This option turns on the -fstack-protector GCC feature. This
11675 feature puts, at the beginning of functions, a canary value on
11676 @@ -1637,6 +1639,7 @@ source kernel/Kconfig.hz
11677
11678 config KEXEC
11679 bool "kexec system call"
11680 + depends on !GRKERNSEC_KMEM
11681 ---help---
11682 kexec is a system call that implements the ability to shutdown your
11683 current kernel, and to start another kernel. It is like a reboot
11684 @@ -1738,6 +1741,8 @@ config X86_NEED_RELOCS
11685 config PHYSICAL_ALIGN
11686 hex "Alignment value to which kernel should be aligned"
11687 default "0x1000000"
11688 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11689 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11690 range 0x2000 0x1000000 if X86_32
11691 range 0x200000 0x1000000 if X86_64
11692 ---help---
11693 @@ -1817,9 +1822,10 @@ config DEBUG_HOTPLUG_CPU0
11694 If unsure, say N.
11695
11696 config COMPAT_VDSO
11697 - def_bool y
11698 + def_bool n
11699 prompt "Compat VDSO support"
11700 depends on X86_32 || IA32_EMULATION
11701 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11702 ---help---
11703 Map the 32-bit VDSO to the predictable old-style address too.
11704
11705 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11706 index c026cca..14657ae 100644
11707 --- a/arch/x86/Kconfig.cpu
11708 +++ b/arch/x86/Kconfig.cpu
11709 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11710
11711 config X86_F00F_BUG
11712 def_bool y
11713 - depends on M586MMX || M586TSC || M586 || M486
11714 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11715
11716 config X86_INVD_BUG
11717 def_bool y
11718 @@ -327,7 +327,7 @@ config X86_INVD_BUG
11719
11720 config X86_ALIGNMENT_16
11721 def_bool y
11722 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11723 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11724
11725 config X86_INTEL_USERCOPY
11726 def_bool y
11727 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
11728 # generates cmov.
11729 config X86_CMOV
11730 def_bool y
11731 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11732 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11733
11734 config X86_MINIMUM_CPU_FAMILY
11735 int
11736 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11737 index 0f3621e..282f24b 100644
11738 --- a/arch/x86/Kconfig.debug
11739 +++ b/arch/x86/Kconfig.debug
11740 @@ -84,7 +84,7 @@ config X86_PTDUMP
11741 config DEBUG_RODATA
11742 bool "Write protect kernel read-only data structures"
11743 default y
11744 - depends on DEBUG_KERNEL
11745 + depends on DEBUG_KERNEL && BROKEN
11746 ---help---
11747 Mark the kernel read-only data as write-protected in the pagetables,
11748 in order to catch accidental (and incorrect) writes to such const
11749 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
11750
11751 config DEBUG_SET_MODULE_RONX
11752 bool "Set loadable kernel module data as NX and text as RO"
11753 - depends on MODULES
11754 + depends on MODULES && BROKEN
11755 ---help---
11756 This option helps catch unintended modifications to loadable
11757 kernel module's text and read-only data. It also prevents execution
11758 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11759 index 57d0215..b4373fb 100644
11760 --- a/arch/x86/Makefile
11761 +++ b/arch/x86/Makefile
11762 @@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
11763 # CPU-specific tuning. Anything which can be shared with UML should go here.
11764 include $(srctree)/arch/x86/Makefile_32.cpu
11765 KBUILD_CFLAGS += $(cflags-y)
11766 -
11767 - # temporary until string.h is fixed
11768 - KBUILD_CFLAGS += -ffreestanding
11769 else
11770 BITS := 64
11771 UTS_MACHINE := x86_64
11772 CHECKFLAGS += -D__x86_64__ -m64
11773
11774 + biarch := $(call cc-option,-m64)
11775 KBUILD_AFLAGS += -m64
11776 KBUILD_CFLAGS += -m64
11777
11778 @@ -89,6 +87,9 @@ else
11779 KBUILD_CFLAGS += -maccumulate-outgoing-args
11780 endif
11781
11782 +# temporary until string.h is fixed
11783 +KBUILD_CFLAGS += -ffreestanding
11784 +
11785 ifdef CONFIG_CC_STACKPROTECTOR
11786 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11787 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
11788 @@ -247,3 +248,12 @@ define archhelp
11789 echo ' FDINITRD=file initrd for the booted kernel'
11790 echo ' kvmconfig - Enable additional options for guest kernel support'
11791 endef
11792 +
11793 +define OLD_LD
11794 +
11795 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11796 +*** Please upgrade your binutils to 2.18 or newer
11797 +endef
11798 +
11799 +archprepare:
11800 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11801 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11802 index d9c1195..a26ca0d 100644
11803 --- a/arch/x86/boot/Makefile
11804 +++ b/arch/x86/boot/Makefile
11805 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
11806 $(call cc-option, -fno-unit-at-a-time)) \
11807 $(call cc-option, -fno-stack-protector) \
11808 $(call cc-option, -mpreferred-stack-boundary=2)
11809 +ifdef CONSTIFY_PLUGIN
11810 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11811 +endif
11812 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11813 GCOV_PROFILE := n
11814
11815 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11816 index 878e4b9..20537ab 100644
11817 --- a/arch/x86/boot/bitops.h
11818 +++ b/arch/x86/boot/bitops.h
11819 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11820 u8 v;
11821 const u32 *p = (const u32 *)addr;
11822
11823 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11824 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11825 return v;
11826 }
11827
11828 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11829
11830 static inline void set_bit(int nr, void *addr)
11831 {
11832 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11833 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11834 }
11835
11836 #endif /* BOOT_BITOPS_H */
11837 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11838 index ef72bae..353a184 100644
11839 --- a/arch/x86/boot/boot.h
11840 +++ b/arch/x86/boot/boot.h
11841 @@ -85,7 +85,7 @@ static inline void io_delay(void)
11842 static inline u16 ds(void)
11843 {
11844 u16 seg;
11845 - asm("movw %%ds,%0" : "=rm" (seg));
11846 + asm volatile("movw %%ds,%0" : "=rm" (seg));
11847 return seg;
11848 }
11849
11850 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11851 static inline int memcmp(const void *s1, const void *s2, size_t len)
11852 {
11853 u8 diff;
11854 - asm("repe; cmpsb; setnz %0"
11855 + asm volatile("repe; cmpsb; setnz %0"
11856 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11857 return diff;
11858 }
11859 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11860 index c8a6792..2402765 100644
11861 --- a/arch/x86/boot/compressed/Makefile
11862 +++ b/arch/x86/boot/compressed/Makefile
11863 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
11864 KBUILD_CFLAGS += -mno-mmx -mno-sse
11865 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11866 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11867 +ifdef CONSTIFY_PLUGIN
11868 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11869 +endif
11870
11871 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11872 GCOV_PROFILE := n
11873 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11874 index a53440e..c3dbf1e 100644
11875 --- a/arch/x86/boot/compressed/efi_stub_32.S
11876 +++ b/arch/x86/boot/compressed/efi_stub_32.S
11877 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11878 * parameter 2, ..., param n. To make things easy, we save the return
11879 * address of efi_call_phys in a global variable.
11880 */
11881 - popl %ecx
11882 - movl %ecx, saved_return_addr(%edx)
11883 - /* get the function pointer into ECX*/
11884 - popl %ecx
11885 - movl %ecx, efi_rt_function_ptr(%edx)
11886 + popl saved_return_addr(%edx)
11887 + popl efi_rt_function_ptr(%edx)
11888
11889 /*
11890 * 3. Call the physical function.
11891 */
11892 - call *%ecx
11893 + call *efi_rt_function_ptr(%edx)
11894
11895 /*
11896 * 4. Balance the stack. And because EAX contain the return value,
11897 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11898 1: popl %edx
11899 subl $1b, %edx
11900
11901 - movl efi_rt_function_ptr(%edx), %ecx
11902 - pushl %ecx
11903 + pushl efi_rt_function_ptr(%edx)
11904
11905 /*
11906 * 10. Push the saved return address onto the stack and return.
11907 */
11908 - movl saved_return_addr(%edx), %ecx
11909 - pushl %ecx
11910 - ret
11911 + jmpl *saved_return_addr(%edx)
11912 ENDPROC(efi_call_phys)
11913 .previous
11914
11915 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11916 index 5d6f689..9d06730 100644
11917 --- a/arch/x86/boot/compressed/head_32.S
11918 +++ b/arch/x86/boot/compressed/head_32.S
11919 @@ -118,7 +118,7 @@ preferred_addr:
11920 notl %eax
11921 andl %eax, %ebx
11922 #else
11923 - movl $LOAD_PHYSICAL_ADDR, %ebx
11924 + movl $____LOAD_PHYSICAL_ADDR, %ebx
11925 #endif
11926
11927 /* Target address to relocate to for decompression */
11928 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11929 index c337422..2c5be72 100644
11930 --- a/arch/x86/boot/compressed/head_64.S
11931 +++ b/arch/x86/boot/compressed/head_64.S
11932 @@ -95,7 +95,7 @@ ENTRY(startup_32)
11933 notl %eax
11934 andl %eax, %ebx
11935 #else
11936 - movl $LOAD_PHYSICAL_ADDR, %ebx
11937 + movl $____LOAD_PHYSICAL_ADDR, %ebx
11938 #endif
11939
11940 /* Target address to relocate to for decompression */
11941 @@ -270,7 +270,7 @@ preferred_addr:
11942 notq %rax
11943 andq %rax, %rbp
11944 #else
11945 - movq $LOAD_PHYSICAL_ADDR, %rbp
11946 + movq $____LOAD_PHYSICAL_ADDR, %rbp
11947 #endif
11948
11949 /* Target address to relocate to for decompression */
11950 @@ -362,8 +362,8 @@ gdt:
11951 .long gdt
11952 .word 0
11953 .quad 0x0000000000000000 /* NULL descriptor */
11954 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
11955 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
11956 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
11957 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
11958 .quad 0x0080890000000000 /* TS descriptor */
11959 .quad 0x0000000000000000 /* TS continued */
11960 gdt_end:
11961 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11962 index 434f077..b6b4b38 100644
11963 --- a/arch/x86/boot/compressed/misc.c
11964 +++ b/arch/x86/boot/compressed/misc.c
11965 @@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
11966 * Calculate the delta between where vmlinux was linked to load
11967 * and where it was actually loaded.
11968 */
11969 - delta = min_addr - LOAD_PHYSICAL_ADDR;
11970 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
11971 if (!delta) {
11972 debug_putstr("No relocation needed... ");
11973 return;
11974 @@ -380,7 +380,7 @@ static void parse_elf(void *output)
11975 case PT_LOAD:
11976 #ifdef CONFIG_RELOCATABLE
11977 dest = output;
11978 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11979 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11980 #else
11981 dest = (void *)(phdr->p_paddr);
11982 #endif
11983 @@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11984 error("Destination address too large");
11985 #endif
11986 #ifndef CONFIG_RELOCATABLE
11987 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11988 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11989 error("Wrong destination address");
11990 #endif
11991
11992 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11993 index 4d3ff03..e4972ff 100644
11994 --- a/arch/x86/boot/cpucheck.c
11995 +++ b/arch/x86/boot/cpucheck.c
11996 @@ -74,7 +74,7 @@ static int has_fpu(void)
11997 u16 fcw = -1, fsw = -1;
11998 u32 cr0;
11999
12000 - asm("movl %%cr0,%0" : "=r" (cr0));
12001 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
12002 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12003 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12004 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12005 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12006 {
12007 u32 f0, f1;
12008
12009 - asm("pushfl ; "
12010 + asm volatile("pushfl ; "
12011 "pushfl ; "
12012 "popl %0 ; "
12013 "movl %0,%1 ; "
12014 @@ -115,7 +115,7 @@ static void get_flags(void)
12015 set_bit(X86_FEATURE_FPU, cpu.flags);
12016
12017 if (has_eflag(X86_EFLAGS_ID)) {
12018 - asm("cpuid"
12019 + asm volatile("cpuid"
12020 : "=a" (max_intel_level),
12021 "=b" (cpu_vendor[0]),
12022 "=d" (cpu_vendor[1]),
12023 @@ -124,7 +124,7 @@ static void get_flags(void)
12024
12025 if (max_intel_level >= 0x00000001 &&
12026 max_intel_level <= 0x0000ffff) {
12027 - asm("cpuid"
12028 + asm volatile("cpuid"
12029 : "=a" (tfms),
12030 "=c" (cpu.flags[4]),
12031 "=d" (cpu.flags[0])
12032 @@ -136,7 +136,7 @@ static void get_flags(void)
12033 cpu.model += ((tfms >> 16) & 0xf) << 4;
12034 }
12035
12036 - asm("cpuid"
12037 + asm volatile("cpuid"
12038 : "=a" (max_amd_level)
12039 : "a" (0x80000000)
12040 : "ebx", "ecx", "edx");
12041 @@ -144,7 +144,7 @@ static void get_flags(void)
12042 if (max_amd_level >= 0x80000001 &&
12043 max_amd_level <= 0x8000ffff) {
12044 u32 eax = 0x80000001;
12045 - asm("cpuid"
12046 + asm volatile("cpuid"
12047 : "+a" (eax),
12048 "=c" (cpu.flags[6]),
12049 "=d" (cpu.flags[1])
12050 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12051 u32 ecx = MSR_K7_HWCR;
12052 u32 eax, edx;
12053
12054 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12055 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12056 eax &= ~(1 << 15);
12057 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12058 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12059
12060 get_flags(); /* Make sure it really did something */
12061 err = check_flags();
12062 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12063 u32 ecx = MSR_VIA_FCR;
12064 u32 eax, edx;
12065
12066 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12067 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12068 eax |= (1<<1)|(1<<7);
12069 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12070 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12071
12072 set_bit(X86_FEATURE_CX8, cpu.flags);
12073 err = check_flags();
12074 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12075 u32 eax, edx;
12076 u32 level = 1;
12077
12078 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12079 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12080 - asm("cpuid"
12081 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12082 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12083 + asm volatile("cpuid"
12084 : "+a" (level), "=d" (cpu.flags[0])
12085 : : "ecx", "ebx");
12086 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12087 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12088
12089 err = check_flags();
12090 }
12091 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12092 index 9ec06a1..2c25e79 100644
12093 --- a/arch/x86/boot/header.S
12094 +++ b/arch/x86/boot/header.S
12095 @@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12096 # single linked list of
12097 # struct setup_data
12098
12099 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12100 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12101
12102 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12103 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12104 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12105 +#else
12106 #define VO_INIT_SIZE (VO__end - VO__text)
12107 +#endif
12108 #if ZO_INIT_SIZE > VO_INIT_SIZE
12109 #define INIT_SIZE ZO_INIT_SIZE
12110 #else
12111 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12112 index db75d07..8e6d0af 100644
12113 --- a/arch/x86/boot/memory.c
12114 +++ b/arch/x86/boot/memory.c
12115 @@ -19,7 +19,7 @@
12116
12117 static int detect_memory_e820(void)
12118 {
12119 - int count = 0;
12120 + unsigned int count = 0;
12121 struct biosregs ireg, oreg;
12122 struct e820entry *desc = boot_params.e820_map;
12123 static struct e820entry buf; /* static so it is zeroed */
12124 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12125 index 11e8c6e..fdbb1ed 100644
12126 --- a/arch/x86/boot/video-vesa.c
12127 +++ b/arch/x86/boot/video-vesa.c
12128 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12129
12130 boot_params.screen_info.vesapm_seg = oreg.es;
12131 boot_params.screen_info.vesapm_off = oreg.di;
12132 + boot_params.screen_info.vesapm_size = oreg.cx;
12133 }
12134
12135 /*
12136 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12137 index 43eda28..5ab5fdb 100644
12138 --- a/arch/x86/boot/video.c
12139 +++ b/arch/x86/boot/video.c
12140 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12141 static unsigned int get_entry(void)
12142 {
12143 char entry_buf[4];
12144 - int i, len = 0;
12145 + unsigned int i, len = 0;
12146 int key;
12147 unsigned int v;
12148
12149 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12150 index 9105655..41779c1 100644
12151 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12152 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12153 @@ -8,6 +8,8 @@
12154 * including this sentence is retained in full.
12155 */
12156
12157 +#include <asm/alternative-asm.h>
12158 +
12159 .extern crypto_ft_tab
12160 .extern crypto_it_tab
12161 .extern crypto_fl_tab
12162 @@ -70,6 +72,8 @@
12163 je B192; \
12164 leaq 32(r9),r9;
12165
12166 +#define ret pax_force_retaddr; ret
12167 +
12168 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12169 movq r1,r2; \
12170 movq r3,r4; \
12171 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12172 index 477e9d7..c92c7d8 100644
12173 --- a/arch/x86/crypto/aesni-intel_asm.S
12174 +++ b/arch/x86/crypto/aesni-intel_asm.S
12175 @@ -31,6 +31,7 @@
12176
12177 #include <linux/linkage.h>
12178 #include <asm/inst.h>
12179 +#include <asm/alternative-asm.h>
12180
12181 #ifdef __x86_64__
12182 .data
12183 @@ -205,7 +206,7 @@ enc: .octa 0x2
12184 * num_initial_blocks = b mod 4
12185 * encrypt the initial num_initial_blocks blocks and apply ghash on
12186 * the ciphertext
12187 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12188 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12189 * are clobbered
12190 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12191 */
12192 @@ -214,8 +215,8 @@ enc: .octa 0x2
12193 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12194 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12195 mov arg7, %r10 # %r10 = AAD
12196 - mov arg8, %r12 # %r12 = aadLen
12197 - mov %r12, %r11
12198 + mov arg8, %r15 # %r15 = aadLen
12199 + mov %r15, %r11
12200 pxor %xmm\i, %xmm\i
12201 _get_AAD_loop\num_initial_blocks\operation:
12202 movd (%r10), \TMP1
12203 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12204 psrldq $4, %xmm\i
12205 pxor \TMP1, %xmm\i
12206 add $4, %r10
12207 - sub $4, %r12
12208 + sub $4, %r15
12209 jne _get_AAD_loop\num_initial_blocks\operation
12210 cmp $16, %r11
12211 je _get_AAD_loop2_done\num_initial_blocks\operation
12212 - mov $16, %r12
12213 + mov $16, %r15
12214 _get_AAD_loop2\num_initial_blocks\operation:
12215 psrldq $4, %xmm\i
12216 - sub $4, %r12
12217 - cmp %r11, %r12
12218 + sub $4, %r15
12219 + cmp %r11, %r15
12220 jne _get_AAD_loop2\num_initial_blocks\operation
12221 _get_AAD_loop2_done\num_initial_blocks\operation:
12222 movdqa SHUF_MASK(%rip), %xmm14
12223 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12224 * num_initial_blocks = b mod 4
12225 * encrypt the initial num_initial_blocks blocks and apply ghash on
12226 * the ciphertext
12227 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12228 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12229 * are clobbered
12230 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12231 */
12232 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12233 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12234 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12235 mov arg7, %r10 # %r10 = AAD
12236 - mov arg8, %r12 # %r12 = aadLen
12237 - mov %r12, %r11
12238 + mov arg8, %r15 # %r15 = aadLen
12239 + mov %r15, %r11
12240 pxor %xmm\i, %xmm\i
12241 _get_AAD_loop\num_initial_blocks\operation:
12242 movd (%r10), \TMP1
12243 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12244 psrldq $4, %xmm\i
12245 pxor \TMP1, %xmm\i
12246 add $4, %r10
12247 - sub $4, %r12
12248 + sub $4, %r15
12249 jne _get_AAD_loop\num_initial_blocks\operation
12250 cmp $16, %r11
12251 je _get_AAD_loop2_done\num_initial_blocks\operation
12252 - mov $16, %r12
12253 + mov $16, %r15
12254 _get_AAD_loop2\num_initial_blocks\operation:
12255 psrldq $4, %xmm\i
12256 - sub $4, %r12
12257 - cmp %r11, %r12
12258 + sub $4, %r15
12259 + cmp %r11, %r15
12260 jne _get_AAD_loop2\num_initial_blocks\operation
12261 _get_AAD_loop2_done\num_initial_blocks\operation:
12262 movdqa SHUF_MASK(%rip), %xmm14
12263 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12264 *
12265 *****************************************************************************/
12266 ENTRY(aesni_gcm_dec)
12267 - push %r12
12268 + push %r15
12269 push %r13
12270 push %r14
12271 mov %rsp, %r14
12272 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12273 */
12274 sub $VARIABLE_OFFSET, %rsp
12275 and $~63, %rsp # align rsp to 64 bytes
12276 - mov %arg6, %r12
12277 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12278 + mov %arg6, %r15
12279 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12280 movdqa SHUF_MASK(%rip), %xmm2
12281 PSHUFB_XMM %xmm2, %xmm13
12282
12283 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12284 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12285 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12286 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12287 - mov %r13, %r12
12288 - and $(3<<4), %r12
12289 + mov %r13, %r15
12290 + and $(3<<4), %r15
12291 jz _initial_num_blocks_is_0_decrypt
12292 - cmp $(2<<4), %r12
12293 + cmp $(2<<4), %r15
12294 jb _initial_num_blocks_is_1_decrypt
12295 je _initial_num_blocks_is_2_decrypt
12296 _initial_num_blocks_is_3_decrypt:
12297 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12298 sub $16, %r11
12299 add %r13, %r11
12300 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12301 - lea SHIFT_MASK+16(%rip), %r12
12302 - sub %r13, %r12
12303 + lea SHIFT_MASK+16(%rip), %r15
12304 + sub %r13, %r15
12305 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12306 # (%r13 is the number of bytes in plaintext mod 16)
12307 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12308 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12309 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12310
12311 movdqa %xmm1, %xmm2
12312 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12313 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12314 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12315 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12316 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12317 pand %xmm1, %xmm2
12318 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12319 sub $1, %r13
12320 jne _less_than_8_bytes_left_decrypt
12321 _multiple_of_16_bytes_decrypt:
12322 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12323 - shl $3, %r12 # convert into number of bits
12324 - movd %r12d, %xmm15 # len(A) in %xmm15
12325 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12326 + shl $3, %r15 # convert into number of bits
12327 + movd %r15d, %xmm15 # len(A) in %xmm15
12328 shl $3, %arg4 # len(C) in bits (*128)
12329 MOVQ_R64_XMM %arg4, %xmm1
12330 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12331 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12332 mov %r14, %rsp
12333 pop %r14
12334 pop %r13
12335 - pop %r12
12336 + pop %r15
12337 + pax_force_retaddr
12338 ret
12339 ENDPROC(aesni_gcm_dec)
12340
12341 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12342 * poly = x^128 + x^127 + x^126 + x^121 + 1
12343 ***************************************************************************/
12344 ENTRY(aesni_gcm_enc)
12345 - push %r12
12346 + push %r15
12347 push %r13
12348 push %r14
12349 mov %rsp, %r14
12350 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12351 #
12352 sub $VARIABLE_OFFSET, %rsp
12353 and $~63, %rsp
12354 - mov %arg6, %r12
12355 - movdqu (%r12), %xmm13
12356 + mov %arg6, %r15
12357 + movdqu (%r15), %xmm13
12358 movdqa SHUF_MASK(%rip), %xmm2
12359 PSHUFB_XMM %xmm2, %xmm13
12360
12361 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12362 movdqa %xmm13, HashKey(%rsp)
12363 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12364 and $-16, %r13
12365 - mov %r13, %r12
12366 + mov %r13, %r15
12367
12368 # Encrypt first few blocks
12369
12370 - and $(3<<4), %r12
12371 + and $(3<<4), %r15
12372 jz _initial_num_blocks_is_0_encrypt
12373 - cmp $(2<<4), %r12
12374 + cmp $(2<<4), %r15
12375 jb _initial_num_blocks_is_1_encrypt
12376 je _initial_num_blocks_is_2_encrypt
12377 _initial_num_blocks_is_3_encrypt:
12378 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12379 sub $16, %r11
12380 add %r13, %r11
12381 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12382 - lea SHIFT_MASK+16(%rip), %r12
12383 - sub %r13, %r12
12384 + lea SHIFT_MASK+16(%rip), %r15
12385 + sub %r13, %r15
12386 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12387 # (%r13 is the number of bytes in plaintext mod 16)
12388 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12389 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12390 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12391 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12392 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12393 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12394 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12395 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12396 movdqa SHUF_MASK(%rip), %xmm10
12397 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12398 sub $1, %r13
12399 jne _less_than_8_bytes_left_encrypt
12400 _multiple_of_16_bytes_encrypt:
12401 - mov arg8, %r12 # %r12 = addLen (number of bytes)
12402 - shl $3, %r12
12403 - movd %r12d, %xmm15 # len(A) in %xmm15
12404 + mov arg8, %r15 # %r15 = addLen (number of bytes)
12405 + shl $3, %r15
12406 + movd %r15d, %xmm15 # len(A) in %xmm15
12407 shl $3, %arg4 # len(C) in bits (*128)
12408 MOVQ_R64_XMM %arg4, %xmm1
12409 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12410 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12411 mov %r14, %rsp
12412 pop %r14
12413 pop %r13
12414 - pop %r12
12415 + pop %r15
12416 + pax_force_retaddr
12417 ret
12418 ENDPROC(aesni_gcm_enc)
12419
12420 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
12421 pxor %xmm1, %xmm0
12422 movaps %xmm0, (TKEYP)
12423 add $0x10, TKEYP
12424 + pax_force_retaddr
12425 ret
12426 ENDPROC(_key_expansion_128)
12427 ENDPROC(_key_expansion_256a)
12428 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
12429 shufps $0b01001110, %xmm2, %xmm1
12430 movaps %xmm1, 0x10(TKEYP)
12431 add $0x20, TKEYP
12432 + pax_force_retaddr
12433 ret
12434 ENDPROC(_key_expansion_192a)
12435
12436 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
12437
12438 movaps %xmm0, (TKEYP)
12439 add $0x10, TKEYP
12440 + pax_force_retaddr
12441 ret
12442 ENDPROC(_key_expansion_192b)
12443
12444 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
12445 pxor %xmm1, %xmm2
12446 movaps %xmm2, (TKEYP)
12447 add $0x10, TKEYP
12448 + pax_force_retaddr
12449 ret
12450 ENDPROC(_key_expansion_256b)
12451
12452 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12453 #ifndef __x86_64__
12454 popl KEYP
12455 #endif
12456 + pax_force_retaddr
12457 ret
12458 ENDPROC(aesni_set_key)
12459
12460 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12461 popl KLEN
12462 popl KEYP
12463 #endif
12464 + pax_force_retaddr
12465 ret
12466 ENDPROC(aesni_enc)
12467
12468 @@ -1974,6 +1983,7 @@ _aesni_enc1:
12469 AESENC KEY STATE
12470 movaps 0x70(TKEYP), KEY
12471 AESENCLAST KEY STATE
12472 + pax_force_retaddr
12473 ret
12474 ENDPROC(_aesni_enc1)
12475
12476 @@ -2083,6 +2093,7 @@ _aesni_enc4:
12477 AESENCLAST KEY STATE2
12478 AESENCLAST KEY STATE3
12479 AESENCLAST KEY STATE4
12480 + pax_force_retaddr
12481 ret
12482 ENDPROC(_aesni_enc4)
12483
12484 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12485 popl KLEN
12486 popl KEYP
12487 #endif
12488 + pax_force_retaddr
12489 ret
12490 ENDPROC(aesni_dec)
12491
12492 @@ -2164,6 +2176,7 @@ _aesni_dec1:
12493 AESDEC KEY STATE
12494 movaps 0x70(TKEYP), KEY
12495 AESDECLAST KEY STATE
12496 + pax_force_retaddr
12497 ret
12498 ENDPROC(_aesni_dec1)
12499
12500 @@ -2273,6 +2286,7 @@ _aesni_dec4:
12501 AESDECLAST KEY STATE2
12502 AESDECLAST KEY STATE3
12503 AESDECLAST KEY STATE4
12504 + pax_force_retaddr
12505 ret
12506 ENDPROC(_aesni_dec4)
12507
12508 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12509 popl KEYP
12510 popl LEN
12511 #endif
12512 + pax_force_retaddr
12513 ret
12514 ENDPROC(aesni_ecb_enc)
12515
12516 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12517 popl KEYP
12518 popl LEN
12519 #endif
12520 + pax_force_retaddr
12521 ret
12522 ENDPROC(aesni_ecb_dec)
12523
12524 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12525 popl LEN
12526 popl IVP
12527 #endif
12528 + pax_force_retaddr
12529 ret
12530 ENDPROC(aesni_cbc_enc)
12531
12532 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12533 popl LEN
12534 popl IVP
12535 #endif
12536 + pax_force_retaddr
12537 ret
12538 ENDPROC(aesni_cbc_dec)
12539
12540 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
12541 mov $1, TCTR_LOW
12542 MOVQ_R64_XMM TCTR_LOW INC
12543 MOVQ_R64_XMM CTR TCTR_LOW
12544 + pax_force_retaddr
12545 ret
12546 ENDPROC(_aesni_inc_init)
12547
12548 @@ -2579,6 +2598,7 @@ _aesni_inc:
12549 .Linc_low:
12550 movaps CTR, IV
12551 PSHUFB_XMM BSWAP_MASK IV
12552 + pax_force_retaddr
12553 ret
12554 ENDPROC(_aesni_inc)
12555
12556 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12557 .Lctr_enc_ret:
12558 movups IV, (IVP)
12559 .Lctr_enc_just_ret:
12560 + pax_force_retaddr
12561 ret
12562 ENDPROC(aesni_ctr_enc)
12563
12564 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12565 pxor INC, STATE4
12566 movdqu STATE4, 0x70(OUTP)
12567
12568 + pax_force_retaddr
12569 ret
12570 ENDPROC(aesni_xts_crypt8)
12571
12572 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12573 index 246c670..466e2d6 100644
12574 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12575 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12576 @@ -21,6 +21,7 @@
12577 */
12578
12579 #include <linux/linkage.h>
12580 +#include <asm/alternative-asm.h>
12581
12582 .file "blowfish-x86_64-asm.S"
12583 .text
12584 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12585 jnz .L__enc_xor;
12586
12587 write_block();
12588 + pax_force_retaddr
12589 ret;
12590 .L__enc_xor:
12591 xor_block();
12592 + pax_force_retaddr
12593 ret;
12594 ENDPROC(__blowfish_enc_blk)
12595
12596 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12597
12598 movq %r11, %rbp;
12599
12600 + pax_force_retaddr
12601 ret;
12602 ENDPROC(blowfish_dec_blk)
12603
12604 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12605
12606 popq %rbx;
12607 popq %rbp;
12608 + pax_force_retaddr
12609 ret;
12610
12611 .L__enc_xor4:
12612 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12613
12614 popq %rbx;
12615 popq %rbp;
12616 + pax_force_retaddr
12617 ret;
12618 ENDPROC(__blowfish_enc_blk_4way)
12619
12620 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12621 popq %rbx;
12622 popq %rbp;
12623
12624 + pax_force_retaddr
12625 ret;
12626 ENDPROC(blowfish_dec_blk_4way)
12627 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12628 index ce71f92..1dce7ec 100644
12629 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12630 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12631 @@ -16,6 +16,7 @@
12632 */
12633
12634 #include <linux/linkage.h>
12635 +#include <asm/alternative-asm.h>
12636
12637 #define CAMELLIA_TABLE_BYTE_LEN 272
12638
12639 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12640 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12641 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12642 %rcx, (%r9));
12643 + pax_force_retaddr
12644 ret;
12645 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12646
12647 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12648 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12649 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12650 %rax, (%r9));
12651 + pax_force_retaddr
12652 ret;
12653 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12654
12655 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
12656 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12657 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12658
12659 + pax_force_retaddr
12660 ret;
12661
12662 .align 8
12663 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
12664 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12665 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12666
12667 + pax_force_retaddr
12668 ret;
12669
12670 .align 8
12671 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12672 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12673 %xmm8, %rsi);
12674
12675 + pax_force_retaddr
12676 ret;
12677 ENDPROC(camellia_ecb_enc_16way)
12678
12679 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12680 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12681 %xmm8, %rsi);
12682
12683 + pax_force_retaddr
12684 ret;
12685 ENDPROC(camellia_ecb_dec_16way)
12686
12687 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12688 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12689 %xmm8, %rsi);
12690
12691 + pax_force_retaddr
12692 ret;
12693 ENDPROC(camellia_cbc_dec_16way)
12694
12695 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12696 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12697 %xmm8, %rsi);
12698
12699 + pax_force_retaddr
12700 ret;
12701 ENDPROC(camellia_ctr_16way)
12702
12703 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12704 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12705 %xmm8, %rsi);
12706
12707 + pax_force_retaddr
12708 ret;
12709 ENDPROC(camellia_xts_crypt_16way)
12710
12711 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12712 index 0e0b886..5a3123c 100644
12713 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12714 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12715 @@ -11,6 +11,7 @@
12716 */
12717
12718 #include <linux/linkage.h>
12719 +#include <asm/alternative-asm.h>
12720
12721 #define CAMELLIA_TABLE_BYTE_LEN 272
12722
12723 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12724 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12725 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12726 %rcx, (%r9));
12727 + pax_force_retaddr
12728 ret;
12729 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12730
12731 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12732 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12733 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12734 %rax, (%r9));
12735 + pax_force_retaddr
12736 ret;
12737 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12738
12739 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
12740 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12741 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12742
12743 + pax_force_retaddr
12744 ret;
12745
12746 .align 8
12747 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
12748 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12749 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12750
12751 + pax_force_retaddr
12752 ret;
12753
12754 .align 8
12755 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12756
12757 vzeroupper;
12758
12759 + pax_force_retaddr
12760 ret;
12761 ENDPROC(camellia_ecb_enc_32way)
12762
12763 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12764
12765 vzeroupper;
12766
12767 + pax_force_retaddr
12768 ret;
12769 ENDPROC(camellia_ecb_dec_32way)
12770
12771 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12772
12773 vzeroupper;
12774
12775 + pax_force_retaddr
12776 ret;
12777 ENDPROC(camellia_cbc_dec_32way)
12778
12779 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12780
12781 vzeroupper;
12782
12783 + pax_force_retaddr
12784 ret;
12785 ENDPROC(camellia_ctr_32way)
12786
12787 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12788
12789 vzeroupper;
12790
12791 + pax_force_retaddr
12792 ret;
12793 ENDPROC(camellia_xts_crypt_32way)
12794
12795 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12796 index 310319c..db3d7b5 100644
12797 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12798 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12799 @@ -21,6 +21,7 @@
12800 */
12801
12802 #include <linux/linkage.h>
12803 +#include <asm/alternative-asm.h>
12804
12805 .file "camellia-x86_64-asm_64.S"
12806 .text
12807 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12808 enc_outunpack(mov, RT1);
12809
12810 movq RRBP, %rbp;
12811 + pax_force_retaddr
12812 ret;
12813
12814 .L__enc_xor:
12815 enc_outunpack(xor, RT1);
12816
12817 movq RRBP, %rbp;
12818 + pax_force_retaddr
12819 ret;
12820 ENDPROC(__camellia_enc_blk)
12821
12822 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12823 dec_outunpack();
12824
12825 movq RRBP, %rbp;
12826 + pax_force_retaddr
12827 ret;
12828 ENDPROC(camellia_dec_blk)
12829
12830 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12831
12832 movq RRBP, %rbp;
12833 popq %rbx;
12834 + pax_force_retaddr
12835 ret;
12836
12837 .L__enc2_xor:
12838 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12839
12840 movq RRBP, %rbp;
12841 popq %rbx;
12842 + pax_force_retaddr
12843 ret;
12844 ENDPROC(__camellia_enc_blk_2way)
12845
12846 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12847
12848 movq RRBP, %rbp;
12849 movq RXOR, %rbx;
12850 + pax_force_retaddr
12851 ret;
12852 ENDPROC(camellia_dec_blk_2way)
12853 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12854 index c35fd5d..2d8c7db 100644
12855 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12856 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12857 @@ -24,6 +24,7 @@
12858 */
12859
12860 #include <linux/linkage.h>
12861 +#include <asm/alternative-asm.h>
12862
12863 .file "cast5-avx-x86_64-asm_64.S"
12864
12865 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
12866 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12867 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12868
12869 + pax_force_retaddr
12870 ret;
12871 ENDPROC(__cast5_enc_blk16)
12872
12873 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
12874 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12875 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12876
12877 + pax_force_retaddr
12878 ret;
12879
12880 .L__skip_dec:
12881 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12882 vmovdqu RR4, (6*4*4)(%r11);
12883 vmovdqu RL4, (7*4*4)(%r11);
12884
12885 + pax_force_retaddr
12886 ret;
12887 ENDPROC(cast5_ecb_enc_16way)
12888
12889 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12890 vmovdqu RR4, (6*4*4)(%r11);
12891 vmovdqu RL4, (7*4*4)(%r11);
12892
12893 + pax_force_retaddr
12894 ret;
12895 ENDPROC(cast5_ecb_dec_16way)
12896
12897 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
12898 * %rdx: src
12899 */
12900
12901 - pushq %r12;
12902 + pushq %r14;
12903
12904 movq %rsi, %r11;
12905 - movq %rdx, %r12;
12906 + movq %rdx, %r14;
12907
12908 vmovdqu (0*16)(%rdx), RL1;
12909 vmovdqu (1*16)(%rdx), RR1;
12910 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
12911 call __cast5_dec_blk16;
12912
12913 /* xor with src */
12914 - vmovq (%r12), RX;
12915 + vmovq (%r14), RX;
12916 vpshufd $0x4f, RX, RX;
12917 vpxor RX, RR1, RR1;
12918 - vpxor 0*16+8(%r12), RL1, RL1;
12919 - vpxor 1*16+8(%r12), RR2, RR2;
12920 - vpxor 2*16+8(%r12), RL2, RL2;
12921 - vpxor 3*16+8(%r12), RR3, RR3;
12922 - vpxor 4*16+8(%r12), RL3, RL3;
12923 - vpxor 5*16+8(%r12), RR4, RR4;
12924 - vpxor 6*16+8(%r12), RL4, RL4;
12925 + vpxor 0*16+8(%r14), RL1, RL1;
12926 + vpxor 1*16+8(%r14), RR2, RR2;
12927 + vpxor 2*16+8(%r14), RL2, RL2;
12928 + vpxor 3*16+8(%r14), RR3, RR3;
12929 + vpxor 4*16+8(%r14), RL3, RL3;
12930 + vpxor 5*16+8(%r14), RR4, RR4;
12931 + vpxor 6*16+8(%r14), RL4, RL4;
12932
12933 vmovdqu RR1, (0*16)(%r11);
12934 vmovdqu RL1, (1*16)(%r11);
12935 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
12936 vmovdqu RR4, (6*16)(%r11);
12937 vmovdqu RL4, (7*16)(%r11);
12938
12939 - popq %r12;
12940 + popq %r14;
12941
12942 + pax_force_retaddr
12943 ret;
12944 ENDPROC(cast5_cbc_dec_16way)
12945
12946 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
12947 * %rcx: iv (big endian, 64bit)
12948 */
12949
12950 - pushq %r12;
12951 + pushq %r14;
12952
12953 movq %rsi, %r11;
12954 - movq %rdx, %r12;
12955 + movq %rdx, %r14;
12956
12957 vpcmpeqd RTMP, RTMP, RTMP;
12958 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
12959 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
12960 call __cast5_enc_blk16;
12961
12962 /* dst = src ^ iv */
12963 - vpxor (0*16)(%r12), RR1, RR1;
12964 - vpxor (1*16)(%r12), RL1, RL1;
12965 - vpxor (2*16)(%r12), RR2, RR2;
12966 - vpxor (3*16)(%r12), RL2, RL2;
12967 - vpxor (4*16)(%r12), RR3, RR3;
12968 - vpxor (5*16)(%r12), RL3, RL3;
12969 - vpxor (6*16)(%r12), RR4, RR4;
12970 - vpxor (7*16)(%r12), RL4, RL4;
12971 + vpxor (0*16)(%r14), RR1, RR1;
12972 + vpxor (1*16)(%r14), RL1, RL1;
12973 + vpxor (2*16)(%r14), RR2, RR2;
12974 + vpxor (3*16)(%r14), RL2, RL2;
12975 + vpxor (4*16)(%r14), RR3, RR3;
12976 + vpxor (5*16)(%r14), RL3, RL3;
12977 + vpxor (6*16)(%r14), RR4, RR4;
12978 + vpxor (7*16)(%r14), RL4, RL4;
12979 vmovdqu RR1, (0*16)(%r11);
12980 vmovdqu RL1, (1*16)(%r11);
12981 vmovdqu RR2, (2*16)(%r11);
12982 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
12983 vmovdqu RR4, (6*16)(%r11);
12984 vmovdqu RL4, (7*16)(%r11);
12985
12986 - popq %r12;
12987 + popq %r14;
12988
12989 + pax_force_retaddr
12990 ret;
12991 ENDPROC(cast5_ctr_16way)
12992 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12993 index e3531f8..e123f35 100644
12994 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12995 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12996 @@ -24,6 +24,7 @@
12997 */
12998
12999 #include <linux/linkage.h>
13000 +#include <asm/alternative-asm.h>
13001 #include "glue_helper-asm-avx.S"
13002
13003 .file "cast6-avx-x86_64-asm_64.S"
13004 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13005 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13006 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13007
13008 + pax_force_retaddr
13009 ret;
13010 ENDPROC(__cast6_enc_blk8)
13011
13012 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13013 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13014 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13015
13016 + pax_force_retaddr
13017 ret;
13018 ENDPROC(__cast6_dec_blk8)
13019
13020 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13021
13022 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13023
13024 + pax_force_retaddr
13025 ret;
13026 ENDPROC(cast6_ecb_enc_8way)
13027
13028 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13029
13030 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13031
13032 + pax_force_retaddr
13033 ret;
13034 ENDPROC(cast6_ecb_dec_8way)
13035
13036 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13037 * %rdx: src
13038 */
13039
13040 - pushq %r12;
13041 + pushq %r14;
13042
13043 movq %rsi, %r11;
13044 - movq %rdx, %r12;
13045 + movq %rdx, %r14;
13046
13047 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13048
13049 call __cast6_dec_blk8;
13050
13051 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13052 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13053
13054 - popq %r12;
13055 + popq %r14;
13056
13057 + pax_force_retaddr
13058 ret;
13059 ENDPROC(cast6_cbc_dec_8way)
13060
13061 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13062 * %rcx: iv (little endian, 128bit)
13063 */
13064
13065 - pushq %r12;
13066 + pushq %r14;
13067
13068 movq %rsi, %r11;
13069 - movq %rdx, %r12;
13070 + movq %rdx, %r14;
13071
13072 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13073 RD2, RX, RKR, RKM);
13074
13075 call __cast6_enc_blk8;
13076
13077 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13078 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13079
13080 - popq %r12;
13081 + popq %r14;
13082
13083 + pax_force_retaddr
13084 ret;
13085 ENDPROC(cast6_ctr_8way)
13086
13087 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13088 /* dst <= regs xor IVs(in dst) */
13089 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13090
13091 + pax_force_retaddr
13092 ret;
13093 ENDPROC(cast6_xts_enc_8way)
13094
13095 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13096 /* dst <= regs xor IVs(in dst) */
13097 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13098
13099 + pax_force_retaddr
13100 ret;
13101 ENDPROC(cast6_xts_dec_8way)
13102 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13103 index dbc4339..de6e120 100644
13104 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13105 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13106 @@ -45,6 +45,7 @@
13107
13108 #include <asm/inst.h>
13109 #include <linux/linkage.h>
13110 +#include <asm/alternative-asm.h>
13111
13112 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13113
13114 @@ -312,6 +313,7 @@ do_return:
13115 popq %rsi
13116 popq %rdi
13117 popq %rbx
13118 + pax_force_retaddr
13119 ret
13120
13121 ################################################################
13122 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13123 index 586f41a..d02851e 100644
13124 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13125 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13126 @@ -18,6 +18,7 @@
13127
13128 #include <linux/linkage.h>
13129 #include <asm/inst.h>
13130 +#include <asm/alternative-asm.h>
13131
13132 .data
13133
13134 @@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13135 psrlq $1, T2
13136 pxor T2, T1
13137 pxor T1, DATA
13138 + pax_force_retaddr
13139 ret
13140 ENDPROC(__clmul_gf128mul_ble)
13141
13142 @@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13143 call __clmul_gf128mul_ble
13144 PSHUFB_XMM BSWAP DATA
13145 movups DATA, (%rdi)
13146 + pax_force_retaddr
13147 ret
13148 ENDPROC(clmul_ghash_mul)
13149
13150 @@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13151 PSHUFB_XMM BSWAP DATA
13152 movups DATA, (%rdi)
13153 .Lupdate_just_ret:
13154 + pax_force_retaddr
13155 ret
13156 ENDPROC(clmul_ghash_update)
13157
13158 @@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13159 pand .Lpoly, %xmm1
13160 pxor %xmm1, %xmm0
13161 movups %xmm0, (%rdi)
13162 + pax_force_retaddr
13163 ret
13164 ENDPROC(clmul_ghash_setkey)
13165 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13166 index 9279e0b..c4b3d2c 100644
13167 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13168 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13169 @@ -1,4 +1,5 @@
13170 #include <linux/linkage.h>
13171 +#include <asm/alternative-asm.h>
13172
13173 # enter salsa20_encrypt_bytes
13174 ENTRY(salsa20_encrypt_bytes)
13175 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13176 add %r11,%rsp
13177 mov %rdi,%rax
13178 mov %rsi,%rdx
13179 + pax_force_retaddr
13180 ret
13181 # bytesatleast65:
13182 ._bytesatleast65:
13183 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13184 add %r11,%rsp
13185 mov %rdi,%rax
13186 mov %rsi,%rdx
13187 + pax_force_retaddr
13188 ret
13189 ENDPROC(salsa20_keysetup)
13190
13191 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13192 add %r11,%rsp
13193 mov %rdi,%rax
13194 mov %rsi,%rdx
13195 + pax_force_retaddr
13196 ret
13197 ENDPROC(salsa20_ivsetup)
13198 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13199 index 2f202f4..d9164d6 100644
13200 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13201 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13202 @@ -24,6 +24,7 @@
13203 */
13204
13205 #include <linux/linkage.h>
13206 +#include <asm/alternative-asm.h>
13207 #include "glue_helper-asm-avx.S"
13208
13209 .file "serpent-avx-x86_64-asm_64.S"
13210 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13211 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13212 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13213
13214 + pax_force_retaddr
13215 ret;
13216 ENDPROC(__serpent_enc_blk8_avx)
13217
13218 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13219 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13220 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13221
13222 + pax_force_retaddr
13223 ret;
13224 ENDPROC(__serpent_dec_blk8_avx)
13225
13226 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13227
13228 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13229
13230 + pax_force_retaddr
13231 ret;
13232 ENDPROC(serpent_ecb_enc_8way_avx)
13233
13234 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13235
13236 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13237
13238 + pax_force_retaddr
13239 ret;
13240 ENDPROC(serpent_ecb_dec_8way_avx)
13241
13242 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13243
13244 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13245
13246 + pax_force_retaddr
13247 ret;
13248 ENDPROC(serpent_cbc_dec_8way_avx)
13249
13250 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13251
13252 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13253
13254 + pax_force_retaddr
13255 ret;
13256 ENDPROC(serpent_ctr_8way_avx)
13257
13258 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13259 /* dst <= regs xor IVs(in dst) */
13260 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13261
13262 + pax_force_retaddr
13263 ret;
13264 ENDPROC(serpent_xts_enc_8way_avx)
13265
13266 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13267 /* dst <= regs xor IVs(in dst) */
13268 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13269
13270 + pax_force_retaddr
13271 ret;
13272 ENDPROC(serpent_xts_dec_8way_avx)
13273 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13274 index b222085..abd483c 100644
13275 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13276 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13277 @@ -15,6 +15,7 @@
13278 */
13279
13280 #include <linux/linkage.h>
13281 +#include <asm/alternative-asm.h>
13282 #include "glue_helper-asm-avx2.S"
13283
13284 .file "serpent-avx2-asm_64.S"
13285 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13286 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13287 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13288
13289 + pax_force_retaddr
13290 ret;
13291 ENDPROC(__serpent_enc_blk16)
13292
13293 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13294 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13295 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13296
13297 + pax_force_retaddr
13298 ret;
13299 ENDPROC(__serpent_dec_blk16)
13300
13301 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13302
13303 vzeroupper;
13304
13305 + pax_force_retaddr
13306 ret;
13307 ENDPROC(serpent_ecb_enc_16way)
13308
13309 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13310
13311 vzeroupper;
13312
13313 + pax_force_retaddr
13314 ret;
13315 ENDPROC(serpent_ecb_dec_16way)
13316
13317 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13318
13319 vzeroupper;
13320
13321 + pax_force_retaddr
13322 ret;
13323 ENDPROC(serpent_cbc_dec_16way)
13324
13325 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13326
13327 vzeroupper;
13328
13329 + pax_force_retaddr
13330 ret;
13331 ENDPROC(serpent_ctr_16way)
13332
13333 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13334
13335 vzeroupper;
13336
13337 + pax_force_retaddr
13338 ret;
13339 ENDPROC(serpent_xts_enc_16way)
13340
13341 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13342
13343 vzeroupper;
13344
13345 + pax_force_retaddr
13346 ret;
13347 ENDPROC(serpent_xts_dec_16way)
13348 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13349 index acc066c..1559cc4 100644
13350 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13351 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13352 @@ -25,6 +25,7 @@
13353 */
13354
13355 #include <linux/linkage.h>
13356 +#include <asm/alternative-asm.h>
13357
13358 .file "serpent-sse2-x86_64-asm_64.S"
13359 .text
13360 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13361 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13362 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13363
13364 + pax_force_retaddr
13365 ret;
13366
13367 .L__enc_xor8:
13368 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13369 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13370
13371 + pax_force_retaddr
13372 ret;
13373 ENDPROC(__serpent_enc_blk_8way)
13374
13375 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13376 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13377 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13378
13379 + pax_force_retaddr
13380 ret;
13381 ENDPROC(serpent_dec_blk_8way)
13382 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13383 index a410950..9dfe7ad 100644
13384 --- a/arch/x86/crypto/sha1_ssse3_asm.S
13385 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
13386 @@ -29,6 +29,7 @@
13387 */
13388
13389 #include <linux/linkage.h>
13390 +#include <asm/alternative-asm.h>
13391
13392 #define CTX %rdi // arg1
13393 #define BUF %rsi // arg2
13394 @@ -75,9 +76,9 @@
13395
13396 push %rbx
13397 push %rbp
13398 - push %r12
13399 + push %r14
13400
13401 - mov %rsp, %r12
13402 + mov %rsp, %r14
13403 sub $64, %rsp # allocate workspace
13404 and $~15, %rsp # align stack
13405
13406 @@ -99,11 +100,12 @@
13407 xor %rax, %rax
13408 rep stosq
13409
13410 - mov %r12, %rsp # deallocate workspace
13411 + mov %r14, %rsp # deallocate workspace
13412
13413 - pop %r12
13414 + pop %r14
13415 pop %rbp
13416 pop %rbx
13417 + pax_force_retaddr
13418 ret
13419
13420 ENDPROC(\name)
13421 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13422 index 642f156..51a513c 100644
13423 --- a/arch/x86/crypto/sha256-avx-asm.S
13424 +++ b/arch/x86/crypto/sha256-avx-asm.S
13425 @@ -49,6 +49,7 @@
13426
13427 #ifdef CONFIG_AS_AVX
13428 #include <linux/linkage.h>
13429 +#include <asm/alternative-asm.h>
13430
13431 ## assume buffers not aligned
13432 #define VMOVDQ vmovdqu
13433 @@ -460,6 +461,7 @@ done_hash:
13434 popq %r13
13435 popq %rbp
13436 popq %rbx
13437 + pax_force_retaddr
13438 ret
13439 ENDPROC(sha256_transform_avx)
13440
13441 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13442 index 9e86944..3795e6a 100644
13443 --- a/arch/x86/crypto/sha256-avx2-asm.S
13444 +++ b/arch/x86/crypto/sha256-avx2-asm.S
13445 @@ -50,6 +50,7 @@
13446
13447 #ifdef CONFIG_AS_AVX2
13448 #include <linux/linkage.h>
13449 +#include <asm/alternative-asm.h>
13450
13451 ## assume buffers not aligned
13452 #define VMOVDQ vmovdqu
13453 @@ -720,6 +721,7 @@ done_hash:
13454 popq %r12
13455 popq %rbp
13456 popq %rbx
13457 + pax_force_retaddr
13458 ret
13459 ENDPROC(sha256_transform_rorx)
13460
13461 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13462 index f833b74..8c62a9e 100644
13463 --- a/arch/x86/crypto/sha256-ssse3-asm.S
13464 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
13465 @@ -47,6 +47,7 @@
13466 ########################################################################
13467
13468 #include <linux/linkage.h>
13469 +#include <asm/alternative-asm.h>
13470
13471 ## assume buffers not aligned
13472 #define MOVDQ movdqu
13473 @@ -471,6 +472,7 @@ done_hash:
13474 popq %rbp
13475 popq %rbx
13476
13477 + pax_force_retaddr
13478 ret
13479 ENDPROC(sha256_transform_ssse3)
13480
13481 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13482 index 974dde9..a823ff9 100644
13483 --- a/arch/x86/crypto/sha512-avx-asm.S
13484 +++ b/arch/x86/crypto/sha512-avx-asm.S
13485 @@ -49,6 +49,7 @@
13486
13487 #ifdef CONFIG_AS_AVX
13488 #include <linux/linkage.h>
13489 +#include <asm/alternative-asm.h>
13490
13491 .text
13492
13493 @@ -364,6 +365,7 @@ updateblock:
13494 mov frame_RSPSAVE(%rsp), %rsp
13495
13496 nowork:
13497 + pax_force_retaddr
13498 ret
13499 ENDPROC(sha512_transform_avx)
13500
13501 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13502 index 568b961..ed20c37 100644
13503 --- a/arch/x86/crypto/sha512-avx2-asm.S
13504 +++ b/arch/x86/crypto/sha512-avx2-asm.S
13505 @@ -51,6 +51,7 @@
13506
13507 #ifdef CONFIG_AS_AVX2
13508 #include <linux/linkage.h>
13509 +#include <asm/alternative-asm.h>
13510
13511 .text
13512
13513 @@ -678,6 +679,7 @@ done_hash:
13514
13515 # Restore Stack Pointer
13516 mov frame_RSPSAVE(%rsp), %rsp
13517 + pax_force_retaddr
13518 ret
13519 ENDPROC(sha512_transform_rorx)
13520
13521 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13522 index fb56855..6edd768 100644
13523 --- a/arch/x86/crypto/sha512-ssse3-asm.S
13524 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
13525 @@ -48,6 +48,7 @@
13526 ########################################################################
13527
13528 #include <linux/linkage.h>
13529 +#include <asm/alternative-asm.h>
13530
13531 .text
13532
13533 @@ -363,6 +364,7 @@ updateblock:
13534 mov frame_RSPSAVE(%rsp), %rsp
13535
13536 nowork:
13537 + pax_force_retaddr
13538 ret
13539 ENDPROC(sha512_transform_ssse3)
13540
13541 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13542 index 0505813..b067311 100644
13543 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13544 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13545 @@ -24,6 +24,7 @@
13546 */
13547
13548 #include <linux/linkage.h>
13549 +#include <asm/alternative-asm.h>
13550 #include "glue_helper-asm-avx.S"
13551
13552 .file "twofish-avx-x86_64-asm_64.S"
13553 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
13554 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13555 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13556
13557 + pax_force_retaddr
13558 ret;
13559 ENDPROC(__twofish_enc_blk8)
13560
13561 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
13562 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13563 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13564
13565 + pax_force_retaddr
13566 ret;
13567 ENDPROC(__twofish_dec_blk8)
13568
13569 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13570
13571 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13572
13573 + pax_force_retaddr
13574 ret;
13575 ENDPROC(twofish_ecb_enc_8way)
13576
13577 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13578
13579 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13580
13581 + pax_force_retaddr
13582 ret;
13583 ENDPROC(twofish_ecb_dec_8way)
13584
13585 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
13586 * %rdx: src
13587 */
13588
13589 - pushq %r12;
13590 + pushq %r14;
13591
13592 movq %rsi, %r11;
13593 - movq %rdx, %r12;
13594 + movq %rdx, %r14;
13595
13596 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13597
13598 call __twofish_dec_blk8;
13599
13600 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13601 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13602
13603 - popq %r12;
13604 + popq %r14;
13605
13606 + pax_force_retaddr
13607 ret;
13608 ENDPROC(twofish_cbc_dec_8way)
13609
13610 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
13611 * %rcx: iv (little endian, 128bit)
13612 */
13613
13614 - pushq %r12;
13615 + pushq %r14;
13616
13617 movq %rsi, %r11;
13618 - movq %rdx, %r12;
13619 + movq %rdx, %r14;
13620
13621 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13622 RD2, RX0, RX1, RY0);
13623
13624 call __twofish_enc_blk8;
13625
13626 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13627 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13628
13629 - popq %r12;
13630 + popq %r14;
13631
13632 + pax_force_retaddr
13633 ret;
13634 ENDPROC(twofish_ctr_8way)
13635
13636 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13637 /* dst <= regs xor IVs(in dst) */
13638 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13639
13640 + pax_force_retaddr
13641 ret;
13642 ENDPROC(twofish_xts_enc_8way)
13643
13644 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13645 /* dst <= regs xor IVs(in dst) */
13646 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13647
13648 + pax_force_retaddr
13649 ret;
13650 ENDPROC(twofish_xts_dec_8way)
13651 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13652 index 1c3b7ce..02f578d 100644
13653 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13654 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13655 @@ -21,6 +21,7 @@
13656 */
13657
13658 #include <linux/linkage.h>
13659 +#include <asm/alternative-asm.h>
13660
13661 .file "twofish-x86_64-asm-3way.S"
13662 .text
13663 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13664 popq %r13;
13665 popq %r14;
13666 popq %r15;
13667 + pax_force_retaddr
13668 ret;
13669
13670 .L__enc_xor3:
13671 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13672 popq %r13;
13673 popq %r14;
13674 popq %r15;
13675 + pax_force_retaddr
13676 ret;
13677 ENDPROC(__twofish_enc_blk_3way)
13678
13679 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13680 popq %r13;
13681 popq %r14;
13682 popq %r15;
13683 + pax_force_retaddr
13684 ret;
13685 ENDPROC(twofish_dec_blk_3way)
13686 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13687 index a039d21..524b8b2 100644
13688 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13689 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13690 @@ -22,6 +22,7 @@
13691
13692 #include <linux/linkage.h>
13693 #include <asm/asm-offsets.h>
13694 +#include <asm/alternative-asm.h>
13695
13696 #define a_offset 0
13697 #define b_offset 4
13698 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13699
13700 popq R1
13701 movq $1,%rax
13702 + pax_force_retaddr
13703 ret
13704 ENDPROC(twofish_enc_blk)
13705
13706 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13707
13708 popq R1
13709 movq $1,%rax
13710 + pax_force_retaddr
13711 ret
13712 ENDPROC(twofish_dec_blk)
13713 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13714 index d21ff89..6da8e6e 100644
13715 --- a/arch/x86/ia32/ia32_aout.c
13716 +++ b/arch/x86/ia32/ia32_aout.c
13717 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
13718 unsigned long dump_start, dump_size;
13719 struct user32 dump;
13720
13721 + memset(&dump, 0, sizeof(dump));
13722 +
13723 fs = get_fs();
13724 set_fs(KERNEL_DS);
13725 has_dumped = 1;
13726 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13727 index 2206757..85cbcfa 100644
13728 --- a/arch/x86/ia32/ia32_signal.c
13729 +++ b/arch/x86/ia32/ia32_signal.c
13730 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
13731 if (__get_user(set.sig[0], &frame->sc.oldmask)
13732 || (_COMPAT_NSIG_WORDS > 1
13733 && __copy_from_user((((char *) &set.sig) + 4),
13734 - &frame->extramask,
13735 + frame->extramask,
13736 sizeof(frame->extramask))))
13737 goto badframe;
13738
13739 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13740 sp -= frame_size;
13741 /* Align the stack pointer according to the i386 ABI,
13742 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13743 - sp = ((sp + 4) & -16ul) - 4;
13744 + sp = ((sp - 12) & -16ul) - 4;
13745 return (void __user *) sp;
13746 }
13747
13748 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13749 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13750 sigreturn);
13751 else
13752 - restorer = &frame->retcode;
13753 + restorer = frame->retcode;
13754 }
13755
13756 put_user_try {
13757 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13758 * These are actually not used anymore, but left because some
13759 * gdb versions depend on them as a marker.
13760 */
13761 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13762 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13763 } put_user_catch(err);
13764
13765 if (err)
13766 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13767 0xb8,
13768 __NR_ia32_rt_sigreturn,
13769 0x80cd,
13770 - 0,
13771 + 0
13772 };
13773
13774 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13775 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13776
13777 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13778 restorer = ksig->ka.sa.sa_restorer;
13779 + else if (current->mm->context.vdso)
13780 + /* Return stub is in 32bit vsyscall page */
13781 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13782 else
13783 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13784 - rt_sigreturn);
13785 + restorer = frame->retcode;
13786 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13787
13788 /*
13789 * Not actually used anymore, but left because some gdb
13790 * versions need it.
13791 */
13792 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13793 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13794 } put_user_catch(err);
13795
13796 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13797 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13798 index 4299eb0..c0687a7 100644
13799 --- a/arch/x86/ia32/ia32entry.S
13800 +++ b/arch/x86/ia32/ia32entry.S
13801 @@ -15,8 +15,10 @@
13802 #include <asm/irqflags.h>
13803 #include <asm/asm.h>
13804 #include <asm/smap.h>
13805 +#include <asm/pgtable.h>
13806 #include <linux/linkage.h>
13807 #include <linux/err.h>
13808 +#include <asm/alternative-asm.h>
13809
13810 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13811 #include <linux/elf-em.h>
13812 @@ -62,12 +64,12 @@
13813 */
13814 .macro LOAD_ARGS32 offset, _r9=0
13815 .if \_r9
13816 - movl \offset+16(%rsp),%r9d
13817 + movl \offset+R9(%rsp),%r9d
13818 .endif
13819 - movl \offset+40(%rsp),%ecx
13820 - movl \offset+48(%rsp),%edx
13821 - movl \offset+56(%rsp),%esi
13822 - movl \offset+64(%rsp),%edi
13823 + movl \offset+RCX(%rsp),%ecx
13824 + movl \offset+RDX(%rsp),%edx
13825 + movl \offset+RSI(%rsp),%esi
13826 + movl \offset+RDI(%rsp),%edi
13827 movl %eax,%eax /* zero extension */
13828 .endm
13829
13830 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13831 ENDPROC(native_irq_enable_sysexit)
13832 #endif
13833
13834 + .macro pax_enter_kernel_user
13835 + pax_set_fptr_mask
13836 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13837 + call pax_enter_kernel_user
13838 +#endif
13839 + .endm
13840 +
13841 + .macro pax_exit_kernel_user
13842 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13843 + call pax_exit_kernel_user
13844 +#endif
13845 +#ifdef CONFIG_PAX_RANDKSTACK
13846 + pushq %rax
13847 + pushq %r11
13848 + call pax_randomize_kstack
13849 + popq %r11
13850 + popq %rax
13851 +#endif
13852 + .endm
13853 +
13854 + .macro pax_erase_kstack
13855 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13856 + call pax_erase_kstack
13857 +#endif
13858 + .endm
13859 +
13860 /*
13861 * 32bit SYSENTER instruction entry.
13862 *
13863 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13864 CFI_REGISTER rsp,rbp
13865 SWAPGS_UNSAFE_STACK
13866 movq PER_CPU_VAR(kernel_stack), %rsp
13867 - addq $(KERNEL_STACK_OFFSET),%rsp
13868 - /*
13869 - * No need to follow this irqs on/off section: the syscall
13870 - * disabled irqs, here we enable it straight after entry:
13871 - */
13872 - ENABLE_INTERRUPTS(CLBR_NONE)
13873 movl %ebp,%ebp /* zero extension */
13874 pushq_cfi $__USER32_DS
13875 /*CFI_REL_OFFSET ss,0*/
13876 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13877 CFI_REL_OFFSET rsp,0
13878 pushfq_cfi
13879 /*CFI_REL_OFFSET rflags,0*/
13880 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13881 - CFI_REGISTER rip,r10
13882 + orl $X86_EFLAGS_IF,(%rsp)
13883 + GET_THREAD_INFO(%r11)
13884 + movl TI_sysenter_return(%r11), %r11d
13885 + CFI_REGISTER rip,r11
13886 pushq_cfi $__USER32_CS
13887 /*CFI_REL_OFFSET cs,0*/
13888 movl %eax, %eax
13889 - pushq_cfi %r10
13890 + pushq_cfi %r11
13891 CFI_REL_OFFSET rip,0
13892 pushq_cfi %rax
13893 cld
13894 SAVE_ARGS 0,1,0
13895 + pax_enter_kernel_user
13896 +
13897 +#ifdef CONFIG_PAX_RANDKSTACK
13898 + pax_erase_kstack
13899 +#endif
13900 +
13901 + /*
13902 + * No need to follow this irqs on/off section: the syscall
13903 + * disabled irqs, here we enable it straight after entry:
13904 + */
13905 + ENABLE_INTERRUPTS(CLBR_NONE)
13906 /* no need to do an access_ok check here because rbp has been
13907 32bit zero extended */
13908 +
13909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13910 + addq pax_user_shadow_base,%rbp
13911 + ASM_PAX_OPEN_USERLAND
13912 +#endif
13913 +
13914 ASM_STAC
13915 1: movl (%rbp),%ebp
13916 _ASM_EXTABLE(1b,ia32_badarg)
13917 ASM_CLAC
13918 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13919 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13920 +
13921 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13922 + ASM_PAX_CLOSE_USERLAND
13923 +#endif
13924 +
13925 + GET_THREAD_INFO(%r11)
13926 + orl $TS_COMPAT,TI_status(%r11)
13927 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13928 CFI_REMEMBER_STATE
13929 jnz sysenter_tracesys
13930 cmpq $(IA32_NR_syscalls-1),%rax
13931 @@ -162,15 +209,18 @@ sysenter_do_call:
13932 sysenter_dispatch:
13933 call *ia32_sys_call_table(,%rax,8)
13934 movq %rax,RAX-ARGOFFSET(%rsp)
13935 + GET_THREAD_INFO(%r11)
13936 DISABLE_INTERRUPTS(CLBR_NONE)
13937 TRACE_IRQS_OFF
13938 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13939 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13940 jnz sysexit_audit
13941 sysexit_from_sys_call:
13942 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13943 + pax_exit_kernel_user
13944 + pax_erase_kstack
13945 + andl $~TS_COMPAT,TI_status(%r11)
13946 /* clear IF, that popfq doesn't enable interrupts early */
13947 - andl $~0x200,EFLAGS-R11(%rsp)
13948 - movl RIP-R11(%rsp),%edx /* User %eip */
13949 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
13950 + movl RIP(%rsp),%edx /* User %eip */
13951 CFI_REGISTER rip,rdx
13952 RESTORE_ARGS 0,24,0,0,0,0
13953 xorq %r8,%r8
13954 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
13955 movl %eax,%esi /* 2nd arg: syscall number */
13956 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13957 call __audit_syscall_entry
13958 +
13959 + pax_erase_kstack
13960 +
13961 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13962 cmpq $(IA32_NR_syscalls-1),%rax
13963 ja ia32_badsys
13964 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
13965 .endm
13966
13967 .macro auditsys_exit exit
13968 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13969 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13970 jnz ia32_ret_from_sys_call
13971 TRACE_IRQS_ON
13972 ENABLE_INTERRUPTS(CLBR_NONE)
13973 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
13974 1: setbe %al /* 1 if error, 0 if not */
13975 movzbl %al,%edi /* zero-extend that into %edi */
13976 call __audit_syscall_exit
13977 + GET_THREAD_INFO(%r11)
13978 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13979 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13980 DISABLE_INTERRUPTS(CLBR_NONE)
13981 TRACE_IRQS_OFF
13982 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13983 + testl %edi,TI_flags(%r11)
13984 jz \exit
13985 CLEAR_RREGS -ARGOFFSET
13986 jmp int_with_check
13987 @@ -237,7 +291,7 @@ sysexit_audit:
13988
13989 sysenter_tracesys:
13990 #ifdef CONFIG_AUDITSYSCALL
13991 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13992 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13993 jz sysenter_auditsys
13994 #endif
13995 SAVE_REST
13996 @@ -249,6 +303,9 @@ sysenter_tracesys:
13997 RESTORE_REST
13998 cmpq $(IA32_NR_syscalls-1),%rax
13999 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14000 +
14001 + pax_erase_kstack
14002 +
14003 jmp sysenter_do_call
14004 CFI_ENDPROC
14005 ENDPROC(ia32_sysenter_target)
14006 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14007 ENTRY(ia32_cstar_target)
14008 CFI_STARTPROC32 simple
14009 CFI_SIGNAL_FRAME
14010 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14011 + CFI_DEF_CFA rsp,0
14012 CFI_REGISTER rip,rcx
14013 /*CFI_REGISTER rflags,r11*/
14014 SWAPGS_UNSAFE_STACK
14015 movl %esp,%r8d
14016 CFI_REGISTER rsp,r8
14017 movq PER_CPU_VAR(kernel_stack),%rsp
14018 + SAVE_ARGS 8*6,0,0
14019 + pax_enter_kernel_user
14020 +
14021 +#ifdef CONFIG_PAX_RANDKSTACK
14022 + pax_erase_kstack
14023 +#endif
14024 +
14025 /*
14026 * No need to follow this irqs on/off section: the syscall
14027 * disabled irqs and here we enable it straight after entry:
14028 */
14029 ENABLE_INTERRUPTS(CLBR_NONE)
14030 - SAVE_ARGS 8,0,0
14031 movl %eax,%eax /* zero extension */
14032 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14033 movq %rcx,RIP-ARGOFFSET(%rsp)
14034 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14035 /* no need to do an access_ok check here because r8 has been
14036 32bit zero extended */
14037 /* hardware stack frame is complete now */
14038 +
14039 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14040 + ASM_PAX_OPEN_USERLAND
14041 + movq pax_user_shadow_base,%r8
14042 + addq RSP-ARGOFFSET(%rsp),%r8
14043 +#endif
14044 +
14045 ASM_STAC
14046 1: movl (%r8),%r9d
14047 _ASM_EXTABLE(1b,ia32_badarg)
14048 ASM_CLAC
14049 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14050 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14051 +
14052 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14053 + ASM_PAX_CLOSE_USERLAND
14054 +#endif
14055 +
14056 + GET_THREAD_INFO(%r11)
14057 + orl $TS_COMPAT,TI_status(%r11)
14058 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14059 CFI_REMEMBER_STATE
14060 jnz cstar_tracesys
14061 cmpq $IA32_NR_syscalls-1,%rax
14062 @@ -319,13 +395,16 @@ cstar_do_call:
14063 cstar_dispatch:
14064 call *ia32_sys_call_table(,%rax,8)
14065 movq %rax,RAX-ARGOFFSET(%rsp)
14066 + GET_THREAD_INFO(%r11)
14067 DISABLE_INTERRUPTS(CLBR_NONE)
14068 TRACE_IRQS_OFF
14069 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14070 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14071 jnz sysretl_audit
14072 sysretl_from_sys_call:
14073 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14074 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14075 + pax_exit_kernel_user
14076 + pax_erase_kstack
14077 + andl $~TS_COMPAT,TI_status(%r11)
14078 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14079 movl RIP-ARGOFFSET(%rsp),%ecx
14080 CFI_REGISTER rip,rcx
14081 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14082 @@ -352,7 +431,7 @@ sysretl_audit:
14083
14084 cstar_tracesys:
14085 #ifdef CONFIG_AUDITSYSCALL
14086 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14087 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14088 jz cstar_auditsys
14089 #endif
14090 xchgl %r9d,%ebp
14091 @@ -366,11 +445,19 @@ cstar_tracesys:
14092 xchgl %ebp,%r9d
14093 cmpq $(IA32_NR_syscalls-1),%rax
14094 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14095 +
14096 + pax_erase_kstack
14097 +
14098 jmp cstar_do_call
14099 END(ia32_cstar_target)
14100
14101 ia32_badarg:
14102 ASM_CLAC
14103 +
14104 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14105 + ASM_PAX_CLOSE_USERLAND
14106 +#endif
14107 +
14108 movq $-EFAULT,%rax
14109 jmp ia32_sysret
14110 CFI_ENDPROC
14111 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14112 CFI_REL_OFFSET rip,RIP-RIP
14113 PARAVIRT_ADJUST_EXCEPTION_FRAME
14114 SWAPGS
14115 - /*
14116 - * No need to follow this irqs on/off section: the syscall
14117 - * disabled irqs and here we enable it straight after entry:
14118 - */
14119 - ENABLE_INTERRUPTS(CLBR_NONE)
14120 movl %eax,%eax
14121 pushq_cfi %rax
14122 cld
14123 /* note the registers are not zero extended to the sf.
14124 this could be a problem. */
14125 SAVE_ARGS 0,1,0
14126 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14127 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14128 + pax_enter_kernel_user
14129 +
14130 +#ifdef CONFIG_PAX_RANDKSTACK
14131 + pax_erase_kstack
14132 +#endif
14133 +
14134 + /*
14135 + * No need to follow this irqs on/off section: the syscall
14136 + * disabled irqs and here we enable it straight after entry:
14137 + */
14138 + ENABLE_INTERRUPTS(CLBR_NONE)
14139 + GET_THREAD_INFO(%r11)
14140 + orl $TS_COMPAT,TI_status(%r11)
14141 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14142 jnz ia32_tracesys
14143 cmpq $(IA32_NR_syscalls-1),%rax
14144 ja ia32_badsys
14145 @@ -442,6 +536,9 @@ ia32_tracesys:
14146 RESTORE_REST
14147 cmpq $(IA32_NR_syscalls-1),%rax
14148 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14149 +
14150 + pax_erase_kstack
14151 +
14152 jmp ia32_do_call
14153 END(ia32_syscall)
14154
14155 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14156 index 8e0ceec..af13504 100644
14157 --- a/arch/x86/ia32/sys_ia32.c
14158 +++ b/arch/x86/ia32/sys_ia32.c
14159 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14160 */
14161 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14162 {
14163 - typeof(ubuf->st_uid) uid = 0;
14164 - typeof(ubuf->st_gid) gid = 0;
14165 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14166 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14167 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14168 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14169 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14170 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14171 index 372231c..51b537d 100644
14172 --- a/arch/x86/include/asm/alternative-asm.h
14173 +++ b/arch/x86/include/asm/alternative-asm.h
14174 @@ -18,6 +18,45 @@
14175 .endm
14176 #endif
14177
14178 +#ifdef KERNEXEC_PLUGIN
14179 + .macro pax_force_retaddr_bts rip=0
14180 + btsq $63,\rip(%rsp)
14181 + .endm
14182 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14183 + .macro pax_force_retaddr rip=0, reload=0
14184 + btsq $63,\rip(%rsp)
14185 + .endm
14186 + .macro pax_force_fptr ptr
14187 + btsq $63,\ptr
14188 + .endm
14189 + .macro pax_set_fptr_mask
14190 + .endm
14191 +#endif
14192 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14193 + .macro pax_force_retaddr rip=0, reload=0
14194 + .if \reload
14195 + pax_set_fptr_mask
14196 + .endif
14197 + orq %r12,\rip(%rsp)
14198 + .endm
14199 + .macro pax_force_fptr ptr
14200 + orq %r12,\ptr
14201 + .endm
14202 + .macro pax_set_fptr_mask
14203 + movabs $0x8000000000000000,%r12
14204 + .endm
14205 +#endif
14206 +#else
14207 + .macro pax_force_retaddr rip=0, reload=0
14208 + .endm
14209 + .macro pax_force_fptr ptr
14210 + .endm
14211 + .macro pax_force_retaddr_bts rip=0
14212 + .endm
14213 + .macro pax_set_fptr_mask
14214 + .endm
14215 +#endif
14216 +
14217 .macro altinstruction_entry orig alt feature orig_len alt_len
14218 .long \orig - .
14219 .long \alt - .
14220 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14221 index 0a3f9c9..c9d081d 100644
14222 --- a/arch/x86/include/asm/alternative.h
14223 +++ b/arch/x86/include/asm/alternative.h
14224 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14225 ".pushsection .discard,\"aw\",@progbits\n" \
14226 DISCARD_ENTRY(1) \
14227 ".popsection\n" \
14228 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14229 + ".pushsection .altinstr_replacement, \"a\"\n" \
14230 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14231 ".popsection"
14232
14233 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14234 DISCARD_ENTRY(1) \
14235 DISCARD_ENTRY(2) \
14236 ".popsection\n" \
14237 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14238 + ".pushsection .altinstr_replacement, \"a\"\n" \
14239 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14240 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14241 ".popsection"
14242 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14243 index 1d2091a..f5074c1 100644
14244 --- a/arch/x86/include/asm/apic.h
14245 +++ b/arch/x86/include/asm/apic.h
14246 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14247
14248 #ifdef CONFIG_X86_LOCAL_APIC
14249
14250 -extern unsigned int apic_verbosity;
14251 +extern int apic_verbosity;
14252 extern int local_apic_timer_c2_ok;
14253
14254 extern int disable_apic;
14255 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14256 index 20370c6..a2eb9b0 100644
14257 --- a/arch/x86/include/asm/apm.h
14258 +++ b/arch/x86/include/asm/apm.h
14259 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14260 __asm__ __volatile__(APM_DO_ZERO_SEGS
14261 "pushl %%edi\n\t"
14262 "pushl %%ebp\n\t"
14263 - "lcall *%%cs:apm_bios_entry\n\t"
14264 + "lcall *%%ss:apm_bios_entry\n\t"
14265 "setc %%al\n\t"
14266 "popl %%ebp\n\t"
14267 "popl %%edi\n\t"
14268 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14269 __asm__ __volatile__(APM_DO_ZERO_SEGS
14270 "pushl %%edi\n\t"
14271 "pushl %%ebp\n\t"
14272 - "lcall *%%cs:apm_bios_entry\n\t"
14273 + "lcall *%%ss:apm_bios_entry\n\t"
14274 "setc %%bl\n\t"
14275 "popl %%ebp\n\t"
14276 "popl %%edi\n\t"
14277 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14278 index b17f4f4..9620151 100644
14279 --- a/arch/x86/include/asm/atomic.h
14280 +++ b/arch/x86/include/asm/atomic.h
14281 @@ -23,7 +23,18 @@
14282 */
14283 static inline int atomic_read(const atomic_t *v)
14284 {
14285 - return (*(volatile int *)&(v)->counter);
14286 + return (*(volatile const int *)&(v)->counter);
14287 +}
14288 +
14289 +/**
14290 + * atomic_read_unchecked - read atomic variable
14291 + * @v: pointer of type atomic_unchecked_t
14292 + *
14293 + * Atomically reads the value of @v.
14294 + */
14295 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14296 +{
14297 + return (*(volatile const int *)&(v)->counter);
14298 }
14299
14300 /**
14301 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14302 }
14303
14304 /**
14305 + * atomic_set_unchecked - set atomic variable
14306 + * @v: pointer of type atomic_unchecked_t
14307 + * @i: required value
14308 + *
14309 + * Atomically sets the value of @v to @i.
14310 + */
14311 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14312 +{
14313 + v->counter = i;
14314 +}
14315 +
14316 +/**
14317 * atomic_add - add integer to atomic variable
14318 * @i: integer value to add
14319 * @v: pointer of type atomic_t
14320 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14321 */
14322 static inline void atomic_add(int i, atomic_t *v)
14323 {
14324 - asm volatile(LOCK_PREFIX "addl %1,%0"
14325 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14326 +
14327 +#ifdef CONFIG_PAX_REFCOUNT
14328 + "jno 0f\n"
14329 + LOCK_PREFIX "subl %1,%0\n"
14330 + "int $4\n0:\n"
14331 + _ASM_EXTABLE(0b, 0b)
14332 +#endif
14333 +
14334 + : "+m" (v->counter)
14335 + : "ir" (i));
14336 +}
14337 +
14338 +/**
14339 + * atomic_add_unchecked - add integer to atomic variable
14340 + * @i: integer value to add
14341 + * @v: pointer of type atomic_unchecked_t
14342 + *
14343 + * Atomically adds @i to @v.
14344 + */
14345 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14346 +{
14347 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14348 : "+m" (v->counter)
14349 : "ir" (i));
14350 }
14351 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14352 */
14353 static inline void atomic_sub(int i, atomic_t *v)
14354 {
14355 - asm volatile(LOCK_PREFIX "subl %1,%0"
14356 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14357 +
14358 +#ifdef CONFIG_PAX_REFCOUNT
14359 + "jno 0f\n"
14360 + LOCK_PREFIX "addl %1,%0\n"
14361 + "int $4\n0:\n"
14362 + _ASM_EXTABLE(0b, 0b)
14363 +#endif
14364 +
14365 + : "+m" (v->counter)
14366 + : "ir" (i));
14367 +}
14368 +
14369 +/**
14370 + * atomic_sub_unchecked - subtract integer from atomic variable
14371 + * @i: integer value to subtract
14372 + * @v: pointer of type atomic_unchecked_t
14373 + *
14374 + * Atomically subtracts @i from @v.
14375 + */
14376 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14377 +{
14378 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14379 : "+m" (v->counter)
14380 : "ir" (i));
14381 }
14382 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14383 */
14384 static inline int atomic_sub_and_test(int i, atomic_t *v)
14385 {
14386 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14387 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14388 }
14389
14390 /**
14391 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14392 */
14393 static inline void atomic_inc(atomic_t *v)
14394 {
14395 - asm volatile(LOCK_PREFIX "incl %0"
14396 + asm volatile(LOCK_PREFIX "incl %0\n"
14397 +
14398 +#ifdef CONFIG_PAX_REFCOUNT
14399 + "jno 0f\n"
14400 + LOCK_PREFIX "decl %0\n"
14401 + "int $4\n0:\n"
14402 + _ASM_EXTABLE(0b, 0b)
14403 +#endif
14404 +
14405 + : "+m" (v->counter));
14406 +}
14407 +
14408 +/**
14409 + * atomic_inc_unchecked - increment atomic variable
14410 + * @v: pointer of type atomic_unchecked_t
14411 + *
14412 + * Atomically increments @v by 1.
14413 + */
14414 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14415 +{
14416 + asm volatile(LOCK_PREFIX "incl %0\n"
14417 : "+m" (v->counter));
14418 }
14419
14420 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14421 */
14422 static inline void atomic_dec(atomic_t *v)
14423 {
14424 - asm volatile(LOCK_PREFIX "decl %0"
14425 + asm volatile(LOCK_PREFIX "decl %0\n"
14426 +
14427 +#ifdef CONFIG_PAX_REFCOUNT
14428 + "jno 0f\n"
14429 + LOCK_PREFIX "incl %0\n"
14430 + "int $4\n0:\n"
14431 + _ASM_EXTABLE(0b, 0b)
14432 +#endif
14433 +
14434 + : "+m" (v->counter));
14435 +}
14436 +
14437 +/**
14438 + * atomic_dec_unchecked - decrement atomic variable
14439 + * @v: pointer of type atomic_unchecked_t
14440 + *
14441 + * Atomically decrements @v by 1.
14442 + */
14443 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14444 +{
14445 + asm volatile(LOCK_PREFIX "decl %0\n"
14446 : "+m" (v->counter));
14447 }
14448
14449 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14450 */
14451 static inline int atomic_dec_and_test(atomic_t *v)
14452 {
14453 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14454 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14455 }
14456
14457 /**
14458 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14459 */
14460 static inline int atomic_inc_and_test(atomic_t *v)
14461 {
14462 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14463 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14464 +}
14465 +
14466 +/**
14467 + * atomic_inc_and_test_unchecked - increment and test
14468 + * @v: pointer of type atomic_unchecked_t
14469 + *
14470 + * Atomically increments @v by 1
14471 + * and returns true if the result is zero, or false for all
14472 + * other cases.
14473 + */
14474 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14475 +{
14476 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14477 }
14478
14479 /**
14480 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14481 */
14482 static inline int atomic_add_negative(int i, atomic_t *v)
14483 {
14484 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14485 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14486 }
14487
14488 /**
14489 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14490 */
14491 static inline int atomic_add_return(int i, atomic_t *v)
14492 {
14493 + return i + xadd_check_overflow(&v->counter, i);
14494 +}
14495 +
14496 +/**
14497 + * atomic_add_return_unchecked - add integer and return
14498 + * @i: integer value to add
14499 + * @v: pointer of type atomic_unchecked_t
14500 + *
14501 + * Atomically adds @i to @v and returns @i + @v
14502 + */
14503 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14504 +{
14505 return i + xadd(&v->counter, i);
14506 }
14507
14508 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14509 }
14510
14511 #define atomic_inc_return(v) (atomic_add_return(1, v))
14512 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14513 +{
14514 + return atomic_add_return_unchecked(1, v);
14515 +}
14516 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14517
14518 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14519 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14520 +{
14521 + return cmpxchg(&v->counter, old, new);
14522 +}
14523 +
14524 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14525 {
14526 return cmpxchg(&v->counter, old, new);
14527 }
14528 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14529 return xchg(&v->counter, new);
14530 }
14531
14532 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14533 +{
14534 + return xchg(&v->counter, new);
14535 +}
14536 +
14537 /**
14538 * __atomic_add_unless - add unless the number is already a given value
14539 * @v: pointer of type atomic_t
14540 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
14541 * Atomically adds @a to @v, so long as @v was not already @u.
14542 * Returns the old value of @v.
14543 */
14544 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14545 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
14546 {
14547 - int c, old;
14548 + int c, old, new;
14549 c = atomic_read(v);
14550 for (;;) {
14551 - if (unlikely(c == (u)))
14552 + if (unlikely(c == u))
14553 break;
14554 - old = atomic_cmpxchg((v), c, c + (a));
14555 +
14556 + asm volatile("addl %2,%0\n"
14557 +
14558 +#ifdef CONFIG_PAX_REFCOUNT
14559 + "jno 0f\n"
14560 + "subl %2,%0\n"
14561 + "int $4\n0:\n"
14562 + _ASM_EXTABLE(0b, 0b)
14563 +#endif
14564 +
14565 + : "=r" (new)
14566 + : "0" (c), "ir" (a));
14567 +
14568 + old = atomic_cmpxchg(v, c, new);
14569 if (likely(old == c))
14570 break;
14571 c = old;
14572 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14573 }
14574
14575 /**
14576 + * atomic_inc_not_zero_hint - increment if not null
14577 + * @v: pointer of type atomic_t
14578 + * @hint: probable value of the atomic before the increment
14579 + *
14580 + * This version of atomic_inc_not_zero() gives a hint of probable
14581 + * value of the atomic. This helps processor to not read the memory
14582 + * before doing the atomic read/modify/write cycle, lowering
14583 + * number of bus transactions on some arches.
14584 + *
14585 + * Returns: 0 if increment was not done, 1 otherwise.
14586 + */
14587 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14588 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14589 +{
14590 + int val, c = hint, new;
14591 +
14592 + /* sanity test, should be removed by compiler if hint is a constant */
14593 + if (!hint)
14594 + return __atomic_add_unless(v, 1, 0);
14595 +
14596 + do {
14597 + asm volatile("incl %0\n"
14598 +
14599 +#ifdef CONFIG_PAX_REFCOUNT
14600 + "jno 0f\n"
14601 + "decl %0\n"
14602 + "int $4\n0:\n"
14603 + _ASM_EXTABLE(0b, 0b)
14604 +#endif
14605 +
14606 + : "=r" (new)
14607 + : "0" (c));
14608 +
14609 + val = atomic_cmpxchg(v, c, new);
14610 + if (val == c)
14611 + return 1;
14612 + c = val;
14613 + } while (c);
14614 +
14615 + return 0;
14616 +}
14617 +
14618 +/**
14619 * atomic_inc_short - increment of a short integer
14620 * @v: pointer to type int
14621 *
14622 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14623 #endif
14624
14625 /* These are x86-specific, used by some header files */
14626 -#define atomic_clear_mask(mask, addr) \
14627 - asm volatile(LOCK_PREFIX "andl %0,%1" \
14628 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
14629 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14630 +{
14631 + asm volatile(LOCK_PREFIX "andl %1,%0"
14632 + : "+m" (v->counter)
14633 + : "r" (~(mask))
14634 + : "memory");
14635 +}
14636
14637 -#define atomic_set_mask(mask, addr) \
14638 - asm volatile(LOCK_PREFIX "orl %0,%1" \
14639 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14640 - : "memory")
14641 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14642 +{
14643 + asm volatile(LOCK_PREFIX "andl %1,%0"
14644 + : "+m" (v->counter)
14645 + : "r" (~(mask))
14646 + : "memory");
14647 +}
14648 +
14649 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14650 +{
14651 + asm volatile(LOCK_PREFIX "orl %1,%0"
14652 + : "+m" (v->counter)
14653 + : "r" (mask)
14654 + : "memory");
14655 +}
14656 +
14657 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14658 +{
14659 + asm volatile(LOCK_PREFIX "orl %1,%0"
14660 + : "+m" (v->counter)
14661 + : "r" (mask)
14662 + : "memory");
14663 +}
14664
14665 /* Atomic operations are already serializing on x86 */
14666 #define smp_mb__before_atomic_dec() barrier()
14667 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14668 index b154de7..bf18a5a 100644
14669 --- a/arch/x86/include/asm/atomic64_32.h
14670 +++ b/arch/x86/include/asm/atomic64_32.h
14671 @@ -12,6 +12,14 @@ typedef struct {
14672 u64 __aligned(8) counter;
14673 } atomic64_t;
14674
14675 +#ifdef CONFIG_PAX_REFCOUNT
14676 +typedef struct {
14677 + u64 __aligned(8) counter;
14678 +} atomic64_unchecked_t;
14679 +#else
14680 +typedef atomic64_t atomic64_unchecked_t;
14681 +#endif
14682 +
14683 #define ATOMIC64_INIT(val) { (val) }
14684
14685 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14686 @@ -37,21 +45,31 @@ typedef struct {
14687 ATOMIC64_DECL_ONE(sym##_386)
14688
14689 ATOMIC64_DECL_ONE(add_386);
14690 +ATOMIC64_DECL_ONE(add_unchecked_386);
14691 ATOMIC64_DECL_ONE(sub_386);
14692 +ATOMIC64_DECL_ONE(sub_unchecked_386);
14693 ATOMIC64_DECL_ONE(inc_386);
14694 +ATOMIC64_DECL_ONE(inc_unchecked_386);
14695 ATOMIC64_DECL_ONE(dec_386);
14696 +ATOMIC64_DECL_ONE(dec_unchecked_386);
14697 #endif
14698
14699 #define alternative_atomic64(f, out, in...) \
14700 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14701
14702 ATOMIC64_DECL(read);
14703 +ATOMIC64_DECL(read_unchecked);
14704 ATOMIC64_DECL(set);
14705 +ATOMIC64_DECL(set_unchecked);
14706 ATOMIC64_DECL(xchg);
14707 ATOMIC64_DECL(add_return);
14708 +ATOMIC64_DECL(add_return_unchecked);
14709 ATOMIC64_DECL(sub_return);
14710 +ATOMIC64_DECL(sub_return_unchecked);
14711 ATOMIC64_DECL(inc_return);
14712 +ATOMIC64_DECL(inc_return_unchecked);
14713 ATOMIC64_DECL(dec_return);
14714 +ATOMIC64_DECL(dec_return_unchecked);
14715 ATOMIC64_DECL(dec_if_positive);
14716 ATOMIC64_DECL(inc_not_zero);
14717 ATOMIC64_DECL(add_unless);
14718 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14719 }
14720
14721 /**
14722 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14723 + * @p: pointer to type atomic64_unchecked_t
14724 + * @o: expected value
14725 + * @n: new value
14726 + *
14727 + * Atomically sets @v to @n if it was equal to @o and returns
14728 + * the old value.
14729 + */
14730 +
14731 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14732 +{
14733 + return cmpxchg64(&v->counter, o, n);
14734 +}
14735 +
14736 +/**
14737 * atomic64_xchg - xchg atomic64 variable
14738 * @v: pointer to type atomic64_t
14739 * @n: value to assign
14740 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14741 }
14742
14743 /**
14744 + * atomic64_set_unchecked - set atomic64 variable
14745 + * @v: pointer to type atomic64_unchecked_t
14746 + * @n: value to assign
14747 + *
14748 + * Atomically sets the value of @v to @n.
14749 + */
14750 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14751 +{
14752 + unsigned high = (unsigned)(i >> 32);
14753 + unsigned low = (unsigned)i;
14754 + alternative_atomic64(set, /* no output */,
14755 + "S" (v), "b" (low), "c" (high)
14756 + : "eax", "edx", "memory");
14757 +}
14758 +
14759 +/**
14760 * atomic64_read - read atomic64 variable
14761 * @v: pointer to type atomic64_t
14762 *
14763 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14764 }
14765
14766 /**
14767 + * atomic64_read_unchecked - read atomic64 variable
14768 + * @v: pointer to type atomic64_unchecked_t
14769 + *
14770 + * Atomically reads the value of @v and returns it.
14771 + */
14772 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
14773 +{
14774 + long long r;
14775 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14776 + return r;
14777 + }
14778 +
14779 +/**
14780 * atomic64_add_return - add and return
14781 * @i: integer value to add
14782 * @v: pointer to type atomic64_t
14783 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14784 return i;
14785 }
14786
14787 +/**
14788 + * atomic64_add_return_unchecked - add and return
14789 + * @i: integer value to add
14790 + * @v: pointer to type atomic64_unchecked_t
14791 + *
14792 + * Atomically adds @i to @v and returns @i + *@v
14793 + */
14794 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14795 +{
14796 + alternative_atomic64(add_return_unchecked,
14797 + ASM_OUTPUT2("+A" (i), "+c" (v)),
14798 + ASM_NO_INPUT_CLOBBER("memory"));
14799 + return i;
14800 +}
14801 +
14802 /*
14803 * Other variants with different arithmetic operators:
14804 */
14805 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14806 return a;
14807 }
14808
14809 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14810 +{
14811 + long long a;
14812 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
14813 + "S" (v) : "memory", "ecx");
14814 + return a;
14815 +}
14816 +
14817 static inline long long atomic64_dec_return(atomic64_t *v)
14818 {
14819 long long a;
14820 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14821 }
14822
14823 /**
14824 + * atomic64_add_unchecked - add integer to atomic64 variable
14825 + * @i: integer value to add
14826 + * @v: pointer to type atomic64_unchecked_t
14827 + *
14828 + * Atomically adds @i to @v.
14829 + */
14830 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14831 +{
14832 + __alternative_atomic64(add_unchecked, add_return_unchecked,
14833 + ASM_OUTPUT2("+A" (i), "+c" (v)),
14834 + ASM_NO_INPUT_CLOBBER("memory"));
14835 + return i;
14836 +}
14837 +
14838 +/**
14839 * atomic64_sub - subtract the atomic64 variable
14840 * @i: integer value to subtract
14841 * @v: pointer to type atomic64_t
14842 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14843 index 46e9052..ae45136 100644
14844 --- a/arch/x86/include/asm/atomic64_64.h
14845 +++ b/arch/x86/include/asm/atomic64_64.h
14846 @@ -18,7 +18,19 @@
14847 */
14848 static inline long atomic64_read(const atomic64_t *v)
14849 {
14850 - return (*(volatile long *)&(v)->counter);
14851 + return (*(volatile const long *)&(v)->counter);
14852 +}
14853 +
14854 +/**
14855 + * atomic64_read_unchecked - read atomic64 variable
14856 + * @v: pointer of type atomic64_unchecked_t
14857 + *
14858 + * Atomically reads the value of @v.
14859 + * Doesn't imply a read memory barrier.
14860 + */
14861 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
14862 +{
14863 + return (*(volatile const long *)&(v)->counter);
14864 }
14865
14866 /**
14867 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14868 }
14869
14870 /**
14871 + * atomic64_set_unchecked - set atomic64 variable
14872 + * @v: pointer to type atomic64_unchecked_t
14873 + * @i: required value
14874 + *
14875 + * Atomically sets the value of @v to @i.
14876 + */
14877 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14878 +{
14879 + v->counter = i;
14880 +}
14881 +
14882 +/**
14883 * atomic64_add - add integer to atomic64 variable
14884 * @i: integer value to add
14885 * @v: pointer to type atomic64_t
14886 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14887 */
14888 static inline void atomic64_add(long i, atomic64_t *v)
14889 {
14890 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
14891 +
14892 +#ifdef CONFIG_PAX_REFCOUNT
14893 + "jno 0f\n"
14894 + LOCK_PREFIX "subq %1,%0\n"
14895 + "int $4\n0:\n"
14896 + _ASM_EXTABLE(0b, 0b)
14897 +#endif
14898 +
14899 + : "=m" (v->counter)
14900 + : "er" (i), "m" (v->counter));
14901 +}
14902 +
14903 +/**
14904 + * atomic64_add_unchecked - add integer to atomic64 variable
14905 + * @i: integer value to add
14906 + * @v: pointer to type atomic64_unchecked_t
14907 + *
14908 + * Atomically adds @i to @v.
14909 + */
14910 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14911 +{
14912 asm volatile(LOCK_PREFIX "addq %1,%0"
14913 : "=m" (v->counter)
14914 : "er" (i), "m" (v->counter));
14915 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14916 */
14917 static inline void atomic64_sub(long i, atomic64_t *v)
14918 {
14919 - asm volatile(LOCK_PREFIX "subq %1,%0"
14920 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
14921 +
14922 +#ifdef CONFIG_PAX_REFCOUNT
14923 + "jno 0f\n"
14924 + LOCK_PREFIX "addq %1,%0\n"
14925 + "int $4\n0:\n"
14926 + _ASM_EXTABLE(0b, 0b)
14927 +#endif
14928 +
14929 + : "=m" (v->counter)
14930 + : "er" (i), "m" (v->counter));
14931 +}
14932 +
14933 +/**
14934 + * atomic64_sub_unchecked - subtract the atomic64 variable
14935 + * @i: integer value to subtract
14936 + * @v: pointer to type atomic64_unchecked_t
14937 + *
14938 + * Atomically subtracts @i from @v.
14939 + */
14940 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14941 +{
14942 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
14943 : "=m" (v->counter)
14944 : "er" (i), "m" (v->counter));
14945 }
14946 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
14947 */
14948 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14949 {
14950 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
14951 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
14952 }
14953
14954 /**
14955 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14956 */
14957 static inline void atomic64_inc(atomic64_t *v)
14958 {
14959 + asm volatile(LOCK_PREFIX "incq %0\n"
14960 +
14961 +#ifdef CONFIG_PAX_REFCOUNT
14962 + "jno 0f\n"
14963 + LOCK_PREFIX "decq %0\n"
14964 + "int $4\n0:\n"
14965 + _ASM_EXTABLE(0b, 0b)
14966 +#endif
14967 +
14968 + : "=m" (v->counter)
14969 + : "m" (v->counter));
14970 +}
14971 +
14972 +/**
14973 + * atomic64_inc_unchecked - increment atomic64 variable
14974 + * @v: pointer to type atomic64_unchecked_t
14975 + *
14976 + * Atomically increments @v by 1.
14977 + */
14978 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14979 +{
14980 asm volatile(LOCK_PREFIX "incq %0"
14981 : "=m" (v->counter)
14982 : "m" (v->counter));
14983 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
14984 */
14985 static inline void atomic64_dec(atomic64_t *v)
14986 {
14987 - asm volatile(LOCK_PREFIX "decq %0"
14988 + asm volatile(LOCK_PREFIX "decq %0\n"
14989 +
14990 +#ifdef CONFIG_PAX_REFCOUNT
14991 + "jno 0f\n"
14992 + LOCK_PREFIX "incq %0\n"
14993 + "int $4\n0:\n"
14994 + _ASM_EXTABLE(0b, 0b)
14995 +#endif
14996 +
14997 + : "=m" (v->counter)
14998 + : "m" (v->counter));
14999 +}
15000 +
15001 +/**
15002 + * atomic64_dec_unchecked - decrement atomic64 variable
15003 + * @v: pointer to type atomic64_t
15004 + *
15005 + * Atomically decrements @v by 1.
15006 + */
15007 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15008 +{
15009 + asm volatile(LOCK_PREFIX "decq %0\n"
15010 : "=m" (v->counter)
15011 : "m" (v->counter));
15012 }
15013 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15014 */
15015 static inline int atomic64_dec_and_test(atomic64_t *v)
15016 {
15017 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15018 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15019 }
15020
15021 /**
15022 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15023 */
15024 static inline int atomic64_inc_and_test(atomic64_t *v)
15025 {
15026 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15027 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15028 }
15029
15030 /**
15031 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15032 */
15033 static inline int atomic64_add_negative(long i, atomic64_t *v)
15034 {
15035 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15036 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15037 }
15038
15039 /**
15040 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15041 */
15042 static inline long atomic64_add_return(long i, atomic64_t *v)
15043 {
15044 + return i + xadd_check_overflow(&v->counter, i);
15045 +}
15046 +
15047 +/**
15048 + * atomic64_add_return_unchecked - add and return
15049 + * @i: integer value to add
15050 + * @v: pointer to type atomic64_unchecked_t
15051 + *
15052 + * Atomically adds @i to @v and returns @i + @v
15053 + */
15054 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15055 +{
15056 return i + xadd(&v->counter, i);
15057 }
15058
15059 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15060 }
15061
15062 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15063 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15064 +{
15065 + return atomic64_add_return_unchecked(1, v);
15066 +}
15067 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15068
15069 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15070 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15071 return cmpxchg(&v->counter, old, new);
15072 }
15073
15074 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15075 +{
15076 + return cmpxchg(&v->counter, old, new);
15077 +}
15078 +
15079 static inline long atomic64_xchg(atomic64_t *v, long new)
15080 {
15081 return xchg(&v->counter, new);
15082 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15083 */
15084 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15085 {
15086 - long c, old;
15087 + long c, old, new;
15088 c = atomic64_read(v);
15089 for (;;) {
15090 - if (unlikely(c == (u)))
15091 + if (unlikely(c == u))
15092 break;
15093 - old = atomic64_cmpxchg((v), c, c + (a));
15094 +
15095 + asm volatile("add %2,%0\n"
15096 +
15097 +#ifdef CONFIG_PAX_REFCOUNT
15098 + "jno 0f\n"
15099 + "sub %2,%0\n"
15100 + "int $4\n0:\n"
15101 + _ASM_EXTABLE(0b, 0b)
15102 +#endif
15103 +
15104 + : "=r" (new)
15105 + : "0" (c), "ir" (a));
15106 +
15107 + old = atomic64_cmpxchg(v, c, new);
15108 if (likely(old == c))
15109 break;
15110 c = old;
15111 }
15112 - return c != (u);
15113 + return c != u;
15114 }
15115
15116 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15117 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15118 index 9fc1af7..fc71228 100644
15119 --- a/arch/x86/include/asm/bitops.h
15120 +++ b/arch/x86/include/asm/bitops.h
15121 @@ -49,7 +49,7 @@
15122 * a mask operation on a byte.
15123 */
15124 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15125 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15126 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15127 #define CONST_MASK(nr) (1 << ((nr) & 7))
15128
15129 /**
15130 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15131 */
15132 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15133 {
15134 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15135 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15136 }
15137
15138 /**
15139 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15140 */
15141 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15142 {
15143 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15144 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15145 }
15146
15147 /**
15148 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15149 */
15150 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15151 {
15152 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15153 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15154 }
15155
15156 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15157 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15158 *
15159 * Undefined if no bit exists, so code should check against 0 first.
15160 */
15161 -static inline unsigned long __ffs(unsigned long word)
15162 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15163 {
15164 asm("rep; bsf %1,%0"
15165 : "=r" (word)
15166 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15167 *
15168 * Undefined if no zero exists, so code should check against ~0UL first.
15169 */
15170 -static inline unsigned long ffz(unsigned long word)
15171 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15172 {
15173 asm("rep; bsf %1,%0"
15174 : "=r" (word)
15175 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15176 *
15177 * Undefined if no set bit exists, so code should check against 0 first.
15178 */
15179 -static inline unsigned long __fls(unsigned long word)
15180 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15181 {
15182 asm("bsr %1,%0"
15183 : "=r" (word)
15184 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15185 * set bit if value is nonzero. The last (most significant) bit is
15186 * at position 32.
15187 */
15188 -static inline int fls(int x)
15189 +static inline int __intentional_overflow(-1) fls(int x)
15190 {
15191 int r;
15192
15193 @@ -478,7 +478,7 @@ static inline int fls(int x)
15194 * at position 64.
15195 */
15196 #ifdef CONFIG_X86_64
15197 -static __always_inline int fls64(__u64 x)
15198 +static __always_inline long fls64(__u64 x)
15199 {
15200 int bitpos = -1;
15201 /*
15202 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15203 index 4fa687a..60f2d39 100644
15204 --- a/arch/x86/include/asm/boot.h
15205 +++ b/arch/x86/include/asm/boot.h
15206 @@ -6,10 +6,15 @@
15207 #include <uapi/asm/boot.h>
15208
15209 /* Physical address where kernel should be loaded. */
15210 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15211 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15212 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15213 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15214
15215 +#ifndef __ASSEMBLY__
15216 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15217 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15218 +#endif
15219 +
15220 /* Minimum kernel alignment, as a power of two */
15221 #ifdef CONFIG_X86_64
15222 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15223 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15224 index 48f99f1..d78ebf9 100644
15225 --- a/arch/x86/include/asm/cache.h
15226 +++ b/arch/x86/include/asm/cache.h
15227 @@ -5,12 +5,13 @@
15228
15229 /* L1 cache line size */
15230 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15231 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15232 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15233
15234 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15235 +#define __read_only __attribute__((__section__(".data..read_only")))
15236
15237 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15238 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15239 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15240
15241 #ifdef CONFIG_X86_VSMP
15242 #ifdef CONFIG_SMP
15243 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15244 index 9863ee3..4a1f8e1 100644
15245 --- a/arch/x86/include/asm/cacheflush.h
15246 +++ b/arch/x86/include/asm/cacheflush.h
15247 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15248 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15249
15250 if (pg_flags == _PGMT_DEFAULT)
15251 - return -1;
15252 + return ~0UL;
15253 else if (pg_flags == _PGMT_WC)
15254 return _PAGE_CACHE_WC;
15255 else if (pg_flags == _PGMT_UC_MINUS)
15256 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15257 index cb4c73b..c473c29 100644
15258 --- a/arch/x86/include/asm/calling.h
15259 +++ b/arch/x86/include/asm/calling.h
15260 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15261 #define RSP 152
15262 #define SS 160
15263
15264 -#define ARGOFFSET R11
15265 -#define SWFRAME ORIG_RAX
15266 +#define ARGOFFSET R15
15267
15268 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15269 - subq $9*8+\addskip, %rsp
15270 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15271 - movq_cfi rdi, 8*8
15272 - movq_cfi rsi, 7*8
15273 - movq_cfi rdx, 6*8
15274 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15275 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15276 + movq_cfi rdi, RDI
15277 + movq_cfi rsi, RSI
15278 + movq_cfi rdx, RDX
15279
15280 .if \save_rcx
15281 - movq_cfi rcx, 5*8
15282 + movq_cfi rcx, RCX
15283 .endif
15284
15285 - movq_cfi rax, 4*8
15286 + movq_cfi rax, RAX
15287
15288 .if \save_r891011
15289 - movq_cfi r8, 3*8
15290 - movq_cfi r9, 2*8
15291 - movq_cfi r10, 1*8
15292 - movq_cfi r11, 0*8
15293 + movq_cfi r8, R8
15294 + movq_cfi r9, R9
15295 + movq_cfi r10, R10
15296 + movq_cfi r11, R11
15297 .endif
15298
15299 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15300 + movq_cfi r12, R12
15301 +#endif
15302 +
15303 .endm
15304
15305 -#define ARG_SKIP (9*8)
15306 +#define ARG_SKIP ORIG_RAX
15307
15308 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15309 rstor_r8910=1, rstor_rdx=1
15310 +
15311 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15312 + movq_cfi_restore R12, r12
15313 +#endif
15314 +
15315 .if \rstor_r11
15316 - movq_cfi_restore 0*8, r11
15317 + movq_cfi_restore R11, r11
15318 .endif
15319
15320 .if \rstor_r8910
15321 - movq_cfi_restore 1*8, r10
15322 - movq_cfi_restore 2*8, r9
15323 - movq_cfi_restore 3*8, r8
15324 + movq_cfi_restore R10, r10
15325 + movq_cfi_restore R9, r9
15326 + movq_cfi_restore R8, r8
15327 .endif
15328
15329 .if \rstor_rax
15330 - movq_cfi_restore 4*8, rax
15331 + movq_cfi_restore RAX, rax
15332 .endif
15333
15334 .if \rstor_rcx
15335 - movq_cfi_restore 5*8, rcx
15336 + movq_cfi_restore RCX, rcx
15337 .endif
15338
15339 .if \rstor_rdx
15340 - movq_cfi_restore 6*8, rdx
15341 + movq_cfi_restore RDX, rdx
15342 .endif
15343
15344 - movq_cfi_restore 7*8, rsi
15345 - movq_cfi_restore 8*8, rdi
15346 + movq_cfi_restore RSI, rsi
15347 + movq_cfi_restore RDI, rdi
15348
15349 - .if ARG_SKIP+\addskip > 0
15350 - addq $ARG_SKIP+\addskip, %rsp
15351 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15352 + .if ORIG_RAX+\addskip > 0
15353 + addq $ORIG_RAX+\addskip, %rsp
15354 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15355 .endif
15356 .endm
15357
15358 - .macro LOAD_ARGS offset, skiprax=0
15359 - movq \offset(%rsp), %r11
15360 - movq \offset+8(%rsp), %r10
15361 - movq \offset+16(%rsp), %r9
15362 - movq \offset+24(%rsp), %r8
15363 - movq \offset+40(%rsp), %rcx
15364 - movq \offset+48(%rsp), %rdx
15365 - movq \offset+56(%rsp), %rsi
15366 - movq \offset+64(%rsp), %rdi
15367 + .macro LOAD_ARGS skiprax=0
15368 + movq R11(%rsp), %r11
15369 + movq R10(%rsp), %r10
15370 + movq R9(%rsp), %r9
15371 + movq R8(%rsp), %r8
15372 + movq RCX(%rsp), %rcx
15373 + movq RDX(%rsp), %rdx
15374 + movq RSI(%rsp), %rsi
15375 + movq RDI(%rsp), %rdi
15376 .if \skiprax
15377 .else
15378 - movq \offset+72(%rsp), %rax
15379 + movq RAX(%rsp), %rax
15380 .endif
15381 .endm
15382
15383 -#define REST_SKIP (6*8)
15384 -
15385 .macro SAVE_REST
15386 - subq $REST_SKIP, %rsp
15387 - CFI_ADJUST_CFA_OFFSET REST_SKIP
15388 - movq_cfi rbx, 5*8
15389 - movq_cfi rbp, 4*8
15390 - movq_cfi r12, 3*8
15391 - movq_cfi r13, 2*8
15392 - movq_cfi r14, 1*8
15393 - movq_cfi r15, 0*8
15394 + movq_cfi rbx, RBX
15395 + movq_cfi rbp, RBP
15396 +
15397 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15398 + movq_cfi r12, R12
15399 +#endif
15400 +
15401 + movq_cfi r13, R13
15402 + movq_cfi r14, R14
15403 + movq_cfi r15, R15
15404 .endm
15405
15406 .macro RESTORE_REST
15407 - movq_cfi_restore 0*8, r15
15408 - movq_cfi_restore 1*8, r14
15409 - movq_cfi_restore 2*8, r13
15410 - movq_cfi_restore 3*8, r12
15411 - movq_cfi_restore 4*8, rbp
15412 - movq_cfi_restore 5*8, rbx
15413 - addq $REST_SKIP, %rsp
15414 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15415 + movq_cfi_restore R15, r15
15416 + movq_cfi_restore R14, r14
15417 + movq_cfi_restore R13, r13
15418 +
15419 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15420 + movq_cfi_restore R12, r12
15421 +#endif
15422 +
15423 + movq_cfi_restore RBP, rbp
15424 + movq_cfi_restore RBX, rbx
15425 .endm
15426
15427 .macro SAVE_ALL
15428 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15429 index f50de69..2b0a458 100644
15430 --- a/arch/x86/include/asm/checksum_32.h
15431 +++ b/arch/x86/include/asm/checksum_32.h
15432 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15433 int len, __wsum sum,
15434 int *src_err_ptr, int *dst_err_ptr);
15435
15436 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15437 + int len, __wsum sum,
15438 + int *src_err_ptr, int *dst_err_ptr);
15439 +
15440 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15441 + int len, __wsum sum,
15442 + int *src_err_ptr, int *dst_err_ptr);
15443 +
15444 /*
15445 * Note: when you get a NULL pointer exception here this means someone
15446 * passed in an incorrect kernel address to one of these functions.
15447 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15448
15449 might_sleep();
15450 stac();
15451 - ret = csum_partial_copy_generic((__force void *)src, dst,
15452 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15453 len, sum, err_ptr, NULL);
15454 clac();
15455
15456 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15457 might_sleep();
15458 if (access_ok(VERIFY_WRITE, dst, len)) {
15459 stac();
15460 - ret = csum_partial_copy_generic(src, (__force void *)dst,
15461 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15462 len, sum, NULL, err_ptr);
15463 clac();
15464 return ret;
15465 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15466 index d47786a..ce1b05d 100644
15467 --- a/arch/x86/include/asm/cmpxchg.h
15468 +++ b/arch/x86/include/asm/cmpxchg.h
15469 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15470 __compiletime_error("Bad argument size for cmpxchg");
15471 extern void __xadd_wrong_size(void)
15472 __compiletime_error("Bad argument size for xadd");
15473 +extern void __xadd_check_overflow_wrong_size(void)
15474 + __compiletime_error("Bad argument size for xadd_check_overflow");
15475 extern void __add_wrong_size(void)
15476 __compiletime_error("Bad argument size for add");
15477 +extern void __add_check_overflow_wrong_size(void)
15478 + __compiletime_error("Bad argument size for add_check_overflow");
15479
15480 /*
15481 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15482 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15483 __ret; \
15484 })
15485
15486 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15487 + ({ \
15488 + __typeof__ (*(ptr)) __ret = (arg); \
15489 + switch (sizeof(*(ptr))) { \
15490 + case __X86_CASE_L: \
15491 + asm volatile (lock #op "l %0, %1\n" \
15492 + "jno 0f\n" \
15493 + "mov %0,%1\n" \
15494 + "int $4\n0:\n" \
15495 + _ASM_EXTABLE(0b, 0b) \
15496 + : "+r" (__ret), "+m" (*(ptr)) \
15497 + : : "memory", "cc"); \
15498 + break; \
15499 + case __X86_CASE_Q: \
15500 + asm volatile (lock #op "q %q0, %1\n" \
15501 + "jno 0f\n" \
15502 + "mov %0,%1\n" \
15503 + "int $4\n0:\n" \
15504 + _ASM_EXTABLE(0b, 0b) \
15505 + : "+r" (__ret), "+m" (*(ptr)) \
15506 + : : "memory", "cc"); \
15507 + break; \
15508 + default: \
15509 + __ ## op ## _check_overflow_wrong_size(); \
15510 + } \
15511 + __ret; \
15512 + })
15513 +
15514 /*
15515 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15516 * Since this is generally used to protect other memory information, we
15517 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15518 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15519 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15520
15521 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15522 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15523 +
15524 #define __add(ptr, inc, lock) \
15525 ({ \
15526 __typeof__ (*(ptr)) __ret = (inc); \
15527 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15528 index 59c6c40..5e0b22c 100644
15529 --- a/arch/x86/include/asm/compat.h
15530 +++ b/arch/x86/include/asm/compat.h
15531 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15532 typedef u32 compat_uint_t;
15533 typedef u32 compat_ulong_t;
15534 typedef u64 __attribute__((aligned(4))) compat_u64;
15535 -typedef u32 compat_uptr_t;
15536 +typedef u32 __user compat_uptr_t;
15537
15538 struct compat_timespec {
15539 compat_time_t tv_sec;
15540 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
15541 index 89270b4..f0abf8e 100644
15542 --- a/arch/x86/include/asm/cpufeature.h
15543 +++ b/arch/x86/include/asm/cpufeature.h
15544 @@ -203,7 +203,7 @@
15545 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
15546 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
15547 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
15548 -
15549 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
15550
15551 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
15552 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
15553 @@ -211,7 +211,7 @@
15554 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
15555 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
15556 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
15557 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
15558 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
15559 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
15560 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
15561 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
15562 @@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
15563 #undef cpu_has_centaur_mcr
15564 #define cpu_has_centaur_mcr 0
15565
15566 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
15567 #endif /* CONFIG_X86_64 */
15568
15569 #if __GNUC__ >= 4
15570 @@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15571
15572 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
15573 t_warn:
15574 - warn_pre_alternatives();
15575 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
15576 + warn_pre_alternatives();
15577 return false;
15578 #endif
15579
15580 @@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15581 ".section .discard,\"aw\",@progbits\n"
15582 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15583 ".previous\n"
15584 - ".section .altinstr_replacement,\"ax\"\n"
15585 + ".section .altinstr_replacement,\"a\"\n"
15586 "3: movb $1,%0\n"
15587 "4:\n"
15588 ".previous\n"
15589 @@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15590 " .byte 2b - 1b\n" /* src len */
15591 " .byte 4f - 3f\n" /* repl len */
15592 ".previous\n"
15593 - ".section .altinstr_replacement,\"ax\"\n"
15594 + ".section .altinstr_replacement,\"a\"\n"
15595 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
15596 "4:\n"
15597 ".previous\n"
15598 @@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15599 ".section .discard,\"aw\",@progbits\n"
15600 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15601 ".previous\n"
15602 - ".section .altinstr_replacement,\"ax\"\n"
15603 + ".section .altinstr_replacement,\"a\"\n"
15604 "3: movb $0,%0\n"
15605 "4:\n"
15606 ".previous\n"
15607 @@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15608 ".section .discard,\"aw\",@progbits\n"
15609 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
15610 ".previous\n"
15611 - ".section .altinstr_replacement,\"ax\"\n"
15612 + ".section .altinstr_replacement,\"a\"\n"
15613 "5: movb $1,%0\n"
15614 "6:\n"
15615 ".previous\n"
15616 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
15617 index 50d033a..37deb26 100644
15618 --- a/arch/x86/include/asm/desc.h
15619 +++ b/arch/x86/include/asm/desc.h
15620 @@ -4,6 +4,7 @@
15621 #include <asm/desc_defs.h>
15622 #include <asm/ldt.h>
15623 #include <asm/mmu.h>
15624 +#include <asm/pgtable.h>
15625
15626 #include <linux/smp.h>
15627 #include <linux/percpu.h>
15628 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15629
15630 desc->type = (info->read_exec_only ^ 1) << 1;
15631 desc->type |= info->contents << 2;
15632 + desc->type |= info->seg_not_present ^ 1;
15633
15634 desc->s = 1;
15635 desc->dpl = 0x3;
15636 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15637 }
15638
15639 extern struct desc_ptr idt_descr;
15640 -extern gate_desc idt_table[];
15641 -extern struct desc_ptr debug_idt_descr;
15642 -extern gate_desc debug_idt_table[];
15643 -
15644 -struct gdt_page {
15645 - struct desc_struct gdt[GDT_ENTRIES];
15646 -} __attribute__((aligned(PAGE_SIZE)));
15647 -
15648 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15649 +extern gate_desc idt_table[IDT_ENTRIES];
15650 +extern const struct desc_ptr debug_idt_descr;
15651 +extern gate_desc debug_idt_table[IDT_ENTRIES];
15652
15653 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15654 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15655 {
15656 - return per_cpu(gdt_page, cpu).gdt;
15657 + return cpu_gdt_table[cpu];
15658 }
15659
15660 #ifdef CONFIG_X86_64
15661 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15662 unsigned long base, unsigned dpl, unsigned flags,
15663 unsigned short seg)
15664 {
15665 - gate->a = (seg << 16) | (base & 0xffff);
15666 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15667 + gate->gate.offset_low = base;
15668 + gate->gate.seg = seg;
15669 + gate->gate.reserved = 0;
15670 + gate->gate.type = type;
15671 + gate->gate.s = 0;
15672 + gate->gate.dpl = dpl;
15673 + gate->gate.p = 1;
15674 + gate->gate.offset_high = base >> 16;
15675 }
15676
15677 #endif
15678 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15679
15680 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15681 {
15682 + pax_open_kernel();
15683 memcpy(&idt[entry], gate, sizeof(*gate));
15684 + pax_close_kernel();
15685 }
15686
15687 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15688 {
15689 + pax_open_kernel();
15690 memcpy(&ldt[entry], desc, 8);
15691 + pax_close_kernel();
15692 }
15693
15694 static inline void
15695 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15696 default: size = sizeof(*gdt); break;
15697 }
15698
15699 + pax_open_kernel();
15700 memcpy(&gdt[entry], desc, size);
15701 + pax_close_kernel();
15702 }
15703
15704 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15705 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15706
15707 static inline void native_load_tr_desc(void)
15708 {
15709 + pax_open_kernel();
15710 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15711 + pax_close_kernel();
15712 }
15713
15714 static inline void native_load_gdt(const struct desc_ptr *dtr)
15715 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15716 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15717 unsigned int i;
15718
15719 + pax_open_kernel();
15720 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15721 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15722 + pax_close_kernel();
15723 }
15724
15725 #define _LDT_empty(info) \
15726 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15727 preempt_enable();
15728 }
15729
15730 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
15731 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15732 {
15733 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15734 }
15735 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15736 }
15737
15738 #ifdef CONFIG_X86_64
15739 -static inline void set_nmi_gate(int gate, void *addr)
15740 +static inline void set_nmi_gate(int gate, const void *addr)
15741 {
15742 gate_desc s;
15743
15744 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
15745 #endif
15746
15747 #ifdef CONFIG_TRACING
15748 -extern struct desc_ptr trace_idt_descr;
15749 -extern gate_desc trace_idt_table[];
15750 +extern const struct desc_ptr trace_idt_descr;
15751 +extern gate_desc trace_idt_table[IDT_ENTRIES];
15752 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15753 {
15754 write_idt_entry(trace_idt_table, entry, gate);
15755 }
15756
15757 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
15758 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
15759 unsigned dpl, unsigned ist, unsigned seg)
15760 {
15761 gate_desc s;
15762 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15763 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
15764 #endif
15765
15766 -static inline void _set_gate(int gate, unsigned type, void *addr,
15767 +static inline void _set_gate(int gate, unsigned type, const void *addr,
15768 unsigned dpl, unsigned ist, unsigned seg)
15769 {
15770 gate_desc s;
15771 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15772 #define set_intr_gate(n, addr) \
15773 do { \
15774 BUG_ON((unsigned)n > 0xFF); \
15775 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
15776 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
15777 __KERNEL_CS); \
15778 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
15779 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
15780 0, 0, __KERNEL_CS); \
15781 } while (0)
15782
15783 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
15784 /*
15785 * This routine sets up an interrupt gate at directory privilege level 3.
15786 */
15787 -static inline void set_system_intr_gate(unsigned int n, void *addr)
15788 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
15789 {
15790 BUG_ON((unsigned)n > 0xFF);
15791 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15792 }
15793
15794 -static inline void set_system_trap_gate(unsigned int n, void *addr)
15795 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
15796 {
15797 BUG_ON((unsigned)n > 0xFF);
15798 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15799 }
15800
15801 -static inline void set_trap_gate(unsigned int n, void *addr)
15802 +static inline void set_trap_gate(unsigned int n, const void *addr)
15803 {
15804 BUG_ON((unsigned)n > 0xFF);
15805 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15806 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15807 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15808 {
15809 BUG_ON((unsigned)n > 0xFF);
15810 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15811 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15812 }
15813
15814 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15815 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15816 {
15817 BUG_ON((unsigned)n > 0xFF);
15818 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15819 }
15820
15821 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15822 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15823 {
15824 BUG_ON((unsigned)n > 0xFF);
15825 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15826 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
15827 else
15828 load_idt((const struct desc_ptr *)&idt_descr);
15829 }
15830 +
15831 +#ifdef CONFIG_X86_32
15832 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15833 +{
15834 + struct desc_struct d;
15835 +
15836 + if (likely(limit))
15837 + limit = (limit - 1UL) >> PAGE_SHIFT;
15838 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
15839 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15840 +}
15841 +#endif
15842 +
15843 #endif /* _ASM_X86_DESC_H */
15844 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15845 index 278441f..b95a174 100644
15846 --- a/arch/x86/include/asm/desc_defs.h
15847 +++ b/arch/x86/include/asm/desc_defs.h
15848 @@ -31,6 +31,12 @@ struct desc_struct {
15849 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15850 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15851 };
15852 + struct {
15853 + u16 offset_low;
15854 + u16 seg;
15855 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15856 + unsigned offset_high: 16;
15857 + } gate;
15858 };
15859 } __attribute__((packed));
15860
15861 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15862 index ced283a..ffe04cc 100644
15863 --- a/arch/x86/include/asm/div64.h
15864 +++ b/arch/x86/include/asm/div64.h
15865 @@ -39,7 +39,7 @@
15866 __mod; \
15867 })
15868
15869 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15870 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15871 {
15872 union {
15873 u64 v64;
15874 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15875 index 9c999c1..3860cb8 100644
15876 --- a/arch/x86/include/asm/elf.h
15877 +++ b/arch/x86/include/asm/elf.h
15878 @@ -243,7 +243,25 @@ extern int force_personality32;
15879 the loader. We need to make sure that it is out of the way of the program
15880 that it will "exec", and that there is sufficient room for the brk. */
15881
15882 +#ifdef CONFIG_PAX_SEGMEXEC
15883 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15884 +#else
15885 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15886 +#endif
15887 +
15888 +#ifdef CONFIG_PAX_ASLR
15889 +#ifdef CONFIG_X86_32
15890 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15891 +
15892 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15893 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15894 +#else
15895 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
15896 +
15897 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15898 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15899 +#endif
15900 +#endif
15901
15902 /* This yields a mask that user programs can use to figure out what
15903 instruction set this CPU supports. This could be done in user space,
15904 @@ -296,16 +314,12 @@ do { \
15905
15906 #define ARCH_DLINFO \
15907 do { \
15908 - if (vdso_enabled) \
15909 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15910 - (unsigned long)current->mm->context.vdso); \
15911 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15912 } while (0)
15913
15914 #define ARCH_DLINFO_X32 \
15915 do { \
15916 - if (vdso_enabled) \
15917 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15918 - (unsigned long)current->mm->context.vdso); \
15919 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15920 } while (0)
15921
15922 #define AT_SYSINFO 32
15923 @@ -320,7 +334,7 @@ else \
15924
15925 #endif /* !CONFIG_X86_32 */
15926
15927 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15928 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15929
15930 #define VDSO_ENTRY \
15931 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15932 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15933 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15934 #define compat_arch_setup_additional_pages syscall32_setup_pages
15935
15936 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15937 -#define arch_randomize_brk arch_randomize_brk
15938 -
15939 /*
15940 * True on X86_32 or when emulating IA32 on X86_64
15941 */
15942 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15943 index 77a99ac..39ff7f5 100644
15944 --- a/arch/x86/include/asm/emergency-restart.h
15945 +++ b/arch/x86/include/asm/emergency-restart.h
15946 @@ -1,6 +1,6 @@
15947 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15948 #define _ASM_X86_EMERGENCY_RESTART_H
15949
15950 -extern void machine_emergency_restart(void);
15951 +extern void machine_emergency_restart(void) __noreturn;
15952
15953 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15954 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
15955 index d3d7469..677ef72 100644
15956 --- a/arch/x86/include/asm/floppy.h
15957 +++ b/arch/x86/include/asm/floppy.h
15958 @@ -229,18 +229,18 @@ static struct fd_routine_l {
15959 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
15960 } fd_routine[] = {
15961 {
15962 - request_dma,
15963 - free_dma,
15964 - get_dma_residue,
15965 - dma_mem_alloc,
15966 - hard_dma_setup
15967 + ._request_dma = request_dma,
15968 + ._free_dma = free_dma,
15969 + ._get_dma_residue = get_dma_residue,
15970 + ._dma_mem_alloc = dma_mem_alloc,
15971 + ._dma_setup = hard_dma_setup
15972 },
15973 {
15974 - vdma_request_dma,
15975 - vdma_nop,
15976 - vdma_get_dma_residue,
15977 - vdma_mem_alloc,
15978 - vdma_dma_setup
15979 + ._request_dma = vdma_request_dma,
15980 + ._free_dma = vdma_nop,
15981 + ._get_dma_residue = vdma_get_dma_residue,
15982 + ._dma_mem_alloc = vdma_mem_alloc,
15983 + ._dma_setup = vdma_dma_setup
15984 }
15985 };
15986
15987 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15988 index cea1c76..6c0d79b 100644
15989 --- a/arch/x86/include/asm/fpu-internal.h
15990 +++ b/arch/x86/include/asm/fpu-internal.h
15991 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15992 #define user_insn(insn, output, input...) \
15993 ({ \
15994 int err; \
15995 + pax_open_userland(); \
15996 asm volatile(ASM_STAC "\n" \
15997 - "1:" #insn "\n\t" \
15998 + "1:" \
15999 + __copyuser_seg \
16000 + #insn "\n\t" \
16001 "2: " ASM_CLAC "\n" \
16002 ".section .fixup,\"ax\"\n" \
16003 "3: movl $-1,%[err]\n" \
16004 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16005 _ASM_EXTABLE(1b, 3b) \
16006 : [err] "=r" (err), output \
16007 : "0"(0), input); \
16008 + pax_close_userland(); \
16009 err; \
16010 })
16011
16012 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16013 "fnclex\n\t"
16014 "emms\n\t"
16015 "fildl %P[addr]" /* set F?P to defined value */
16016 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16017 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16018 }
16019
16020 return fpu_restore_checking(&tsk->thread.fpu);
16021 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16022 index be27ba1..04a8801 100644
16023 --- a/arch/x86/include/asm/futex.h
16024 +++ b/arch/x86/include/asm/futex.h
16025 @@ -12,6 +12,7 @@
16026 #include <asm/smap.h>
16027
16028 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16029 + typecheck(u32 __user *, uaddr); \
16030 asm volatile("\t" ASM_STAC "\n" \
16031 "1:\t" insn "\n" \
16032 "2:\t" ASM_CLAC "\n" \
16033 @@ -20,15 +21,16 @@
16034 "\tjmp\t2b\n" \
16035 "\t.previous\n" \
16036 _ASM_EXTABLE(1b, 3b) \
16037 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16038 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16039 : "i" (-EFAULT), "0" (oparg), "1" (0))
16040
16041 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16042 + typecheck(u32 __user *, uaddr); \
16043 asm volatile("\t" ASM_STAC "\n" \
16044 "1:\tmovl %2, %0\n" \
16045 "\tmovl\t%0, %3\n" \
16046 "\t" insn "\n" \
16047 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16048 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16049 "\tjnz\t1b\n" \
16050 "3:\t" ASM_CLAC "\n" \
16051 "\t.section .fixup,\"ax\"\n" \
16052 @@ -38,7 +40,7 @@
16053 _ASM_EXTABLE(1b, 4b) \
16054 _ASM_EXTABLE(2b, 4b) \
16055 : "=&a" (oldval), "=&r" (ret), \
16056 - "+m" (*uaddr), "=&r" (tem) \
16057 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16058 : "r" (oparg), "i" (-EFAULT), "1" (0))
16059
16060 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16061 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16062
16063 pagefault_disable();
16064
16065 + pax_open_userland();
16066 switch (op) {
16067 case FUTEX_OP_SET:
16068 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16069 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16070 break;
16071 case FUTEX_OP_ADD:
16072 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16073 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16074 uaddr, oparg);
16075 break;
16076 case FUTEX_OP_OR:
16077 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16078 default:
16079 ret = -ENOSYS;
16080 }
16081 + pax_close_userland();
16082
16083 pagefault_enable();
16084
16085 @@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16086 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16087 return -EFAULT;
16088
16089 + pax_open_userland();
16090 asm volatile("\t" ASM_STAC "\n"
16091 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16092 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16093 "2:\t" ASM_CLAC "\n"
16094 "\t.section .fixup, \"ax\"\n"
16095 "3:\tmov %3, %0\n"
16096 "\tjmp 2b\n"
16097 "\t.previous\n"
16098 _ASM_EXTABLE(1b, 3b)
16099 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16100 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16101 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16102 : "memory"
16103 );
16104 + pax_close_userland();
16105
16106 *uval = oldval;
16107 return ret;
16108 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16109 index cba45d9..86344ba 100644
16110 --- a/arch/x86/include/asm/hw_irq.h
16111 +++ b/arch/x86/include/asm/hw_irq.h
16112 @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16113 extern void enable_IO_APIC(void);
16114
16115 /* Statistics */
16116 -extern atomic_t irq_err_count;
16117 -extern atomic_t irq_mis_count;
16118 +extern atomic_unchecked_t irq_err_count;
16119 +extern atomic_unchecked_t irq_mis_count;
16120
16121 /* EISA */
16122 extern void eisa_set_level_irq(unsigned int irq);
16123 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16124 index a203659..9889f1c 100644
16125 --- a/arch/x86/include/asm/i8259.h
16126 +++ b/arch/x86/include/asm/i8259.h
16127 @@ -62,7 +62,7 @@ struct legacy_pic {
16128 void (*init)(int auto_eoi);
16129 int (*irq_pending)(unsigned int irq);
16130 void (*make_irq)(unsigned int irq);
16131 -};
16132 +} __do_const;
16133
16134 extern struct legacy_pic *legacy_pic;
16135 extern struct legacy_pic null_legacy_pic;
16136 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16137 index 34f69cb..6d95446 100644
16138 --- a/arch/x86/include/asm/io.h
16139 +++ b/arch/x86/include/asm/io.h
16140 @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16141 "m" (*(volatile type __force *)addr) barrier); }
16142
16143 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16144 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16145 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16146 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16147 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16148
16149 build_mmio_read(__readb, "b", unsigned char, "=q", )
16150 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16151 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16152 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16153 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16154
16155 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16156 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16157 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16158 return ioremap_nocache(offset, size);
16159 }
16160
16161 -extern void iounmap(volatile void __iomem *addr);
16162 +extern void iounmap(const volatile void __iomem *addr);
16163
16164 extern void set_iounmap_nonlazy(void);
16165
16166 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16167
16168 #include <linux/vmalloc.h>
16169
16170 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16171 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16172 +{
16173 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16174 +}
16175 +
16176 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16177 +{
16178 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16179 +}
16180 +
16181 /*
16182 * Convert a virtual cached pointer to an uncached pointer
16183 */
16184 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16185 index bba3cf8..06bc8da 100644
16186 --- a/arch/x86/include/asm/irqflags.h
16187 +++ b/arch/x86/include/asm/irqflags.h
16188 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16189 sti; \
16190 sysexit
16191
16192 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16193 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16194 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16195 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16196 +
16197 #else
16198 #define INTERRUPT_RETURN iret
16199 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16200 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16201 index 9454c16..e4100e3 100644
16202 --- a/arch/x86/include/asm/kprobes.h
16203 +++ b/arch/x86/include/asm/kprobes.h
16204 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16205 #define RELATIVEJUMP_SIZE 5
16206 #define RELATIVECALL_OPCODE 0xe8
16207 #define RELATIVE_ADDR_SIZE 4
16208 -#define MAX_STACK_SIZE 64
16209 -#define MIN_STACK_SIZE(ADDR) \
16210 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16211 - THREAD_SIZE - (unsigned long)(ADDR))) \
16212 - ? (MAX_STACK_SIZE) \
16213 - : (((unsigned long)current_thread_info()) + \
16214 - THREAD_SIZE - (unsigned long)(ADDR)))
16215 +#define MAX_STACK_SIZE 64UL
16216 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16217
16218 #define flush_insn_slot(p) do { } while (0)
16219
16220 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16221 index 4ad6560..75c7bdd 100644
16222 --- a/arch/x86/include/asm/local.h
16223 +++ b/arch/x86/include/asm/local.h
16224 @@ -10,33 +10,97 @@ typedef struct {
16225 atomic_long_t a;
16226 } local_t;
16227
16228 +typedef struct {
16229 + atomic_long_unchecked_t a;
16230 +} local_unchecked_t;
16231 +
16232 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16233
16234 #define local_read(l) atomic_long_read(&(l)->a)
16235 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16236 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16237 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16238
16239 static inline void local_inc(local_t *l)
16240 {
16241 - asm volatile(_ASM_INC "%0"
16242 + asm volatile(_ASM_INC "%0\n"
16243 +
16244 +#ifdef CONFIG_PAX_REFCOUNT
16245 + "jno 0f\n"
16246 + _ASM_DEC "%0\n"
16247 + "int $4\n0:\n"
16248 + _ASM_EXTABLE(0b, 0b)
16249 +#endif
16250 +
16251 + : "+m" (l->a.counter));
16252 +}
16253 +
16254 +static inline void local_inc_unchecked(local_unchecked_t *l)
16255 +{
16256 + asm volatile(_ASM_INC "%0\n"
16257 : "+m" (l->a.counter));
16258 }
16259
16260 static inline void local_dec(local_t *l)
16261 {
16262 - asm volatile(_ASM_DEC "%0"
16263 + asm volatile(_ASM_DEC "%0\n"
16264 +
16265 +#ifdef CONFIG_PAX_REFCOUNT
16266 + "jno 0f\n"
16267 + _ASM_INC "%0\n"
16268 + "int $4\n0:\n"
16269 + _ASM_EXTABLE(0b, 0b)
16270 +#endif
16271 +
16272 + : "+m" (l->a.counter));
16273 +}
16274 +
16275 +static inline void local_dec_unchecked(local_unchecked_t *l)
16276 +{
16277 + asm volatile(_ASM_DEC "%0\n"
16278 : "+m" (l->a.counter));
16279 }
16280
16281 static inline void local_add(long i, local_t *l)
16282 {
16283 - asm volatile(_ASM_ADD "%1,%0"
16284 + asm volatile(_ASM_ADD "%1,%0\n"
16285 +
16286 +#ifdef CONFIG_PAX_REFCOUNT
16287 + "jno 0f\n"
16288 + _ASM_SUB "%1,%0\n"
16289 + "int $4\n0:\n"
16290 + _ASM_EXTABLE(0b, 0b)
16291 +#endif
16292 +
16293 + : "+m" (l->a.counter)
16294 + : "ir" (i));
16295 +}
16296 +
16297 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16298 +{
16299 + asm volatile(_ASM_ADD "%1,%0\n"
16300 : "+m" (l->a.counter)
16301 : "ir" (i));
16302 }
16303
16304 static inline void local_sub(long i, local_t *l)
16305 {
16306 - asm volatile(_ASM_SUB "%1,%0"
16307 + asm volatile(_ASM_SUB "%1,%0\n"
16308 +
16309 +#ifdef CONFIG_PAX_REFCOUNT
16310 + "jno 0f\n"
16311 + _ASM_ADD "%1,%0\n"
16312 + "int $4\n0:\n"
16313 + _ASM_EXTABLE(0b, 0b)
16314 +#endif
16315 +
16316 + : "+m" (l->a.counter)
16317 + : "ir" (i));
16318 +}
16319 +
16320 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16321 +{
16322 + asm volatile(_ASM_SUB "%1,%0\n"
16323 : "+m" (l->a.counter)
16324 : "ir" (i));
16325 }
16326 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16327 */
16328 static inline int local_sub_and_test(long i, local_t *l)
16329 {
16330 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16331 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16332 }
16333
16334 /**
16335 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16336 */
16337 static inline int local_dec_and_test(local_t *l)
16338 {
16339 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16340 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16341 }
16342
16343 /**
16344 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16345 */
16346 static inline int local_inc_and_test(local_t *l)
16347 {
16348 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16349 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16350 }
16351
16352 /**
16353 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16354 */
16355 static inline int local_add_negative(long i, local_t *l)
16356 {
16357 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16358 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16359 }
16360
16361 /**
16362 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16363 static inline long local_add_return(long i, local_t *l)
16364 {
16365 long __i = i;
16366 + asm volatile(_ASM_XADD "%0, %1\n"
16367 +
16368 +#ifdef CONFIG_PAX_REFCOUNT
16369 + "jno 0f\n"
16370 + _ASM_MOV "%0,%1\n"
16371 + "int $4\n0:\n"
16372 + _ASM_EXTABLE(0b, 0b)
16373 +#endif
16374 +
16375 + : "+r" (i), "+m" (l->a.counter)
16376 + : : "memory");
16377 + return i + __i;
16378 +}
16379 +
16380 +/**
16381 + * local_add_return_unchecked - add and return
16382 + * @i: integer value to add
16383 + * @l: pointer to type local_unchecked_t
16384 + *
16385 + * Atomically adds @i to @l and returns @i + @l
16386 + */
16387 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16388 +{
16389 + long __i = i;
16390 asm volatile(_ASM_XADD "%0, %1;"
16391 : "+r" (i), "+m" (l->a.counter)
16392 : : "memory");
16393 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16394
16395 #define local_cmpxchg(l, o, n) \
16396 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16397 +#define local_cmpxchg_unchecked(l, o, n) \
16398 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
16399 /* Always has a lock prefix */
16400 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16401
16402 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16403 new file mode 100644
16404 index 0000000..2bfd3ba
16405 --- /dev/null
16406 +++ b/arch/x86/include/asm/mman.h
16407 @@ -0,0 +1,15 @@
16408 +#ifndef _X86_MMAN_H
16409 +#define _X86_MMAN_H
16410 +
16411 +#include <uapi/asm/mman.h>
16412 +
16413 +#ifdef __KERNEL__
16414 +#ifndef __ASSEMBLY__
16415 +#ifdef CONFIG_X86_32
16416 +#define arch_mmap_check i386_mmap_check
16417 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16418 +#endif
16419 +#endif
16420 +#endif
16421 +
16422 +#endif /* X86_MMAN_H */
16423 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16424 index 5f55e69..e20bfb1 100644
16425 --- a/arch/x86/include/asm/mmu.h
16426 +++ b/arch/x86/include/asm/mmu.h
16427 @@ -9,7 +9,7 @@
16428 * we put the segment information here.
16429 */
16430 typedef struct {
16431 - void *ldt;
16432 + struct desc_struct *ldt;
16433 int size;
16434
16435 #ifdef CONFIG_X86_64
16436 @@ -18,7 +18,19 @@ typedef struct {
16437 #endif
16438
16439 struct mutex lock;
16440 - void *vdso;
16441 + unsigned long vdso;
16442 +
16443 +#ifdef CONFIG_X86_32
16444 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16445 + unsigned long user_cs_base;
16446 + unsigned long user_cs_limit;
16447 +
16448 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16449 + cpumask_t cpu_user_cs_mask;
16450 +#endif
16451 +
16452 +#endif
16453 +#endif
16454 } mm_context_t;
16455
16456 #ifdef CONFIG_SMP
16457 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16458 index be12c53..4d24039 100644
16459 --- a/arch/x86/include/asm/mmu_context.h
16460 +++ b/arch/x86/include/asm/mmu_context.h
16461 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16462
16463 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16464 {
16465 +
16466 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16467 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
16468 + unsigned int i;
16469 + pgd_t *pgd;
16470 +
16471 + pax_open_kernel();
16472 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
16473 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16474 + set_pgd_batched(pgd+i, native_make_pgd(0));
16475 + pax_close_kernel();
16476 + }
16477 +#endif
16478 +
16479 #ifdef CONFIG_SMP
16480 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16481 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16482 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16483 struct task_struct *tsk)
16484 {
16485 unsigned cpu = smp_processor_id();
16486 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16487 + int tlbstate = TLBSTATE_OK;
16488 +#endif
16489
16490 if (likely(prev != next)) {
16491 #ifdef CONFIG_SMP
16492 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16493 + tlbstate = this_cpu_read(cpu_tlbstate.state);
16494 +#endif
16495 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16496 this_cpu_write(cpu_tlbstate.active_mm, next);
16497 #endif
16498 cpumask_set_cpu(cpu, mm_cpumask(next));
16499
16500 /* Re-load page tables */
16501 +#ifdef CONFIG_PAX_PER_CPU_PGD
16502 + pax_open_kernel();
16503 +
16504 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16505 + if (static_cpu_has(X86_FEATURE_PCID))
16506 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16507 + else
16508 +#endif
16509 +
16510 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16511 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16512 + pax_close_kernel();
16513 + 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));
16514 +
16515 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16516 + if (static_cpu_has(X86_FEATURE_PCID)) {
16517 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
16518 + u64 descriptor[2];
16519 + descriptor[0] = PCID_USER;
16520 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16521 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16522 + descriptor[0] = PCID_KERNEL;
16523 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16524 + }
16525 + } else {
16526 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16527 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16528 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16529 + else
16530 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16531 + }
16532 + } else
16533 +#endif
16534 +
16535 + load_cr3(get_cpu_pgd(cpu, kernel));
16536 +#else
16537 load_cr3(next->pgd);
16538 +#endif
16539
16540 /* Stop flush ipis for the previous mm */
16541 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16542 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16543 /* Load the LDT, if the LDT is different: */
16544 if (unlikely(prev->context.ldt != next->context.ldt))
16545 load_LDT_nolock(&next->context);
16546 +
16547 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16548 + if (!(__supported_pte_mask & _PAGE_NX)) {
16549 + smp_mb__before_clear_bit();
16550 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16551 + smp_mb__after_clear_bit();
16552 + cpu_set(cpu, next->context.cpu_user_cs_mask);
16553 + }
16554 +#endif
16555 +
16556 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16557 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16558 + prev->context.user_cs_limit != next->context.user_cs_limit))
16559 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16560 +#ifdef CONFIG_SMP
16561 + else if (unlikely(tlbstate != TLBSTATE_OK))
16562 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16563 +#endif
16564 +#endif
16565 +
16566 }
16567 + else {
16568 +
16569 +#ifdef CONFIG_PAX_PER_CPU_PGD
16570 + pax_open_kernel();
16571 +
16572 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16573 + if (static_cpu_has(X86_FEATURE_PCID))
16574 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16575 + else
16576 +#endif
16577 +
16578 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16579 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16580 + pax_close_kernel();
16581 + 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));
16582 +
16583 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16584 + if (static_cpu_has(X86_FEATURE_PCID)) {
16585 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
16586 + u64 descriptor[2];
16587 + descriptor[0] = PCID_USER;
16588 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16589 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16590 + descriptor[0] = PCID_KERNEL;
16591 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16592 + }
16593 + } else {
16594 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16595 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16596 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16597 + else
16598 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16599 + }
16600 + } else
16601 +#endif
16602 +
16603 + load_cr3(get_cpu_pgd(cpu, kernel));
16604 +#endif
16605 +
16606 #ifdef CONFIG_SMP
16607 - else {
16608 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16609 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
16610
16611 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16612 * tlb flush IPI delivery. We must reload CR3
16613 * to make sure to use no freed page tables.
16614 */
16615 +
16616 +#ifndef CONFIG_PAX_PER_CPU_PGD
16617 load_cr3(next->pgd);
16618 +#endif
16619 +
16620 load_LDT_nolock(&next->context);
16621 +
16622 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16623 + if (!(__supported_pte_mask & _PAGE_NX))
16624 + cpu_set(cpu, next->context.cpu_user_cs_mask);
16625 +#endif
16626 +
16627 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16628 +#ifdef CONFIG_PAX_PAGEEXEC
16629 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
16630 +#endif
16631 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16632 +#endif
16633 +
16634 }
16635 +#endif
16636 }
16637 -#endif
16638 }
16639
16640 #define activate_mm(prev, next) \
16641 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16642 index e3b7819..b257c64 100644
16643 --- a/arch/x86/include/asm/module.h
16644 +++ b/arch/x86/include/asm/module.h
16645 @@ -5,6 +5,7 @@
16646
16647 #ifdef CONFIG_X86_64
16648 /* X86_64 does not define MODULE_PROC_FAMILY */
16649 +#define MODULE_PROC_FAMILY ""
16650 #elif defined CONFIG_M486
16651 #define MODULE_PROC_FAMILY "486 "
16652 #elif defined CONFIG_M586
16653 @@ -57,8 +58,20 @@
16654 #error unknown processor family
16655 #endif
16656
16657 -#ifdef CONFIG_X86_32
16658 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16659 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16660 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16661 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16662 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16663 +#else
16664 +#define MODULE_PAX_KERNEXEC ""
16665 #endif
16666
16667 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16668 +#define MODULE_PAX_UDEREF "UDEREF "
16669 +#else
16670 +#define MODULE_PAX_UDEREF ""
16671 +#endif
16672 +
16673 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16674 +
16675 #endif /* _ASM_X86_MODULE_H */
16676 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16677 index 86f9301..b365cda 100644
16678 --- a/arch/x86/include/asm/nmi.h
16679 +++ b/arch/x86/include/asm/nmi.h
16680 @@ -40,11 +40,11 @@ struct nmiaction {
16681 nmi_handler_t handler;
16682 unsigned long flags;
16683 const char *name;
16684 -};
16685 +} __do_const;
16686
16687 #define register_nmi_handler(t, fn, fg, n, init...) \
16688 ({ \
16689 - static struct nmiaction init fn##_na = { \
16690 + static const struct nmiaction init fn##_na = { \
16691 .handler = (fn), \
16692 .name = (n), \
16693 .flags = (fg), \
16694 @@ -52,7 +52,7 @@ struct nmiaction {
16695 __register_nmi_handler((t), &fn##_na); \
16696 })
16697
16698 -int __register_nmi_handler(unsigned int, struct nmiaction *);
16699 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
16700
16701 void unregister_nmi_handler(unsigned int, const char *);
16702
16703 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16704 index c878924..21f4889 100644
16705 --- a/arch/x86/include/asm/page.h
16706 +++ b/arch/x86/include/asm/page.h
16707 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16708 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16709
16710 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16711 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16712
16713 #define __boot_va(x) __va(x)
16714 #define __boot_pa(x) __pa(x)
16715 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16716 index 0f1ddee..e2fc3d1 100644
16717 --- a/arch/x86/include/asm/page_64.h
16718 +++ b/arch/x86/include/asm/page_64.h
16719 @@ -7,9 +7,9 @@
16720
16721 /* duplicated to the one in bootmem.h */
16722 extern unsigned long max_pfn;
16723 -extern unsigned long phys_base;
16724 +extern const unsigned long phys_base;
16725
16726 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
16727 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16728 {
16729 unsigned long y = x - __START_KERNEL_map;
16730
16731 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16732 index 401f350..dee5d13 100644
16733 --- a/arch/x86/include/asm/paravirt.h
16734 +++ b/arch/x86/include/asm/paravirt.h
16735 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16736 return (pmd_t) { ret };
16737 }
16738
16739 -static inline pmdval_t pmd_val(pmd_t pmd)
16740 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16741 {
16742 pmdval_t ret;
16743
16744 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16745 val);
16746 }
16747
16748 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16749 +{
16750 + pgdval_t val = native_pgd_val(pgd);
16751 +
16752 + if (sizeof(pgdval_t) > sizeof(long))
16753 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16754 + val, (u64)val >> 32);
16755 + else
16756 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16757 + val);
16758 +}
16759 +
16760 static inline void pgd_clear(pgd_t *pgdp)
16761 {
16762 set_pgd(pgdp, __pgd(0));
16763 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16764 pv_mmu_ops.set_fixmap(idx, phys, flags);
16765 }
16766
16767 +#ifdef CONFIG_PAX_KERNEXEC
16768 +static inline unsigned long pax_open_kernel(void)
16769 +{
16770 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16771 +}
16772 +
16773 +static inline unsigned long pax_close_kernel(void)
16774 +{
16775 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16776 +}
16777 +#else
16778 +static inline unsigned long pax_open_kernel(void) { return 0; }
16779 +static inline unsigned long pax_close_kernel(void) { return 0; }
16780 +#endif
16781 +
16782 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16783
16784 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
16785 @@ -906,7 +933,7 @@ extern void default_banner(void);
16786
16787 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16788 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16789 -#define PARA_INDIRECT(addr) *%cs:addr
16790 +#define PARA_INDIRECT(addr) *%ss:addr
16791 #endif
16792
16793 #define INTERRUPT_RETURN \
16794 @@ -981,6 +1008,21 @@ extern void default_banner(void);
16795 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16796 CLBR_NONE, \
16797 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16798 +
16799 +#define GET_CR0_INTO_RDI \
16800 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16801 + mov %rax,%rdi
16802 +
16803 +#define SET_RDI_INTO_CR0 \
16804 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16805 +
16806 +#define GET_CR3_INTO_RDI \
16807 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16808 + mov %rax,%rdi
16809 +
16810 +#define SET_RDI_INTO_CR3 \
16811 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16812 +
16813 #endif /* CONFIG_X86_32 */
16814
16815 #endif /* __ASSEMBLY__ */
16816 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16817 index aab8f67..0fb0ee4 100644
16818 --- a/arch/x86/include/asm/paravirt_types.h
16819 +++ b/arch/x86/include/asm/paravirt_types.h
16820 @@ -84,7 +84,7 @@ struct pv_init_ops {
16821 */
16822 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16823 unsigned long addr, unsigned len);
16824 -};
16825 +} __no_const __no_randomize_layout;
16826
16827
16828 struct pv_lazy_ops {
16829 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
16830 void (*enter)(void);
16831 void (*leave)(void);
16832 void (*flush)(void);
16833 -};
16834 +} __no_randomize_layout;
16835
16836 struct pv_time_ops {
16837 unsigned long long (*sched_clock)(void);
16838 unsigned long long (*steal_clock)(int cpu);
16839 unsigned long (*get_tsc_khz)(void);
16840 -};
16841 +} __no_const __no_randomize_layout;
16842
16843 struct pv_cpu_ops {
16844 /* hooks for various privileged instructions */
16845 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
16846
16847 void (*start_context_switch)(struct task_struct *prev);
16848 void (*end_context_switch)(struct task_struct *next);
16849 -};
16850 +} __no_const __no_randomize_layout;
16851
16852 struct pv_irq_ops {
16853 /*
16854 @@ -215,7 +215,7 @@ struct pv_irq_ops {
16855 #ifdef CONFIG_X86_64
16856 void (*adjust_exception_frame)(void);
16857 #endif
16858 -};
16859 +} __no_randomize_layout;
16860
16861 struct pv_apic_ops {
16862 #ifdef CONFIG_X86_LOCAL_APIC
16863 @@ -223,7 +223,7 @@ struct pv_apic_ops {
16864 unsigned long start_eip,
16865 unsigned long start_esp);
16866 #endif
16867 -};
16868 +} __no_const __no_randomize_layout;
16869
16870 struct pv_mmu_ops {
16871 unsigned long (*read_cr2)(void);
16872 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
16873 struct paravirt_callee_save make_pud;
16874
16875 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16876 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16877 #endif /* PAGETABLE_LEVELS == 4 */
16878 #endif /* PAGETABLE_LEVELS >= 3 */
16879
16880 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
16881 an mfn. We can tell which is which from the index. */
16882 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16883 phys_addr_t phys, pgprot_t flags);
16884 -};
16885 +
16886 +#ifdef CONFIG_PAX_KERNEXEC
16887 + unsigned long (*pax_open_kernel)(void);
16888 + unsigned long (*pax_close_kernel)(void);
16889 +#endif
16890 +
16891 +} __no_randomize_layout;
16892
16893 struct arch_spinlock;
16894 #ifdef CONFIG_SMP
16895 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
16896 struct pv_lock_ops {
16897 struct paravirt_callee_save lock_spinning;
16898 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
16899 -};
16900 +} __no_randomize_layout;
16901
16902 /* This contains all the paravirt structures: we get a convenient
16903 * number for each function using the offset which we use to indicate
16904 - * what to patch. */
16905 + * what to patch.
16906 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
16907 + */
16908 +
16909 struct paravirt_patch_template {
16910 struct pv_init_ops pv_init_ops;
16911 struct pv_time_ops pv_time_ops;
16912 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
16913 struct pv_apic_ops pv_apic_ops;
16914 struct pv_mmu_ops pv_mmu_ops;
16915 struct pv_lock_ops pv_lock_ops;
16916 -};
16917 +} __no_randomize_layout;
16918
16919 extern struct pv_info pv_info;
16920 extern struct pv_init_ops pv_init_ops;
16921 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16922 index c4412e9..90e88c5 100644
16923 --- a/arch/x86/include/asm/pgalloc.h
16924 +++ b/arch/x86/include/asm/pgalloc.h
16925 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16926 pmd_t *pmd, pte_t *pte)
16927 {
16928 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16929 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16930 +}
16931 +
16932 +static inline void pmd_populate_user(struct mm_struct *mm,
16933 + pmd_t *pmd, pte_t *pte)
16934 +{
16935 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16936 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16937 }
16938
16939 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16940
16941 #ifdef CONFIG_X86_PAE
16942 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16943 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16944 +{
16945 + pud_populate(mm, pudp, pmd);
16946 +}
16947 #else /* !CONFIG_X86_PAE */
16948 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16949 {
16950 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16951 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16952 }
16953 +
16954 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16955 +{
16956 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16957 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16958 +}
16959 #endif /* CONFIG_X86_PAE */
16960
16961 #if PAGETABLE_LEVELS > 3
16962 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16963 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16964 }
16965
16966 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16967 +{
16968 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16969 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16970 +}
16971 +
16972 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16973 {
16974 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16975 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16976 index 3bf2dd0..23d2a9f 100644
16977 --- a/arch/x86/include/asm/pgtable-2level.h
16978 +++ b/arch/x86/include/asm/pgtable-2level.h
16979 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16980
16981 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16982 {
16983 + pax_open_kernel();
16984 *pmdp = pmd;
16985 + pax_close_kernel();
16986 }
16987
16988 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16989 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16990 index 81bb91b..9392125 100644
16991 --- a/arch/x86/include/asm/pgtable-3level.h
16992 +++ b/arch/x86/include/asm/pgtable-3level.h
16993 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16994
16995 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16996 {
16997 + pax_open_kernel();
16998 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16999 + pax_close_kernel();
17000 }
17001
17002 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17003 {
17004 + pax_open_kernel();
17005 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17006 + pax_close_kernel();
17007 }
17008
17009 /*
17010 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17011 index bbc8b12..f228861 100644
17012 --- a/arch/x86/include/asm/pgtable.h
17013 +++ b/arch/x86/include/asm/pgtable.h
17014 @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17015
17016 #ifndef __PAGETABLE_PUD_FOLDED
17017 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17018 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17019 #define pgd_clear(pgd) native_pgd_clear(pgd)
17020 #endif
17021
17022 @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17023
17024 #define arch_end_context_switch(prev) do {} while(0)
17025
17026 +#define pax_open_kernel() native_pax_open_kernel()
17027 +#define pax_close_kernel() native_pax_close_kernel()
17028 #endif /* CONFIG_PARAVIRT */
17029
17030 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17031 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17032 +
17033 +#ifdef CONFIG_PAX_KERNEXEC
17034 +static inline unsigned long native_pax_open_kernel(void)
17035 +{
17036 + unsigned long cr0;
17037 +
17038 + preempt_disable();
17039 + barrier();
17040 + cr0 = read_cr0() ^ X86_CR0_WP;
17041 + BUG_ON(cr0 & X86_CR0_WP);
17042 + write_cr0(cr0);
17043 + return cr0 ^ X86_CR0_WP;
17044 +}
17045 +
17046 +static inline unsigned long native_pax_close_kernel(void)
17047 +{
17048 + unsigned long cr0;
17049 +
17050 + cr0 = read_cr0() ^ X86_CR0_WP;
17051 + BUG_ON(!(cr0 & X86_CR0_WP));
17052 + write_cr0(cr0);
17053 + barrier();
17054 + preempt_enable_no_resched();
17055 + return cr0 ^ X86_CR0_WP;
17056 +}
17057 +#else
17058 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17059 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17060 +#endif
17061 +
17062 /*
17063 * The following only work if pte_present() is true.
17064 * Undefined behaviour if not..
17065 */
17066 +static inline int pte_user(pte_t pte)
17067 +{
17068 + return pte_val(pte) & _PAGE_USER;
17069 +}
17070 +
17071 static inline int pte_dirty(pte_t pte)
17072 {
17073 return pte_flags(pte) & _PAGE_DIRTY;
17074 @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17075 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17076 }
17077
17078 +static inline unsigned long pgd_pfn(pgd_t pgd)
17079 +{
17080 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17081 +}
17082 +
17083 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17084
17085 static inline int pmd_large(pmd_t pte)
17086 @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17087 return pte_clear_flags(pte, _PAGE_RW);
17088 }
17089
17090 +static inline pte_t pte_mkread(pte_t pte)
17091 +{
17092 + return __pte(pte_val(pte) | _PAGE_USER);
17093 +}
17094 +
17095 static inline pte_t pte_mkexec(pte_t pte)
17096 {
17097 - return pte_clear_flags(pte, _PAGE_NX);
17098 +#ifdef CONFIG_X86_PAE
17099 + if (__supported_pte_mask & _PAGE_NX)
17100 + return pte_clear_flags(pte, _PAGE_NX);
17101 + else
17102 +#endif
17103 + return pte_set_flags(pte, _PAGE_USER);
17104 +}
17105 +
17106 +static inline pte_t pte_exprotect(pte_t pte)
17107 +{
17108 +#ifdef CONFIG_X86_PAE
17109 + if (__supported_pte_mask & _PAGE_NX)
17110 + return pte_set_flags(pte, _PAGE_NX);
17111 + else
17112 +#endif
17113 + return pte_clear_flags(pte, _PAGE_USER);
17114 }
17115
17116 static inline pte_t pte_mkdirty(pte_t pte)
17117 @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17118 #endif
17119
17120 #ifndef __ASSEMBLY__
17121 +
17122 +#ifdef CONFIG_PAX_PER_CPU_PGD
17123 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17124 +enum cpu_pgd_type {kernel = 0, user = 1};
17125 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17126 +{
17127 + return cpu_pgd[cpu][type];
17128 +}
17129 +#endif
17130 +
17131 #include <linux/mm_types.h>
17132 #include <linux/mmdebug.h>
17133 #include <linux/log2.h>
17134 @@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17135 * Currently stuck as a macro due to indirect forward reference to
17136 * linux/mmzone.h's __section_mem_map_addr() definition:
17137 */
17138 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17139 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17140
17141 /* Find an entry in the second-level page table.. */
17142 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17143 @@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17144 * Currently stuck as a macro due to indirect forward reference to
17145 * linux/mmzone.h's __section_mem_map_addr() definition:
17146 */
17147 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17148 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17149
17150 /* to find an entry in a page-table-directory. */
17151 static inline unsigned long pud_index(unsigned long address)
17152 @@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17153
17154 static inline int pgd_bad(pgd_t pgd)
17155 {
17156 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17157 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17158 }
17159
17160 static inline int pgd_none(pgd_t pgd)
17161 @@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17162 * pgd_offset() returns a (pgd_t *)
17163 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17164 */
17165 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17166 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17167 +
17168 +#ifdef CONFIG_PAX_PER_CPU_PGD
17169 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17170 +#endif
17171 +
17172 /*
17173 * a shortcut which implies the use of the kernel's pgd, instead
17174 * of a process's
17175 @@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17176 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17177 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17178
17179 +#ifdef CONFIG_X86_32
17180 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17181 +#else
17182 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17183 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17184 +
17185 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17186 +#ifdef __ASSEMBLY__
17187 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17188 +#else
17189 +extern unsigned long pax_user_shadow_base;
17190 +extern pgdval_t clone_pgd_mask;
17191 +#endif
17192 +#endif
17193 +
17194 +#endif
17195 +
17196 #ifndef __ASSEMBLY__
17197
17198 extern int direct_gbpages;
17199 @@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17200 * dst and src can be on the same page, but the range must not overlap,
17201 * and must not cross a page boundary.
17202 */
17203 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17204 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17205 {
17206 - memcpy(dst, src, count * sizeof(pgd_t));
17207 + pax_open_kernel();
17208 + while (count--)
17209 + *dst++ = *src++;
17210 + pax_close_kernel();
17211 }
17212
17213 +#ifdef CONFIG_PAX_PER_CPU_PGD
17214 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17215 +#endif
17216 +
17217 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17218 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17219 +#else
17220 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17221 +#endif
17222 +
17223 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17224 static inline int page_level_shift(enum pg_level level)
17225 {
17226 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17227 index 9ee3221..b979c6b 100644
17228 --- a/arch/x86/include/asm/pgtable_32.h
17229 +++ b/arch/x86/include/asm/pgtable_32.h
17230 @@ -25,9 +25,6 @@
17231 struct mm_struct;
17232 struct vm_area_struct;
17233
17234 -extern pgd_t swapper_pg_dir[1024];
17235 -extern pgd_t initial_page_table[1024];
17236 -
17237 static inline void pgtable_cache_init(void) { }
17238 static inline void check_pgt_cache(void) { }
17239 void paging_init(void);
17240 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17241 # include <asm/pgtable-2level.h>
17242 #endif
17243
17244 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17245 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17246 +#ifdef CONFIG_X86_PAE
17247 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17248 +#endif
17249 +
17250 #if defined(CONFIG_HIGHPTE)
17251 #define pte_offset_map(dir, address) \
17252 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17253 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17254 /* Clear a kernel PTE and flush it from the TLB */
17255 #define kpte_clear_flush(ptep, vaddr) \
17256 do { \
17257 + pax_open_kernel(); \
17258 pte_clear(&init_mm, (vaddr), (ptep)); \
17259 + pax_close_kernel(); \
17260 __flush_tlb_one((vaddr)); \
17261 } while (0)
17262
17263 #endif /* !__ASSEMBLY__ */
17264
17265 +#define HAVE_ARCH_UNMAPPED_AREA
17266 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17267 +
17268 /*
17269 * kern_addr_valid() is (1) for FLATMEM and (0) for
17270 * SPARSEMEM and DISCONTIGMEM
17271 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17272 index ed5903b..c7fe163 100644
17273 --- a/arch/x86/include/asm/pgtable_32_types.h
17274 +++ b/arch/x86/include/asm/pgtable_32_types.h
17275 @@ -8,7 +8,7 @@
17276 */
17277 #ifdef CONFIG_X86_PAE
17278 # include <asm/pgtable-3level_types.h>
17279 -# define PMD_SIZE (1UL << PMD_SHIFT)
17280 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17281 # define PMD_MASK (~(PMD_SIZE - 1))
17282 #else
17283 # include <asm/pgtable-2level_types.h>
17284 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17285 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17286 #endif
17287
17288 +#ifdef CONFIG_PAX_KERNEXEC
17289 +#ifndef __ASSEMBLY__
17290 +extern unsigned char MODULES_EXEC_VADDR[];
17291 +extern unsigned char MODULES_EXEC_END[];
17292 +#endif
17293 +#include <asm/boot.h>
17294 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17295 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17296 +#else
17297 +#define ktla_ktva(addr) (addr)
17298 +#define ktva_ktla(addr) (addr)
17299 +#endif
17300 +
17301 #define MODULES_VADDR VMALLOC_START
17302 #define MODULES_END VMALLOC_END
17303 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17304 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17305 index e22c1db..23a625a 100644
17306 --- a/arch/x86/include/asm/pgtable_64.h
17307 +++ b/arch/x86/include/asm/pgtable_64.h
17308 @@ -16,10 +16,14 @@
17309
17310 extern pud_t level3_kernel_pgt[512];
17311 extern pud_t level3_ident_pgt[512];
17312 +extern pud_t level3_vmalloc_start_pgt[512];
17313 +extern pud_t level3_vmalloc_end_pgt[512];
17314 +extern pud_t level3_vmemmap_pgt[512];
17315 +extern pud_t level2_vmemmap_pgt[512];
17316 extern pmd_t level2_kernel_pgt[512];
17317 extern pmd_t level2_fixmap_pgt[512];
17318 -extern pmd_t level2_ident_pgt[512];
17319 -extern pgd_t init_level4_pgt[];
17320 +extern pmd_t level2_ident_pgt[512*2];
17321 +extern pgd_t init_level4_pgt[512];
17322
17323 #define swapper_pg_dir init_level4_pgt
17324
17325 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17326
17327 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17328 {
17329 + pax_open_kernel();
17330 *pmdp = pmd;
17331 + pax_close_kernel();
17332 }
17333
17334 static inline void native_pmd_clear(pmd_t *pmd)
17335 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17336
17337 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17338 {
17339 + pax_open_kernel();
17340 *pudp = pud;
17341 + pax_close_kernel();
17342 }
17343
17344 static inline void native_pud_clear(pud_t *pud)
17345 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17346
17347 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17348 {
17349 + pax_open_kernel();
17350 + *pgdp = pgd;
17351 + pax_close_kernel();
17352 +}
17353 +
17354 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17355 +{
17356 *pgdp = pgd;
17357 }
17358
17359 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17360 index 2d88344..4679fc3 100644
17361 --- a/arch/x86/include/asm/pgtable_64_types.h
17362 +++ b/arch/x86/include/asm/pgtable_64_types.h
17363 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17364 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17365 #define MODULES_END _AC(0xffffffffff000000, UL)
17366 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17367 +#define MODULES_EXEC_VADDR MODULES_VADDR
17368 +#define MODULES_EXEC_END MODULES_END
17369 +
17370 +#define ktla_ktva(addr) (addr)
17371 +#define ktva_ktla(addr) (addr)
17372
17373 #define EARLY_DYNAMIC_PAGE_TABLES 64
17374
17375 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17376 index 0ecac25..7a15e09 100644
17377 --- a/arch/x86/include/asm/pgtable_types.h
17378 +++ b/arch/x86/include/asm/pgtable_types.h
17379 @@ -16,13 +16,12 @@
17380 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17381 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17382 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17383 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17384 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17385 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17386 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17387 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17388 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17389 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17390 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17391 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17392 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17393 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17394
17395 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17396 @@ -40,7 +39,6 @@
17397 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17398 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17399 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17400 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17401 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17402 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17403 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17404 @@ -87,8 +85,10 @@
17405
17406 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17407 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17408 -#else
17409 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17410 #define _PAGE_NX (_AT(pteval_t, 0))
17411 +#else
17412 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17413 #endif
17414
17415 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17416 @@ -146,6 +146,9 @@
17417 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17418 _PAGE_ACCESSED)
17419
17420 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
17421 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
17422 +
17423 #define __PAGE_KERNEL_EXEC \
17424 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17425 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17426 @@ -156,7 +159,7 @@
17427 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17428 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17429 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17430 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17431 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17432 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17433 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17434 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17435 @@ -218,8 +221,8 @@
17436 * bits are combined, this will alow user to access the high address mapped
17437 * VDSO in the presence of CONFIG_COMPAT_VDSO
17438 */
17439 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17440 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17441 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17442 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17443 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17444 #endif
17445
17446 @@ -257,7 +260,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17447 {
17448 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17449 }
17450 +#endif
17451
17452 +#if PAGETABLE_LEVELS == 3
17453 +#include <asm-generic/pgtable-nopud.h>
17454 +#endif
17455 +
17456 +#if PAGETABLE_LEVELS == 2
17457 +#include <asm-generic/pgtable-nopmd.h>
17458 +#endif
17459 +
17460 +#ifndef __ASSEMBLY__
17461 #if PAGETABLE_LEVELS > 3
17462 typedef struct { pudval_t pud; } pud_t;
17463
17464 @@ -271,8 +284,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17465 return pud.pud;
17466 }
17467 #else
17468 -#include <asm-generic/pgtable-nopud.h>
17469 -
17470 static inline pudval_t native_pud_val(pud_t pud)
17471 {
17472 return native_pgd_val(pud.pgd);
17473 @@ -292,8 +303,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17474 return pmd.pmd;
17475 }
17476 #else
17477 -#include <asm-generic/pgtable-nopmd.h>
17478 -
17479 static inline pmdval_t native_pmd_val(pmd_t pmd)
17480 {
17481 return native_pgd_val(pmd.pud.pgd);
17482 @@ -333,7 +342,6 @@ typedef struct page *pgtable_t;
17483
17484 extern pteval_t __supported_pte_mask;
17485 extern void set_nx(void);
17486 -extern int nx_enabled;
17487
17488 #define pgprot_writecombine pgprot_writecombine
17489 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17490 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17491 index c8b0519..fd29e73 100644
17492 --- a/arch/x86/include/asm/preempt.h
17493 +++ b/arch/x86/include/asm/preempt.h
17494 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17495 */
17496 static __always_inline bool __preempt_count_dec_and_test(void)
17497 {
17498 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17499 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17500 }
17501
17502 /*
17503 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17504 index 7b034a4..4fe3e3f 100644
17505 --- a/arch/x86/include/asm/processor.h
17506 +++ b/arch/x86/include/asm/processor.h
17507 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17508 /* Index into per_cpu list: */
17509 u16 cpu_index;
17510 u32 microcode;
17511 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17512 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17513
17514 #define X86_VENDOR_INTEL 0
17515 #define X86_VENDOR_CYRIX 1
17516 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17517 : "memory");
17518 }
17519
17520 +/* invpcid (%rdx),%rax */
17521 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17522 +
17523 +#define INVPCID_SINGLE_ADDRESS 0UL
17524 +#define INVPCID_SINGLE_CONTEXT 1UL
17525 +#define INVPCID_ALL_GLOBAL 2UL
17526 +#define INVPCID_ALL_MONGLOBAL 3UL
17527 +
17528 +#define PCID_KERNEL 0UL
17529 +#define PCID_USER 1UL
17530 +#define PCID_NOFLUSH (1UL << 63)
17531 +
17532 static inline void load_cr3(pgd_t *pgdir)
17533 {
17534 - write_cr3(__pa(pgdir));
17535 + write_cr3(__pa(pgdir) | PCID_KERNEL);
17536 }
17537
17538 #ifdef CONFIG_X86_32
17539 @@ -283,7 +295,7 @@ struct tss_struct {
17540
17541 } ____cacheline_aligned;
17542
17543 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17544 +extern struct tss_struct init_tss[NR_CPUS];
17545
17546 /*
17547 * Save the original ist values for checking stack pointers during debugging
17548 @@ -453,6 +465,7 @@ struct thread_struct {
17549 unsigned short ds;
17550 unsigned short fsindex;
17551 unsigned short gsindex;
17552 + unsigned short ss;
17553 #endif
17554 #ifdef CONFIG_X86_32
17555 unsigned long ip;
17556 @@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
17557 extern unsigned long mmu_cr4_features;
17558 extern u32 *trampoline_cr4_features;
17559
17560 -static inline void set_in_cr4(unsigned long mask)
17561 -{
17562 - unsigned long cr4;
17563 -
17564 - mmu_cr4_features |= mask;
17565 - if (trampoline_cr4_features)
17566 - *trampoline_cr4_features = mmu_cr4_features;
17567 - cr4 = read_cr4();
17568 - cr4 |= mask;
17569 - write_cr4(cr4);
17570 -}
17571 -
17572 -static inline void clear_in_cr4(unsigned long mask)
17573 -{
17574 - unsigned long cr4;
17575 -
17576 - mmu_cr4_features &= ~mask;
17577 - if (trampoline_cr4_features)
17578 - *trampoline_cr4_features = mmu_cr4_features;
17579 - cr4 = read_cr4();
17580 - cr4 &= ~mask;
17581 - write_cr4(cr4);
17582 -}
17583 +extern void set_in_cr4(unsigned long mask);
17584 +extern void clear_in_cr4(unsigned long mask);
17585
17586 typedef struct {
17587 unsigned long seg;
17588 @@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
17589 */
17590 #define TASK_SIZE PAGE_OFFSET
17591 #define TASK_SIZE_MAX TASK_SIZE
17592 +
17593 +#ifdef CONFIG_PAX_SEGMEXEC
17594 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
17595 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
17596 +#else
17597 #define STACK_TOP TASK_SIZE
17598 -#define STACK_TOP_MAX STACK_TOP
17599 +#endif
17600 +
17601 +#define STACK_TOP_MAX TASK_SIZE
17602
17603 #define INIT_THREAD { \
17604 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
17605 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17606 .vm86_info = NULL, \
17607 .sysenter_cs = __KERNEL_CS, \
17608 .io_bitmap_ptr = NULL, \
17609 @@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
17610 */
17611 #define INIT_TSS { \
17612 .x86_tss = { \
17613 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
17614 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17615 .ss0 = __KERNEL_DS, \
17616 .ss1 = __KERNEL_CS, \
17617 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
17618 @@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
17619 extern unsigned long thread_saved_pc(struct task_struct *tsk);
17620
17621 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
17622 -#define KSTK_TOP(info) \
17623 -({ \
17624 - unsigned long *__ptr = (unsigned long *)(info); \
17625 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
17626 -})
17627 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
17628
17629 /*
17630 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
17631 @@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17632 #define task_pt_regs(task) \
17633 ({ \
17634 struct pt_regs *__regs__; \
17635 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
17636 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
17637 __regs__ - 1; \
17638 })
17639
17640 @@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17641 /*
17642 * User space process size. 47bits minus one guard page.
17643 */
17644 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
17645 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
17646
17647 /* This decides where the kernel will search for a free chunk of vm
17648 * space during mmap's.
17649 */
17650 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
17651 - 0xc0000000 : 0xFFFFe000)
17652 + 0xc0000000 : 0xFFFFf000)
17653
17654 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
17655 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
17656 @@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17657 #define STACK_TOP_MAX TASK_SIZE_MAX
17658
17659 #define INIT_THREAD { \
17660 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17661 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17662 }
17663
17664 #define INIT_TSS { \
17665 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17666 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17667 }
17668
17669 /*
17670 @@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
17671 */
17672 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
17673
17674 +#ifdef CONFIG_PAX_SEGMEXEC
17675 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
17676 +#endif
17677 +
17678 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
17679
17680 /* Get/set a process' ability to use the timestamp counter instruction */
17681 @@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
17682 return 0;
17683 }
17684
17685 -extern unsigned long arch_align_stack(unsigned long sp);
17686 +#define arch_align_stack(x) ((x) & ~0xfUL)
17687 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17688
17689 void default_idle(void);
17690 @@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
17691 #define xen_set_default_idle 0
17692 #endif
17693
17694 -void stop_this_cpu(void *dummy);
17695 +void stop_this_cpu(void *dummy) __noreturn;
17696 void df_debug(struct pt_regs *regs, long error_code);
17697 #endif /* _ASM_X86_PROCESSOR_H */
17698 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17699 index 942a086..6c26446 100644
17700 --- a/arch/x86/include/asm/ptrace.h
17701 +++ b/arch/x86/include/asm/ptrace.h
17702 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17703 }
17704
17705 /*
17706 - * user_mode_vm(regs) determines whether a register set came from user mode.
17707 + * user_mode(regs) determines whether a register set came from user mode.
17708 * This is true if V8086 mode was enabled OR if the register set was from
17709 * protected mode with RPL-3 CS value. This tricky test checks that with
17710 * one comparison. Many places in the kernel can bypass this full check
17711 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17712 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17713 + * be used.
17714 */
17715 -static inline int user_mode(struct pt_regs *regs)
17716 +static inline int user_mode_novm(struct pt_regs *regs)
17717 {
17718 #ifdef CONFIG_X86_32
17719 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17720 #else
17721 - return !!(regs->cs & 3);
17722 + return !!(regs->cs & SEGMENT_RPL_MASK);
17723 #endif
17724 }
17725
17726 -static inline int user_mode_vm(struct pt_regs *regs)
17727 +static inline int user_mode(struct pt_regs *regs)
17728 {
17729 #ifdef CONFIG_X86_32
17730 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17731 USER_RPL;
17732 #else
17733 - return user_mode(regs);
17734 + return user_mode_novm(regs);
17735 #endif
17736 }
17737
17738 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17739 #ifdef CONFIG_X86_64
17740 static inline bool user_64bit_mode(struct pt_regs *regs)
17741 {
17742 + unsigned long cs = regs->cs & 0xffff;
17743 #ifndef CONFIG_PARAVIRT
17744 /*
17745 * On non-paravirt systems, this is the only long mode CPL 3
17746 * selector. We do not allow long mode selectors in the LDT.
17747 */
17748 - return regs->cs == __USER_CS;
17749 + return cs == __USER_CS;
17750 #else
17751 /* Headers are too twisted for this to go in paravirt.h. */
17752 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17753 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17754 #endif
17755 }
17756
17757 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17758 * Traps from the kernel do not save sp and ss.
17759 * Use the helper function to retrieve sp.
17760 */
17761 - if (offset == offsetof(struct pt_regs, sp) &&
17762 - regs->cs == __KERNEL_CS)
17763 - return kernel_stack_pointer(regs);
17764 + if (offset == offsetof(struct pt_regs, sp)) {
17765 + unsigned long cs = regs->cs & 0xffff;
17766 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17767 + return kernel_stack_pointer(regs);
17768 + }
17769 #endif
17770 return *(unsigned long *)((unsigned long)regs + offset);
17771 }
17772 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17773 index 9c6b890..5305f53 100644
17774 --- a/arch/x86/include/asm/realmode.h
17775 +++ b/arch/x86/include/asm/realmode.h
17776 @@ -22,16 +22,14 @@ struct real_mode_header {
17777 #endif
17778 /* APM/BIOS reboot */
17779 u32 machine_real_restart_asm;
17780 -#ifdef CONFIG_X86_64
17781 u32 machine_real_restart_seg;
17782 -#endif
17783 };
17784
17785 /* This must match data at trampoline_32/64.S */
17786 struct trampoline_header {
17787 #ifdef CONFIG_X86_32
17788 u32 start;
17789 - u16 gdt_pad;
17790 + u16 boot_cs;
17791 u16 gdt_limit;
17792 u32 gdt_base;
17793 #else
17794 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17795 index a82c4f1..ac45053 100644
17796 --- a/arch/x86/include/asm/reboot.h
17797 +++ b/arch/x86/include/asm/reboot.h
17798 @@ -6,13 +6,13 @@
17799 struct pt_regs;
17800
17801 struct machine_ops {
17802 - void (*restart)(char *cmd);
17803 - void (*halt)(void);
17804 - void (*power_off)(void);
17805 + void (* __noreturn restart)(char *cmd);
17806 + void (* __noreturn halt)(void);
17807 + void (* __noreturn power_off)(void);
17808 void (*shutdown)(void);
17809 void (*crash_shutdown)(struct pt_regs *);
17810 - void (*emergency_restart)(void);
17811 -};
17812 + void (* __noreturn emergency_restart)(void);
17813 +} __no_const;
17814
17815 extern struct machine_ops machine_ops;
17816
17817 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
17818 index 8f7866a..e442f20 100644
17819 --- a/arch/x86/include/asm/rmwcc.h
17820 +++ b/arch/x86/include/asm/rmwcc.h
17821 @@ -3,7 +3,34 @@
17822
17823 #ifdef CC_HAVE_ASM_GOTO
17824
17825 -#define __GEN_RMWcc(fullop, var, cc, ...) \
17826 +#ifdef CONFIG_PAX_REFCOUNT
17827 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17828 +do { \
17829 + asm_volatile_goto (fullop \
17830 + ";jno 0f\n" \
17831 + fullantiop \
17832 + ";int $4\n0:\n" \
17833 + _ASM_EXTABLE(0b, 0b) \
17834 + ";j" cc " %l[cc_label]" \
17835 + : : "m" (var), ## __VA_ARGS__ \
17836 + : "memory" : cc_label); \
17837 + return 0; \
17838 +cc_label: \
17839 + return 1; \
17840 +} while (0)
17841 +#else
17842 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17843 +do { \
17844 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
17845 + : : "m" (var), ## __VA_ARGS__ \
17846 + : "memory" : cc_label); \
17847 + return 0; \
17848 +cc_label: \
17849 + return 1; \
17850 +} while (0)
17851 +#endif
17852 +
17853 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
17854 do { \
17855 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
17856 : : "m" (var), ## __VA_ARGS__ \
17857 @@ -13,15 +40,46 @@ cc_label: \
17858 return 1; \
17859 } while (0)
17860
17861 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
17862 - __GEN_RMWcc(op " " arg0, var, cc)
17863 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
17864 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
17865
17866 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
17867 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
17868 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
17869 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
17870 +
17871 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
17872 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
17873 +
17874 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
17875 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
17876
17877 #else /* !CC_HAVE_ASM_GOTO */
17878
17879 -#define __GEN_RMWcc(fullop, var, cc, ...) \
17880 +#ifdef CONFIG_PAX_REFCOUNT
17881 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17882 +do { \
17883 + char c; \
17884 + asm volatile (fullop \
17885 + ";jno 0f\n" \
17886 + fullantiop \
17887 + ";int $4\n0:\n" \
17888 + _ASM_EXTABLE(0b, 0b) \
17889 + "; set" cc " %1" \
17890 + : "+m" (var), "=qm" (c) \
17891 + : __VA_ARGS__ : "memory"); \
17892 + return c != 0; \
17893 +} while (0)
17894 +#else
17895 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17896 +do { \
17897 + char c; \
17898 + asm volatile (fullop "; set" cc " %1" \
17899 + : "+m" (var), "=qm" (c) \
17900 + : __VA_ARGS__ : "memory"); \
17901 + return c != 0; \
17902 +} while (0)
17903 +#endif
17904 +
17905 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
17906 do { \
17907 char c; \
17908 asm volatile (fullop "; set" cc " %1" \
17909 @@ -30,11 +88,17 @@ do { \
17910 return c != 0; \
17911 } while (0)
17912
17913 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
17914 - __GEN_RMWcc(op " " arg0, var, cc)
17915 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
17916 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
17917 +
17918 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
17919 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
17920 +
17921 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
17922 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
17923
17924 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
17925 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
17926 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
17927 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
17928
17929 #endif /* CC_HAVE_ASM_GOTO */
17930
17931 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17932 index cad82c9..2e5c5c1 100644
17933 --- a/arch/x86/include/asm/rwsem.h
17934 +++ b/arch/x86/include/asm/rwsem.h
17935 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17936 {
17937 asm volatile("# beginning down_read\n\t"
17938 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17939 +
17940 +#ifdef CONFIG_PAX_REFCOUNT
17941 + "jno 0f\n"
17942 + LOCK_PREFIX _ASM_DEC "(%1)\n"
17943 + "int $4\n0:\n"
17944 + _ASM_EXTABLE(0b, 0b)
17945 +#endif
17946 +
17947 /* adds 0x00000001 */
17948 " jns 1f\n"
17949 " call call_rwsem_down_read_failed\n"
17950 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17951 "1:\n\t"
17952 " mov %1,%2\n\t"
17953 " add %3,%2\n\t"
17954 +
17955 +#ifdef CONFIG_PAX_REFCOUNT
17956 + "jno 0f\n"
17957 + "sub %3,%2\n"
17958 + "int $4\n0:\n"
17959 + _ASM_EXTABLE(0b, 0b)
17960 +#endif
17961 +
17962 " jle 2f\n\t"
17963 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17964 " jnz 1b\n\t"
17965 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17966 long tmp;
17967 asm volatile("# beginning down_write\n\t"
17968 LOCK_PREFIX " xadd %1,(%2)\n\t"
17969 +
17970 +#ifdef CONFIG_PAX_REFCOUNT
17971 + "jno 0f\n"
17972 + "mov %1,(%2)\n"
17973 + "int $4\n0:\n"
17974 + _ASM_EXTABLE(0b, 0b)
17975 +#endif
17976 +
17977 /* adds 0xffff0001, returns the old value */
17978 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17979 /* was the active mask 0 before? */
17980 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17981 long tmp;
17982 asm volatile("# beginning __up_read\n\t"
17983 LOCK_PREFIX " xadd %1,(%2)\n\t"
17984 +
17985 +#ifdef CONFIG_PAX_REFCOUNT
17986 + "jno 0f\n"
17987 + "mov %1,(%2)\n"
17988 + "int $4\n0:\n"
17989 + _ASM_EXTABLE(0b, 0b)
17990 +#endif
17991 +
17992 /* subtracts 1, returns the old value */
17993 " jns 1f\n\t"
17994 " call call_rwsem_wake\n" /* expects old value in %edx */
17995 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17996 long tmp;
17997 asm volatile("# beginning __up_write\n\t"
17998 LOCK_PREFIX " xadd %1,(%2)\n\t"
17999 +
18000 +#ifdef CONFIG_PAX_REFCOUNT
18001 + "jno 0f\n"
18002 + "mov %1,(%2)\n"
18003 + "int $4\n0:\n"
18004 + _ASM_EXTABLE(0b, 0b)
18005 +#endif
18006 +
18007 /* subtracts 0xffff0001, returns the old value */
18008 " jns 1f\n\t"
18009 " call call_rwsem_wake\n" /* expects old value in %edx */
18010 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18011 {
18012 asm volatile("# beginning __downgrade_write\n\t"
18013 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18014 +
18015 +#ifdef CONFIG_PAX_REFCOUNT
18016 + "jno 0f\n"
18017 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18018 + "int $4\n0:\n"
18019 + _ASM_EXTABLE(0b, 0b)
18020 +#endif
18021 +
18022 /*
18023 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18024 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18025 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18026 */
18027 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18028 {
18029 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18030 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18031 +
18032 +#ifdef CONFIG_PAX_REFCOUNT
18033 + "jno 0f\n"
18034 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18035 + "int $4\n0:\n"
18036 + _ASM_EXTABLE(0b, 0b)
18037 +#endif
18038 +
18039 : "+m" (sem->count)
18040 : "er" (delta));
18041 }
18042 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18043 */
18044 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18045 {
18046 - return delta + xadd(&sem->count, delta);
18047 + return delta + xadd_check_overflow(&sem->count, delta);
18048 }
18049
18050 #endif /* __KERNEL__ */
18051 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18052 index 6f1c3a8..7744f19 100644
18053 --- a/arch/x86/include/asm/segment.h
18054 +++ b/arch/x86/include/asm/segment.h
18055 @@ -64,10 +64,15 @@
18056 * 26 - ESPFIX small SS
18057 * 27 - per-cpu [ offset to per-cpu data area ]
18058 * 28 - stack_canary-20 [ for stack protector ]
18059 - * 29 - unused
18060 - * 30 - unused
18061 + * 29 - PCI BIOS CS
18062 + * 30 - PCI BIOS DS
18063 * 31 - TSS for double fault handler
18064 */
18065 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18066 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18067 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18068 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18069 +
18070 #define GDT_ENTRY_TLS_MIN 6
18071 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18072
18073 @@ -79,6 +84,8 @@
18074
18075 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18076
18077 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18078 +
18079 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18080
18081 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18082 @@ -104,6 +111,12 @@
18083 #define __KERNEL_STACK_CANARY 0
18084 #endif
18085
18086 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18087 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18088 +
18089 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18090 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18091 +
18092 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18093
18094 /*
18095 @@ -141,7 +154,7 @@
18096 */
18097
18098 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18099 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18100 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18101
18102
18103 #else
18104 @@ -165,6 +178,8 @@
18105 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18106 #define __USER32_DS __USER_DS
18107
18108 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18109 +
18110 #define GDT_ENTRY_TSS 8 /* needs two entries */
18111 #define GDT_ENTRY_LDT 10 /* needs two entries */
18112 #define GDT_ENTRY_TLS_MIN 12
18113 @@ -173,6 +188,8 @@
18114 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18115 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18116
18117 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18118 +
18119 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18120 #define FS_TLS 0
18121 #define GS_TLS 1
18122 @@ -180,12 +197,14 @@
18123 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18124 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18125
18126 -#define GDT_ENTRIES 16
18127 +#define GDT_ENTRIES 17
18128
18129 #endif
18130
18131 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18132 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18133 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18134 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18135 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18136 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18137 #ifndef CONFIG_PARAVIRT
18138 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18139 {
18140 unsigned long __limit;
18141 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18142 - return __limit + 1;
18143 + return __limit;
18144 }
18145
18146 #endif /* !__ASSEMBLY__ */
18147 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18148 index 8d3120f..352b440 100644
18149 --- a/arch/x86/include/asm/smap.h
18150 +++ b/arch/x86/include/asm/smap.h
18151 @@ -25,11 +25,40 @@
18152
18153 #include <asm/alternative-asm.h>
18154
18155 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18156 +#define ASM_PAX_OPEN_USERLAND \
18157 + 661: jmp 663f; \
18158 + .pushsection .altinstr_replacement, "a" ; \
18159 + 662: pushq %rax; nop; \
18160 + .popsection ; \
18161 + .pushsection .altinstructions, "a" ; \
18162 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18163 + .popsection ; \
18164 + call __pax_open_userland; \
18165 + popq %rax; \
18166 + 663:
18167 +
18168 +#define ASM_PAX_CLOSE_USERLAND \
18169 + 661: jmp 663f; \
18170 + .pushsection .altinstr_replacement, "a" ; \
18171 + 662: pushq %rax; nop; \
18172 + .popsection; \
18173 + .pushsection .altinstructions, "a" ; \
18174 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18175 + .popsection; \
18176 + call __pax_close_userland; \
18177 + popq %rax; \
18178 + 663:
18179 +#else
18180 +#define ASM_PAX_OPEN_USERLAND
18181 +#define ASM_PAX_CLOSE_USERLAND
18182 +#endif
18183 +
18184 #ifdef CONFIG_X86_SMAP
18185
18186 #define ASM_CLAC \
18187 661: ASM_NOP3 ; \
18188 - .pushsection .altinstr_replacement, "ax" ; \
18189 + .pushsection .altinstr_replacement, "a" ; \
18190 662: __ASM_CLAC ; \
18191 .popsection ; \
18192 .pushsection .altinstructions, "a" ; \
18193 @@ -38,7 +67,7 @@
18194
18195 #define ASM_STAC \
18196 661: ASM_NOP3 ; \
18197 - .pushsection .altinstr_replacement, "ax" ; \
18198 + .pushsection .altinstr_replacement, "a" ; \
18199 662: __ASM_STAC ; \
18200 .popsection ; \
18201 .pushsection .altinstructions, "a" ; \
18202 @@ -56,6 +85,37 @@
18203
18204 #include <asm/alternative.h>
18205
18206 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18207 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18208 +
18209 +extern void __pax_open_userland(void);
18210 +static __always_inline unsigned long pax_open_userland(void)
18211 +{
18212 +
18213 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18214 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18215 + :
18216 + : [open] "i" (__pax_open_userland)
18217 + : "memory", "rax");
18218 +#endif
18219 +
18220 + return 0;
18221 +}
18222 +
18223 +extern void __pax_close_userland(void);
18224 +static __always_inline unsigned long pax_close_userland(void)
18225 +{
18226 +
18227 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18228 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18229 + :
18230 + : [close] "i" (__pax_close_userland)
18231 + : "memory", "rax");
18232 +#endif
18233 +
18234 + return 0;
18235 +}
18236 +
18237 #ifdef CONFIG_X86_SMAP
18238
18239 static __always_inline void clac(void)
18240 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18241 index 4137890..03fa172 100644
18242 --- a/arch/x86/include/asm/smp.h
18243 +++ b/arch/x86/include/asm/smp.h
18244 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18245 /* cpus sharing the last level cache: */
18246 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18247 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18248 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18249 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18250
18251 static inline struct cpumask *cpu_sibling_mask(int cpu)
18252 {
18253 @@ -79,7 +79,7 @@ struct smp_ops {
18254
18255 void (*send_call_func_ipi)(const struct cpumask *mask);
18256 void (*send_call_func_single_ipi)(int cpu);
18257 -};
18258 +} __no_const;
18259
18260 /* Globals due to paravirt */
18261 extern void set_cpu_sibling_map(int cpu);
18262 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18263 extern int safe_smp_processor_id(void);
18264
18265 #elif defined(CONFIG_X86_64_SMP)
18266 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18267 -
18268 -#define stack_smp_processor_id() \
18269 -({ \
18270 - struct thread_info *ti; \
18271 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18272 - ti->cpu; \
18273 -})
18274 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18275 +#define stack_smp_processor_id() raw_smp_processor_id()
18276 #define safe_smp_processor_id() smp_processor_id()
18277
18278 #endif
18279 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18280 index bf156de..1a782ab 100644
18281 --- a/arch/x86/include/asm/spinlock.h
18282 +++ b/arch/x86/include/asm/spinlock.h
18283 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18284 static inline void arch_read_lock(arch_rwlock_t *rw)
18285 {
18286 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18287 +
18288 +#ifdef CONFIG_PAX_REFCOUNT
18289 + "jno 0f\n"
18290 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18291 + "int $4\n0:\n"
18292 + _ASM_EXTABLE(0b, 0b)
18293 +#endif
18294 +
18295 "jns 1f\n"
18296 "call __read_lock_failed\n\t"
18297 "1:\n"
18298 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18299 static inline void arch_write_lock(arch_rwlock_t *rw)
18300 {
18301 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18302 +
18303 +#ifdef CONFIG_PAX_REFCOUNT
18304 + "jno 0f\n"
18305 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18306 + "int $4\n0:\n"
18307 + _ASM_EXTABLE(0b, 0b)
18308 +#endif
18309 +
18310 "jz 1f\n"
18311 "call __write_lock_failed\n\t"
18312 "1:\n"
18313 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18314
18315 static inline void arch_read_unlock(arch_rwlock_t *rw)
18316 {
18317 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18318 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18319 +
18320 +#ifdef CONFIG_PAX_REFCOUNT
18321 + "jno 0f\n"
18322 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18323 + "int $4\n0:\n"
18324 + _ASM_EXTABLE(0b, 0b)
18325 +#endif
18326 +
18327 :"+m" (rw->lock) : : "memory");
18328 }
18329
18330 static inline void arch_write_unlock(arch_rwlock_t *rw)
18331 {
18332 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18333 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18334 +
18335 +#ifdef CONFIG_PAX_REFCOUNT
18336 + "jno 0f\n"
18337 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18338 + "int $4\n0:\n"
18339 + _ASM_EXTABLE(0b, 0b)
18340 +#endif
18341 +
18342 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18343 }
18344
18345 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18346 index 6a99859..03cb807 100644
18347 --- a/arch/x86/include/asm/stackprotector.h
18348 +++ b/arch/x86/include/asm/stackprotector.h
18349 @@ -47,7 +47,7 @@
18350 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18351 */
18352 #define GDT_STACK_CANARY_INIT \
18353 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18354 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18355
18356 /*
18357 * Initialize the stackprotector canary value.
18358 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18359
18360 static inline void load_stack_canary_segment(void)
18361 {
18362 -#ifdef CONFIG_X86_32
18363 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18364 asm volatile ("mov %0, %%gs" : : "r" (0));
18365 #endif
18366 }
18367 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18368 index 70bbe39..4ae2bd4 100644
18369 --- a/arch/x86/include/asm/stacktrace.h
18370 +++ b/arch/x86/include/asm/stacktrace.h
18371 @@ -11,28 +11,20 @@
18372
18373 extern int kstack_depth_to_print;
18374
18375 -struct thread_info;
18376 +struct task_struct;
18377 struct stacktrace_ops;
18378
18379 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18380 - unsigned long *stack,
18381 - unsigned long bp,
18382 - const struct stacktrace_ops *ops,
18383 - void *data,
18384 - unsigned long *end,
18385 - int *graph);
18386 +typedef unsigned long walk_stack_t(struct task_struct *task,
18387 + void *stack_start,
18388 + unsigned long *stack,
18389 + unsigned long bp,
18390 + const struct stacktrace_ops *ops,
18391 + void *data,
18392 + unsigned long *end,
18393 + int *graph);
18394
18395 -extern unsigned long
18396 -print_context_stack(struct thread_info *tinfo,
18397 - unsigned long *stack, unsigned long bp,
18398 - const struct stacktrace_ops *ops, void *data,
18399 - unsigned long *end, int *graph);
18400 -
18401 -extern unsigned long
18402 -print_context_stack_bp(struct thread_info *tinfo,
18403 - unsigned long *stack, unsigned long bp,
18404 - const struct stacktrace_ops *ops, void *data,
18405 - unsigned long *end, int *graph);
18406 +extern walk_stack_t print_context_stack;
18407 +extern walk_stack_t print_context_stack_bp;
18408
18409 /* Generic stack tracer with callbacks */
18410
18411 @@ -40,7 +32,7 @@ struct stacktrace_ops {
18412 void (*address)(void *data, unsigned long address, int reliable);
18413 /* On negative return stop dumping */
18414 int (*stack)(void *data, char *name);
18415 - walk_stack_t walk_stack;
18416 + walk_stack_t *walk_stack;
18417 };
18418
18419 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18420 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18421 index d7f3b3b..3cc39f1 100644
18422 --- a/arch/x86/include/asm/switch_to.h
18423 +++ b/arch/x86/include/asm/switch_to.h
18424 @@ -108,7 +108,7 @@ do { \
18425 "call __switch_to\n\t" \
18426 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18427 __switch_canary \
18428 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
18429 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18430 "movq %%rax,%%rdi\n\t" \
18431 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18432 "jnz ret_from_fork\n\t" \
18433 @@ -119,7 +119,7 @@ do { \
18434 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18435 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18436 [_tif_fork] "i" (_TIF_FORK), \
18437 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
18438 + [thread_info] "m" (current_tinfo), \
18439 [current_task] "m" (current_task) \
18440 __switch_canary_iparam \
18441 : "memory", "cc" __EXTRA_CLOBBER)
18442 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18443 index 3ba3de4..6c113b2 100644
18444 --- a/arch/x86/include/asm/thread_info.h
18445 +++ b/arch/x86/include/asm/thread_info.h
18446 @@ -10,6 +10,7 @@
18447 #include <linux/compiler.h>
18448 #include <asm/page.h>
18449 #include <asm/types.h>
18450 +#include <asm/percpu.h>
18451
18452 /*
18453 * low level task data that entry.S needs immediate access to
18454 @@ -23,7 +24,6 @@ struct exec_domain;
18455 #include <linux/atomic.h>
18456
18457 struct thread_info {
18458 - struct task_struct *task; /* main task structure */
18459 struct exec_domain *exec_domain; /* execution domain */
18460 __u32 flags; /* low level flags */
18461 __u32 status; /* thread synchronous flags */
18462 @@ -32,19 +32,13 @@ struct thread_info {
18463 mm_segment_t addr_limit;
18464 struct restart_block restart_block;
18465 void __user *sysenter_return;
18466 -#ifdef CONFIG_X86_32
18467 - unsigned long previous_esp; /* ESP of the previous stack in
18468 - case of nested (IRQ) stacks
18469 - */
18470 - __u8 supervisor_stack[0];
18471 -#endif
18472 + unsigned long lowest_stack;
18473 unsigned int sig_on_uaccess_error:1;
18474 unsigned int uaccess_err:1; /* uaccess failed */
18475 };
18476
18477 -#define INIT_THREAD_INFO(tsk) \
18478 +#define INIT_THREAD_INFO \
18479 { \
18480 - .task = &tsk, \
18481 .exec_domain = &default_exec_domain, \
18482 .flags = 0, \
18483 .cpu = 0, \
18484 @@ -55,7 +49,7 @@ struct thread_info {
18485 }, \
18486 }
18487
18488 -#define init_thread_info (init_thread_union.thread_info)
18489 +#define init_thread_info (init_thread_union.stack)
18490 #define init_stack (init_thread_union.stack)
18491
18492 #else /* !__ASSEMBLY__ */
18493 @@ -95,6 +89,7 @@ struct thread_info {
18494 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18495 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18496 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18497 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18498
18499 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18500 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18501 @@ -118,17 +113,18 @@ struct thread_info {
18502 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18503 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18504 #define _TIF_X32 (1 << TIF_X32)
18505 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18506
18507 /* work to do in syscall_trace_enter() */
18508 #define _TIF_WORK_SYSCALL_ENTRY \
18509 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18510 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18511 - _TIF_NOHZ)
18512 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18513
18514 /* work to do in syscall_trace_leave() */
18515 #define _TIF_WORK_SYSCALL_EXIT \
18516 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18517 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18518 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18519
18520 /* work to do on interrupt/exception return */
18521 #define _TIF_WORK_MASK \
18522 @@ -139,7 +135,7 @@ struct thread_info {
18523 /* work to do on any return to user space */
18524 #define _TIF_ALLWORK_MASK \
18525 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18526 - _TIF_NOHZ)
18527 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18528
18529 /* Only used for 64 bit */
18530 #define _TIF_DO_NOTIFY_MASK \
18531 @@ -153,45 +149,40 @@ struct thread_info {
18532 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
18533 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
18534
18535 -#ifdef CONFIG_X86_32
18536 -
18537 -#define STACK_WARN (THREAD_SIZE/8)
18538 -/*
18539 - * macros/functions for gaining access to the thread information structure
18540 - *
18541 - * preempt_count needs to be 1 initially, until the scheduler is functional.
18542 - */
18543 -#ifndef __ASSEMBLY__
18544 -
18545 -
18546 -/* how to get the current stack pointer from C */
18547 -register unsigned long current_stack_pointer asm("esp") __used;
18548 -
18549 -/* how to get the thread information struct from C */
18550 -static inline struct thread_info *current_thread_info(void)
18551 -{
18552 - return (struct thread_info *)
18553 - (current_stack_pointer & ~(THREAD_SIZE - 1));
18554 -}
18555 -
18556 -#else /* !__ASSEMBLY__ */
18557 -
18558 +#ifdef __ASSEMBLY__
18559 /* how to get the thread information struct from ASM */
18560 #define GET_THREAD_INFO(reg) \
18561 - movl $-THREAD_SIZE, reg; \
18562 - andl %esp, reg
18563 + mov PER_CPU_VAR(current_tinfo), reg
18564
18565 /* use this one if reg already contains %esp */
18566 -#define GET_THREAD_INFO_WITH_ESP(reg) \
18567 - andl $-THREAD_SIZE, reg
18568 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18569 +#else
18570 +/* how to get the thread information struct from C */
18571 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18572 +
18573 +static __always_inline struct thread_info *current_thread_info(void)
18574 +{
18575 + return this_cpu_read_stable(current_tinfo);
18576 +}
18577 +#endif
18578 +
18579 +#ifdef CONFIG_X86_32
18580 +
18581 +#define STACK_WARN (THREAD_SIZE/8)
18582 +/*
18583 + * macros/functions for gaining access to the thread information structure
18584 + *
18585 + * preempt_count needs to be 1 initially, until the scheduler is functional.
18586 + */
18587 +#ifndef __ASSEMBLY__
18588 +
18589 +/* how to get the current stack pointer from C */
18590 +register unsigned long current_stack_pointer asm("esp") __used;
18591
18592 #endif
18593
18594 #else /* X86_32 */
18595
18596 -#include <asm/percpu.h>
18597 -#define KERNEL_STACK_OFFSET (5*8)
18598 -
18599 /*
18600 * macros/functions for gaining access to the thread information structure
18601 * preempt_count needs to be 1 initially, until the scheduler is functional.
18602 @@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
18603 #ifndef __ASSEMBLY__
18604 DECLARE_PER_CPU(unsigned long, kernel_stack);
18605
18606 -static inline struct thread_info *current_thread_info(void)
18607 -{
18608 - struct thread_info *ti;
18609 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
18610 - KERNEL_STACK_OFFSET - THREAD_SIZE);
18611 - return ti;
18612 -}
18613 -
18614 -#else /* !__ASSEMBLY__ */
18615 -
18616 -/* how to get the thread information struct from ASM */
18617 -#define GET_THREAD_INFO(reg) \
18618 - movq PER_CPU_VAR(kernel_stack),reg ; \
18619 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
18620 -
18621 -/*
18622 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
18623 - * a certain register (to be used in assembler memory operands).
18624 - */
18625 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
18626 -
18627 +/* how to get the current stack pointer from C */
18628 +register unsigned long current_stack_pointer asm("rsp") __used;
18629 #endif
18630
18631 #endif /* !X86_32 */
18632 @@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
18633 extern void arch_task_cache_init(void);
18634 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
18635 extern void arch_release_task_struct(struct task_struct *tsk);
18636 +
18637 +#define __HAVE_THREAD_FUNCTIONS
18638 +#define task_thread_info(task) (&(task)->tinfo)
18639 +#define task_stack_page(task) ((task)->stack)
18640 +#define setup_thread_stack(p, org) do {} while (0)
18641 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
18642 +
18643 #endif
18644 #endif /* _ASM_X86_THREAD_INFO_H */
18645 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
18646 index e6d90ba..0897f44 100644
18647 --- a/arch/x86/include/asm/tlbflush.h
18648 +++ b/arch/x86/include/asm/tlbflush.h
18649 @@ -17,18 +17,44 @@
18650
18651 static inline void __native_flush_tlb(void)
18652 {
18653 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18654 + u64 descriptor[2];
18655 +
18656 + descriptor[0] = PCID_KERNEL;
18657 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
18658 + return;
18659 + }
18660 +
18661 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18662 + if (static_cpu_has(X86_FEATURE_PCID)) {
18663 + unsigned int cpu = raw_get_cpu();
18664 +
18665 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18666 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18667 + raw_put_cpu_no_resched();
18668 + return;
18669 + }
18670 +#endif
18671 +
18672 native_write_cr3(native_read_cr3());
18673 }
18674
18675 static inline void __native_flush_tlb_global_irq_disabled(void)
18676 {
18677 - unsigned long cr4;
18678 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18679 + u64 descriptor[2];
18680
18681 - cr4 = native_read_cr4();
18682 - /* clear PGE */
18683 - native_write_cr4(cr4 & ~X86_CR4_PGE);
18684 - /* write old PGE again and flush TLBs */
18685 - native_write_cr4(cr4);
18686 + descriptor[0] = PCID_KERNEL;
18687 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
18688 + } else {
18689 + unsigned long cr4;
18690 +
18691 + cr4 = native_read_cr4();
18692 + /* clear PGE */
18693 + native_write_cr4(cr4 & ~X86_CR4_PGE);
18694 + /* write old PGE again and flush TLBs */
18695 + native_write_cr4(cr4);
18696 + }
18697 }
18698
18699 static inline void __native_flush_tlb_global(void)
18700 @@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
18701
18702 static inline void __native_flush_tlb_single(unsigned long addr)
18703 {
18704 +
18705 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18706 + u64 descriptor[2];
18707 +
18708 + descriptor[0] = PCID_KERNEL;
18709 + descriptor[1] = addr;
18710 +
18711 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18712 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
18713 + if (addr < TASK_SIZE_MAX)
18714 + descriptor[1] += pax_user_shadow_base;
18715 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18716 + }
18717 +
18718 + descriptor[0] = PCID_USER;
18719 + descriptor[1] = addr;
18720 +#endif
18721 +
18722 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18723 + return;
18724 + }
18725 +
18726 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18727 + if (static_cpu_has(X86_FEATURE_PCID)) {
18728 + unsigned int cpu = raw_get_cpu();
18729 +
18730 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
18731 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18732 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18733 + raw_put_cpu_no_resched();
18734 +
18735 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
18736 + addr += pax_user_shadow_base;
18737 + }
18738 +#endif
18739 +
18740 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18741 }
18742
18743 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
18744 index 8ec57c0..3ee58c9 100644
18745 --- a/arch/x86/include/asm/uaccess.h
18746 +++ b/arch/x86/include/asm/uaccess.h
18747 @@ -7,6 +7,7 @@
18748 #include <linux/compiler.h>
18749 #include <linux/thread_info.h>
18750 #include <linux/string.h>
18751 +#include <linux/spinlock.h>
18752 #include <asm/asm.h>
18753 #include <asm/page.h>
18754 #include <asm/smap.h>
18755 @@ -29,7 +30,12 @@
18756
18757 #define get_ds() (KERNEL_DS)
18758 #define get_fs() (current_thread_info()->addr_limit)
18759 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18760 +void __set_fs(mm_segment_t x);
18761 +void set_fs(mm_segment_t x);
18762 +#else
18763 #define set_fs(x) (current_thread_info()->addr_limit = (x))
18764 +#endif
18765
18766 #define segment_eq(a, b) ((a).seg == (b).seg)
18767
18768 @@ -77,8 +83,34 @@
18769 * checks that the pointer is in the user space range - after calling
18770 * this function, memory access functions may still return -EFAULT.
18771 */
18772 -#define access_ok(type, addr, size) \
18773 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18774 +extern int _cond_resched(void);
18775 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18776 +#define access_ok(type, addr, size) \
18777 +({ \
18778 + long __size = size; \
18779 + unsigned long __addr = (unsigned long)addr; \
18780 + unsigned long __addr_ao = __addr & PAGE_MASK; \
18781 + unsigned long __end_ao = __addr + __size - 1; \
18782 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
18783 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
18784 + while(__addr_ao <= __end_ao) { \
18785 + char __c_ao; \
18786 + __addr_ao += PAGE_SIZE; \
18787 + if (__size > PAGE_SIZE) \
18788 + _cond_resched(); \
18789 + if (__get_user(__c_ao, (char __user *)__addr)) \
18790 + break; \
18791 + if (type != VERIFY_WRITE) { \
18792 + __addr = __addr_ao; \
18793 + continue; \
18794 + } \
18795 + if (__put_user(__c_ao, (char __user *)__addr)) \
18796 + break; \
18797 + __addr = __addr_ao; \
18798 + } \
18799 + } \
18800 + __ret_ao; \
18801 +})
18802
18803 /*
18804 * The exception table consists of pairs of addresses relative to the
18805 @@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18806 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
18807 __chk_user_ptr(ptr); \
18808 might_fault(); \
18809 + pax_open_userland(); \
18810 asm volatile("call __get_user_%P3" \
18811 : "=a" (__ret_gu), "=r" (__val_gu) \
18812 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18813 (x) = (__typeof__(*(ptr))) __val_gu; \
18814 + pax_close_userland(); \
18815 __ret_gu; \
18816 })
18817
18818 @@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18819 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18820 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18821
18822 -
18823 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18824 +#define __copyuser_seg "gs;"
18825 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18826 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18827 +#else
18828 +#define __copyuser_seg
18829 +#define __COPYUSER_SET_ES
18830 +#define __COPYUSER_RESTORE_ES
18831 +#endif
18832
18833 #ifdef CONFIG_X86_32
18834 #define __put_user_asm_u64(x, addr, err, errret) \
18835 asm volatile(ASM_STAC "\n" \
18836 - "1: movl %%eax,0(%2)\n" \
18837 - "2: movl %%edx,4(%2)\n" \
18838 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18839 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18840 "3: " ASM_CLAC "\n" \
18841 ".section .fixup,\"ax\"\n" \
18842 "4: movl %3,%0\n" \
18843 @@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18844
18845 #define __put_user_asm_ex_u64(x, addr) \
18846 asm volatile(ASM_STAC "\n" \
18847 - "1: movl %%eax,0(%1)\n" \
18848 - "2: movl %%edx,4(%1)\n" \
18849 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18850 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18851 "3: " ASM_CLAC "\n" \
18852 _ASM_EXTABLE_EX(1b, 2b) \
18853 _ASM_EXTABLE_EX(2b, 3b) \
18854 @@ -249,7 +291,8 @@ extern void __put_user_8(void);
18855 __typeof__(*(ptr)) __pu_val; \
18856 __chk_user_ptr(ptr); \
18857 might_fault(); \
18858 - __pu_val = x; \
18859 + __pu_val = (x); \
18860 + pax_open_userland(); \
18861 switch (sizeof(*(ptr))) { \
18862 case 1: \
18863 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18864 @@ -267,6 +310,7 @@ extern void __put_user_8(void);
18865 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18866 break; \
18867 } \
18868 + pax_close_userland(); \
18869 __ret_pu; \
18870 })
18871
18872 @@ -347,8 +391,10 @@ do { \
18873 } while (0)
18874
18875 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18876 +do { \
18877 + pax_open_userland(); \
18878 asm volatile(ASM_STAC "\n" \
18879 - "1: mov"itype" %2,%"rtype"1\n" \
18880 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18881 "2: " ASM_CLAC "\n" \
18882 ".section .fixup,\"ax\"\n" \
18883 "3: mov %3,%0\n" \
18884 @@ -356,8 +402,10 @@ do { \
18885 " jmp 2b\n" \
18886 ".previous\n" \
18887 _ASM_EXTABLE(1b, 3b) \
18888 - : "=r" (err), ltype(x) \
18889 - : "m" (__m(addr)), "i" (errret), "0" (err))
18890 + : "=r" (err), ltype (x) \
18891 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
18892 + pax_close_userland(); \
18893 +} while (0)
18894
18895 #define __get_user_size_ex(x, ptr, size) \
18896 do { \
18897 @@ -381,7 +429,7 @@ do { \
18898 } while (0)
18899
18900 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18901 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18902 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18903 "2:\n" \
18904 _ASM_EXTABLE_EX(1b, 2b) \
18905 : ltype(x) : "m" (__m(addr)))
18906 @@ -398,13 +446,24 @@ do { \
18907 int __gu_err; \
18908 unsigned long __gu_val; \
18909 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18910 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
18911 + (x) = (__typeof__(*(ptr)))__gu_val; \
18912 __gu_err; \
18913 })
18914
18915 /* FIXME: this hack is definitely wrong -AK */
18916 struct __large_struct { unsigned long buf[100]; };
18917 -#define __m(x) (*(struct __large_struct __user *)(x))
18918 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18919 +#define ____m(x) \
18920 +({ \
18921 + unsigned long ____x = (unsigned long)(x); \
18922 + if (____x < pax_user_shadow_base) \
18923 + ____x += pax_user_shadow_base; \
18924 + (typeof(x))____x; \
18925 +})
18926 +#else
18927 +#define ____m(x) (x)
18928 +#endif
18929 +#define __m(x) (*(struct __large_struct __user *)____m(x))
18930
18931 /*
18932 * Tell gcc we read from memory instead of writing: this is because
18933 @@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
18934 * aliasing issues.
18935 */
18936 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18937 +do { \
18938 + pax_open_userland(); \
18939 asm volatile(ASM_STAC "\n" \
18940 - "1: mov"itype" %"rtype"1,%2\n" \
18941 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18942 "2: " ASM_CLAC "\n" \
18943 ".section .fixup,\"ax\"\n" \
18944 "3: mov %3,%0\n" \
18945 @@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
18946 ".previous\n" \
18947 _ASM_EXTABLE(1b, 3b) \
18948 : "=r"(err) \
18949 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18950 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18951 + pax_close_userland(); \
18952 +} while (0)
18953
18954 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18955 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18956 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18957 "2:\n" \
18958 _ASM_EXTABLE_EX(1b, 2b) \
18959 : : ltype(x), "m" (__m(addr)))
18960 @@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
18961 */
18962 #define uaccess_try do { \
18963 current_thread_info()->uaccess_err = 0; \
18964 + pax_open_userland(); \
18965 stac(); \
18966 barrier();
18967
18968 #define uaccess_catch(err) \
18969 clac(); \
18970 + pax_close_userland(); \
18971 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18972 } while (0)
18973
18974 @@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
18975 * On error, the variable @x is set to zero.
18976 */
18977
18978 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18979 +#define __get_user(x, ptr) get_user((x), (ptr))
18980 +#else
18981 #define __get_user(x, ptr) \
18982 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18983 +#endif
18984
18985 /**
18986 * __put_user: - Write a simple value into user space, with less checking.
18987 @@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
18988 * Returns zero on success, or -EFAULT on error.
18989 */
18990
18991 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18992 +#define __put_user(x, ptr) put_user((x), (ptr))
18993 +#else
18994 #define __put_user(x, ptr) \
18995 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18996 +#endif
18997
18998 #define __get_user_unaligned __get_user
18999 #define __put_user_unaligned __put_user
19000 @@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19001 #define get_user_ex(x, ptr) do { \
19002 unsigned long __gue_val; \
19003 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19004 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19005 + (x) = (__typeof__(*(ptr)))__gue_val; \
19006 } while (0)
19007
19008 #define put_user_try uaccess_try
19009 @@ -536,17 +609,6 @@ extern struct movsl_mask {
19010
19011 #define ARCH_HAS_NOCACHE_UACCESS 1
19012
19013 -#ifdef CONFIG_X86_32
19014 -# include <asm/uaccess_32.h>
19015 -#else
19016 -# include <asm/uaccess_64.h>
19017 -#endif
19018 -
19019 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19020 - unsigned n);
19021 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19022 - unsigned n);
19023 -
19024 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19025 # define copy_user_diag __compiletime_error
19026 #else
19027 @@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19028 extern void copy_user_diag("copy_from_user() buffer size is too small")
19029 copy_from_user_overflow(void);
19030 extern void copy_user_diag("copy_to_user() buffer size is too small")
19031 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19032 +copy_to_user_overflow(void);
19033
19034 #undef copy_user_diag
19035
19036 @@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19037
19038 extern void
19039 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19040 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19041 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19042 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19043
19044 #else
19045 @@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19046
19047 #endif
19048
19049 +#ifdef CONFIG_X86_32
19050 +# include <asm/uaccess_32.h>
19051 +#else
19052 +# include <asm/uaccess_64.h>
19053 +#endif
19054 +
19055 static inline unsigned long __must_check
19056 copy_from_user(void *to, const void __user *from, unsigned long n)
19057 {
19058 - int sz = __compiletime_object_size(to);
19059 + size_t sz = __compiletime_object_size(to);
19060
19061 might_fault();
19062
19063 @@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19064 * case, and do only runtime checking for non-constant sizes.
19065 */
19066
19067 - if (likely(sz < 0 || sz >= n))
19068 - n = _copy_from_user(to, from, n);
19069 - else if(__builtin_constant_p(n))
19070 - copy_from_user_overflow();
19071 - else
19072 - __copy_from_user_overflow(sz, n);
19073 + if (likely(sz != (size_t)-1 && sz < n)) {
19074 + if(__builtin_constant_p(n))
19075 + copy_from_user_overflow();
19076 + else
19077 + __copy_from_user_overflow(sz, n);
19078 + } if (access_ok(VERIFY_READ, from, n))
19079 + n = __copy_from_user(to, from, n);
19080 + else if ((long)n > 0)
19081 + memset(to, 0, n);
19082
19083 return n;
19084 }
19085 @@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19086 static inline unsigned long __must_check
19087 copy_to_user(void __user *to, const void *from, unsigned long n)
19088 {
19089 - int sz = __compiletime_object_size(from);
19090 + size_t sz = __compiletime_object_size(from);
19091
19092 might_fault();
19093
19094 /* See the comment in copy_from_user() above. */
19095 - if (likely(sz < 0 || sz >= n))
19096 - n = _copy_to_user(to, from, n);
19097 - else if(__builtin_constant_p(n))
19098 - copy_to_user_overflow();
19099 - else
19100 - __copy_to_user_overflow(sz, n);
19101 + if (likely(sz != (size_t)-1 && sz < n)) {
19102 + if(__builtin_constant_p(n))
19103 + copy_to_user_overflow();
19104 + else
19105 + __copy_to_user_overflow(sz, n);
19106 + } else if (access_ok(VERIFY_WRITE, to, n))
19107 + n = __copy_to_user(to, from, n);
19108
19109 return n;
19110 }
19111 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19112 index 3c03a5d..1071638 100644
19113 --- a/arch/x86/include/asm/uaccess_32.h
19114 +++ b/arch/x86/include/asm/uaccess_32.h
19115 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19116 static __always_inline unsigned long __must_check
19117 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19118 {
19119 + if ((long)n < 0)
19120 + return n;
19121 +
19122 + check_object_size(from, n, true);
19123 +
19124 if (__builtin_constant_p(n)) {
19125 unsigned long ret;
19126
19127 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19128 __copy_to_user(void __user *to, const void *from, unsigned long n)
19129 {
19130 might_fault();
19131 +
19132 return __copy_to_user_inatomic(to, from, n);
19133 }
19134
19135 static __always_inline unsigned long
19136 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19137 {
19138 + if ((long)n < 0)
19139 + return n;
19140 +
19141 /* Avoid zeroing the tail if the copy fails..
19142 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19143 * but as the zeroing behaviour is only significant when n is not
19144 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19145 __copy_from_user(void *to, const void __user *from, unsigned long n)
19146 {
19147 might_fault();
19148 +
19149 + if ((long)n < 0)
19150 + return n;
19151 +
19152 + check_object_size(to, n, false);
19153 +
19154 if (__builtin_constant_p(n)) {
19155 unsigned long ret;
19156
19157 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19158 const void __user *from, unsigned long n)
19159 {
19160 might_fault();
19161 +
19162 + if ((long)n < 0)
19163 + return n;
19164 +
19165 if (__builtin_constant_p(n)) {
19166 unsigned long ret;
19167
19168 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19169 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19170 unsigned long n)
19171 {
19172 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19173 + if ((long)n < 0)
19174 + return n;
19175 +
19176 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19177 }
19178
19179 #endif /* _ASM_X86_UACCESS_32_H */
19180 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19181 index 190413d..8a80c2a 100644
19182 --- a/arch/x86/include/asm/uaccess_64.h
19183 +++ b/arch/x86/include/asm/uaccess_64.h
19184 @@ -10,6 +10,9 @@
19185 #include <asm/alternative.h>
19186 #include <asm/cpufeature.h>
19187 #include <asm/page.h>
19188 +#include <asm/pgtable.h>
19189 +
19190 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19191
19192 /*
19193 * Copy To/From Userspace
19194 @@ -17,14 +20,14 @@
19195
19196 /* Handles exceptions in both to and from, but doesn't do access_ok */
19197 __must_check unsigned long
19198 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19199 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19200 __must_check unsigned long
19201 -copy_user_generic_string(void *to, const void *from, unsigned len);
19202 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19203 __must_check unsigned long
19204 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19205 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19206
19207 static __always_inline __must_check unsigned long
19208 -copy_user_generic(void *to, const void *from, unsigned len)
19209 +copy_user_generic(void *to, const void *from, unsigned long len)
19210 {
19211 unsigned ret;
19212
19213 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19214 }
19215
19216 __must_check unsigned long
19217 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19218 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19219
19220 static __always_inline __must_check
19221 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19222 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19223 {
19224 - int ret = 0;
19225 + size_t sz = __compiletime_object_size(dst);
19226 + unsigned ret = 0;
19227 +
19228 + if (size > INT_MAX)
19229 + return size;
19230 +
19231 + check_object_size(dst, size, false);
19232 +
19233 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19234 + if (!__access_ok(VERIFY_READ, src, size))
19235 + return size;
19236 +#endif
19237 +
19238 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19239 + if(__builtin_constant_p(size))
19240 + copy_from_user_overflow();
19241 + else
19242 + __copy_from_user_overflow(sz, size);
19243 + return size;
19244 + }
19245
19246 if (!__builtin_constant_p(size))
19247 - return copy_user_generic(dst, (__force void *)src, size);
19248 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19249 switch (size) {
19250 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19251 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19252 ret, "b", "b", "=q", 1);
19253 return ret;
19254 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19255 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19256 ret, "w", "w", "=r", 2);
19257 return ret;
19258 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19259 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19260 ret, "l", "k", "=r", 4);
19261 return ret;
19262 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19263 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19264 ret, "q", "", "=r", 8);
19265 return ret;
19266 case 10:
19267 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19268 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19269 ret, "q", "", "=r", 10);
19270 if (unlikely(ret))
19271 return ret;
19272 __get_user_asm(*(u16 *)(8 + (char *)dst),
19273 - (u16 __user *)(8 + (char __user *)src),
19274 + (const u16 __user *)(8 + (const char __user *)src),
19275 ret, "w", "w", "=r", 2);
19276 return ret;
19277 case 16:
19278 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19279 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19280 ret, "q", "", "=r", 16);
19281 if (unlikely(ret))
19282 return ret;
19283 __get_user_asm(*(u64 *)(8 + (char *)dst),
19284 - (u64 __user *)(8 + (char __user *)src),
19285 + (const u64 __user *)(8 + (const char __user *)src),
19286 ret, "q", "", "=r", 8);
19287 return ret;
19288 default:
19289 - return copy_user_generic(dst, (__force void *)src, size);
19290 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19291 }
19292 }
19293
19294 static __always_inline __must_check
19295 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19296 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19297 {
19298 might_fault();
19299 return __copy_from_user_nocheck(dst, src, size);
19300 }
19301
19302 static __always_inline __must_check
19303 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19304 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19305 {
19306 - int ret = 0;
19307 + size_t sz = __compiletime_object_size(src);
19308 + unsigned ret = 0;
19309 +
19310 + if (size > INT_MAX)
19311 + return size;
19312 +
19313 + check_object_size(src, size, true);
19314 +
19315 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19316 + if (!__access_ok(VERIFY_WRITE, dst, size))
19317 + return size;
19318 +#endif
19319 +
19320 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19321 + if(__builtin_constant_p(size))
19322 + copy_to_user_overflow();
19323 + else
19324 + __copy_to_user_overflow(sz, size);
19325 + return size;
19326 + }
19327
19328 if (!__builtin_constant_p(size))
19329 - return copy_user_generic((__force void *)dst, src, size);
19330 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19331 switch (size) {
19332 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19333 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19334 ret, "b", "b", "iq", 1);
19335 return ret;
19336 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19337 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19338 ret, "w", "w", "ir", 2);
19339 return ret;
19340 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19341 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19342 ret, "l", "k", "ir", 4);
19343 return ret;
19344 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19345 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19346 ret, "q", "", "er", 8);
19347 return ret;
19348 case 10:
19349 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19350 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19351 ret, "q", "", "er", 10);
19352 if (unlikely(ret))
19353 return ret;
19354 asm("":::"memory");
19355 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19356 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19357 ret, "w", "w", "ir", 2);
19358 return ret;
19359 case 16:
19360 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19361 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19362 ret, "q", "", "er", 16);
19363 if (unlikely(ret))
19364 return ret;
19365 asm("":::"memory");
19366 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19367 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19368 ret, "q", "", "er", 8);
19369 return ret;
19370 default:
19371 - return copy_user_generic((__force void *)dst, src, size);
19372 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19373 }
19374 }
19375
19376 static __always_inline __must_check
19377 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
19378 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19379 {
19380 might_fault();
19381 return __copy_to_user_nocheck(dst, src, size);
19382 }
19383
19384 static __always_inline __must_check
19385 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19386 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19387 {
19388 - int ret = 0;
19389 + unsigned ret = 0;
19390
19391 might_fault();
19392 +
19393 + if (size > INT_MAX)
19394 + return size;
19395 +
19396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19397 + if (!__access_ok(VERIFY_READ, src, size))
19398 + return size;
19399 + if (!__access_ok(VERIFY_WRITE, dst, size))
19400 + return size;
19401 +#endif
19402 +
19403 if (!__builtin_constant_p(size))
19404 - return copy_user_generic((__force void *)dst,
19405 - (__force void *)src, size);
19406 + return copy_user_generic((__force_kernel void *)____m(dst),
19407 + (__force_kernel const void *)____m(src), size);
19408 switch (size) {
19409 case 1: {
19410 u8 tmp;
19411 - __get_user_asm(tmp, (u8 __user *)src,
19412 + __get_user_asm(tmp, (const u8 __user *)src,
19413 ret, "b", "b", "=q", 1);
19414 if (likely(!ret))
19415 __put_user_asm(tmp, (u8 __user *)dst,
19416 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19417 }
19418 case 2: {
19419 u16 tmp;
19420 - __get_user_asm(tmp, (u16 __user *)src,
19421 + __get_user_asm(tmp, (const u16 __user *)src,
19422 ret, "w", "w", "=r", 2);
19423 if (likely(!ret))
19424 __put_user_asm(tmp, (u16 __user *)dst,
19425 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19426
19427 case 4: {
19428 u32 tmp;
19429 - __get_user_asm(tmp, (u32 __user *)src,
19430 + __get_user_asm(tmp, (const u32 __user *)src,
19431 ret, "l", "k", "=r", 4);
19432 if (likely(!ret))
19433 __put_user_asm(tmp, (u32 __user *)dst,
19434 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19435 }
19436 case 8: {
19437 u64 tmp;
19438 - __get_user_asm(tmp, (u64 __user *)src,
19439 + __get_user_asm(tmp, (const u64 __user *)src,
19440 ret, "q", "", "=r", 8);
19441 if (likely(!ret))
19442 __put_user_asm(tmp, (u64 __user *)dst,
19443 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19444 return ret;
19445 }
19446 default:
19447 - return copy_user_generic((__force void *)dst,
19448 - (__force void *)src, size);
19449 + return copy_user_generic((__force_kernel void *)____m(dst),
19450 + (__force_kernel const void *)____m(src), size);
19451 }
19452 }
19453
19454 -static __must_check __always_inline int
19455 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19456 +static __must_check __always_inline unsigned long
19457 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19458 {
19459 - return __copy_from_user_nocheck(dst, (__force const void *)src, size);
19460 + return __copy_from_user_nocheck(dst, src, size);
19461 }
19462
19463 -static __must_check __always_inline int
19464 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19465 +static __must_check __always_inline unsigned long
19466 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19467 {
19468 - return __copy_to_user_nocheck((__force void *)dst, src, size);
19469 + return __copy_to_user_nocheck(dst, src, size);
19470 }
19471
19472 -extern long __copy_user_nocache(void *dst, const void __user *src,
19473 - unsigned size, int zerorest);
19474 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19475 + unsigned long size, int zerorest);
19476
19477 -static inline int
19478 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19479 +static inline unsigned long
19480 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19481 {
19482 might_fault();
19483 +
19484 + if (size > INT_MAX)
19485 + return size;
19486 +
19487 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19488 + if (!__access_ok(VERIFY_READ, src, size))
19489 + return size;
19490 +#endif
19491 +
19492 return __copy_user_nocache(dst, src, size, 1);
19493 }
19494
19495 -static inline int
19496 +static inline unsigned long
19497 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
19498 - unsigned size)
19499 + unsigned long size)
19500 {
19501 + if (size > INT_MAX)
19502 + return size;
19503 +
19504 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19505 + if (!__access_ok(VERIFY_READ, src, size))
19506 + return size;
19507 +#endif
19508 +
19509 return __copy_user_nocache(dst, src, size, 0);
19510 }
19511
19512 unsigned long
19513 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
19514 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
19515
19516 #endif /* _ASM_X86_UACCESS_64_H */
19517 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
19518 index 5b238981..77fdd78 100644
19519 --- a/arch/x86/include/asm/word-at-a-time.h
19520 +++ b/arch/x86/include/asm/word-at-a-time.h
19521 @@ -11,7 +11,7 @@
19522 * and shift, for example.
19523 */
19524 struct word_at_a_time {
19525 - const unsigned long one_bits, high_bits;
19526 + unsigned long one_bits, high_bits;
19527 };
19528
19529 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19530 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
19531 index 0f1be11..f7542bf 100644
19532 --- a/arch/x86/include/asm/x86_init.h
19533 +++ b/arch/x86/include/asm/x86_init.h
19534 @@ -129,7 +129,7 @@ struct x86_init_ops {
19535 struct x86_init_timers timers;
19536 struct x86_init_iommu iommu;
19537 struct x86_init_pci pci;
19538 -};
19539 +} __no_const;
19540
19541 /**
19542 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
19543 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
19544 void (*setup_percpu_clockev)(void);
19545 void (*early_percpu_clock_init)(void);
19546 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
19547 -};
19548 +} __no_const;
19549
19550 struct timespec;
19551
19552 @@ -168,7 +168,7 @@ struct x86_platform_ops {
19553 void (*save_sched_clock_state)(void);
19554 void (*restore_sched_clock_state)(void);
19555 void (*apic_post_init)(void);
19556 -};
19557 +} __no_const;
19558
19559 struct pci_dev;
19560 struct msi_msg;
19561 @@ -185,7 +185,7 @@ struct x86_msi_ops {
19562 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
19563 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
19564 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
19565 -};
19566 +} __no_const;
19567
19568 struct IO_APIC_route_entry;
19569 struct io_apic_irq_attr;
19570 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
19571 unsigned int destination, int vector,
19572 struct io_apic_irq_attr *attr);
19573 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
19574 -};
19575 +} __no_const;
19576
19577 extern struct x86_init_ops x86_init;
19578 extern struct x86_cpuinit_ops x86_cpuinit;
19579 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
19580 index b913915..4f5a581 100644
19581 --- a/arch/x86/include/asm/xen/page.h
19582 +++ b/arch/x86/include/asm/xen/page.h
19583 @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
19584 extern struct page *m2p_find_override(unsigned long mfn);
19585 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
19586
19587 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
19588 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
19589 {
19590 unsigned long mfn;
19591
19592 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
19593 index 0415cda..3b22adc 100644
19594 --- a/arch/x86/include/asm/xsave.h
19595 +++ b/arch/x86/include/asm/xsave.h
19596 @@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19597 if (unlikely(err))
19598 return -EFAULT;
19599
19600 + pax_open_userland();
19601 __asm__ __volatile__(ASM_STAC "\n"
19602 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
19603 + "1:"
19604 + __copyuser_seg
19605 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
19606 "2: " ASM_CLAC "\n"
19607 ".section .fixup,\"ax\"\n"
19608 "3: movl $-1,%[err]\n"
19609 @@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19610 : [err] "=r" (err)
19611 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
19612 : "memory");
19613 + pax_close_userland();
19614 return err;
19615 }
19616
19617 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19618 {
19619 int err;
19620 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
19621 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
19622 u32 lmask = mask;
19623 u32 hmask = mask >> 32;
19624
19625 + pax_open_userland();
19626 __asm__ __volatile__(ASM_STAC "\n"
19627 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19628 + "1:"
19629 + __copyuser_seg
19630 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19631 "2: " ASM_CLAC "\n"
19632 ".section .fixup,\"ax\"\n"
19633 "3: movl $-1,%[err]\n"
19634 @@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19635 : [err] "=r" (err)
19636 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
19637 : "memory"); /* memory required? */
19638 + pax_close_userland();
19639 return err;
19640 }
19641
19642 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
19643 index bbae024..e1528f9 100644
19644 --- a/arch/x86/include/uapi/asm/e820.h
19645 +++ b/arch/x86/include/uapi/asm/e820.h
19646 @@ -63,7 +63,7 @@ struct e820map {
19647 #define ISA_START_ADDRESS 0xa0000
19648 #define ISA_END_ADDRESS 0x100000
19649
19650 -#define BIOS_BEGIN 0x000a0000
19651 +#define BIOS_BEGIN 0x000c0000
19652 #define BIOS_END 0x00100000
19653
19654 #define BIOS_ROM_BASE 0xffe00000
19655 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
19656 index 7b0a55a..ad115bf 100644
19657 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
19658 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
19659 @@ -49,7 +49,6 @@
19660 #define EFLAGS 144
19661 #define RSP 152
19662 #define SS 160
19663 -#define ARGOFFSET R11
19664 #endif /* __ASSEMBLY__ */
19665
19666 /* top of stack page */
19667 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
19668 index 9b0a34e..fc7e553 100644
19669 --- a/arch/x86/kernel/Makefile
19670 +++ b/arch/x86/kernel/Makefile
19671 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
19672 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
19673 obj-$(CONFIG_IRQ_WORK) += irq_work.o
19674 obj-y += probe_roms.o
19675 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
19676 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
19677 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
19678 obj-y += syscall_$(BITS).o
19679 obj-$(CONFIG_X86_64) += vsyscall_64.o
19680 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
19681 index 6c0b43b..e67bb31 100644
19682 --- a/arch/x86/kernel/acpi/boot.c
19683 +++ b/arch/x86/kernel/acpi/boot.c
19684 @@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
19685 * If your system is blacklisted here, but you find that acpi=force
19686 * works for you, please contact linux-acpi@vger.kernel.org
19687 */
19688 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
19689 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
19690 /*
19691 * Boxes that need ACPI disabled
19692 */
19693 @@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
19694 };
19695
19696 /* second table for DMI checks that should run after early-quirks */
19697 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
19698 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
19699 /*
19700 * HP laptops which use a DSDT reporting as HP/SB400/10000,
19701 * which includes some code which overrides all temperature
19702 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
19703 index 3a2ae4c..9db31d6 100644
19704 --- a/arch/x86/kernel/acpi/sleep.c
19705 +++ b/arch/x86/kernel/acpi/sleep.c
19706 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
19707 #else /* CONFIG_64BIT */
19708 #ifdef CONFIG_SMP
19709 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
19710 +
19711 + pax_open_kernel();
19712 early_gdt_descr.address =
19713 (unsigned long)get_cpu_gdt_table(smp_processor_id());
19714 + pax_close_kernel();
19715 +
19716 initial_gs = per_cpu_offset(smp_processor_id());
19717 #endif
19718 initial_code = (unsigned long)wakeup_long64;
19719 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
19720 index 665c6b7..eae4d56 100644
19721 --- a/arch/x86/kernel/acpi/wakeup_32.S
19722 +++ b/arch/x86/kernel/acpi/wakeup_32.S
19723 @@ -29,13 +29,11 @@ wakeup_pmode_return:
19724 # and restore the stack ... but you need gdt for this to work
19725 movl saved_context_esp, %esp
19726
19727 - movl %cs:saved_magic, %eax
19728 - cmpl $0x12345678, %eax
19729 + cmpl $0x12345678, saved_magic
19730 jne bogus_magic
19731
19732 # jump to place where we left off
19733 - movl saved_eip, %eax
19734 - jmp *%eax
19735 + jmp *(saved_eip)
19736
19737 bogus_magic:
19738 jmp bogus_magic
19739 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
19740 index df94598..f3b29bf 100644
19741 --- a/arch/x86/kernel/alternative.c
19742 +++ b/arch/x86/kernel/alternative.c
19743 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
19744 */
19745 for (a = start; a < end; a++) {
19746 instr = (u8 *)&a->instr_offset + a->instr_offset;
19747 +
19748 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19749 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19750 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19751 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19752 +#endif
19753 +
19754 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19755 BUG_ON(a->replacementlen > a->instrlen);
19756 BUG_ON(a->instrlen > sizeof(insnbuf));
19757 @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19758 for (poff = start; poff < end; poff++) {
19759 u8 *ptr = (u8 *)poff + *poff;
19760
19761 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19762 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19763 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19764 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19765 +#endif
19766 +
19767 if (!*poff || ptr < text || ptr >= text_end)
19768 continue;
19769 /* turn DS segment override prefix into lock prefix */
19770 - if (*ptr == 0x3e)
19771 + if (*ktla_ktva(ptr) == 0x3e)
19772 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19773 }
19774 mutex_unlock(&text_mutex);
19775 @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19776 for (poff = start; poff < end; poff++) {
19777 u8 *ptr = (u8 *)poff + *poff;
19778
19779 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19780 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19781 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19782 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19783 +#endif
19784 +
19785 if (!*poff || ptr < text || ptr >= text_end)
19786 continue;
19787 /* turn lock prefix into DS segment override prefix */
19788 - if (*ptr == 0xf0)
19789 + if (*ktla_ktva(ptr) == 0xf0)
19790 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19791 }
19792 mutex_unlock(&text_mutex);
19793 @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19794
19795 BUG_ON(p->len > MAX_PATCH_LEN);
19796 /* prep the buffer with the original instructions */
19797 - memcpy(insnbuf, p->instr, p->len);
19798 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19799 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19800 (unsigned long)p->instr, p->len);
19801
19802 @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
19803 if (!uniproc_patched || num_possible_cpus() == 1)
19804 free_init_pages("SMP alternatives",
19805 (unsigned long)__smp_locks,
19806 - (unsigned long)__smp_locks_end);
19807 + PAGE_ALIGN((unsigned long)__smp_locks_end));
19808 #endif
19809
19810 apply_paravirt(__parainstructions, __parainstructions_end);
19811 @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
19812 * instructions. And on the local CPU you need to be protected again NMI or MCE
19813 * handlers seeing an inconsistent instruction while you patch.
19814 */
19815 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
19816 +void *__kprobes text_poke_early(void *addr, const void *opcode,
19817 size_t len)
19818 {
19819 unsigned long flags;
19820 local_irq_save(flags);
19821 - memcpy(addr, opcode, len);
19822 +
19823 + pax_open_kernel();
19824 + memcpy(ktla_ktva(addr), opcode, len);
19825 sync_core();
19826 + pax_close_kernel();
19827 +
19828 local_irq_restore(flags);
19829 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19830 that causes hangs on some VIA CPUs. */
19831 @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19832 */
19833 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19834 {
19835 - unsigned long flags;
19836 - char *vaddr;
19837 + unsigned char *vaddr = ktla_ktva(addr);
19838 struct page *pages[2];
19839 - int i;
19840 + size_t i;
19841
19842 if (!core_kernel_text((unsigned long)addr)) {
19843 - pages[0] = vmalloc_to_page(addr);
19844 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19845 + pages[0] = vmalloc_to_page(vaddr);
19846 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19847 } else {
19848 - pages[0] = virt_to_page(addr);
19849 + pages[0] = virt_to_page(vaddr);
19850 WARN_ON(!PageReserved(pages[0]));
19851 - pages[1] = virt_to_page(addr + PAGE_SIZE);
19852 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19853 }
19854 BUG_ON(!pages[0]);
19855 - local_irq_save(flags);
19856 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19857 - if (pages[1])
19858 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19859 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19860 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19861 - clear_fixmap(FIX_TEXT_POKE0);
19862 - if (pages[1])
19863 - clear_fixmap(FIX_TEXT_POKE1);
19864 - local_flush_tlb();
19865 - sync_core();
19866 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
19867 - that causes hangs on some VIA CPUs. */
19868 + text_poke_early(addr, opcode, len);
19869 for (i = 0; i < len; i++)
19870 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19871 - local_irq_restore(flags);
19872 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19873 return addr;
19874 }
19875
19876 @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
19877 if (likely(!bp_patching_in_progress))
19878 return 0;
19879
19880 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
19881 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
19882 return 0;
19883
19884 /* set up the specified breakpoint handler */
19885 @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
19886 */
19887 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
19888 {
19889 - unsigned char int3 = 0xcc;
19890 + const unsigned char int3 = 0xcc;
19891
19892 bp_int3_handler = handler;
19893 bp_int3_addr = (u8 *)addr + sizeof(int3);
19894 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19895 index d278736..0b4af9a8 100644
19896 --- a/arch/x86/kernel/apic/apic.c
19897 +++ b/arch/x86/kernel/apic/apic.c
19898 @@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
19899 /*
19900 * Debug level, exported for io_apic.c
19901 */
19902 -unsigned int apic_verbosity;
19903 +int apic_verbosity;
19904
19905 int pic_mode;
19906
19907 @@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19908 apic_write(APIC_ESR, 0);
19909 v1 = apic_read(APIC_ESR);
19910 ack_APIC_irq();
19911 - atomic_inc(&irq_err_count);
19912 + atomic_inc_unchecked(&irq_err_count);
19913
19914 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19915 smp_processor_id(), v0 , v1);
19916 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19917 index 00c77cf..2dc6a2d 100644
19918 --- a/arch/x86/kernel/apic/apic_flat_64.c
19919 +++ b/arch/x86/kernel/apic/apic_flat_64.c
19920 @@ -157,7 +157,7 @@ static int flat_probe(void)
19921 return 1;
19922 }
19923
19924 -static struct apic apic_flat = {
19925 +static struct apic apic_flat __read_only = {
19926 .name = "flat",
19927 .probe = flat_probe,
19928 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19929 @@ -271,7 +271,7 @@ static int physflat_probe(void)
19930 return 0;
19931 }
19932
19933 -static struct apic apic_physflat = {
19934 +static struct apic apic_physflat __read_only = {
19935
19936 .name = "physical flat",
19937 .probe = physflat_probe,
19938 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19939 index e145f28..2752888 100644
19940 --- a/arch/x86/kernel/apic/apic_noop.c
19941 +++ b/arch/x86/kernel/apic/apic_noop.c
19942 @@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19943 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19944 }
19945
19946 -struct apic apic_noop = {
19947 +struct apic apic_noop __read_only = {
19948 .name = "noop",
19949 .probe = noop_probe,
19950 .acpi_madt_oem_check = NULL,
19951 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19952 index d50e364..543bee3 100644
19953 --- a/arch/x86/kernel/apic/bigsmp_32.c
19954 +++ b/arch/x86/kernel/apic/bigsmp_32.c
19955 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19956 return dmi_bigsmp;
19957 }
19958
19959 -static struct apic apic_bigsmp = {
19960 +static struct apic apic_bigsmp __read_only = {
19961
19962 .name = "bigsmp",
19963 .probe = probe_bigsmp,
19964 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19965 index c552247..587a316 100644
19966 --- a/arch/x86/kernel/apic/es7000_32.c
19967 +++ b/arch/x86/kernel/apic/es7000_32.c
19968 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19969 return ret && es7000_apic_is_cluster();
19970 }
19971
19972 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19973 -static struct apic __refdata apic_es7000_cluster = {
19974 +static struct apic apic_es7000_cluster __read_only = {
19975
19976 .name = "es7000",
19977 .probe = probe_es7000,
19978 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19979 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19980 };
19981
19982 -static struct apic __refdata apic_es7000 = {
19983 +static struct apic apic_es7000 __read_only = {
19984
19985 .name = "es7000",
19986 .probe = probe_es7000,
19987 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19988 index e63a5bd..c0babf8 100644
19989 --- a/arch/x86/kernel/apic/io_apic.c
19990 +++ b/arch/x86/kernel/apic/io_apic.c
19991 @@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19992 }
19993 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19994
19995 -void lock_vector_lock(void)
19996 +void lock_vector_lock(void) __acquires(vector_lock)
19997 {
19998 /* Used to the online set of cpus does not change
19999 * during assign_irq_vector.
20000 @@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20001 raw_spin_lock(&vector_lock);
20002 }
20003
20004 -void unlock_vector_lock(void)
20005 +void unlock_vector_lock(void) __releases(vector_lock)
20006 {
20007 raw_spin_unlock(&vector_lock);
20008 }
20009 @@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20010 ack_APIC_irq();
20011 }
20012
20013 -atomic_t irq_mis_count;
20014 +atomic_unchecked_t irq_mis_count;
20015
20016 #ifdef CONFIG_GENERIC_PENDING_IRQ
20017 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20018 @@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20019 * at the cpu.
20020 */
20021 if (!(v & (1 << (i & 0x1f)))) {
20022 - atomic_inc(&irq_mis_count);
20023 + atomic_inc_unchecked(&irq_mis_count);
20024
20025 eoi_ioapic_irq(irq, cfg);
20026 }
20027 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20028 index 1e42e8f..daacf44 100644
20029 --- a/arch/x86/kernel/apic/numaq_32.c
20030 +++ b/arch/x86/kernel/apic/numaq_32.c
20031 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20032 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20033 }
20034
20035 -/* Use __refdata to keep false positive warning calm. */
20036 -static struct apic __refdata apic_numaq = {
20037 +static struct apic apic_numaq __read_only = {
20038
20039 .name = "NUMAQ",
20040 .probe = probe_numaq,
20041 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20042 index eb35ef9..f184a21 100644
20043 --- a/arch/x86/kernel/apic/probe_32.c
20044 +++ b/arch/x86/kernel/apic/probe_32.c
20045 @@ -72,7 +72,7 @@ static int probe_default(void)
20046 return 1;
20047 }
20048
20049 -static struct apic apic_default = {
20050 +static struct apic apic_default __read_only = {
20051
20052 .name = "default",
20053 .probe = probe_default,
20054 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20055 index 77c95c0..434f8a4 100644
20056 --- a/arch/x86/kernel/apic/summit_32.c
20057 +++ b/arch/x86/kernel/apic/summit_32.c
20058 @@ -486,7 +486,7 @@ void setup_summit(void)
20059 }
20060 #endif
20061
20062 -static struct apic apic_summit = {
20063 +static struct apic apic_summit __read_only = {
20064
20065 .name = "summit",
20066 .probe = probe_summit,
20067 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20068 index 140e29d..d88bc95 100644
20069 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20070 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20071 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20072 return notifier_from_errno(err);
20073 }
20074
20075 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20076 +static struct notifier_block x2apic_cpu_notifier = {
20077 .notifier_call = update_clusterinfo,
20078 };
20079
20080 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20081 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20082 }
20083
20084 -static struct apic apic_x2apic_cluster = {
20085 +static struct apic apic_x2apic_cluster __read_only = {
20086
20087 .name = "cluster x2apic",
20088 .probe = x2apic_cluster_probe,
20089 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20090 index 562a76d..a003c0f 100644
20091 --- a/arch/x86/kernel/apic/x2apic_phys.c
20092 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20093 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20094 return apic == &apic_x2apic_phys;
20095 }
20096
20097 -static struct apic apic_x2apic_phys = {
20098 +static struct apic apic_x2apic_phys __read_only = {
20099
20100 .name = "physical x2apic",
20101 .probe = x2apic_phys_probe,
20102 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20103 index ad0dc04..0d9cc56 100644
20104 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20105 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20106 @@ -350,7 +350,7 @@ static int uv_probe(void)
20107 return apic == &apic_x2apic_uv_x;
20108 }
20109
20110 -static struct apic __refdata apic_x2apic_uv_x = {
20111 +static struct apic apic_x2apic_uv_x __read_only = {
20112
20113 .name = "UV large system",
20114 .probe = uv_probe,
20115 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20116 index 3ab0343..814c4787 100644
20117 --- a/arch/x86/kernel/apm_32.c
20118 +++ b/arch/x86/kernel/apm_32.c
20119 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20120 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20121 * even though they are called in protected mode.
20122 */
20123 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20124 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20125 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20126
20127 static const char driver_version[] = "1.16ac"; /* no spaces */
20128 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20129 BUG_ON(cpu != 0);
20130 gdt = get_cpu_gdt_table(cpu);
20131 save_desc_40 = gdt[0x40 / 8];
20132 +
20133 + pax_open_kernel();
20134 gdt[0x40 / 8] = bad_bios_desc;
20135 + pax_close_kernel();
20136
20137 apm_irq_save(flags);
20138 APM_DO_SAVE_SEGS;
20139 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20140 &call->esi);
20141 APM_DO_RESTORE_SEGS;
20142 apm_irq_restore(flags);
20143 +
20144 + pax_open_kernel();
20145 gdt[0x40 / 8] = save_desc_40;
20146 + pax_close_kernel();
20147 +
20148 put_cpu();
20149
20150 return call->eax & 0xff;
20151 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20152 BUG_ON(cpu != 0);
20153 gdt = get_cpu_gdt_table(cpu);
20154 save_desc_40 = gdt[0x40 / 8];
20155 +
20156 + pax_open_kernel();
20157 gdt[0x40 / 8] = bad_bios_desc;
20158 + pax_close_kernel();
20159
20160 apm_irq_save(flags);
20161 APM_DO_SAVE_SEGS;
20162 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20163 &call->eax);
20164 APM_DO_RESTORE_SEGS;
20165 apm_irq_restore(flags);
20166 +
20167 + pax_open_kernel();
20168 gdt[0x40 / 8] = save_desc_40;
20169 + pax_close_kernel();
20170 +
20171 put_cpu();
20172 return error;
20173 }
20174 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20175 * code to that CPU.
20176 */
20177 gdt = get_cpu_gdt_table(0);
20178 +
20179 + pax_open_kernel();
20180 set_desc_base(&gdt[APM_CS >> 3],
20181 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20182 set_desc_base(&gdt[APM_CS_16 >> 3],
20183 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20184 set_desc_base(&gdt[APM_DS >> 3],
20185 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20186 + pax_close_kernel();
20187
20188 proc_create("apm", 0, NULL, &apm_file_ops);
20189
20190 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20191 index 9f6b934..cf5ffb3 100644
20192 --- a/arch/x86/kernel/asm-offsets.c
20193 +++ b/arch/x86/kernel/asm-offsets.c
20194 @@ -32,6 +32,8 @@ void common(void) {
20195 OFFSET(TI_flags, thread_info, flags);
20196 OFFSET(TI_status, thread_info, status);
20197 OFFSET(TI_addr_limit, thread_info, addr_limit);
20198 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20199 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20200
20201 BLANK();
20202 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20203 @@ -52,8 +54,26 @@ void common(void) {
20204 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20205 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20206 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20207 +
20208 +#ifdef CONFIG_PAX_KERNEXEC
20209 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20210 #endif
20211
20212 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20213 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20214 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20215 +#ifdef CONFIG_X86_64
20216 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20217 +#endif
20218 +#endif
20219 +
20220 +#endif
20221 +
20222 + BLANK();
20223 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20224 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20225 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20226 +
20227 #ifdef CONFIG_XEN
20228 BLANK();
20229 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20230 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20231 index e7c798b..2b2019b 100644
20232 --- a/arch/x86/kernel/asm-offsets_64.c
20233 +++ b/arch/x86/kernel/asm-offsets_64.c
20234 @@ -77,6 +77,7 @@ int main(void)
20235 BLANK();
20236 #undef ENTRY
20237
20238 + DEFINE(TSS_size, sizeof(struct tss_struct));
20239 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20240 BLANK();
20241
20242 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20243 index 47b56a7..efc2bc6 100644
20244 --- a/arch/x86/kernel/cpu/Makefile
20245 +++ b/arch/x86/kernel/cpu/Makefile
20246 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20247 CFLAGS_REMOVE_perf_event.o = -pg
20248 endif
20249
20250 -# Make sure load_percpu_segment has no stackprotector
20251 -nostackp := $(call cc-option, -fno-stack-protector)
20252 -CFLAGS_common.o := $(nostackp)
20253 -
20254 obj-y := intel_cacheinfo.o scattered.o topology.o
20255 obj-y += proc.o capflags.o powerflags.o common.o
20256 obj-y += rdrand.o
20257 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20258 index bca023b..c544908 100644
20259 --- a/arch/x86/kernel/cpu/amd.c
20260 +++ b/arch/x86/kernel/cpu/amd.c
20261 @@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20262 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20263 {
20264 /* AMD errata T13 (order #21922) */
20265 - if ((c->x86 == 6)) {
20266 + if (c->x86 == 6) {
20267 /* Duron Rev A0 */
20268 if (c->x86_model == 3 && c->x86_mask == 0)
20269 size = 64;
20270 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20271 index 6abc172..3b0df94 100644
20272 --- a/arch/x86/kernel/cpu/common.c
20273 +++ b/arch/x86/kernel/cpu/common.c
20274 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20275
20276 static const struct cpu_dev *this_cpu = &default_cpu;
20277
20278 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20279 -#ifdef CONFIG_X86_64
20280 - /*
20281 - * We need valid kernel segments for data and code in long mode too
20282 - * IRET will check the segment types kkeil 2000/10/28
20283 - * Also sysret mandates a special GDT layout
20284 - *
20285 - * TLS descriptors are currently at a different place compared to i386.
20286 - * Hopefully nobody expects them at a fixed place (Wine?)
20287 - */
20288 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20289 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20290 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20291 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20292 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20293 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20294 -#else
20295 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20296 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20297 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20298 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20299 - /*
20300 - * Segments used for calling PnP BIOS have byte granularity.
20301 - * They code segments and data segments have fixed 64k limits,
20302 - * the transfer segment sizes are set at run time.
20303 - */
20304 - /* 32-bit code */
20305 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20306 - /* 16-bit code */
20307 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20308 - /* 16-bit data */
20309 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20310 - /* 16-bit data */
20311 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20312 - /* 16-bit data */
20313 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20314 - /*
20315 - * The APM segments have byte granularity and their bases
20316 - * are set at run time. All have 64k limits.
20317 - */
20318 - /* 32-bit code */
20319 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20320 - /* 16-bit code */
20321 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20322 - /* data */
20323 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20324 -
20325 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20326 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20327 - GDT_STACK_CANARY_INIT
20328 -#endif
20329 -} };
20330 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20331 -
20332 static int __init x86_xsave_setup(char *s)
20333 {
20334 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20335 @@ -288,6 +234,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20336 set_in_cr4(X86_CR4_SMAP);
20337 }
20338
20339 +#ifdef CONFIG_X86_64
20340 +static __init int setup_disable_pcid(char *arg)
20341 +{
20342 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20343 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20344 +
20345 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20346 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20347 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20348 +#endif
20349 +
20350 + return 1;
20351 +}
20352 +__setup("nopcid", setup_disable_pcid);
20353 +
20354 +static void setup_pcid(struct cpuinfo_x86 *c)
20355 +{
20356 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20357 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20358 +
20359 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20360 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20361 + pax_open_kernel();
20362 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20363 + pax_close_kernel();
20364 + printk("PAX: slow and weak UDEREF enabled\n");
20365 + } else
20366 + printk("PAX: UDEREF disabled\n");
20367 +#endif
20368 +
20369 + return;
20370 + }
20371 +
20372 + printk("PAX: PCID detected\n");
20373 + set_in_cr4(X86_CR4_PCIDE);
20374 +
20375 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20376 + pax_open_kernel();
20377 + clone_pgd_mask = ~(pgdval_t)0UL;
20378 + pax_close_kernel();
20379 + if (pax_user_shadow_base)
20380 + printk("PAX: weak UDEREF enabled\n");
20381 + else {
20382 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20383 + printk("PAX: strong UDEREF enabled\n");
20384 + }
20385 +#endif
20386 +
20387 + if (cpu_has(c, X86_FEATURE_INVPCID))
20388 + printk("PAX: INVPCID detected\n");
20389 +}
20390 +#endif
20391 +
20392 /*
20393 * Some CPU features depend on higher CPUID levels, which may not always
20394 * be available due to CPUID level capping or broken virtualization
20395 @@ -388,7 +387,7 @@ void switch_to_new_gdt(int cpu)
20396 {
20397 struct desc_ptr gdt_descr;
20398
20399 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20400 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20401 gdt_descr.size = GDT_SIZE - 1;
20402 load_gdt(&gdt_descr);
20403 /* Reload the per-cpu base */
20404 @@ -877,6 +876,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20405 setup_smep(c);
20406 setup_smap(c);
20407
20408 +#ifdef CONFIG_X86_64
20409 + setup_pcid(c);
20410 +#endif
20411 +
20412 /*
20413 * The vendor-specific functions might have changed features.
20414 * Now we do "generic changes."
20415 @@ -885,6 +888,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20416 /* Filter out anything that depends on CPUID levels we don't have */
20417 filter_cpuid_features(c, true);
20418
20419 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20420 + setup_clear_cpu_cap(X86_FEATURE_SEP);
20421 +#endif
20422 +
20423 /* If the model name is still unset, do table lookup. */
20424 if (!c->x86_model_id[0]) {
20425 const char *p;
20426 @@ -1072,10 +1079,12 @@ static __init int setup_disablecpuid(char *arg)
20427 }
20428 __setup("clearcpuid=", setup_disablecpuid);
20429
20430 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20431 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
20432 +
20433 #ifdef CONFIG_X86_64
20434 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20435 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20436 - (unsigned long) debug_idt_table };
20437 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20438 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20439
20440 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20441 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20442 @@ -1089,7 +1098,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20443 EXPORT_PER_CPU_SYMBOL(current_task);
20444
20445 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20446 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20447 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20448 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20449
20450 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20451 @@ -1239,7 +1248,7 @@ void cpu_init(void)
20452 load_ucode_ap();
20453
20454 cpu = stack_smp_processor_id();
20455 - t = &per_cpu(init_tss, cpu);
20456 + t = init_tss + cpu;
20457 oist = &per_cpu(orig_ist, cpu);
20458
20459 #ifdef CONFIG_NUMA
20460 @@ -1274,7 +1283,6 @@ void cpu_init(void)
20461 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20462 barrier();
20463
20464 - x86_configure_nx();
20465 enable_x2apic();
20466
20467 /*
20468 @@ -1326,7 +1334,7 @@ void cpu_init(void)
20469 {
20470 int cpu = smp_processor_id();
20471 struct task_struct *curr = current;
20472 - struct tss_struct *t = &per_cpu(init_tss, cpu);
20473 + struct tss_struct *t = init_tss + cpu;
20474 struct thread_struct *thread = &curr->thread;
20475
20476 show_ucode_info_early();
20477 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20478 index 0641113..06f5ba4 100644
20479 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20480 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20481 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20482 };
20483
20484 #ifdef CONFIG_AMD_NB
20485 +static struct attribute *default_attrs_amd_nb[] = {
20486 + &type.attr,
20487 + &level.attr,
20488 + &coherency_line_size.attr,
20489 + &physical_line_partition.attr,
20490 + &ways_of_associativity.attr,
20491 + &number_of_sets.attr,
20492 + &size.attr,
20493 + &shared_cpu_map.attr,
20494 + &shared_cpu_list.attr,
20495 + NULL,
20496 + NULL,
20497 + NULL,
20498 + NULL
20499 +};
20500 +
20501 static struct attribute **amd_l3_attrs(void)
20502 {
20503 static struct attribute **attrs;
20504 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
20505
20506 n = ARRAY_SIZE(default_attrs);
20507
20508 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
20509 - n += 2;
20510 -
20511 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
20512 - n += 1;
20513 -
20514 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
20515 - if (attrs == NULL)
20516 - return attrs = default_attrs;
20517 -
20518 - for (n = 0; default_attrs[n]; n++)
20519 - attrs[n] = default_attrs[n];
20520 + attrs = default_attrs_amd_nb;
20521
20522 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
20523 attrs[n++] = &cache_disable_0.attr;
20524 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
20525 .default_attrs = default_attrs,
20526 };
20527
20528 +#ifdef CONFIG_AMD_NB
20529 +static struct kobj_type ktype_cache_amd_nb = {
20530 + .sysfs_ops = &sysfs_ops,
20531 + .default_attrs = default_attrs_amd_nb,
20532 +};
20533 +#endif
20534 +
20535 static struct kobj_type ktype_percpu_entry = {
20536 .sysfs_ops = &sysfs_ops,
20537 };
20538 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
20539 return retval;
20540 }
20541
20542 +#ifdef CONFIG_AMD_NB
20543 + amd_l3_attrs();
20544 +#endif
20545 +
20546 for (i = 0; i < num_cache_leaves; i++) {
20547 + struct kobj_type *ktype;
20548 +
20549 this_object = INDEX_KOBJECT_PTR(cpu, i);
20550 this_object->cpu = cpu;
20551 this_object->index = i;
20552
20553 this_leaf = CPUID4_INFO_IDX(cpu, i);
20554
20555 - ktype_cache.default_attrs = default_attrs;
20556 + ktype = &ktype_cache;
20557 #ifdef CONFIG_AMD_NB
20558 if (this_leaf->base.nb)
20559 - ktype_cache.default_attrs = amd_l3_attrs();
20560 + ktype = &ktype_cache_amd_nb;
20561 #endif
20562 retval = kobject_init_and_add(&(this_object->kobj),
20563 - &ktype_cache,
20564 + ktype,
20565 per_cpu(ici_cache_kobject, cpu),
20566 "index%1lu", i);
20567 if (unlikely(retval)) {
20568 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
20569 index b3218cd..99a75de 100644
20570 --- a/arch/x86/kernel/cpu/mcheck/mce.c
20571 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
20572 @@ -45,6 +45,7 @@
20573 #include <asm/processor.h>
20574 #include <asm/mce.h>
20575 #include <asm/msr.h>
20576 +#include <asm/local.h>
20577
20578 #include "mce-internal.h"
20579
20580 @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
20581 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
20582 m->cs, m->ip);
20583
20584 - if (m->cs == __KERNEL_CS)
20585 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
20586 print_symbol("{%s}", m->ip);
20587 pr_cont("\n");
20588 }
20589 @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
20590
20591 #define PANIC_TIMEOUT 5 /* 5 seconds */
20592
20593 -static atomic_t mce_paniced;
20594 +static atomic_unchecked_t mce_paniced;
20595
20596 static int fake_panic;
20597 -static atomic_t mce_fake_paniced;
20598 +static atomic_unchecked_t mce_fake_paniced;
20599
20600 /* Panic in progress. Enable interrupts and wait for final IPI */
20601 static void wait_for_panic(void)
20602 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20603 /*
20604 * Make sure only one CPU runs in machine check panic
20605 */
20606 - if (atomic_inc_return(&mce_paniced) > 1)
20607 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
20608 wait_for_panic();
20609 barrier();
20610
20611 @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20612 console_verbose();
20613 } else {
20614 /* Don't log too much for fake panic */
20615 - if (atomic_inc_return(&mce_fake_paniced) > 1)
20616 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
20617 return;
20618 }
20619 /* First print corrected ones that are still unlogged */
20620 @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20621 if (!fake_panic) {
20622 if (panic_timeout == 0)
20623 panic_timeout = mca_cfg.panic_timeout;
20624 - panic(msg);
20625 + panic("%s", msg);
20626 } else
20627 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
20628 }
20629 @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
20630 * might have been modified by someone else.
20631 */
20632 rmb();
20633 - if (atomic_read(&mce_paniced))
20634 + if (atomic_read_unchecked(&mce_paniced))
20635 wait_for_panic();
20636 if (!mca_cfg.monarch_timeout)
20637 goto out;
20638 @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
20639 }
20640
20641 /* Call the installed machine check handler for this CPU setup. */
20642 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
20643 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
20644 unexpected_machine_check;
20645
20646 /*
20647 @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20648 return;
20649 }
20650
20651 + pax_open_kernel();
20652 machine_check_vector = do_machine_check;
20653 + pax_close_kernel();
20654
20655 __mcheck_cpu_init_generic();
20656 __mcheck_cpu_init_vendor(c);
20657 @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20658 */
20659
20660 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
20661 -static int mce_chrdev_open_count; /* #times opened */
20662 +static local_t mce_chrdev_open_count; /* #times opened */
20663 static int mce_chrdev_open_exclu; /* already open exclusive? */
20664
20665 static int mce_chrdev_open(struct inode *inode, struct file *file)
20666 @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20667 spin_lock(&mce_chrdev_state_lock);
20668
20669 if (mce_chrdev_open_exclu ||
20670 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
20671 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
20672 spin_unlock(&mce_chrdev_state_lock);
20673
20674 return -EBUSY;
20675 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20676
20677 if (file->f_flags & O_EXCL)
20678 mce_chrdev_open_exclu = 1;
20679 - mce_chrdev_open_count++;
20680 + local_inc(&mce_chrdev_open_count);
20681
20682 spin_unlock(&mce_chrdev_state_lock);
20683
20684 @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
20685 {
20686 spin_lock(&mce_chrdev_state_lock);
20687
20688 - mce_chrdev_open_count--;
20689 + local_dec(&mce_chrdev_open_count);
20690 mce_chrdev_open_exclu = 0;
20691
20692 spin_unlock(&mce_chrdev_state_lock);
20693 @@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
20694
20695 for (i = 0; i < mca_cfg.banks; i++) {
20696 struct mce_bank *b = &mce_banks[i];
20697 - struct device_attribute *a = &b->attr;
20698 + device_attribute_no_const *a = &b->attr;
20699
20700 sysfs_attr_init(&a->attr);
20701 a->attr.name = b->attrname;
20702 @@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
20703 static void mce_reset(void)
20704 {
20705 cpu_missing = 0;
20706 - atomic_set(&mce_fake_paniced, 0);
20707 + atomic_set_unchecked(&mce_fake_paniced, 0);
20708 atomic_set(&mce_executing, 0);
20709 atomic_set(&mce_callin, 0);
20710 atomic_set(&global_nwo, 0);
20711 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
20712 index 1c044b1..37a2a43 100644
20713 --- a/arch/x86/kernel/cpu/mcheck/p5.c
20714 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
20715 @@ -11,6 +11,7 @@
20716 #include <asm/processor.h>
20717 #include <asm/mce.h>
20718 #include <asm/msr.h>
20719 +#include <asm/pgtable.h>
20720
20721 /* By default disabled */
20722 int mce_p5_enabled __read_mostly;
20723 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
20724 if (!cpu_has(c, X86_FEATURE_MCE))
20725 return;
20726
20727 + pax_open_kernel();
20728 machine_check_vector = pentium_machine_check;
20729 + pax_close_kernel();
20730 /* Make sure the vector pointer is visible before we enable MCEs: */
20731 wmb();
20732
20733 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
20734 index e9a701a..35317d6 100644
20735 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
20736 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
20737 @@ -10,6 +10,7 @@
20738 #include <asm/processor.h>
20739 #include <asm/mce.h>
20740 #include <asm/msr.h>
20741 +#include <asm/pgtable.h>
20742
20743 /* Machine check handler for WinChip C6: */
20744 static void winchip_machine_check(struct pt_regs *regs, long error_code)
20745 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
20746 {
20747 u32 lo, hi;
20748
20749 + pax_open_kernel();
20750 machine_check_vector = winchip_machine_check;
20751 + pax_close_kernel();
20752 /* Make sure the vector pointer is visible before we enable MCEs: */
20753 wmb();
20754
20755 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
20756 index f961de9..8a9d332 100644
20757 --- a/arch/x86/kernel/cpu/mtrr/main.c
20758 +++ b/arch/x86/kernel/cpu/mtrr/main.c
20759 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
20760 u64 size_or_mask, size_and_mask;
20761 static bool mtrr_aps_delayed_init;
20762
20763 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
20764 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20765
20766 const struct mtrr_ops *mtrr_if;
20767
20768 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20769 index df5e41f..816c719 100644
20770 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20771 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20772 @@ -25,7 +25,7 @@ struct mtrr_ops {
20773 int (*validate_add_page)(unsigned long base, unsigned long size,
20774 unsigned int type);
20775 int (*have_wrcomb)(void);
20776 -};
20777 +} __do_const;
20778
20779 extern int generic_get_free_region(unsigned long base, unsigned long size,
20780 int replace_reg);
20781 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20782 index 8e13293..9bfd68c 100644
20783 --- a/arch/x86/kernel/cpu/perf_event.c
20784 +++ b/arch/x86/kernel/cpu/perf_event.c
20785 @@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
20786 pr_info("no hardware sampling interrupt available.\n");
20787 }
20788
20789 -static struct attribute_group x86_pmu_format_group = {
20790 +static attribute_group_no_const x86_pmu_format_group = {
20791 .name = "format",
20792 .attrs = NULL,
20793 };
20794 @@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
20795 NULL,
20796 };
20797
20798 -static struct attribute_group x86_pmu_events_group = {
20799 +static attribute_group_no_const x86_pmu_events_group = {
20800 .name = "events",
20801 .attrs = events_attr,
20802 };
20803 @@ -1958,7 +1958,7 @@ static unsigned long get_segment_base(unsigned int segment)
20804 if (idx > GDT_ENTRIES)
20805 return 0;
20806
20807 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20808 + desc = get_cpu_gdt_table(smp_processor_id());
20809 }
20810
20811 return get_desc_base(desc + idx);
20812 @@ -2048,7 +2048,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20813 break;
20814
20815 perf_callchain_store(entry, frame.return_address);
20816 - fp = frame.next_frame;
20817 + fp = (const void __force_user *)frame.next_frame;
20818 }
20819 }
20820
20821 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20822 index 639d128..e92d7e5 100644
20823 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20824 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20825 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20826 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20827 {
20828 struct attribute **attrs;
20829 - struct attribute_group *attr_group;
20830 + attribute_group_no_const *attr_group;
20831 int i = 0, j;
20832
20833 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20834 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20835 index 0fa4f24..17990ed 100644
20836 --- a/arch/x86/kernel/cpu/perf_event_intel.c
20837 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
20838 @@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
20839 * v2 and above have a perf capabilities MSR
20840 */
20841 if (version > 1) {
20842 - u64 capabilities;
20843 + u64 capabilities = x86_pmu.intel_cap.capabilities;
20844
20845 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20846 - x86_pmu.intel_cap.capabilities = capabilities;
20847 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20848 + x86_pmu.intel_cap.capabilities = capabilities;
20849 }
20850
20851 intel_ds_init();
20852 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20853 index 29c2487..a5606fa 100644
20854 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20855 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20856 @@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20857 static int __init uncore_type_init(struct intel_uncore_type *type)
20858 {
20859 struct intel_uncore_pmu *pmus;
20860 - struct attribute_group *attr_group;
20861 + attribute_group_no_const *attr_group;
20862 struct attribute **attrs;
20863 int i, j;
20864
20865 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20866 index a80ab71..4089da5 100644
20867 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20868 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20869 @@ -498,7 +498,7 @@ struct intel_uncore_box {
20870 struct uncore_event_desc {
20871 struct kobj_attribute attr;
20872 const char *config;
20873 -};
20874 +} __do_const;
20875
20876 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20877 { \
20878 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20879 index 7d9481c..99c7e4b 100644
20880 --- a/arch/x86/kernel/cpuid.c
20881 +++ b/arch/x86/kernel/cpuid.c
20882 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20883 return notifier_from_errno(err);
20884 }
20885
20886 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
20887 +static struct notifier_block cpuid_class_cpu_notifier =
20888 {
20889 .notifier_call = cpuid_class_cpu_callback,
20890 };
20891 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20892 index 18677a9..f67c45b 100644
20893 --- a/arch/x86/kernel/crash.c
20894 +++ b/arch/x86/kernel/crash.c
20895 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20896 {
20897 #ifdef CONFIG_X86_32
20898 struct pt_regs fixed_regs;
20899 -#endif
20900
20901 -#ifdef CONFIG_X86_32
20902 - if (!user_mode_vm(regs)) {
20903 + if (!user_mode(regs)) {
20904 crash_fixup_ss_esp(&fixed_regs, regs);
20905 regs = &fixed_regs;
20906 }
20907 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20908 index afa64ad..dce67dd 100644
20909 --- a/arch/x86/kernel/crash_dump_64.c
20910 +++ b/arch/x86/kernel/crash_dump_64.c
20911 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20912 return -ENOMEM;
20913
20914 if (userbuf) {
20915 - if (copy_to_user(buf, vaddr + offset, csize)) {
20916 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20917 iounmap(vaddr);
20918 return -EFAULT;
20919 }
20920 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20921 index 5d3fe8d..02e1429 100644
20922 --- a/arch/x86/kernel/doublefault.c
20923 +++ b/arch/x86/kernel/doublefault.c
20924 @@ -13,7 +13,7 @@
20925
20926 #define DOUBLEFAULT_STACKSIZE (1024)
20927 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20928 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20929 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20930
20931 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20932
20933 @@ -23,7 +23,7 @@ static void doublefault_fn(void)
20934 unsigned long gdt, tss;
20935
20936 native_store_gdt(&gdt_desc);
20937 - gdt = gdt_desc.address;
20938 + gdt = (unsigned long)gdt_desc.address;
20939
20940 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20941
20942 @@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20943 /* 0x2 bit is always set */
20944 .flags = X86_EFLAGS_SF | 0x2,
20945 .sp = STACK_START,
20946 - .es = __USER_DS,
20947 + .es = __KERNEL_DS,
20948 .cs = __KERNEL_CS,
20949 .ss = __KERNEL_DS,
20950 - .ds = __USER_DS,
20951 + .ds = __KERNEL_DS,
20952 .fs = __KERNEL_PERCPU,
20953
20954 .__cr3 = __pa_nodebug(swapper_pg_dir),
20955 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20956 index d9c12d3..7858b62 100644
20957 --- a/arch/x86/kernel/dumpstack.c
20958 +++ b/arch/x86/kernel/dumpstack.c
20959 @@ -2,6 +2,9 @@
20960 * Copyright (C) 1991, 1992 Linus Torvalds
20961 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20962 */
20963 +#ifdef CONFIG_GRKERNSEC_HIDESYM
20964 +#define __INCLUDED_BY_HIDESYM 1
20965 +#endif
20966 #include <linux/kallsyms.h>
20967 #include <linux/kprobes.h>
20968 #include <linux/uaccess.h>
20969 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
20970 static void
20971 print_ftrace_graph_addr(unsigned long addr, void *data,
20972 const struct stacktrace_ops *ops,
20973 - struct thread_info *tinfo, int *graph)
20974 + struct task_struct *task, int *graph)
20975 {
20976 - struct task_struct *task;
20977 unsigned long ret_addr;
20978 int index;
20979
20980 if (addr != (unsigned long)return_to_handler)
20981 return;
20982
20983 - task = tinfo->task;
20984 index = task->curr_ret_stack;
20985
20986 if (!task->ret_stack || index < *graph)
20987 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20988 static inline void
20989 print_ftrace_graph_addr(unsigned long addr, void *data,
20990 const struct stacktrace_ops *ops,
20991 - struct thread_info *tinfo, int *graph)
20992 + struct task_struct *task, int *graph)
20993 { }
20994 #endif
20995
20996 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20997 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20998 */
20999
21000 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21001 - void *p, unsigned int size, void *end)
21002 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21003 {
21004 - void *t = tinfo;
21005 if (end) {
21006 if (p < end && p >= (end-THREAD_SIZE))
21007 return 1;
21008 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21009 }
21010
21011 unsigned long
21012 -print_context_stack(struct thread_info *tinfo,
21013 +print_context_stack(struct task_struct *task, void *stack_start,
21014 unsigned long *stack, unsigned long bp,
21015 const struct stacktrace_ops *ops, void *data,
21016 unsigned long *end, int *graph)
21017 {
21018 struct stack_frame *frame = (struct stack_frame *)bp;
21019
21020 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21021 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21022 unsigned long addr;
21023
21024 addr = *stack;
21025 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21026 } else {
21027 ops->address(data, addr, 0);
21028 }
21029 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21030 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21031 }
21032 stack++;
21033 }
21034 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21035 EXPORT_SYMBOL_GPL(print_context_stack);
21036
21037 unsigned long
21038 -print_context_stack_bp(struct thread_info *tinfo,
21039 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21040 unsigned long *stack, unsigned long bp,
21041 const struct stacktrace_ops *ops, void *data,
21042 unsigned long *end, int *graph)
21043 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21044 struct stack_frame *frame = (struct stack_frame *)bp;
21045 unsigned long *ret_addr = &frame->return_address;
21046
21047 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21048 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21049 unsigned long addr = *ret_addr;
21050
21051 if (!__kernel_text_address(addr))
21052 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21053 ops->address(data, addr, 1);
21054 frame = frame->next_frame;
21055 ret_addr = &frame->return_address;
21056 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21057 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21058 }
21059
21060 return (unsigned long)frame;
21061 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21062 static void print_trace_address(void *data, unsigned long addr, int reliable)
21063 {
21064 touch_nmi_watchdog();
21065 - printk(data);
21066 + printk("%s", (char *)data);
21067 printk_stack_address(addr, reliable);
21068 }
21069
21070 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21071 }
21072 EXPORT_SYMBOL_GPL(oops_begin);
21073
21074 +extern void gr_handle_kernel_exploit(void);
21075 +
21076 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21077 {
21078 if (regs && kexec_should_crash(current))
21079 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21080 panic("Fatal exception in interrupt");
21081 if (panic_on_oops)
21082 panic("Fatal exception");
21083 - do_exit(signr);
21084 +
21085 + gr_handle_kernel_exploit();
21086 +
21087 + do_group_exit(signr);
21088 }
21089
21090 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21091 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21092 print_modules();
21093 show_regs(regs);
21094 #ifdef CONFIG_X86_32
21095 - if (user_mode_vm(regs)) {
21096 + if (user_mode(regs)) {
21097 sp = regs->sp;
21098 ss = regs->ss & 0xffff;
21099 } else {
21100 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21101 unsigned long flags = oops_begin();
21102 int sig = SIGSEGV;
21103
21104 - if (!user_mode_vm(regs))
21105 + if (!user_mode(regs))
21106 report_bug(regs->ip, regs);
21107
21108 if (__die(str, regs, err))
21109 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21110 index f2a1770..540657f 100644
21111 --- a/arch/x86/kernel/dumpstack_32.c
21112 +++ b/arch/x86/kernel/dumpstack_32.c
21113 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21114 bp = stack_frame(task, regs);
21115
21116 for (;;) {
21117 - struct thread_info *context;
21118 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21119
21120 - context = (struct thread_info *)
21121 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21122 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21123 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21124
21125 - stack = (unsigned long *)context->previous_esp;
21126 - if (!stack)
21127 + if (stack_start == task_stack_page(task))
21128 break;
21129 + stack = *(unsigned long **)stack_start;
21130 if (ops->stack(data, "IRQ") < 0)
21131 break;
21132 touch_nmi_watchdog();
21133 @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21134 int i;
21135
21136 show_regs_print_info(KERN_EMERG);
21137 - __show_regs(regs, !user_mode_vm(regs));
21138 + __show_regs(regs, !user_mode(regs));
21139
21140 /*
21141 * When in-kernel, we also print out the stack and code at the
21142 * time of the fault..
21143 */
21144 - if (!user_mode_vm(regs)) {
21145 + if (!user_mode(regs)) {
21146 unsigned int code_prologue = code_bytes * 43 / 64;
21147 unsigned int code_len = code_bytes;
21148 unsigned char c;
21149 u8 *ip;
21150 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21151
21152 pr_emerg("Stack:\n");
21153 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21154
21155 pr_emerg("Code:");
21156
21157 - ip = (u8 *)regs->ip - code_prologue;
21158 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21159 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21160 /* try starting at IP */
21161 - ip = (u8 *)regs->ip;
21162 + ip = (u8 *)regs->ip + cs_base;
21163 code_len = code_len - code_prologue + 1;
21164 }
21165 for (i = 0; i < code_len; i++, ip++) {
21166 @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21167 pr_cont(" Bad EIP value.");
21168 break;
21169 }
21170 - if (ip == (u8 *)regs->ip)
21171 + if (ip == (u8 *)regs->ip + cs_base)
21172 pr_cont(" <%02x>", c);
21173 else
21174 pr_cont(" %02x", c);
21175 @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21176 {
21177 unsigned short ud2;
21178
21179 + ip = ktla_ktva(ip);
21180 if (ip < PAGE_OFFSET)
21181 return 0;
21182 if (probe_kernel_address((unsigned short *)ip, ud2))
21183 @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21184
21185 return ud2 == 0x0b0f;
21186 }
21187 +
21188 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21189 +void pax_check_alloca(unsigned long size)
21190 +{
21191 + unsigned long sp = (unsigned long)&sp, stack_left;
21192 +
21193 + /* all kernel stacks are of the same size */
21194 + stack_left = sp & (THREAD_SIZE - 1);
21195 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21196 +}
21197 +EXPORT_SYMBOL(pax_check_alloca);
21198 +#endif
21199 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21200 index addb207..99635fa 100644
21201 --- a/arch/x86/kernel/dumpstack_64.c
21202 +++ b/arch/x86/kernel/dumpstack_64.c
21203 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21204 unsigned long *irq_stack_end =
21205 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21206 unsigned used = 0;
21207 - struct thread_info *tinfo;
21208 int graph = 0;
21209 unsigned long dummy;
21210 + void *stack_start;
21211
21212 if (!task)
21213 task = current;
21214 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21215 * current stack address. If the stacks consist of nested
21216 * exceptions
21217 */
21218 - tinfo = task_thread_info(task);
21219 for (;;) {
21220 char *id;
21221 unsigned long *estack_end;
21222 +
21223 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21224 &used, &id);
21225
21226 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21227 if (ops->stack(data, id) < 0)
21228 break;
21229
21230 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21231 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21232 data, estack_end, &graph);
21233 ops->stack(data, "<EOE>");
21234 /*
21235 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21236 * second-to-last pointer (index -2 to end) in the
21237 * exception stack:
21238 */
21239 + if ((u16)estack_end[-1] != __KERNEL_DS)
21240 + goto out;
21241 stack = (unsigned long *) estack_end[-2];
21242 continue;
21243 }
21244 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21245 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21246 if (ops->stack(data, "IRQ") < 0)
21247 break;
21248 - bp = ops->walk_stack(tinfo, stack, bp,
21249 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21250 ops, data, irq_stack_end, &graph);
21251 /*
21252 * We link to the next stack (which would be
21253 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21254 /*
21255 * This handles the process stack:
21256 */
21257 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21258 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21259 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21260 +out:
21261 put_cpu();
21262 }
21263 EXPORT_SYMBOL(dump_trace);
21264 @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21265
21266 return ud2 == 0x0b0f;
21267 }
21268 +
21269 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21270 +void pax_check_alloca(unsigned long size)
21271 +{
21272 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21273 + unsigned cpu, used;
21274 + char *id;
21275 +
21276 + /* check the process stack first */
21277 + stack_start = (unsigned long)task_stack_page(current);
21278 + stack_end = stack_start + THREAD_SIZE;
21279 + if (likely(stack_start <= sp && sp < stack_end)) {
21280 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21281 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21282 + return;
21283 + }
21284 +
21285 + cpu = get_cpu();
21286 +
21287 + /* check the irq stacks */
21288 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21289 + stack_start = stack_end - IRQ_STACK_SIZE;
21290 + if (stack_start <= sp && sp < stack_end) {
21291 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21292 + put_cpu();
21293 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21294 + return;
21295 + }
21296 +
21297 + /* check the exception stacks */
21298 + used = 0;
21299 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21300 + stack_start = stack_end - EXCEPTION_STKSZ;
21301 + if (stack_end && stack_start <= sp && sp < stack_end) {
21302 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21303 + put_cpu();
21304 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21305 + return;
21306 + }
21307 +
21308 + put_cpu();
21309 +
21310 + /* unknown stack */
21311 + BUG();
21312 +}
21313 +EXPORT_SYMBOL(pax_check_alloca);
21314 +#endif
21315 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21316 index 174da5f..5e55606 100644
21317 --- a/arch/x86/kernel/e820.c
21318 +++ b/arch/x86/kernel/e820.c
21319 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21320
21321 static void early_panic(char *msg)
21322 {
21323 - early_printk(msg);
21324 - panic(msg);
21325 + early_printk("%s", msg);
21326 + panic("%s", msg);
21327 }
21328
21329 static int userdef __initdata;
21330 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21331 index 01d1c18..8073693 100644
21332 --- a/arch/x86/kernel/early_printk.c
21333 +++ b/arch/x86/kernel/early_printk.c
21334 @@ -7,6 +7,7 @@
21335 #include <linux/pci_regs.h>
21336 #include <linux/pci_ids.h>
21337 #include <linux/errno.h>
21338 +#include <linux/sched.h>
21339 #include <asm/io.h>
21340 #include <asm/processor.h>
21341 #include <asm/fcntl.h>
21342 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21343 index a2a4f46..6cab058 100644
21344 --- a/arch/x86/kernel/entry_32.S
21345 +++ b/arch/x86/kernel/entry_32.S
21346 @@ -177,13 +177,153 @@
21347 /*CFI_REL_OFFSET gs, PT_GS*/
21348 .endm
21349 .macro SET_KERNEL_GS reg
21350 +
21351 +#ifdef CONFIG_CC_STACKPROTECTOR
21352 movl $(__KERNEL_STACK_CANARY), \reg
21353 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21354 + movl $(__USER_DS), \reg
21355 +#else
21356 + xorl \reg, \reg
21357 +#endif
21358 +
21359 movl \reg, %gs
21360 .endm
21361
21362 #endif /* CONFIG_X86_32_LAZY_GS */
21363
21364 -.macro SAVE_ALL
21365 +.macro pax_enter_kernel
21366 +#ifdef CONFIG_PAX_KERNEXEC
21367 + call pax_enter_kernel
21368 +#endif
21369 +.endm
21370 +
21371 +.macro pax_exit_kernel
21372 +#ifdef CONFIG_PAX_KERNEXEC
21373 + call pax_exit_kernel
21374 +#endif
21375 +.endm
21376 +
21377 +#ifdef CONFIG_PAX_KERNEXEC
21378 +ENTRY(pax_enter_kernel)
21379 +#ifdef CONFIG_PARAVIRT
21380 + pushl %eax
21381 + pushl %ecx
21382 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21383 + mov %eax, %esi
21384 +#else
21385 + mov %cr0, %esi
21386 +#endif
21387 + bts $16, %esi
21388 + jnc 1f
21389 + mov %cs, %esi
21390 + cmp $__KERNEL_CS, %esi
21391 + jz 3f
21392 + ljmp $__KERNEL_CS, $3f
21393 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21394 +2:
21395 +#ifdef CONFIG_PARAVIRT
21396 + mov %esi, %eax
21397 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21398 +#else
21399 + mov %esi, %cr0
21400 +#endif
21401 +3:
21402 +#ifdef CONFIG_PARAVIRT
21403 + popl %ecx
21404 + popl %eax
21405 +#endif
21406 + ret
21407 +ENDPROC(pax_enter_kernel)
21408 +
21409 +ENTRY(pax_exit_kernel)
21410 +#ifdef CONFIG_PARAVIRT
21411 + pushl %eax
21412 + pushl %ecx
21413 +#endif
21414 + mov %cs, %esi
21415 + cmp $__KERNEXEC_KERNEL_CS, %esi
21416 + jnz 2f
21417 +#ifdef CONFIG_PARAVIRT
21418 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21419 + mov %eax, %esi
21420 +#else
21421 + mov %cr0, %esi
21422 +#endif
21423 + btr $16, %esi
21424 + ljmp $__KERNEL_CS, $1f
21425 +1:
21426 +#ifdef CONFIG_PARAVIRT
21427 + mov %esi, %eax
21428 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21429 +#else
21430 + mov %esi, %cr0
21431 +#endif
21432 +2:
21433 +#ifdef CONFIG_PARAVIRT
21434 + popl %ecx
21435 + popl %eax
21436 +#endif
21437 + ret
21438 +ENDPROC(pax_exit_kernel)
21439 +#endif
21440 +
21441 + .macro pax_erase_kstack
21442 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21443 + call pax_erase_kstack
21444 +#endif
21445 + .endm
21446 +
21447 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21448 +/*
21449 + * ebp: thread_info
21450 + */
21451 +ENTRY(pax_erase_kstack)
21452 + pushl %edi
21453 + pushl %ecx
21454 + pushl %eax
21455 +
21456 + mov TI_lowest_stack(%ebp), %edi
21457 + mov $-0xBEEF, %eax
21458 + std
21459 +
21460 +1: mov %edi, %ecx
21461 + and $THREAD_SIZE_asm - 1, %ecx
21462 + shr $2, %ecx
21463 + repne scasl
21464 + jecxz 2f
21465 +
21466 + cmp $2*16, %ecx
21467 + jc 2f
21468 +
21469 + mov $2*16, %ecx
21470 + repe scasl
21471 + jecxz 2f
21472 + jne 1b
21473 +
21474 +2: cld
21475 + mov %esp, %ecx
21476 + sub %edi, %ecx
21477 +
21478 + cmp $THREAD_SIZE_asm, %ecx
21479 + jb 3f
21480 + ud2
21481 +3:
21482 +
21483 + shr $2, %ecx
21484 + rep stosl
21485 +
21486 + mov TI_task_thread_sp0(%ebp), %edi
21487 + sub $128, %edi
21488 + mov %edi, TI_lowest_stack(%ebp)
21489 +
21490 + popl %eax
21491 + popl %ecx
21492 + popl %edi
21493 + ret
21494 +ENDPROC(pax_erase_kstack)
21495 +#endif
21496 +
21497 +.macro __SAVE_ALL _DS
21498 cld
21499 PUSH_GS
21500 pushl_cfi %fs
21501 @@ -206,7 +346,7 @@
21502 CFI_REL_OFFSET ecx, 0
21503 pushl_cfi %ebx
21504 CFI_REL_OFFSET ebx, 0
21505 - movl $(__USER_DS), %edx
21506 + movl $\_DS, %edx
21507 movl %edx, %ds
21508 movl %edx, %es
21509 movl $(__KERNEL_PERCPU), %edx
21510 @@ -214,6 +354,15 @@
21511 SET_KERNEL_GS %edx
21512 .endm
21513
21514 +.macro SAVE_ALL
21515 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21516 + __SAVE_ALL __KERNEL_DS
21517 + pax_enter_kernel
21518 +#else
21519 + __SAVE_ALL __USER_DS
21520 +#endif
21521 +.endm
21522 +
21523 .macro RESTORE_INT_REGS
21524 popl_cfi %ebx
21525 CFI_RESTORE ebx
21526 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
21527 popfl_cfi
21528 jmp syscall_exit
21529 CFI_ENDPROC
21530 -END(ret_from_fork)
21531 +ENDPROC(ret_from_fork)
21532
21533 ENTRY(ret_from_kernel_thread)
21534 CFI_STARTPROC
21535 @@ -344,7 +493,15 @@ ret_from_intr:
21536 andl $SEGMENT_RPL_MASK, %eax
21537 #endif
21538 cmpl $USER_RPL, %eax
21539 +
21540 +#ifdef CONFIG_PAX_KERNEXEC
21541 + jae resume_userspace
21542 +
21543 + pax_exit_kernel
21544 + jmp resume_kernel
21545 +#else
21546 jb resume_kernel # not returning to v8086 or userspace
21547 +#endif
21548
21549 ENTRY(resume_userspace)
21550 LOCKDEP_SYS_EXIT
21551 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
21552 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
21553 # int/exception return?
21554 jne work_pending
21555 - jmp restore_all
21556 -END(ret_from_exception)
21557 + jmp restore_all_pax
21558 +ENDPROC(ret_from_exception)
21559
21560 #ifdef CONFIG_PREEMPT
21561 ENTRY(resume_kernel)
21562 @@ -369,7 +526,7 @@ need_resched:
21563 jz restore_all
21564 call preempt_schedule_irq
21565 jmp need_resched
21566 -END(resume_kernel)
21567 +ENDPROC(resume_kernel)
21568 #endif
21569 CFI_ENDPROC
21570 /*
21571 @@ -403,30 +560,45 @@ sysenter_past_esp:
21572 /*CFI_REL_OFFSET cs, 0*/
21573 /*
21574 * Push current_thread_info()->sysenter_return to the stack.
21575 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
21576 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
21577 */
21578 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
21579 + pushl_cfi $0
21580 CFI_REL_OFFSET eip, 0
21581
21582 pushl_cfi %eax
21583 SAVE_ALL
21584 + GET_THREAD_INFO(%ebp)
21585 + movl TI_sysenter_return(%ebp),%ebp
21586 + movl %ebp,PT_EIP(%esp)
21587 ENABLE_INTERRUPTS(CLBR_NONE)
21588
21589 /*
21590 * Load the potential sixth argument from user stack.
21591 * Careful about security.
21592 */
21593 + movl PT_OLDESP(%esp),%ebp
21594 +
21595 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21596 + mov PT_OLDSS(%esp),%ds
21597 +1: movl %ds:(%ebp),%ebp
21598 + push %ss
21599 + pop %ds
21600 +#else
21601 cmpl $__PAGE_OFFSET-3,%ebp
21602 jae syscall_fault
21603 ASM_STAC
21604 1: movl (%ebp),%ebp
21605 ASM_CLAC
21606 +#endif
21607 +
21608 movl %ebp,PT_EBP(%esp)
21609 _ASM_EXTABLE(1b,syscall_fault)
21610
21611 GET_THREAD_INFO(%ebp)
21612
21613 +#ifdef CONFIG_PAX_RANDKSTACK
21614 + pax_erase_kstack
21615 +#endif
21616 +
21617 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21618 jnz sysenter_audit
21619 sysenter_do_call:
21620 @@ -441,12 +613,24 @@ sysenter_do_call:
21621 testl $_TIF_ALLWORK_MASK, %ecx
21622 jne sysexit_audit
21623 sysenter_exit:
21624 +
21625 +#ifdef CONFIG_PAX_RANDKSTACK
21626 + pushl_cfi %eax
21627 + movl %esp, %eax
21628 + call pax_randomize_kstack
21629 + popl_cfi %eax
21630 +#endif
21631 +
21632 + pax_erase_kstack
21633 +
21634 /* if something modifies registers it must also disable sysexit */
21635 movl PT_EIP(%esp), %edx
21636 movl PT_OLDESP(%esp), %ecx
21637 xorl %ebp,%ebp
21638 TRACE_IRQS_ON
21639 1: mov PT_FS(%esp), %fs
21640 +2: mov PT_DS(%esp), %ds
21641 +3: mov PT_ES(%esp), %es
21642 PTGS_TO_GS
21643 ENABLE_INTERRUPTS_SYSEXIT
21644
21645 @@ -463,6 +647,9 @@ sysenter_audit:
21646 movl %eax,%edx /* 2nd arg: syscall number */
21647 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
21648 call __audit_syscall_entry
21649 +
21650 + pax_erase_kstack
21651 +
21652 pushl_cfi %ebx
21653 movl PT_EAX(%esp),%eax /* reload syscall number */
21654 jmp sysenter_do_call
21655 @@ -488,10 +675,16 @@ sysexit_audit:
21656
21657 CFI_ENDPROC
21658 .pushsection .fixup,"ax"
21659 -2: movl $0,PT_FS(%esp)
21660 +4: movl $0,PT_FS(%esp)
21661 + jmp 1b
21662 +5: movl $0,PT_DS(%esp)
21663 + jmp 1b
21664 +6: movl $0,PT_ES(%esp)
21665 jmp 1b
21666 .popsection
21667 - _ASM_EXTABLE(1b,2b)
21668 + _ASM_EXTABLE(1b,4b)
21669 + _ASM_EXTABLE(2b,5b)
21670 + _ASM_EXTABLE(3b,6b)
21671 PTGS_TO_GS_EX
21672 ENDPROC(ia32_sysenter_target)
21673
21674 @@ -506,6 +699,11 @@ ENTRY(system_call)
21675 pushl_cfi %eax # save orig_eax
21676 SAVE_ALL
21677 GET_THREAD_INFO(%ebp)
21678 +
21679 +#ifdef CONFIG_PAX_RANDKSTACK
21680 + pax_erase_kstack
21681 +#endif
21682 +
21683 # system call tracing in operation / emulation
21684 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21685 jnz syscall_trace_entry
21686 @@ -524,6 +722,15 @@ syscall_exit:
21687 testl $_TIF_ALLWORK_MASK, %ecx # current->work
21688 jne syscall_exit_work
21689
21690 +restore_all_pax:
21691 +
21692 +#ifdef CONFIG_PAX_RANDKSTACK
21693 + movl %esp, %eax
21694 + call pax_randomize_kstack
21695 +#endif
21696 +
21697 + pax_erase_kstack
21698 +
21699 restore_all:
21700 TRACE_IRQS_IRET
21701 restore_all_notrace:
21702 @@ -580,14 +787,34 @@ ldt_ss:
21703 * compensating for the offset by changing to the ESPFIX segment with
21704 * a base address that matches for the difference.
21705 */
21706 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
21707 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
21708 mov %esp, %edx /* load kernel esp */
21709 mov PT_OLDESP(%esp), %eax /* load userspace esp */
21710 mov %dx, %ax /* eax: new kernel esp */
21711 sub %eax, %edx /* offset (low word is 0) */
21712 +#ifdef CONFIG_SMP
21713 + movl PER_CPU_VAR(cpu_number), %ebx
21714 + shll $PAGE_SHIFT_asm, %ebx
21715 + addl $cpu_gdt_table, %ebx
21716 +#else
21717 + movl $cpu_gdt_table, %ebx
21718 +#endif
21719 shr $16, %edx
21720 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
21721 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
21722 +
21723 +#ifdef CONFIG_PAX_KERNEXEC
21724 + mov %cr0, %esi
21725 + btr $16, %esi
21726 + mov %esi, %cr0
21727 +#endif
21728 +
21729 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
21730 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
21731 +
21732 +#ifdef CONFIG_PAX_KERNEXEC
21733 + bts $16, %esi
21734 + mov %esi, %cr0
21735 +#endif
21736 +
21737 pushl_cfi $__ESPFIX_SS
21738 pushl_cfi %eax /* new kernel esp */
21739 /* Disable interrupts, but do not irqtrace this section: we
21740 @@ -616,20 +843,18 @@ work_resched:
21741 movl TI_flags(%ebp), %ecx
21742 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
21743 # than syscall tracing?
21744 - jz restore_all
21745 + jz restore_all_pax
21746 testb $_TIF_NEED_RESCHED, %cl
21747 jnz work_resched
21748
21749 work_notifysig: # deal with pending signals and
21750 # notify-resume requests
21751 + movl %esp, %eax
21752 #ifdef CONFIG_VM86
21753 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
21754 - movl %esp, %eax
21755 jne work_notifysig_v86 # returning to kernel-space or
21756 # vm86-space
21757 1:
21758 -#else
21759 - movl %esp, %eax
21760 #endif
21761 TRACE_IRQS_ON
21762 ENABLE_INTERRUPTS(CLBR_NONE)
21763 @@ -650,7 +875,7 @@ work_notifysig_v86:
21764 movl %eax, %esp
21765 jmp 1b
21766 #endif
21767 -END(work_pending)
21768 +ENDPROC(work_pending)
21769
21770 # perform syscall exit tracing
21771 ALIGN
21772 @@ -658,11 +883,14 @@ syscall_trace_entry:
21773 movl $-ENOSYS,PT_EAX(%esp)
21774 movl %esp, %eax
21775 call syscall_trace_enter
21776 +
21777 + pax_erase_kstack
21778 +
21779 /* What it returned is what we'll actually use. */
21780 cmpl $(NR_syscalls), %eax
21781 jnae syscall_call
21782 jmp syscall_exit
21783 -END(syscall_trace_entry)
21784 +ENDPROC(syscall_trace_entry)
21785
21786 # perform syscall exit tracing
21787 ALIGN
21788 @@ -675,21 +903,25 @@ syscall_exit_work:
21789 movl %esp, %eax
21790 call syscall_trace_leave
21791 jmp resume_userspace
21792 -END(syscall_exit_work)
21793 +ENDPROC(syscall_exit_work)
21794 CFI_ENDPROC
21795
21796 RING0_INT_FRAME # can't unwind into user space anyway
21797 syscall_fault:
21798 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21799 + push %ss
21800 + pop %ds
21801 +#endif
21802 ASM_CLAC
21803 GET_THREAD_INFO(%ebp)
21804 movl $-EFAULT,PT_EAX(%esp)
21805 jmp resume_userspace
21806 -END(syscall_fault)
21807 +ENDPROC(syscall_fault)
21808
21809 syscall_badsys:
21810 movl $-ENOSYS,PT_EAX(%esp)
21811 jmp resume_userspace
21812 -END(syscall_badsys)
21813 +ENDPROC(syscall_badsys)
21814 CFI_ENDPROC
21815 /*
21816 * End of kprobes section
21817 @@ -705,8 +937,15 @@ END(syscall_badsys)
21818 * normal stack and adjusts ESP with the matching offset.
21819 */
21820 /* fixup the stack */
21821 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21822 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21823 +#ifdef CONFIG_SMP
21824 + movl PER_CPU_VAR(cpu_number), %ebx
21825 + shll $PAGE_SHIFT_asm, %ebx
21826 + addl $cpu_gdt_table, %ebx
21827 +#else
21828 + movl $cpu_gdt_table, %ebx
21829 +#endif
21830 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21831 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21832 shl $16, %eax
21833 addl %esp, %eax /* the adjusted stack pointer */
21834 pushl_cfi $__KERNEL_DS
21835 @@ -759,7 +998,7 @@ vector=vector+1
21836 .endr
21837 2: jmp common_interrupt
21838 .endr
21839 -END(irq_entries_start)
21840 +ENDPROC(irq_entries_start)
21841
21842 .previous
21843 END(interrupt)
21844 @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
21845 pushl_cfi $do_coprocessor_error
21846 jmp error_code
21847 CFI_ENDPROC
21848 -END(coprocessor_error)
21849 +ENDPROC(coprocessor_error)
21850
21851 ENTRY(simd_coprocessor_error)
21852 RING0_INT_FRAME
21853 @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
21854 .section .altinstructions,"a"
21855 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21856 .previous
21857 -.section .altinstr_replacement,"ax"
21858 +.section .altinstr_replacement,"a"
21859 663: pushl $do_simd_coprocessor_error
21860 664:
21861 .previous
21862 @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
21863 #endif
21864 jmp error_code
21865 CFI_ENDPROC
21866 -END(simd_coprocessor_error)
21867 +ENDPROC(simd_coprocessor_error)
21868
21869 ENTRY(device_not_available)
21870 RING0_INT_FRAME
21871 @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
21872 pushl_cfi $do_device_not_available
21873 jmp error_code
21874 CFI_ENDPROC
21875 -END(device_not_available)
21876 +ENDPROC(device_not_available)
21877
21878 #ifdef CONFIG_PARAVIRT
21879 ENTRY(native_iret)
21880 iret
21881 _ASM_EXTABLE(native_iret, iret_exc)
21882 -END(native_iret)
21883 +ENDPROC(native_iret)
21884
21885 ENTRY(native_irq_enable_sysexit)
21886 sti
21887 sysexit
21888 -END(native_irq_enable_sysexit)
21889 +ENDPROC(native_irq_enable_sysexit)
21890 #endif
21891
21892 ENTRY(overflow)
21893 @@ -872,7 +1111,7 @@ ENTRY(overflow)
21894 pushl_cfi $do_overflow
21895 jmp error_code
21896 CFI_ENDPROC
21897 -END(overflow)
21898 +ENDPROC(overflow)
21899
21900 ENTRY(bounds)
21901 RING0_INT_FRAME
21902 @@ -881,7 +1120,7 @@ ENTRY(bounds)
21903 pushl_cfi $do_bounds
21904 jmp error_code
21905 CFI_ENDPROC
21906 -END(bounds)
21907 +ENDPROC(bounds)
21908
21909 ENTRY(invalid_op)
21910 RING0_INT_FRAME
21911 @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
21912 pushl_cfi $do_invalid_op
21913 jmp error_code
21914 CFI_ENDPROC
21915 -END(invalid_op)
21916 +ENDPROC(invalid_op)
21917
21918 ENTRY(coprocessor_segment_overrun)
21919 RING0_INT_FRAME
21920 @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
21921 pushl_cfi $do_coprocessor_segment_overrun
21922 jmp error_code
21923 CFI_ENDPROC
21924 -END(coprocessor_segment_overrun)
21925 +ENDPROC(coprocessor_segment_overrun)
21926
21927 ENTRY(invalid_TSS)
21928 RING0_EC_FRAME
21929 @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
21930 pushl_cfi $do_invalid_TSS
21931 jmp error_code
21932 CFI_ENDPROC
21933 -END(invalid_TSS)
21934 +ENDPROC(invalid_TSS)
21935
21936 ENTRY(segment_not_present)
21937 RING0_EC_FRAME
21938 @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
21939 pushl_cfi $do_segment_not_present
21940 jmp error_code
21941 CFI_ENDPROC
21942 -END(segment_not_present)
21943 +ENDPROC(segment_not_present)
21944
21945 ENTRY(stack_segment)
21946 RING0_EC_FRAME
21947 @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
21948 pushl_cfi $do_stack_segment
21949 jmp error_code
21950 CFI_ENDPROC
21951 -END(stack_segment)
21952 +ENDPROC(stack_segment)
21953
21954 ENTRY(alignment_check)
21955 RING0_EC_FRAME
21956 @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
21957 pushl_cfi $do_alignment_check
21958 jmp error_code
21959 CFI_ENDPROC
21960 -END(alignment_check)
21961 +ENDPROC(alignment_check)
21962
21963 ENTRY(divide_error)
21964 RING0_INT_FRAME
21965 @@ -940,7 +1179,7 @@ ENTRY(divide_error)
21966 pushl_cfi $do_divide_error
21967 jmp error_code
21968 CFI_ENDPROC
21969 -END(divide_error)
21970 +ENDPROC(divide_error)
21971
21972 #ifdef CONFIG_X86_MCE
21973 ENTRY(machine_check)
21974 @@ -950,7 +1189,7 @@ ENTRY(machine_check)
21975 pushl_cfi machine_check_vector
21976 jmp error_code
21977 CFI_ENDPROC
21978 -END(machine_check)
21979 +ENDPROC(machine_check)
21980 #endif
21981
21982 ENTRY(spurious_interrupt_bug)
21983 @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
21984 pushl_cfi $do_spurious_interrupt_bug
21985 jmp error_code
21986 CFI_ENDPROC
21987 -END(spurious_interrupt_bug)
21988 +ENDPROC(spurious_interrupt_bug)
21989 /*
21990 * End of kprobes section
21991 */
21992 @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21993
21994 ENTRY(mcount)
21995 ret
21996 -END(mcount)
21997 +ENDPROC(mcount)
21998
21999 ENTRY(ftrace_caller)
22000 cmpl $0, function_trace_stop
22001 @@ -1103,7 +1342,7 @@ ftrace_graph_call:
22002 .globl ftrace_stub
22003 ftrace_stub:
22004 ret
22005 -END(ftrace_caller)
22006 +ENDPROC(ftrace_caller)
22007
22008 ENTRY(ftrace_regs_caller)
22009 pushf /* push flags before compare (in cs location) */
22010 @@ -1207,7 +1446,7 @@ trace:
22011 popl %ecx
22012 popl %eax
22013 jmp ftrace_stub
22014 -END(mcount)
22015 +ENDPROC(mcount)
22016 #endif /* CONFIG_DYNAMIC_FTRACE */
22017 #endif /* CONFIG_FUNCTION_TRACER */
22018
22019 @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22020 popl %ecx
22021 popl %eax
22022 ret
22023 -END(ftrace_graph_caller)
22024 +ENDPROC(ftrace_graph_caller)
22025
22026 .globl return_to_handler
22027 return_to_handler:
22028 @@ -1291,15 +1530,18 @@ error_code:
22029 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22030 REG_TO_PTGS %ecx
22031 SET_KERNEL_GS %ecx
22032 - movl $(__USER_DS), %ecx
22033 + movl $(__KERNEL_DS), %ecx
22034 movl %ecx, %ds
22035 movl %ecx, %es
22036 +
22037 + pax_enter_kernel
22038 +
22039 TRACE_IRQS_OFF
22040 movl %esp,%eax # pt_regs pointer
22041 call *%edi
22042 jmp ret_from_exception
22043 CFI_ENDPROC
22044 -END(page_fault)
22045 +ENDPROC(page_fault)
22046
22047 /*
22048 * Debug traps and NMI can happen at the one SYSENTER instruction
22049 @@ -1342,7 +1584,7 @@ debug_stack_correct:
22050 call do_debug
22051 jmp ret_from_exception
22052 CFI_ENDPROC
22053 -END(debug)
22054 +ENDPROC(debug)
22055
22056 /*
22057 * NMI is doubly nasty. It can happen _while_ we're handling
22058 @@ -1380,6 +1622,9 @@ nmi_stack_correct:
22059 xorl %edx,%edx # zero error code
22060 movl %esp,%eax # pt_regs pointer
22061 call do_nmi
22062 +
22063 + pax_exit_kernel
22064 +
22065 jmp restore_all_notrace
22066 CFI_ENDPROC
22067
22068 @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22069 FIXUP_ESPFIX_STACK # %eax == %esp
22070 xorl %edx,%edx # zero error code
22071 call do_nmi
22072 +
22073 + pax_exit_kernel
22074 +
22075 RESTORE_REGS
22076 lss 12+4(%esp), %esp # back to espfix stack
22077 CFI_ADJUST_CFA_OFFSET -24
22078 jmp irq_return
22079 CFI_ENDPROC
22080 -END(nmi)
22081 +ENDPROC(nmi)
22082
22083 ENTRY(int3)
22084 RING0_INT_FRAME
22085 @@ -1434,14 +1682,14 @@ ENTRY(int3)
22086 call do_int3
22087 jmp ret_from_exception
22088 CFI_ENDPROC
22089 -END(int3)
22090 +ENDPROC(int3)
22091
22092 ENTRY(general_protection)
22093 RING0_EC_FRAME
22094 pushl_cfi $do_general_protection
22095 jmp error_code
22096 CFI_ENDPROC
22097 -END(general_protection)
22098 +ENDPROC(general_protection)
22099
22100 #ifdef CONFIG_KVM_GUEST
22101 ENTRY(async_page_fault)
22102 @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22103 pushl_cfi $do_async_page_fault
22104 jmp error_code
22105 CFI_ENDPROC
22106 -END(async_page_fault)
22107 +ENDPROC(async_page_fault)
22108 #endif
22109
22110 /*
22111 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22112 index 1e96c36..3ff710a 100644
22113 --- a/arch/x86/kernel/entry_64.S
22114 +++ b/arch/x86/kernel/entry_64.S
22115 @@ -59,6 +59,8 @@
22116 #include <asm/context_tracking.h>
22117 #include <asm/smap.h>
22118 #include <linux/err.h>
22119 +#include <asm/pgtable.h>
22120 +#include <asm/alternative-asm.h>
22121
22122 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22123 #include <linux/elf-em.h>
22124 @@ -80,8 +82,9 @@
22125 #ifdef CONFIG_DYNAMIC_FTRACE
22126
22127 ENTRY(function_hook)
22128 + pax_force_retaddr
22129 retq
22130 -END(function_hook)
22131 +ENDPROC(function_hook)
22132
22133 /* skip is set if stack has been adjusted */
22134 .macro ftrace_caller_setup skip=0
22135 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22136 #endif
22137
22138 GLOBAL(ftrace_stub)
22139 + pax_force_retaddr
22140 retq
22141 -END(ftrace_caller)
22142 +ENDPROC(ftrace_caller)
22143
22144 ENTRY(ftrace_regs_caller)
22145 /* Save the current flags before compare (in SS location)*/
22146 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22147 popfq
22148 jmp ftrace_stub
22149
22150 -END(ftrace_regs_caller)
22151 +ENDPROC(ftrace_regs_caller)
22152
22153
22154 #else /* ! CONFIG_DYNAMIC_FTRACE */
22155 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22156 #endif
22157
22158 GLOBAL(ftrace_stub)
22159 + pax_force_retaddr
22160 retq
22161
22162 trace:
22163 @@ -225,12 +230,13 @@ trace:
22164 #endif
22165 subq $MCOUNT_INSN_SIZE, %rdi
22166
22167 + pax_force_fptr ftrace_trace_function
22168 call *ftrace_trace_function
22169
22170 MCOUNT_RESTORE_FRAME
22171
22172 jmp ftrace_stub
22173 -END(function_hook)
22174 +ENDPROC(function_hook)
22175 #endif /* CONFIG_DYNAMIC_FTRACE */
22176 #endif /* CONFIG_FUNCTION_TRACER */
22177
22178 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22179
22180 MCOUNT_RESTORE_FRAME
22181
22182 + pax_force_retaddr
22183 retq
22184 -END(ftrace_graph_caller)
22185 +ENDPROC(ftrace_graph_caller)
22186
22187 GLOBAL(return_to_handler)
22188 subq $24, %rsp
22189 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22190 movq 8(%rsp), %rdx
22191 movq (%rsp), %rax
22192 addq $24, %rsp
22193 + pax_force_fptr %rdi
22194 jmp *%rdi
22195 +ENDPROC(return_to_handler)
22196 #endif
22197
22198
22199 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22200 ENDPROC(native_usergs_sysret64)
22201 #endif /* CONFIG_PARAVIRT */
22202
22203 + .macro ljmpq sel, off
22204 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22205 + .byte 0x48; ljmp *1234f(%rip)
22206 + .pushsection .rodata
22207 + .align 16
22208 + 1234: .quad \off; .word \sel
22209 + .popsection
22210 +#else
22211 + pushq $\sel
22212 + pushq $\off
22213 + lretq
22214 +#endif
22215 + .endm
22216 +
22217 + .macro pax_enter_kernel
22218 + pax_set_fptr_mask
22219 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22220 + call pax_enter_kernel
22221 +#endif
22222 + .endm
22223 +
22224 + .macro pax_exit_kernel
22225 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22226 + call pax_exit_kernel
22227 +#endif
22228 +
22229 + .endm
22230 +
22231 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22232 +ENTRY(pax_enter_kernel)
22233 + pushq %rdi
22234 +
22235 +#ifdef CONFIG_PARAVIRT
22236 + PV_SAVE_REGS(CLBR_RDI)
22237 +#endif
22238 +
22239 +#ifdef CONFIG_PAX_KERNEXEC
22240 + GET_CR0_INTO_RDI
22241 + bts $16,%rdi
22242 + jnc 3f
22243 + mov %cs,%edi
22244 + cmp $__KERNEL_CS,%edi
22245 + jnz 2f
22246 +1:
22247 +#endif
22248 +
22249 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22250 + 661: jmp 111f
22251 + .pushsection .altinstr_replacement, "a"
22252 + 662: ASM_NOP2
22253 + .popsection
22254 + .pushsection .altinstructions, "a"
22255 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22256 + .popsection
22257 + GET_CR3_INTO_RDI
22258 + cmp $0,%dil
22259 + jnz 112f
22260 + mov $__KERNEL_DS,%edi
22261 + mov %edi,%ss
22262 + jmp 111f
22263 +112: cmp $1,%dil
22264 + jz 113f
22265 + ud2
22266 +113: sub $4097,%rdi
22267 + bts $63,%rdi
22268 + SET_RDI_INTO_CR3
22269 + mov $__UDEREF_KERNEL_DS,%edi
22270 + mov %edi,%ss
22271 +111:
22272 +#endif
22273 +
22274 +#ifdef CONFIG_PARAVIRT
22275 + PV_RESTORE_REGS(CLBR_RDI)
22276 +#endif
22277 +
22278 + popq %rdi
22279 + pax_force_retaddr
22280 + retq
22281 +
22282 +#ifdef CONFIG_PAX_KERNEXEC
22283 +2: ljmpq __KERNEL_CS,1b
22284 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22285 +4: SET_RDI_INTO_CR0
22286 + jmp 1b
22287 +#endif
22288 +ENDPROC(pax_enter_kernel)
22289 +
22290 +ENTRY(pax_exit_kernel)
22291 + pushq %rdi
22292 +
22293 +#ifdef CONFIG_PARAVIRT
22294 + PV_SAVE_REGS(CLBR_RDI)
22295 +#endif
22296 +
22297 +#ifdef CONFIG_PAX_KERNEXEC
22298 + mov %cs,%rdi
22299 + cmp $__KERNEXEC_KERNEL_CS,%edi
22300 + jz 2f
22301 + GET_CR0_INTO_RDI
22302 + bts $16,%rdi
22303 + jnc 4f
22304 +1:
22305 +#endif
22306 +
22307 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22308 + 661: jmp 111f
22309 + .pushsection .altinstr_replacement, "a"
22310 + 662: ASM_NOP2
22311 + .popsection
22312 + .pushsection .altinstructions, "a"
22313 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22314 + .popsection
22315 + mov %ss,%edi
22316 + cmp $__UDEREF_KERNEL_DS,%edi
22317 + jnz 111f
22318 + GET_CR3_INTO_RDI
22319 + cmp $0,%dil
22320 + jz 112f
22321 + ud2
22322 +112: add $4097,%rdi
22323 + bts $63,%rdi
22324 + SET_RDI_INTO_CR3
22325 + mov $__KERNEL_DS,%edi
22326 + mov %edi,%ss
22327 +111:
22328 +#endif
22329 +
22330 +#ifdef CONFIG_PARAVIRT
22331 + PV_RESTORE_REGS(CLBR_RDI);
22332 +#endif
22333 +
22334 + popq %rdi
22335 + pax_force_retaddr
22336 + retq
22337 +
22338 +#ifdef CONFIG_PAX_KERNEXEC
22339 +2: GET_CR0_INTO_RDI
22340 + btr $16,%rdi
22341 + jnc 4f
22342 + ljmpq __KERNEL_CS,3f
22343 +3: SET_RDI_INTO_CR0
22344 + jmp 1b
22345 +4: ud2
22346 + jmp 4b
22347 +#endif
22348 +ENDPROC(pax_exit_kernel)
22349 +#endif
22350 +
22351 + .macro pax_enter_kernel_user
22352 + pax_set_fptr_mask
22353 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22354 + call pax_enter_kernel_user
22355 +#endif
22356 + .endm
22357 +
22358 + .macro pax_exit_kernel_user
22359 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22360 + call pax_exit_kernel_user
22361 +#endif
22362 +#ifdef CONFIG_PAX_RANDKSTACK
22363 + pushq %rax
22364 + pushq %r11
22365 + call pax_randomize_kstack
22366 + popq %r11
22367 + popq %rax
22368 +#endif
22369 + .endm
22370 +
22371 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22372 +ENTRY(pax_enter_kernel_user)
22373 + pushq %rdi
22374 + pushq %rbx
22375 +
22376 +#ifdef CONFIG_PARAVIRT
22377 + PV_SAVE_REGS(CLBR_RDI)
22378 +#endif
22379 +
22380 + 661: jmp 111f
22381 + .pushsection .altinstr_replacement, "a"
22382 + 662: ASM_NOP2
22383 + .popsection
22384 + .pushsection .altinstructions, "a"
22385 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22386 + .popsection
22387 + GET_CR3_INTO_RDI
22388 + cmp $1,%dil
22389 + jnz 4f
22390 + sub $4097,%rdi
22391 + bts $63,%rdi
22392 + SET_RDI_INTO_CR3
22393 + jmp 3f
22394 +111:
22395 +
22396 + GET_CR3_INTO_RDI
22397 + mov %rdi,%rbx
22398 + add $__START_KERNEL_map,%rbx
22399 + sub phys_base(%rip),%rbx
22400 +
22401 +#ifdef CONFIG_PARAVIRT
22402 + cmpl $0, pv_info+PARAVIRT_enabled
22403 + jz 1f
22404 + pushq %rdi
22405 + i = 0
22406 + .rept USER_PGD_PTRS
22407 + mov i*8(%rbx),%rsi
22408 + mov $0,%sil
22409 + lea i*8(%rbx),%rdi
22410 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22411 + i = i + 1
22412 + .endr
22413 + popq %rdi
22414 + jmp 2f
22415 +1:
22416 +#endif
22417 +
22418 + i = 0
22419 + .rept USER_PGD_PTRS
22420 + movb $0,i*8(%rbx)
22421 + i = i + 1
22422 + .endr
22423 +
22424 +2: SET_RDI_INTO_CR3
22425 +
22426 +#ifdef CONFIG_PAX_KERNEXEC
22427 + GET_CR0_INTO_RDI
22428 + bts $16,%rdi
22429 + SET_RDI_INTO_CR0
22430 +#endif
22431 +
22432 +3:
22433 +
22434 +#ifdef CONFIG_PARAVIRT
22435 + PV_RESTORE_REGS(CLBR_RDI)
22436 +#endif
22437 +
22438 + popq %rbx
22439 + popq %rdi
22440 + pax_force_retaddr
22441 + retq
22442 +4: ud2
22443 +ENDPROC(pax_enter_kernel_user)
22444 +
22445 +ENTRY(pax_exit_kernel_user)
22446 + pushq %rdi
22447 + pushq %rbx
22448 +
22449 +#ifdef CONFIG_PARAVIRT
22450 + PV_SAVE_REGS(CLBR_RDI)
22451 +#endif
22452 +
22453 + GET_CR3_INTO_RDI
22454 + 661: jmp 1f
22455 + .pushsection .altinstr_replacement, "a"
22456 + 662: ASM_NOP2
22457 + .popsection
22458 + .pushsection .altinstructions, "a"
22459 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22460 + .popsection
22461 + cmp $0,%dil
22462 + jnz 3f
22463 + add $4097,%rdi
22464 + bts $63,%rdi
22465 + SET_RDI_INTO_CR3
22466 + jmp 2f
22467 +1:
22468 +
22469 + mov %rdi,%rbx
22470 +
22471 +#ifdef CONFIG_PAX_KERNEXEC
22472 + GET_CR0_INTO_RDI
22473 + btr $16,%rdi
22474 + jnc 3f
22475 + SET_RDI_INTO_CR0
22476 +#endif
22477 +
22478 + add $__START_KERNEL_map,%rbx
22479 + sub phys_base(%rip),%rbx
22480 +
22481 +#ifdef CONFIG_PARAVIRT
22482 + cmpl $0, pv_info+PARAVIRT_enabled
22483 + jz 1f
22484 + i = 0
22485 + .rept USER_PGD_PTRS
22486 + mov i*8(%rbx),%rsi
22487 + mov $0x67,%sil
22488 + lea i*8(%rbx),%rdi
22489 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22490 + i = i + 1
22491 + .endr
22492 + jmp 2f
22493 +1:
22494 +#endif
22495 +
22496 + i = 0
22497 + .rept USER_PGD_PTRS
22498 + movb $0x67,i*8(%rbx)
22499 + i = i + 1
22500 + .endr
22501 +2:
22502 +
22503 +#ifdef CONFIG_PARAVIRT
22504 + PV_RESTORE_REGS(CLBR_RDI)
22505 +#endif
22506 +
22507 + popq %rbx
22508 + popq %rdi
22509 + pax_force_retaddr
22510 + retq
22511 +3: ud2
22512 +ENDPROC(pax_exit_kernel_user)
22513 +#endif
22514 +
22515 + .macro pax_enter_kernel_nmi
22516 + pax_set_fptr_mask
22517 +
22518 +#ifdef CONFIG_PAX_KERNEXEC
22519 + GET_CR0_INTO_RDI
22520 + bts $16,%rdi
22521 + jc 110f
22522 + SET_RDI_INTO_CR0
22523 + or $2,%ebx
22524 +110:
22525 +#endif
22526 +
22527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22528 + 661: jmp 111f
22529 + .pushsection .altinstr_replacement, "a"
22530 + 662: ASM_NOP2
22531 + .popsection
22532 + .pushsection .altinstructions, "a"
22533 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22534 + .popsection
22535 + GET_CR3_INTO_RDI
22536 + cmp $0,%dil
22537 + jz 111f
22538 + sub $4097,%rdi
22539 + or $4,%ebx
22540 + bts $63,%rdi
22541 + SET_RDI_INTO_CR3
22542 + mov $__UDEREF_KERNEL_DS,%edi
22543 + mov %edi,%ss
22544 +111:
22545 +#endif
22546 + .endm
22547 +
22548 + .macro pax_exit_kernel_nmi
22549 +#ifdef CONFIG_PAX_KERNEXEC
22550 + btr $1,%ebx
22551 + jnc 110f
22552 + GET_CR0_INTO_RDI
22553 + btr $16,%rdi
22554 + SET_RDI_INTO_CR0
22555 +110:
22556 +#endif
22557 +
22558 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22559 + btr $2,%ebx
22560 + jnc 111f
22561 + GET_CR3_INTO_RDI
22562 + add $4097,%rdi
22563 + bts $63,%rdi
22564 + SET_RDI_INTO_CR3
22565 + mov $__KERNEL_DS,%edi
22566 + mov %edi,%ss
22567 +111:
22568 +#endif
22569 + .endm
22570 +
22571 + .macro pax_erase_kstack
22572 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22573 + call pax_erase_kstack
22574 +#endif
22575 + .endm
22576 +
22577 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22578 +ENTRY(pax_erase_kstack)
22579 + pushq %rdi
22580 + pushq %rcx
22581 + pushq %rax
22582 + pushq %r11
22583 +
22584 + GET_THREAD_INFO(%r11)
22585 + mov TI_lowest_stack(%r11), %rdi
22586 + mov $-0xBEEF, %rax
22587 + std
22588 +
22589 +1: mov %edi, %ecx
22590 + and $THREAD_SIZE_asm - 1, %ecx
22591 + shr $3, %ecx
22592 + repne scasq
22593 + jecxz 2f
22594 +
22595 + cmp $2*8, %ecx
22596 + jc 2f
22597 +
22598 + mov $2*8, %ecx
22599 + repe scasq
22600 + jecxz 2f
22601 + jne 1b
22602 +
22603 +2: cld
22604 + mov %esp, %ecx
22605 + sub %edi, %ecx
22606 +
22607 + cmp $THREAD_SIZE_asm, %rcx
22608 + jb 3f
22609 + ud2
22610 +3:
22611 +
22612 + shr $3, %ecx
22613 + rep stosq
22614 +
22615 + mov TI_task_thread_sp0(%r11), %rdi
22616 + sub $256, %rdi
22617 + mov %rdi, TI_lowest_stack(%r11)
22618 +
22619 + popq %r11
22620 + popq %rax
22621 + popq %rcx
22622 + popq %rdi
22623 + pax_force_retaddr
22624 + ret
22625 +ENDPROC(pax_erase_kstack)
22626 +#endif
22627
22628 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
22629 #ifdef CONFIG_TRACE_IRQFLAGS
22630 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
22631 .endm
22632
22633 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
22634 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
22635 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
22636 jnc 1f
22637 TRACE_IRQS_ON_DEBUG
22638 1:
22639 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
22640 movq \tmp,R11+\offset(%rsp)
22641 .endm
22642
22643 - .macro FAKE_STACK_FRAME child_rip
22644 - /* push in order ss, rsp, eflags, cs, rip */
22645 - xorl %eax, %eax
22646 - pushq_cfi $__KERNEL_DS /* ss */
22647 - /*CFI_REL_OFFSET ss,0*/
22648 - pushq_cfi %rax /* rsp */
22649 - CFI_REL_OFFSET rsp,0
22650 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
22651 - /*CFI_REL_OFFSET rflags,0*/
22652 - pushq_cfi $__KERNEL_CS /* cs */
22653 - /*CFI_REL_OFFSET cs,0*/
22654 - pushq_cfi \child_rip /* rip */
22655 - CFI_REL_OFFSET rip,0
22656 - pushq_cfi %rax /* orig rax */
22657 - .endm
22658 -
22659 - .macro UNFAKE_STACK_FRAME
22660 - addq $8*6, %rsp
22661 - CFI_ADJUST_CFA_OFFSET -(6*8)
22662 - .endm
22663 -
22664 /*
22665 * initial frame state for interrupts (and exceptions without error code)
22666 */
22667 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
22668 /* save partial stack frame */
22669 .macro SAVE_ARGS_IRQ
22670 cld
22671 - /* start from rbp in pt_regs and jump over */
22672 - movq_cfi rdi, (RDI-RBP)
22673 - movq_cfi rsi, (RSI-RBP)
22674 - movq_cfi rdx, (RDX-RBP)
22675 - movq_cfi rcx, (RCX-RBP)
22676 - movq_cfi rax, (RAX-RBP)
22677 - movq_cfi r8, (R8-RBP)
22678 - movq_cfi r9, (R9-RBP)
22679 - movq_cfi r10, (R10-RBP)
22680 - movq_cfi r11, (R11-RBP)
22681 + /* start from r15 in pt_regs and jump over */
22682 + movq_cfi rdi, RDI
22683 + movq_cfi rsi, RSI
22684 + movq_cfi rdx, RDX
22685 + movq_cfi rcx, RCX
22686 + movq_cfi rax, RAX
22687 + movq_cfi r8, R8
22688 + movq_cfi r9, R9
22689 + movq_cfi r10, R10
22690 + movq_cfi r11, R11
22691 + movq_cfi r12, R12
22692
22693 /* Save rbp so that we can unwind from get_irq_regs() */
22694 - movq_cfi rbp, 0
22695 + movq_cfi rbp, RBP
22696
22697 /* Save previous stack value */
22698 movq %rsp, %rsi
22699
22700 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
22701 - testl $3, CS-RBP(%rsi)
22702 + movq %rsp,%rdi /* arg1 for handler */
22703 + testb $3, CS(%rsi)
22704 je 1f
22705 SWAPGS
22706 /*
22707 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
22708 0x06 /* DW_OP_deref */, \
22709 0x08 /* DW_OP_const1u */, SS+8-RBP, \
22710 0x22 /* DW_OP_plus */
22711 +
22712 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22713 + testb $3, CS(%rdi)
22714 + jnz 1f
22715 + pax_enter_kernel
22716 + jmp 2f
22717 +1: pax_enter_kernel_user
22718 +2:
22719 +#else
22720 + pax_enter_kernel
22721 +#endif
22722 +
22723 /* We entered an interrupt context - irqs are off: */
22724 TRACE_IRQS_OFF
22725 .endm
22726 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
22727 js 1f /* negative -> in kernel */
22728 SWAPGS
22729 xorl %ebx,%ebx
22730 -1: ret
22731 +1:
22732 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22733 + testb $3, CS+8(%rsp)
22734 + jnz 1f
22735 + pax_enter_kernel
22736 + jmp 2f
22737 +1: pax_enter_kernel_user
22738 +2:
22739 +#else
22740 + pax_enter_kernel
22741 +#endif
22742 + pax_force_retaddr
22743 + ret
22744 CFI_ENDPROC
22745 -END(save_paranoid)
22746 +ENDPROC(save_paranoid)
22747 +
22748 +ENTRY(save_paranoid_nmi)
22749 + XCPT_FRAME 1 RDI+8
22750 + cld
22751 + movq_cfi rdi, RDI+8
22752 + movq_cfi rsi, RSI+8
22753 + movq_cfi rdx, RDX+8
22754 + movq_cfi rcx, RCX+8
22755 + movq_cfi rax, RAX+8
22756 + movq_cfi r8, R8+8
22757 + movq_cfi r9, R9+8
22758 + movq_cfi r10, R10+8
22759 + movq_cfi r11, R11+8
22760 + movq_cfi rbx, RBX+8
22761 + movq_cfi rbp, RBP+8
22762 + movq_cfi r12, R12+8
22763 + movq_cfi r13, R13+8
22764 + movq_cfi r14, R14+8
22765 + movq_cfi r15, R15+8
22766 + movl $1,%ebx
22767 + movl $MSR_GS_BASE,%ecx
22768 + rdmsr
22769 + testl %edx,%edx
22770 + js 1f /* negative -> in kernel */
22771 + SWAPGS
22772 + xorl %ebx,%ebx
22773 +1: pax_enter_kernel_nmi
22774 + pax_force_retaddr
22775 + ret
22776 + CFI_ENDPROC
22777 +ENDPROC(save_paranoid_nmi)
22778 .popsection
22779
22780 /*
22781 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
22782
22783 RESTORE_REST
22784
22785 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22786 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22787 jz 1f
22788
22789 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
22790 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
22791 jmp ret_from_sys_call # go to the SYSRET fastpath
22792
22793 1:
22794 - subq $REST_SKIP, %rsp # leave space for volatiles
22795 - CFI_ADJUST_CFA_OFFSET REST_SKIP
22796 movq %rbp, %rdi
22797 call *%rbx
22798 movl $0, RAX(%rsp)
22799 RESTORE_REST
22800 jmp int_ret_from_sys_call
22801 CFI_ENDPROC
22802 -END(ret_from_fork)
22803 +ENDPROC(ret_from_fork)
22804
22805 /*
22806 * System call entry. Up to 6 arguments in registers are supported.
22807 @@ -593,7 +1059,7 @@ END(ret_from_fork)
22808 ENTRY(system_call)
22809 CFI_STARTPROC simple
22810 CFI_SIGNAL_FRAME
22811 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
22812 + CFI_DEF_CFA rsp,0
22813 CFI_REGISTER rip,rcx
22814 /*CFI_REGISTER rflags,r11*/
22815 SWAPGS_UNSAFE_STACK
22816 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
22817
22818 movq %rsp,PER_CPU_VAR(old_rsp)
22819 movq PER_CPU_VAR(kernel_stack),%rsp
22820 + SAVE_ARGS 8*6,0
22821 + pax_enter_kernel_user
22822 +
22823 +#ifdef CONFIG_PAX_RANDKSTACK
22824 + pax_erase_kstack
22825 +#endif
22826 +
22827 /*
22828 * No need to follow this irqs off/on section - it's straight
22829 * and short:
22830 */
22831 ENABLE_INTERRUPTS(CLBR_NONE)
22832 - SAVE_ARGS 8,0
22833 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
22834 movq %rcx,RIP-ARGOFFSET(%rsp)
22835 CFI_REL_OFFSET rip,RIP-ARGOFFSET
22836 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22837 + GET_THREAD_INFO(%rcx)
22838 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
22839 jnz tracesys
22840 system_call_fastpath:
22841 #if __SYSCALL_MASK == ~0
22842 @@ -639,10 +1112,13 @@ sysret_check:
22843 LOCKDEP_SYS_EXIT
22844 DISABLE_INTERRUPTS(CLBR_NONE)
22845 TRACE_IRQS_OFF
22846 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
22847 + GET_THREAD_INFO(%rcx)
22848 + movl TI_flags(%rcx),%edx
22849 andl %edi,%edx
22850 jnz sysret_careful
22851 CFI_REMEMBER_STATE
22852 + pax_exit_kernel_user
22853 + pax_erase_kstack
22854 /*
22855 * sysretq will re-enable interrupts:
22856 */
22857 @@ -701,6 +1177,9 @@ auditsys:
22858 movq %rax,%rsi /* 2nd arg: syscall number */
22859 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
22860 call __audit_syscall_entry
22861 +
22862 + pax_erase_kstack
22863 +
22864 LOAD_ARGS 0 /* reload call-clobbered registers */
22865 jmp system_call_fastpath
22866
22867 @@ -722,7 +1201,7 @@ sysret_audit:
22868 /* Do syscall tracing */
22869 tracesys:
22870 #ifdef CONFIG_AUDITSYSCALL
22871 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22872 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22873 jz auditsys
22874 #endif
22875 SAVE_REST
22876 @@ -730,12 +1209,15 @@ tracesys:
22877 FIXUP_TOP_OF_STACK %rdi
22878 movq %rsp,%rdi
22879 call syscall_trace_enter
22880 +
22881 + pax_erase_kstack
22882 +
22883 /*
22884 * Reload arg registers from stack in case ptrace changed them.
22885 * We don't reload %rax because syscall_trace_enter() returned
22886 * the value it wants us to use in the table lookup.
22887 */
22888 - LOAD_ARGS ARGOFFSET, 1
22889 + LOAD_ARGS 1
22890 RESTORE_REST
22891 #if __SYSCALL_MASK == ~0
22892 cmpq $__NR_syscall_max,%rax
22893 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
22894 andl %edi,%edx
22895 jnz int_careful
22896 andl $~TS_COMPAT,TI_status(%rcx)
22897 - jmp retint_swapgs
22898 + pax_exit_kernel_user
22899 + pax_erase_kstack
22900 + jmp retint_swapgs_pax
22901
22902 /* Either reschedule or signal or syscall exit tracking needed. */
22903 /* First do a reschedule test. */
22904 @@ -811,7 +1295,7 @@ int_restore_rest:
22905 TRACE_IRQS_OFF
22906 jmp int_with_check
22907 CFI_ENDPROC
22908 -END(system_call)
22909 +ENDPROC(system_call)
22910
22911 .macro FORK_LIKE func
22912 ENTRY(stub_\func)
22913 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
22914 DEFAULT_FRAME 0 8 /* offset 8: return address */
22915 call sys_\func
22916 RESTORE_TOP_OF_STACK %r11, 8
22917 - ret $REST_SKIP /* pop extended registers */
22918 + pax_force_retaddr
22919 + ret
22920 CFI_ENDPROC
22921 -END(stub_\func)
22922 +ENDPROC(stub_\func)
22923 .endm
22924
22925 .macro FIXED_FRAME label,func
22926 @@ -836,9 +1321,10 @@ ENTRY(\label)
22927 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22928 call \func
22929 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22930 + pax_force_retaddr
22931 ret
22932 CFI_ENDPROC
22933 -END(\label)
22934 +ENDPROC(\label)
22935 .endm
22936
22937 FORK_LIKE clone
22938 @@ -846,19 +1332,6 @@ END(\label)
22939 FORK_LIKE vfork
22940 FIXED_FRAME stub_iopl, sys_iopl
22941
22942 -ENTRY(ptregscall_common)
22943 - DEFAULT_FRAME 1 8 /* offset 8: return address */
22944 - RESTORE_TOP_OF_STACK %r11, 8
22945 - movq_cfi_restore R15+8, r15
22946 - movq_cfi_restore R14+8, r14
22947 - movq_cfi_restore R13+8, r13
22948 - movq_cfi_restore R12+8, r12
22949 - movq_cfi_restore RBP+8, rbp
22950 - movq_cfi_restore RBX+8, rbx
22951 - ret $REST_SKIP /* pop extended registers */
22952 - CFI_ENDPROC
22953 -END(ptregscall_common)
22954 -
22955 ENTRY(stub_execve)
22956 CFI_STARTPROC
22957 addq $8, %rsp
22958 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
22959 RESTORE_REST
22960 jmp int_ret_from_sys_call
22961 CFI_ENDPROC
22962 -END(stub_execve)
22963 +ENDPROC(stub_execve)
22964
22965 /*
22966 * sigreturn is special because it needs to restore all registers on return.
22967 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
22968 RESTORE_REST
22969 jmp int_ret_from_sys_call
22970 CFI_ENDPROC
22971 -END(stub_rt_sigreturn)
22972 +ENDPROC(stub_rt_sigreturn)
22973
22974 #ifdef CONFIG_X86_X32_ABI
22975 ENTRY(stub_x32_rt_sigreturn)
22976 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
22977 RESTORE_REST
22978 jmp int_ret_from_sys_call
22979 CFI_ENDPROC
22980 -END(stub_x32_rt_sigreturn)
22981 +ENDPROC(stub_x32_rt_sigreturn)
22982
22983 ENTRY(stub_x32_execve)
22984 CFI_STARTPROC
22985 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
22986 RESTORE_REST
22987 jmp int_ret_from_sys_call
22988 CFI_ENDPROC
22989 -END(stub_x32_execve)
22990 +ENDPROC(stub_x32_execve)
22991
22992 #endif
22993
22994 @@ -952,7 +1425,7 @@ vector=vector+1
22995 2: jmp common_interrupt
22996 .endr
22997 CFI_ENDPROC
22998 -END(irq_entries_start)
22999 +ENDPROC(irq_entries_start)
23000
23001 .previous
23002 END(interrupt)
23003 @@ -969,8 +1442,8 @@ END(interrupt)
23004 /* 0(%rsp): ~(interrupt number) */
23005 .macro interrupt func
23006 /* reserve pt_regs for scratch regs and rbp */
23007 - subq $ORIG_RAX-RBP, %rsp
23008 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23009 + subq $ORIG_RAX, %rsp
23010 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23011 SAVE_ARGS_IRQ
23012 call \func
23013 .endm
23014 @@ -997,14 +1470,14 @@ ret_from_intr:
23015
23016 /* Restore saved previous stack */
23017 popq %rsi
23018 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23019 - leaq ARGOFFSET-RBP(%rsi), %rsp
23020 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23021 + movq %rsi, %rsp
23022 CFI_DEF_CFA_REGISTER rsp
23023 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23024 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23025
23026 exit_intr:
23027 GET_THREAD_INFO(%rcx)
23028 - testl $3,CS-ARGOFFSET(%rsp)
23029 + testb $3,CS-ARGOFFSET(%rsp)
23030 je retint_kernel
23031
23032 /* Interrupt came from user space */
23033 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23034 * The iretq could re-enable interrupts:
23035 */
23036 DISABLE_INTERRUPTS(CLBR_ANY)
23037 + pax_exit_kernel_user
23038 +retint_swapgs_pax:
23039 TRACE_IRQS_IRETQ
23040 SWAPGS
23041 jmp restore_args
23042
23043 retint_restore_args: /* return to kernel space */
23044 DISABLE_INTERRUPTS(CLBR_ANY)
23045 + pax_exit_kernel
23046 + pax_force_retaddr (RIP-ARGOFFSET)
23047 /*
23048 * The iretq could re-enable interrupts:
23049 */
23050 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23051 #endif
23052
23053 CFI_ENDPROC
23054 -END(common_interrupt)
23055 +ENDPROC(common_interrupt)
23056 /*
23057 * End of kprobes section
23058 */
23059 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23060 interrupt \do_sym
23061 jmp ret_from_intr
23062 CFI_ENDPROC
23063 -END(\sym)
23064 +ENDPROC(\sym)
23065 .endm
23066
23067 #ifdef CONFIG_TRACING
23068 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23069 call \do_sym
23070 jmp error_exit /* %ebx: no swapgs flag */
23071 CFI_ENDPROC
23072 -END(\sym)
23073 +ENDPROC(\sym)
23074 .endm
23075
23076 .macro paranoidzeroentry sym do_sym
23077 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23078 call \do_sym
23079 jmp paranoid_exit /* %ebx: no swapgs flag */
23080 CFI_ENDPROC
23081 -END(\sym)
23082 +ENDPROC(\sym)
23083 .endm
23084
23085 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23086 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23087 .macro paranoidzeroentry_ist sym do_sym ist
23088 ENTRY(\sym)
23089 INTR_FRAME
23090 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23091 TRACE_IRQS_OFF_DEBUG
23092 movq %rsp,%rdi /* pt_regs pointer */
23093 xorl %esi,%esi /* no error code */
23094 +#ifdef CONFIG_SMP
23095 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23096 + lea init_tss(%r13), %r13
23097 +#else
23098 + lea init_tss(%rip), %r13
23099 +#endif
23100 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23101 call \do_sym
23102 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23103 jmp paranoid_exit /* %ebx: no swapgs flag */
23104 CFI_ENDPROC
23105 -END(\sym)
23106 +ENDPROC(\sym)
23107 .endm
23108
23109 .macro errorentry sym do_sym
23110 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23111 call \do_sym
23112 jmp error_exit /* %ebx: no swapgs flag */
23113 CFI_ENDPROC
23114 -END(\sym)
23115 +ENDPROC(\sym)
23116 .endm
23117
23118 #ifdef CONFIG_TRACING
23119 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23120 call \do_sym
23121 jmp paranoid_exit /* %ebx: no swapgs flag */
23122 CFI_ENDPROC
23123 -END(\sym)
23124 +ENDPROC(\sym)
23125 .endm
23126
23127 zeroentry divide_error do_divide_error
23128 @@ -1336,9 +1819,10 @@ gs_change:
23129 2: mfence /* workaround */
23130 SWAPGS
23131 popfq_cfi
23132 + pax_force_retaddr
23133 ret
23134 CFI_ENDPROC
23135 -END(native_load_gs_index)
23136 +ENDPROC(native_load_gs_index)
23137
23138 _ASM_EXTABLE(gs_change,bad_gs)
23139 .section .fixup,"ax"
23140 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23141 CFI_DEF_CFA_REGISTER rsp
23142 CFI_ADJUST_CFA_OFFSET -8
23143 decl PER_CPU_VAR(irq_count)
23144 + pax_force_retaddr
23145 ret
23146 CFI_ENDPROC
23147 -END(do_softirq_own_stack)
23148 +ENDPROC(do_softirq_own_stack)
23149
23150 #ifdef CONFIG_XEN
23151 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23152 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23153 decl PER_CPU_VAR(irq_count)
23154 jmp error_exit
23155 CFI_ENDPROC
23156 -END(xen_do_hypervisor_callback)
23157 +ENDPROC(xen_do_hypervisor_callback)
23158
23159 /*
23160 * Hypervisor uses this for application faults while it executes.
23161 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23162 SAVE_ALL
23163 jmp error_exit
23164 CFI_ENDPROC
23165 -END(xen_failsafe_callback)
23166 +ENDPROC(xen_failsafe_callback)
23167
23168 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23169 xen_hvm_callback_vector xen_evtchn_do_upcall
23170 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23171 DEFAULT_FRAME
23172 DISABLE_INTERRUPTS(CLBR_NONE)
23173 TRACE_IRQS_OFF_DEBUG
23174 - testl %ebx,%ebx /* swapgs needed? */
23175 + testl $1,%ebx /* swapgs needed? */
23176 jnz paranoid_restore
23177 - testl $3,CS(%rsp)
23178 + testb $3,CS(%rsp)
23179 jnz paranoid_userspace
23180 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23181 + pax_exit_kernel
23182 + TRACE_IRQS_IRETQ 0
23183 + SWAPGS_UNSAFE_STACK
23184 + RESTORE_ALL 8
23185 + pax_force_retaddr_bts
23186 + jmp irq_return
23187 +#endif
23188 paranoid_swapgs:
23189 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23190 + pax_exit_kernel_user
23191 +#else
23192 + pax_exit_kernel
23193 +#endif
23194 TRACE_IRQS_IRETQ 0
23195 SWAPGS_UNSAFE_STACK
23196 RESTORE_ALL 8
23197 jmp irq_return
23198 paranoid_restore:
23199 + pax_exit_kernel
23200 TRACE_IRQS_IRETQ_DEBUG 0
23201 RESTORE_ALL 8
23202 + pax_force_retaddr_bts
23203 jmp irq_return
23204 paranoid_userspace:
23205 GET_THREAD_INFO(%rcx)
23206 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23207 TRACE_IRQS_OFF
23208 jmp paranoid_userspace
23209 CFI_ENDPROC
23210 -END(paranoid_exit)
23211 +ENDPROC(paranoid_exit)
23212
23213 /*
23214 * Exception entry point. This expects an error code/orig_rax on the stack.
23215 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23216 movq_cfi r14, R14+8
23217 movq_cfi r15, R15+8
23218 xorl %ebx,%ebx
23219 - testl $3,CS+8(%rsp)
23220 + testb $3,CS+8(%rsp)
23221 je error_kernelspace
23222 error_swapgs:
23223 SWAPGS
23224 error_sti:
23225 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23226 + testb $3, CS+8(%rsp)
23227 + jnz 1f
23228 + pax_enter_kernel
23229 + jmp 2f
23230 +1: pax_enter_kernel_user
23231 +2:
23232 +#else
23233 + pax_enter_kernel
23234 +#endif
23235 TRACE_IRQS_OFF
23236 + pax_force_retaddr
23237 ret
23238
23239 /*
23240 @@ -1616,7 +2127,7 @@ bstep_iret:
23241 movq %rcx,RIP+8(%rsp)
23242 jmp error_swapgs
23243 CFI_ENDPROC
23244 -END(error_entry)
23245 +ENDPROC(error_entry)
23246
23247
23248 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23249 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23250 DISABLE_INTERRUPTS(CLBR_NONE)
23251 TRACE_IRQS_OFF
23252 GET_THREAD_INFO(%rcx)
23253 - testl %eax,%eax
23254 + testl $1,%eax
23255 jne retint_kernel
23256 LOCKDEP_SYS_EXIT_IRQ
23257 movl TI_flags(%rcx),%edx
23258 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23259 jnz retint_careful
23260 jmp retint_swapgs
23261 CFI_ENDPROC
23262 -END(error_exit)
23263 +ENDPROC(error_exit)
23264
23265 /*
23266 * Test if a given stack is an NMI stack or not.
23267 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23268 * If %cs was not the kernel segment, then the NMI triggered in user
23269 * space, which means it is definitely not nested.
23270 */
23271 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23272 + je 1f
23273 cmpl $__KERNEL_CS, 16(%rsp)
23274 jne first_nmi
23275 -
23276 +1:
23277 /*
23278 * Check the special variable on the stack to see if NMIs are
23279 * executing.
23280 @@ -1730,8 +2243,7 @@ nested_nmi:
23281
23282 1:
23283 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23284 - leaq -1*8(%rsp), %rdx
23285 - movq %rdx, %rsp
23286 + subq $8, %rsp
23287 CFI_ADJUST_CFA_OFFSET 1*8
23288 leaq -10*8(%rsp), %rdx
23289 pushq_cfi $__KERNEL_DS
23290 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23291 CFI_RESTORE rdx
23292
23293 /* No need to check faults here */
23294 +# pax_force_retaddr_bts
23295 INTERRUPT_RETURN
23296
23297 CFI_RESTORE_STATE
23298 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23299 subq $ORIG_RAX-R15, %rsp
23300 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23301 /*
23302 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23303 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23304 * as we should not be calling schedule in NMI context.
23305 * Even with normal interrupts enabled. An NMI should not be
23306 * setting NEED_RESCHED or anything that normal interrupts and
23307 * exceptions might do.
23308 */
23309 - call save_paranoid
23310 + call save_paranoid_nmi
23311 DEFAULT_FRAME 0
23312
23313 /*
23314 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23315 * NMI itself takes a page fault, the page fault that was preempted
23316 * will read the information from the NMI page fault and not the
23317 * origin fault. Save it off and restore it if it changes.
23318 - * Use the r12 callee-saved register.
23319 + * Use the r13 callee-saved register.
23320 */
23321 - movq %cr2, %r12
23322 + movq %cr2, %r13
23323
23324 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23325 movq %rsp,%rdi
23326 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
23327
23328 /* Did the NMI take a page fault? Restore cr2 if it did */
23329 movq %cr2, %rcx
23330 - cmpq %rcx, %r12
23331 + cmpq %rcx, %r13
23332 je 1f
23333 - movq %r12, %cr2
23334 + movq %r13, %cr2
23335 1:
23336
23337 - testl %ebx,%ebx /* swapgs needed? */
23338 + testl $1,%ebx /* swapgs needed? */
23339 jnz nmi_restore
23340 nmi_swapgs:
23341 SWAPGS_UNSAFE_STACK
23342 nmi_restore:
23343 + pax_exit_kernel_nmi
23344 /* Pop the extra iret frame at once */
23345 RESTORE_ALL 6*8
23346 + testb $3, 8(%rsp)
23347 + jnz 1f
23348 + pax_force_retaddr_bts
23349 +1:
23350
23351 /* Clear the NMI executing stack variable */
23352 movq $0, 5*8(%rsp)
23353 jmp irq_return
23354 CFI_ENDPROC
23355 -END(nmi)
23356 +ENDPROC(nmi)
23357
23358 ENTRY(ignore_sysret)
23359 CFI_STARTPROC
23360 mov $-ENOSYS,%eax
23361 sysret
23362 CFI_ENDPROC
23363 -END(ignore_sysret)
23364 +ENDPROC(ignore_sysret)
23365
23366 /*
23367 * End of kprobes section
23368 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23369 index d4bdd25..912664c 100644
23370 --- a/arch/x86/kernel/ftrace.c
23371 +++ b/arch/x86/kernel/ftrace.c
23372 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23373 {
23374 unsigned char replaced[MCOUNT_INSN_SIZE];
23375
23376 + ip = ktla_ktva(ip);
23377 +
23378 /*
23379 * Note: Due to modules and __init, code can
23380 * disappear and change, we need to protect against faulting
23381 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23382 unsigned char old[MCOUNT_INSN_SIZE], *new;
23383 int ret;
23384
23385 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
23386 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
23387 new = ftrace_call_replace(ip, (unsigned long)func);
23388
23389 /* See comment above by declaration of modifying_ftrace_code */
23390 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23391 /* Also update the regs callback function */
23392 if (!ret) {
23393 ip = (unsigned long)(&ftrace_regs_call);
23394 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
23395 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
23396 new = ftrace_call_replace(ip, (unsigned long)func);
23397 ret = ftrace_modify_code(ip, old, new);
23398 }
23399 @@ -291,7 +293,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23400 * kernel identity mapping to modify code.
23401 */
23402 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23403 - ip = (unsigned long)__va(__pa_symbol(ip));
23404 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23405
23406 return probe_kernel_write((void *)ip, val, size);
23407 }
23408 @@ -301,7 +303,7 @@ static int add_break(unsigned long ip, const char *old)
23409 unsigned char replaced[MCOUNT_INSN_SIZE];
23410 unsigned char brk = BREAKPOINT_INSTRUCTION;
23411
23412 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23413 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23414 return -EFAULT;
23415
23416 /* Make sure it is what we expect it to be */
23417 @@ -649,7 +651,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23418 return ret;
23419
23420 fail_update:
23421 - probe_kernel_write((void *)ip, &old_code[0], 1);
23422 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23423 goto out;
23424 }
23425
23426 @@ -682,6 +684,8 @@ static int ftrace_mod_jmp(unsigned long ip,
23427 {
23428 unsigned char code[MCOUNT_INSN_SIZE];
23429
23430 + ip = ktla_ktva(ip);
23431 +
23432 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
23433 return -EFAULT;
23434
23435 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23436 index 85126cc..1bbce17 100644
23437 --- a/arch/x86/kernel/head64.c
23438 +++ b/arch/x86/kernel/head64.c
23439 @@ -67,12 +67,12 @@ again:
23440 pgd = *pgd_p;
23441
23442 /*
23443 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23444 - * critical -- __PAGE_OFFSET would point us back into the dynamic
23445 + * The use of __early_va rather than __va here is critical:
23446 + * __va would point us back into the dynamic
23447 * range and we might end up looping forever...
23448 */
23449 if (pgd)
23450 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23451 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23452 else {
23453 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23454 reset_early_page_tables();
23455 @@ -82,13 +82,13 @@ again:
23456 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23457 for (i = 0; i < PTRS_PER_PUD; i++)
23458 pud_p[i] = 0;
23459 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23460 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23461 }
23462 pud_p += pud_index(address);
23463 pud = *pud_p;
23464
23465 if (pud)
23466 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23467 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23468 else {
23469 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23470 reset_early_page_tables();
23471 @@ -98,7 +98,7 @@ again:
23472 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
23473 for (i = 0; i < PTRS_PER_PMD; i++)
23474 pmd_p[i] = 0;
23475 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23476 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
23477 }
23478 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
23479 pmd_p[pmd_index(address)] = pmd;
23480 @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
23481 if (console_loglevel == 10)
23482 early_printk("Kernel alive\n");
23483
23484 - clear_page(init_level4_pgt);
23485 /* set init_level4_pgt kernel high mapping*/
23486 init_level4_pgt[511] = early_level4_pgt[511];
23487
23488 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
23489 index 81ba276..30c5411 100644
23490 --- a/arch/x86/kernel/head_32.S
23491 +++ b/arch/x86/kernel/head_32.S
23492 @@ -26,6 +26,12 @@
23493 /* Physical address */
23494 #define pa(X) ((X) - __PAGE_OFFSET)
23495
23496 +#ifdef CONFIG_PAX_KERNEXEC
23497 +#define ta(X) (X)
23498 +#else
23499 +#define ta(X) ((X) - __PAGE_OFFSET)
23500 +#endif
23501 +
23502 /*
23503 * References to members of the new_cpu_data structure.
23504 */
23505 @@ -55,11 +61,7 @@
23506 * and small than max_low_pfn, otherwise will waste some page table entries
23507 */
23508
23509 -#if PTRS_PER_PMD > 1
23510 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
23511 -#else
23512 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
23513 -#endif
23514 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
23515
23516 /* Number of possible pages in the lowmem region */
23517 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
23518 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
23519 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23520
23521 /*
23522 + * Real beginning of normal "text" segment
23523 + */
23524 +ENTRY(stext)
23525 +ENTRY(_stext)
23526 +
23527 +/*
23528 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
23529 * %esi points to the real-mode code as a 32-bit pointer.
23530 * CS and DS must be 4 GB flat segments, but we don't depend on
23531 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23532 * can.
23533 */
23534 __HEAD
23535 +
23536 +#ifdef CONFIG_PAX_KERNEXEC
23537 + jmp startup_32
23538 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
23539 +.fill PAGE_SIZE-5,1,0xcc
23540 +#endif
23541 +
23542 ENTRY(startup_32)
23543 movl pa(stack_start),%ecx
23544
23545 @@ -106,6 +121,59 @@ ENTRY(startup_32)
23546 2:
23547 leal -__PAGE_OFFSET(%ecx),%esp
23548
23549 +#ifdef CONFIG_SMP
23550 + movl $pa(cpu_gdt_table),%edi
23551 + movl $__per_cpu_load,%eax
23552 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
23553 + rorl $16,%eax
23554 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
23555 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
23556 + movl $__per_cpu_end - 1,%eax
23557 + subl $__per_cpu_start,%eax
23558 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
23559 +#endif
23560 +
23561 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23562 + movl $NR_CPUS,%ecx
23563 + movl $pa(cpu_gdt_table),%edi
23564 +1:
23565 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
23566 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
23567 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
23568 + addl $PAGE_SIZE_asm,%edi
23569 + loop 1b
23570 +#endif
23571 +
23572 +#ifdef CONFIG_PAX_KERNEXEC
23573 + movl $pa(boot_gdt),%edi
23574 + movl $__LOAD_PHYSICAL_ADDR,%eax
23575 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
23576 + rorl $16,%eax
23577 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
23578 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
23579 + rorl $16,%eax
23580 +
23581 + ljmp $(__BOOT_CS),$1f
23582 +1:
23583 +
23584 + movl $NR_CPUS,%ecx
23585 + movl $pa(cpu_gdt_table),%edi
23586 + addl $__PAGE_OFFSET,%eax
23587 +1:
23588 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
23589 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
23590 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
23591 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
23592 + rorl $16,%eax
23593 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
23594 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
23595 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
23596 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
23597 + rorl $16,%eax
23598 + addl $PAGE_SIZE_asm,%edi
23599 + loop 1b
23600 +#endif
23601 +
23602 /*
23603 * Clear BSS first so that there are no surprises...
23604 */
23605 @@ -201,8 +269,11 @@ ENTRY(startup_32)
23606 movl %eax, pa(max_pfn_mapped)
23607
23608 /* Do early initialization of the fixmap area */
23609 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23610 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
23611 +#ifdef CONFIG_COMPAT_VDSO
23612 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
23613 +#else
23614 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
23615 +#endif
23616 #else /* Not PAE */
23617
23618 page_pde_offset = (__PAGE_OFFSET >> 20);
23619 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23620 movl %eax, pa(max_pfn_mapped)
23621
23622 /* Do early initialization of the fixmap area */
23623 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23624 - movl %eax,pa(initial_page_table+0xffc)
23625 +#ifdef CONFIG_COMPAT_VDSO
23626 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
23627 +#else
23628 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
23629 +#endif
23630 #endif
23631
23632 #ifdef CONFIG_PARAVIRT
23633 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23634 cmpl $num_subarch_entries, %eax
23635 jae bad_subarch
23636
23637 - movl pa(subarch_entries)(,%eax,4), %eax
23638 - subl $__PAGE_OFFSET, %eax
23639 - jmp *%eax
23640 + jmp *pa(subarch_entries)(,%eax,4)
23641
23642 bad_subarch:
23643 WEAK(lguest_entry)
23644 @@ -261,10 +333,10 @@ WEAK(xen_entry)
23645 __INITDATA
23646
23647 subarch_entries:
23648 - .long default_entry /* normal x86/PC */
23649 - .long lguest_entry /* lguest hypervisor */
23650 - .long xen_entry /* Xen hypervisor */
23651 - .long default_entry /* Moorestown MID */
23652 + .long ta(default_entry) /* normal x86/PC */
23653 + .long ta(lguest_entry) /* lguest hypervisor */
23654 + .long ta(xen_entry) /* Xen hypervisor */
23655 + .long ta(default_entry) /* Moorestown MID */
23656 num_subarch_entries = (. - subarch_entries) / 4
23657 .previous
23658 #else
23659 @@ -354,6 +426,7 @@ default_entry:
23660 movl pa(mmu_cr4_features),%eax
23661 movl %eax,%cr4
23662
23663 +#ifdef CONFIG_X86_PAE
23664 testb $X86_CR4_PAE, %al # check if PAE is enabled
23665 jz enable_paging
23666
23667 @@ -382,6 +455,9 @@ default_entry:
23668 /* Make changes effective */
23669 wrmsr
23670
23671 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
23672 +#endif
23673 +
23674 enable_paging:
23675
23676 /*
23677 @@ -449,14 +525,20 @@ is486:
23678 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
23679 movl %eax,%ss # after changing gdt.
23680
23681 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
23682 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
23683 movl %eax,%ds
23684 movl %eax,%es
23685
23686 movl $(__KERNEL_PERCPU), %eax
23687 movl %eax,%fs # set this cpu's percpu
23688
23689 +#ifdef CONFIG_CC_STACKPROTECTOR
23690 movl $(__KERNEL_STACK_CANARY),%eax
23691 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23692 + movl $(__USER_DS),%eax
23693 +#else
23694 + xorl %eax,%eax
23695 +#endif
23696 movl %eax,%gs
23697
23698 xorl %eax,%eax # Clear LDT
23699 @@ -512,8 +594,11 @@ setup_once:
23700 * relocation. Manually set base address in stack canary
23701 * segment descriptor.
23702 */
23703 - movl $gdt_page,%eax
23704 + movl $cpu_gdt_table,%eax
23705 movl $stack_canary,%ecx
23706 +#ifdef CONFIG_SMP
23707 + addl $__per_cpu_load,%ecx
23708 +#endif
23709 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
23710 shrl $16, %ecx
23711 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
23712 @@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
23713 /* This is global to keep gas from relaxing the jumps */
23714 ENTRY(early_idt_handler)
23715 cld
23716 - cmpl $2,%ss:early_recursion_flag
23717 + cmpl $1,%ss:early_recursion_flag
23718 je hlt_loop
23719 incl %ss:early_recursion_flag
23720
23721 @@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
23722 pushl (20+6*4)(%esp) /* trapno */
23723 pushl $fault_msg
23724 call printk
23725 -#endif
23726 call dump_stack
23727 +#endif
23728 hlt_loop:
23729 hlt
23730 jmp hlt_loop
23731 @@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
23732 /* This is the default interrupt "handler" :-) */
23733 ALIGN
23734 ignore_int:
23735 - cld
23736 #ifdef CONFIG_PRINTK
23737 + cmpl $2,%ss:early_recursion_flag
23738 + je hlt_loop
23739 + incl %ss:early_recursion_flag
23740 + cld
23741 pushl %eax
23742 pushl %ecx
23743 pushl %edx
23744 @@ -612,9 +700,6 @@ ignore_int:
23745 movl $(__KERNEL_DS),%eax
23746 movl %eax,%ds
23747 movl %eax,%es
23748 - cmpl $2,early_recursion_flag
23749 - je hlt_loop
23750 - incl early_recursion_flag
23751 pushl 16(%esp)
23752 pushl 24(%esp)
23753 pushl 32(%esp)
23754 @@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
23755 /*
23756 * BSS section
23757 */
23758 -__PAGE_ALIGNED_BSS
23759 - .align PAGE_SIZE
23760 #ifdef CONFIG_X86_PAE
23761 +.section .initial_pg_pmd,"a",@progbits
23762 initial_pg_pmd:
23763 .fill 1024*KPMDS,4,0
23764 #else
23765 +.section .initial_page_table,"a",@progbits
23766 ENTRY(initial_page_table)
23767 .fill 1024,4,0
23768 #endif
23769 +.section .initial_pg_fixmap,"a",@progbits
23770 initial_pg_fixmap:
23771 .fill 1024,4,0
23772 +.section .empty_zero_page,"a",@progbits
23773 ENTRY(empty_zero_page)
23774 .fill 4096,1,0
23775 +.section .swapper_pg_dir,"a",@progbits
23776 ENTRY(swapper_pg_dir)
23777 +#ifdef CONFIG_X86_PAE
23778 + .fill 4,8,0
23779 +#else
23780 .fill 1024,4,0
23781 +#endif
23782
23783 /*
23784 * This starts the data section.
23785 */
23786 #ifdef CONFIG_X86_PAE
23787 -__PAGE_ALIGNED_DATA
23788 - /* Page-aligned for the benefit of paravirt? */
23789 - .align PAGE_SIZE
23790 +.section .initial_page_table,"a",@progbits
23791 ENTRY(initial_page_table)
23792 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
23793 # if KPMDS == 3
23794 @@ -689,12 +779,20 @@ ENTRY(initial_page_table)
23795 # error "Kernel PMDs should be 1, 2 or 3"
23796 # endif
23797 .align PAGE_SIZE /* needs to be page-sized too */
23798 +
23799 +#ifdef CONFIG_PAX_PER_CPU_PGD
23800 +ENTRY(cpu_pgd)
23801 + .rept 2*NR_CPUS
23802 + .fill 4,8,0
23803 + .endr
23804 +#endif
23805 +
23806 #endif
23807
23808 .data
23809 .balign 4
23810 ENTRY(stack_start)
23811 - .long init_thread_union+THREAD_SIZE
23812 + .long init_thread_union+THREAD_SIZE-8
23813
23814 __INITRODATA
23815 int_msg:
23816 @@ -722,7 +820,7 @@ fault_msg:
23817 * segment size, and 32-bit linear address value:
23818 */
23819
23820 - .data
23821 +.section .rodata,"a",@progbits
23822 .globl boot_gdt_descr
23823 .globl idt_descr
23824
23825 @@ -731,7 +829,7 @@ fault_msg:
23826 .word 0 # 32 bit align gdt_desc.address
23827 boot_gdt_descr:
23828 .word __BOOT_DS+7
23829 - .long boot_gdt - __PAGE_OFFSET
23830 + .long pa(boot_gdt)
23831
23832 .word 0 # 32-bit align idt_desc.address
23833 idt_descr:
23834 @@ -742,7 +840,7 @@ idt_descr:
23835 .word 0 # 32 bit align gdt_desc.address
23836 ENTRY(early_gdt_descr)
23837 .word GDT_ENTRIES*8-1
23838 - .long gdt_page /* Overwritten for secondary CPUs */
23839 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
23840
23841 /*
23842 * The boot_gdt must mirror the equivalent in setup.S and is
23843 @@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
23844 .align L1_CACHE_BYTES
23845 ENTRY(boot_gdt)
23846 .fill GDT_ENTRY_BOOT_CS,8,0
23847 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23848 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23849 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23850 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23851 +
23852 + .align PAGE_SIZE_asm
23853 +ENTRY(cpu_gdt_table)
23854 + .rept NR_CPUS
23855 + .quad 0x0000000000000000 /* NULL descriptor */
23856 + .quad 0x0000000000000000 /* 0x0b reserved */
23857 + .quad 0x0000000000000000 /* 0x13 reserved */
23858 + .quad 0x0000000000000000 /* 0x1b reserved */
23859 +
23860 +#ifdef CONFIG_PAX_KERNEXEC
23861 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23862 +#else
23863 + .quad 0x0000000000000000 /* 0x20 unused */
23864 +#endif
23865 +
23866 + .quad 0x0000000000000000 /* 0x28 unused */
23867 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23868 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23869 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23870 + .quad 0x0000000000000000 /* 0x4b reserved */
23871 + .quad 0x0000000000000000 /* 0x53 reserved */
23872 + .quad 0x0000000000000000 /* 0x5b reserved */
23873 +
23874 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23875 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23876 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23877 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23878 +
23879 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23880 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23881 +
23882 + /*
23883 + * Segments used for calling PnP BIOS have byte granularity.
23884 + * The code segments and data segments have fixed 64k limits,
23885 + * the transfer segment sizes are set at run time.
23886 + */
23887 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
23888 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
23889 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
23890 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
23891 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
23892 +
23893 + /*
23894 + * The APM segments have byte granularity and their bases
23895 + * are set at run time. All have 64k limits.
23896 + */
23897 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23898 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23899 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
23900 +
23901 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23902 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23903 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23904 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23905 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23906 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23907 +
23908 + /* Be sure this is zeroed to avoid false validations in Xen */
23909 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23910 + .endr
23911 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23912 index e1aabdb..fee4fee 100644
23913 --- a/arch/x86/kernel/head_64.S
23914 +++ b/arch/x86/kernel/head_64.S
23915 @@ -20,6 +20,8 @@
23916 #include <asm/processor-flags.h>
23917 #include <asm/percpu.h>
23918 #include <asm/nops.h>
23919 +#include <asm/cpufeature.h>
23920 +#include <asm/alternative-asm.h>
23921
23922 #ifdef CONFIG_PARAVIRT
23923 #include <asm/asm-offsets.h>
23924 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23925 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23926 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23927 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23928 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
23929 +L3_VMALLOC_START = pud_index(VMALLOC_START)
23930 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
23931 +L3_VMALLOC_END = pud_index(VMALLOC_END)
23932 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23933 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23934
23935 .text
23936 __HEAD
23937 @@ -89,11 +97,24 @@ startup_64:
23938 * Fixup the physical addresses in the page table
23939 */
23940 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23941 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23942 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23943 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23944 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23945 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23946
23947 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23948 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23949 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
23950 +#ifndef CONFIG_XEN
23951 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
23952 +#endif
23953 +
23954 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23955 +
23956 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23957 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23958
23959 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23960 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23961
23962 /*
23963 * Set up the identity mapping for the switchover. These
23964 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
23965 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23966 1:
23967
23968 - /* Enable PAE mode and PGE */
23969 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23970 + /* Enable PAE mode and PSE/PGE */
23971 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23972 movq %rcx, %cr4
23973
23974 /* Setup early boot stage 4 level pagetables. */
23975 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
23976 movl $MSR_EFER, %ecx
23977 rdmsr
23978 btsl $_EFER_SCE, %eax /* Enable System Call */
23979 - btl $20,%edi /* No Execute supported? */
23980 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23981 jnc 1f
23982 btsl $_EFER_NX, %eax
23983 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23984 +#ifndef CONFIG_EFI
23985 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
23986 +#endif
23987 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
23988 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
23989 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
23990 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
23991 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
23992 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23993 1: wrmsr /* Make changes effective */
23994
23995 /* Setup cr0 */
23996 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
23997 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23998 * address given in m16:64.
23999 */
24000 + pax_set_fptr_mask
24001 movq initial_code(%rip),%rax
24002 pushq $0 # fake return address to stop unwinder
24003 pushq $__KERNEL_CS # set correct cs
24004 @@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
24005 call dump_stack
24006 #ifdef CONFIG_KALLSYMS
24007 leaq early_idt_ripmsg(%rip),%rdi
24008 - movq 40(%rsp),%rsi # %rip again
24009 + movq 88(%rsp),%rsi # %rip again
24010 call __print_symbol
24011 #endif
24012 #endif /* EARLY_PRINTK */
24013 @@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
24014 early_recursion_flag:
24015 .long 0
24016
24017 + .section .rodata,"a",@progbits
24018 #ifdef CONFIG_EARLY_PRINTK
24019 early_idt_msg:
24020 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24021 @@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
24022 NEXT_PAGE(early_dynamic_pgts)
24023 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24024
24025 - .data
24026 + .section .rodata,"a",@progbits
24027
24028 -#ifndef CONFIG_XEN
24029 NEXT_PAGE(init_level4_pgt)
24030 - .fill 512,8,0
24031 -#else
24032 -NEXT_PAGE(init_level4_pgt)
24033 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24034 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24035 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24036 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24037 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24038 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24039 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24040 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24041 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24042 .org init_level4_pgt + L4_START_KERNEL*8, 0
24043 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24044 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24045
24046 +#ifdef CONFIG_PAX_PER_CPU_PGD
24047 +NEXT_PAGE(cpu_pgd)
24048 + .rept 2*NR_CPUS
24049 + .fill 512,8,0
24050 + .endr
24051 +#endif
24052 +
24053 NEXT_PAGE(level3_ident_pgt)
24054 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24055 +#ifdef CONFIG_XEN
24056 .fill 511, 8, 0
24057 +#else
24058 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24059 + .fill 510,8,0
24060 +#endif
24061 +
24062 +NEXT_PAGE(level3_vmalloc_start_pgt)
24063 + .fill 512,8,0
24064 +
24065 +NEXT_PAGE(level3_vmalloc_end_pgt)
24066 + .fill 512,8,0
24067 +
24068 +NEXT_PAGE(level3_vmemmap_pgt)
24069 + .fill L3_VMEMMAP_START,8,0
24070 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24071 +
24072 NEXT_PAGE(level2_ident_pgt)
24073 - /* Since I easily can, map the first 1G.
24074 + /* Since I easily can, map the first 2G.
24075 * Don't set NX because code runs from these pages.
24076 */
24077 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24078 -#endif
24079 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24080
24081 NEXT_PAGE(level3_kernel_pgt)
24082 .fill L3_START_KERNEL,8,0
24083 @@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
24084 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24085 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24086
24087 +NEXT_PAGE(level2_vmemmap_pgt)
24088 + .fill 512,8,0
24089 +
24090 NEXT_PAGE(level2_kernel_pgt)
24091 /*
24092 * 512 MB kernel mapping. We spend a full page on this pagetable
24093 @@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
24094 NEXT_PAGE(level2_fixmap_pgt)
24095 .fill 506,8,0
24096 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24097 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24098 - .fill 5,8,0
24099 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24100 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24101 + .fill 4,8,0
24102
24103 NEXT_PAGE(level1_fixmap_pgt)
24104 .fill 512,8,0
24105
24106 +NEXT_PAGE(level1_vsyscall_pgt)
24107 + .fill 512,8,0
24108 +
24109 #undef PMDS
24110
24111 - .data
24112 + .align PAGE_SIZE
24113 +ENTRY(cpu_gdt_table)
24114 + .rept NR_CPUS
24115 + .quad 0x0000000000000000 /* NULL descriptor */
24116 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24117 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24118 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24119 + .quad 0x00cffb000000ffff /* __USER32_CS */
24120 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24121 + .quad 0x00affb000000ffff /* __USER_CS */
24122 +
24123 +#ifdef CONFIG_PAX_KERNEXEC
24124 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24125 +#else
24126 + .quad 0x0 /* unused */
24127 +#endif
24128 +
24129 + .quad 0,0 /* TSS */
24130 + .quad 0,0 /* LDT */
24131 + .quad 0,0,0 /* three TLS descriptors */
24132 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24133 + /* asm/segment.h:GDT_ENTRIES must match this */
24134 +
24135 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24136 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24137 +#else
24138 + .quad 0x0 /* unused */
24139 +#endif
24140 +
24141 + /* zero the remaining page */
24142 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24143 + .endr
24144 +
24145 .align 16
24146 .globl early_gdt_descr
24147 early_gdt_descr:
24148 .word GDT_ENTRIES*8-1
24149 early_gdt_descr_base:
24150 - .quad INIT_PER_CPU_VAR(gdt_page)
24151 + .quad cpu_gdt_table
24152
24153 ENTRY(phys_base)
24154 /* This must match the first entry in level2_kernel_pgt */
24155 .quad 0x0000000000000000
24156
24157 #include "../../x86/xen/xen-head.S"
24158 -
24159 - __PAGE_ALIGNED_BSS
24160 +
24161 + .section .rodata,"a",@progbits
24162 NEXT_PAGE(empty_zero_page)
24163 .skip PAGE_SIZE
24164 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24165 index 05fd74f..c3548b1 100644
24166 --- a/arch/x86/kernel/i386_ksyms_32.c
24167 +++ b/arch/x86/kernel/i386_ksyms_32.c
24168 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24169 EXPORT_SYMBOL(cmpxchg8b_emu);
24170 #endif
24171
24172 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24173 +
24174 /* Networking helper routines. */
24175 EXPORT_SYMBOL(csum_partial_copy_generic);
24176 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24177 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24178
24179 EXPORT_SYMBOL(__get_user_1);
24180 EXPORT_SYMBOL(__get_user_2);
24181 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24182 EXPORT_SYMBOL(___preempt_schedule_context);
24183 #endif
24184 #endif
24185 +
24186 +#ifdef CONFIG_PAX_KERNEXEC
24187 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24188 +#endif
24189 +
24190 +#ifdef CONFIG_PAX_PER_CPU_PGD
24191 +EXPORT_SYMBOL(cpu_pgd);
24192 +#endif
24193 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24194 index e8368c6..9c1a712 100644
24195 --- a/arch/x86/kernel/i387.c
24196 +++ b/arch/x86/kernel/i387.c
24197 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24198 static inline bool interrupted_user_mode(void)
24199 {
24200 struct pt_regs *regs = get_irq_regs();
24201 - return regs && user_mode_vm(regs);
24202 + return regs && user_mode(regs);
24203 }
24204
24205 /*
24206 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24207 index 2e977b5..5f2c273 100644
24208 --- a/arch/x86/kernel/i8259.c
24209 +++ b/arch/x86/kernel/i8259.c
24210 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24211 static void make_8259A_irq(unsigned int irq)
24212 {
24213 disable_irq_nosync(irq);
24214 - io_apic_irqs &= ~(1<<irq);
24215 + io_apic_irqs &= ~(1UL<<irq);
24216 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24217 i8259A_chip.name);
24218 enable_irq(irq);
24219 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24220 "spurious 8259A interrupt: IRQ%d.\n", irq);
24221 spurious_irq_mask |= irqmask;
24222 }
24223 - atomic_inc(&irq_err_count);
24224 + atomic_inc_unchecked(&irq_err_count);
24225 /*
24226 * Theoretically we do not have to handle this IRQ,
24227 * but in Linux this does not cause problems and is
24228 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24229 /* (slave's support for AEOI in flat mode is to be investigated) */
24230 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24231
24232 + pax_open_kernel();
24233 if (auto_eoi)
24234 /*
24235 * In AEOI mode we just have to mask the interrupt
24236 * when acking.
24237 */
24238 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24239 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24240 else
24241 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24242 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24243 + pax_close_kernel();
24244
24245 udelay(100); /* wait for 8259A to initialize */
24246
24247 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24248 index a979b5b..1d6db75 100644
24249 --- a/arch/x86/kernel/io_delay.c
24250 +++ b/arch/x86/kernel/io_delay.c
24251 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24252 * Quirk table for systems that misbehave (lock up, etc.) if port
24253 * 0x80 is used:
24254 */
24255 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24256 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24257 {
24258 .callback = dmi_io_delay_0xed_port,
24259 .ident = "Compaq Presario V6000",
24260 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24261 index 4ddaf66..49d5c18 100644
24262 --- a/arch/x86/kernel/ioport.c
24263 +++ b/arch/x86/kernel/ioport.c
24264 @@ -6,6 +6,7 @@
24265 #include <linux/sched.h>
24266 #include <linux/kernel.h>
24267 #include <linux/capability.h>
24268 +#include <linux/security.h>
24269 #include <linux/errno.h>
24270 #include <linux/types.h>
24271 #include <linux/ioport.h>
24272 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24273 return -EINVAL;
24274 if (turn_on && !capable(CAP_SYS_RAWIO))
24275 return -EPERM;
24276 +#ifdef CONFIG_GRKERNSEC_IO
24277 + if (turn_on && grsec_disable_privio) {
24278 + gr_handle_ioperm();
24279 + return -ENODEV;
24280 + }
24281 +#endif
24282
24283 /*
24284 * If it's the first ioperm() call in this thread's lifetime, set the
24285 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24286 * because the ->io_bitmap_max value must match the bitmap
24287 * contents:
24288 */
24289 - tss = &per_cpu(init_tss, get_cpu());
24290 + tss = init_tss + get_cpu();
24291
24292 if (turn_on)
24293 bitmap_clear(t->io_bitmap_ptr, from, num);
24294 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24295 if (level > old) {
24296 if (!capable(CAP_SYS_RAWIO))
24297 return -EPERM;
24298 +#ifdef CONFIG_GRKERNSEC_IO
24299 + if (grsec_disable_privio) {
24300 + gr_handle_iopl();
24301 + return -ENODEV;
24302 + }
24303 +#endif
24304 }
24305 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24306 t->iopl = level << 12;
24307 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24308 index 22d0687..e07b2a5 100644
24309 --- a/arch/x86/kernel/irq.c
24310 +++ b/arch/x86/kernel/irq.c
24311 @@ -21,7 +21,7 @@
24312 #define CREATE_TRACE_POINTS
24313 #include <asm/trace/irq_vectors.h>
24314
24315 -atomic_t irq_err_count;
24316 +atomic_unchecked_t irq_err_count;
24317
24318 /* Function pointer for generic interrupt vector handling */
24319 void (*x86_platform_ipi_callback)(void) = NULL;
24320 @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24321 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24322 seq_printf(p, " Machine check polls\n");
24323 #endif
24324 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24325 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24326 #if defined(CONFIG_X86_IO_APIC)
24327 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24328 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24329 #endif
24330 return 0;
24331 }
24332 @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24333
24334 u64 arch_irq_stat(void)
24335 {
24336 - u64 sum = atomic_read(&irq_err_count);
24337 + u64 sum = atomic_read_unchecked(&irq_err_count);
24338 return sum;
24339 }
24340
24341 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24342 index d7fcbed..1f747f7 100644
24343 --- a/arch/x86/kernel/irq_32.c
24344 +++ b/arch/x86/kernel/irq_32.c
24345 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24346 __asm__ __volatile__("andl %%esp,%0" :
24347 "=r" (sp) : "0" (THREAD_SIZE - 1));
24348
24349 - return sp < (sizeof(struct thread_info) + STACK_WARN);
24350 + return sp < STACK_WARN;
24351 }
24352
24353 static void print_stack_overflow(void)
24354 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24355 * per-CPU IRQ handling contexts (thread information and stack)
24356 */
24357 union irq_ctx {
24358 - struct thread_info tinfo;
24359 - u32 stack[THREAD_SIZE/sizeof(u32)];
24360 + unsigned long previous_esp;
24361 + u32 stack[THREAD_SIZE/sizeof(u32)];
24362 } __attribute__((aligned(THREAD_SIZE)));
24363
24364 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24365 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24366 static inline int
24367 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24368 {
24369 - union irq_ctx *curctx, *irqctx;
24370 + union irq_ctx *irqctx;
24371 u32 *isp, arg1, arg2;
24372
24373 - curctx = (union irq_ctx *) current_thread_info();
24374 irqctx = __this_cpu_read(hardirq_ctx);
24375
24376 /*
24377 @@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24378 * handler) we can't do that and just have to keep using the
24379 * current stack (which is the irq stack already after all)
24380 */
24381 - if (unlikely(curctx == irqctx))
24382 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24383 return 0;
24384
24385 /* build the stack frame on the IRQ stack */
24386 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24387 - irqctx->tinfo.task = curctx->tinfo.task;
24388 - irqctx->tinfo.previous_esp = current_stack_pointer;
24389 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24390 + irqctx->previous_esp = current_stack_pointer;
24391 +
24392 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24393 + __set_fs(MAKE_MM_SEG(0));
24394 +#endif
24395
24396 if (unlikely(overflow))
24397 call_on_stack(print_stack_overflow, isp);
24398 @@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24399 : "0" (irq), "1" (desc), "2" (isp),
24400 "D" (desc->handle_irq)
24401 : "memory", "cc", "ecx");
24402 +
24403 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24404 + __set_fs(current_thread_info()->addr_limit);
24405 +#endif
24406 +
24407 return 1;
24408 }
24409
24410 @@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24411 */
24412 void irq_ctx_init(int cpu)
24413 {
24414 - union irq_ctx *irqctx;
24415 -
24416 if (per_cpu(hardirq_ctx, cpu))
24417 return;
24418
24419 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24420 - THREADINFO_GFP,
24421 - THREAD_SIZE_ORDER));
24422 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24423 - irqctx->tinfo.cpu = cpu;
24424 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24425 -
24426 - per_cpu(hardirq_ctx, cpu) = irqctx;
24427 -
24428 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24429 - THREADINFO_GFP,
24430 - THREAD_SIZE_ORDER));
24431 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24432 - irqctx->tinfo.cpu = cpu;
24433 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24434 -
24435 - per_cpu(softirq_ctx, cpu) = irqctx;
24436 -
24437 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24438 - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24439 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24440 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24441 }
24442
24443 void do_softirq_own_stack(void)
24444 {
24445 - struct thread_info *curctx;
24446 union irq_ctx *irqctx;
24447 u32 *isp;
24448
24449 - curctx = current_thread_info();
24450 irqctx = __this_cpu_read(softirq_ctx);
24451 - irqctx->tinfo.task = curctx->task;
24452 - irqctx->tinfo.previous_esp = current_stack_pointer;
24453 + irqctx->previous_esp = current_stack_pointer;
24454
24455 /* build the stack frame on the softirq stack */
24456 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24457 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24458 +
24459 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24460 + __set_fs(MAKE_MM_SEG(0));
24461 +#endif
24462
24463 call_on_stack(__do_softirq, isp);
24464 +
24465 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24466 + __set_fs(current_thread_info()->addr_limit);
24467 +#endif
24468 +
24469 }
24470
24471 bool handle_irq(unsigned irq, struct pt_regs *regs)
24472 @@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
24473 if (unlikely(!desc))
24474 return false;
24475
24476 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24477 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24478 if (unlikely(overflow))
24479 print_stack_overflow();
24480 desc->handle_irq(irq, desc);
24481 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
24482 index 4d1c746..232961d 100644
24483 --- a/arch/x86/kernel/irq_64.c
24484 +++ b/arch/x86/kernel/irq_64.c
24485 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
24486 u64 estack_top, estack_bottom;
24487 u64 curbase = (u64)task_stack_page(current);
24488
24489 - if (user_mode_vm(regs))
24490 + if (user_mode(regs))
24491 return;
24492
24493 if (regs->sp >= curbase + sizeof(struct thread_info) +
24494 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
24495 index 26d5a55..a01160a 100644
24496 --- a/arch/x86/kernel/jump_label.c
24497 +++ b/arch/x86/kernel/jump_label.c
24498 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24499 * Jump label is enabled for the first time.
24500 * So we expect a default_nop...
24501 */
24502 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
24503 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
24504 != 0))
24505 bug_at((void *)entry->code, __LINE__);
24506 } else {
24507 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24508 * ...otherwise expect an ideal_nop. Otherwise
24509 * something went horribly wrong.
24510 */
24511 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
24512 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
24513 != 0))
24514 bug_at((void *)entry->code, __LINE__);
24515 }
24516 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
24517 * are converting the default nop to the ideal nop.
24518 */
24519 if (init) {
24520 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
24521 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
24522 bug_at((void *)entry->code, __LINE__);
24523 } else {
24524 code.jump = 0xe9;
24525 code.offset = entry->target -
24526 (entry->code + JUMP_LABEL_NOP_SIZE);
24527 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
24528 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
24529 bug_at((void *)entry->code, __LINE__);
24530 }
24531 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
24532 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
24533 index 836f832..a8bda67 100644
24534 --- a/arch/x86/kernel/kgdb.c
24535 +++ b/arch/x86/kernel/kgdb.c
24536 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
24537 #ifdef CONFIG_X86_32
24538 switch (regno) {
24539 case GDB_SS:
24540 - if (!user_mode_vm(regs))
24541 + if (!user_mode(regs))
24542 *(unsigned long *)mem = __KERNEL_DS;
24543 break;
24544 case GDB_SP:
24545 - if (!user_mode_vm(regs))
24546 + if (!user_mode(regs))
24547 *(unsigned long *)mem = kernel_stack_pointer(regs);
24548 break;
24549 case GDB_GS:
24550 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
24551 bp->attr.bp_addr = breakinfo[breakno].addr;
24552 bp->attr.bp_len = breakinfo[breakno].len;
24553 bp->attr.bp_type = breakinfo[breakno].type;
24554 - info->address = breakinfo[breakno].addr;
24555 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
24556 + info->address = ktla_ktva(breakinfo[breakno].addr);
24557 + else
24558 + info->address = breakinfo[breakno].addr;
24559 info->len = breakinfo[breakno].len;
24560 info->type = breakinfo[breakno].type;
24561 val = arch_install_hw_breakpoint(bp);
24562 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
24563 case 'k':
24564 /* clear the trace bit */
24565 linux_regs->flags &= ~X86_EFLAGS_TF;
24566 - atomic_set(&kgdb_cpu_doing_single_step, -1);
24567 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
24568
24569 /* set the trace bit if we're stepping */
24570 if (remcomInBuffer[0] == 's') {
24571 linux_regs->flags |= X86_EFLAGS_TF;
24572 - atomic_set(&kgdb_cpu_doing_single_step,
24573 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
24574 raw_smp_processor_id());
24575 }
24576
24577 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
24578
24579 switch (cmd) {
24580 case DIE_DEBUG:
24581 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
24582 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
24583 if (user_mode(regs))
24584 return single_step_cont(regs, args);
24585 break;
24586 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24587 #endif /* CONFIG_DEBUG_RODATA */
24588
24589 bpt->type = BP_BREAKPOINT;
24590 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
24591 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
24592 BREAK_INSTR_SIZE);
24593 if (err)
24594 return err;
24595 - err = probe_kernel_write((char *)bpt->bpt_addr,
24596 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24597 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
24598 #ifdef CONFIG_DEBUG_RODATA
24599 if (!err)
24600 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24601 return -EBUSY;
24602 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
24603 BREAK_INSTR_SIZE);
24604 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24605 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24606 if (err)
24607 return err;
24608 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
24609 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
24610 if (mutex_is_locked(&text_mutex))
24611 goto knl_write;
24612 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
24613 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24614 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24615 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
24616 goto knl_write;
24617 return err;
24618 knl_write:
24619 #endif /* CONFIG_DEBUG_RODATA */
24620 - return probe_kernel_write((char *)bpt->bpt_addr,
24621 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24622 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
24623 }
24624
24625 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
24626 index 79a3f96..6ba030a 100644
24627 --- a/arch/x86/kernel/kprobes/core.c
24628 +++ b/arch/x86/kernel/kprobes/core.c
24629 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
24630 s32 raddr;
24631 } __packed *insn;
24632
24633 - insn = (struct __arch_relative_insn *)from;
24634 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
24635 +
24636 + pax_open_kernel();
24637 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
24638 insn->op = op;
24639 + pax_close_kernel();
24640 }
24641
24642 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
24643 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
24644 kprobe_opcode_t opcode;
24645 kprobe_opcode_t *orig_opcodes = opcodes;
24646
24647 - if (search_exception_tables((unsigned long)opcodes))
24648 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
24649 return 0; /* Page fault may occur on this address. */
24650
24651 retry:
24652 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
24653 * for the first byte, we can recover the original instruction
24654 * from it and kp->opcode.
24655 */
24656 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24657 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24658 buf[0] = kp->opcode;
24659 - return (unsigned long)buf;
24660 + return ktva_ktla((unsigned long)buf);
24661 }
24662
24663 /*
24664 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24665 /* Another subsystem puts a breakpoint, failed to recover */
24666 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
24667 return 0;
24668 + pax_open_kernel();
24669 memcpy(dest, insn.kaddr, insn.length);
24670 + pax_close_kernel();
24671
24672 #ifdef CONFIG_X86_64
24673 if (insn_rip_relative(&insn)) {
24674 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24675 return 0;
24676 }
24677 disp = (u8 *) dest + insn_offset_displacement(&insn);
24678 + pax_open_kernel();
24679 *(s32 *) disp = (s32) newdisp;
24680 + pax_close_kernel();
24681 }
24682 #endif
24683 return insn.length;
24684 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24685 * nor set current_kprobe, because it doesn't use single
24686 * stepping.
24687 */
24688 - regs->ip = (unsigned long)p->ainsn.insn;
24689 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24690 preempt_enable_no_resched();
24691 return;
24692 }
24693 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24694 regs->flags &= ~X86_EFLAGS_IF;
24695 /* single step inline if the instruction is an int3 */
24696 if (p->opcode == BREAKPOINT_INSTRUCTION)
24697 - regs->ip = (unsigned long)p->addr;
24698 + regs->ip = ktla_ktva((unsigned long)p->addr);
24699 else
24700 - regs->ip = (unsigned long)p->ainsn.insn;
24701 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24702 }
24703
24704 /*
24705 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
24706 setup_singlestep(p, regs, kcb, 0);
24707 return 1;
24708 }
24709 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
24710 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
24711 /*
24712 * The breakpoint instruction was removed right
24713 * after we hit it. Another cpu has removed
24714 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
24715 " movq %rax, 152(%rsp)\n"
24716 RESTORE_REGS_STRING
24717 " popfq\n"
24718 +#ifdef KERNEXEC_PLUGIN
24719 + " btsq $63,(%rsp)\n"
24720 +#endif
24721 #else
24722 " pushf\n"
24723 SAVE_REGS_STRING
24724 @@ -779,7 +789,7 @@ static void __kprobes
24725 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
24726 {
24727 unsigned long *tos = stack_addr(regs);
24728 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
24729 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
24730 unsigned long orig_ip = (unsigned long)p->addr;
24731 kprobe_opcode_t *insn = p->ainsn.insn;
24732
24733 @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
24734 struct die_args *args = data;
24735 int ret = NOTIFY_DONE;
24736
24737 - if (args->regs && user_mode_vm(args->regs))
24738 + if (args->regs && user_mode(args->regs))
24739 return ret;
24740
24741 switch (val) {
24742 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
24743 index 898160b..758cde8 100644
24744 --- a/arch/x86/kernel/kprobes/opt.c
24745 +++ b/arch/x86/kernel/kprobes/opt.c
24746 @@ -79,6 +79,7 @@ found:
24747 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
24748 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
24749 {
24750 + pax_open_kernel();
24751 #ifdef CONFIG_X86_64
24752 *addr++ = 0x48;
24753 *addr++ = 0xbf;
24754 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
24755 *addr++ = 0xb8;
24756 #endif
24757 *(unsigned long *)addr = val;
24758 + pax_close_kernel();
24759 }
24760
24761 asm (
24762 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24763 * Verify if the address gap is in 2GB range, because this uses
24764 * a relative jump.
24765 */
24766 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
24767 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
24768 if (abs(rel) > 0x7fffffff)
24769 return -ERANGE;
24770
24771 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24772 op->optinsn.size = ret;
24773
24774 /* Copy arch-dep-instance from template */
24775 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
24776 + pax_open_kernel();
24777 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
24778 + pax_close_kernel();
24779
24780 /* Set probe information */
24781 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
24782
24783 /* Set probe function call */
24784 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
24785 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
24786
24787 /* Set returning jmp instruction at the tail of out-of-line buffer */
24788 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
24789 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
24790 (u8 *)op->kp.addr + op->optinsn.size);
24791
24792 flush_icache_range((unsigned long) buf,
24793 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
24794 WARN_ON(kprobe_disabled(&op->kp));
24795
24796 /* Backup instructions which will be replaced by jump address */
24797 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
24798 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
24799 RELATIVE_ADDR_SIZE);
24800
24801 insn_buf[0] = RELATIVEJUMP_OPCODE;
24802 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
24803 /* This kprobe is really able to run optimized path. */
24804 op = container_of(p, struct optimized_kprobe, kp);
24805 /* Detour through copied instructions */
24806 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
24807 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
24808 if (!reenter)
24809 reset_current_kprobe();
24810 preempt_enable_no_resched();
24811 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
24812 index ebc9873..1b9724b 100644
24813 --- a/arch/x86/kernel/ldt.c
24814 +++ b/arch/x86/kernel/ldt.c
24815 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
24816 if (reload) {
24817 #ifdef CONFIG_SMP
24818 preempt_disable();
24819 - load_LDT(pc);
24820 + load_LDT_nolock(pc);
24821 if (!cpumask_equal(mm_cpumask(current->mm),
24822 cpumask_of(smp_processor_id())))
24823 smp_call_function(flush_ldt, current->mm, 1);
24824 preempt_enable();
24825 #else
24826 - load_LDT(pc);
24827 + load_LDT_nolock(pc);
24828 #endif
24829 }
24830 if (oldsize) {
24831 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
24832 return err;
24833
24834 for (i = 0; i < old->size; i++)
24835 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
24836 + write_ldt_entry(new->ldt, i, old->ldt + i);
24837 return 0;
24838 }
24839
24840 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
24841 retval = copy_ldt(&mm->context, &old_mm->context);
24842 mutex_unlock(&old_mm->context.lock);
24843 }
24844 +
24845 + if (tsk == current) {
24846 + mm->context.vdso = 0;
24847 +
24848 +#ifdef CONFIG_X86_32
24849 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24850 + mm->context.user_cs_base = 0UL;
24851 + mm->context.user_cs_limit = ~0UL;
24852 +
24853 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24854 + cpus_clear(mm->context.cpu_user_cs_mask);
24855 +#endif
24856 +
24857 +#endif
24858 +#endif
24859 +
24860 + }
24861 +
24862 return retval;
24863 }
24864
24865 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24866 }
24867 }
24868
24869 +#ifdef CONFIG_PAX_SEGMEXEC
24870 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24871 + error = -EINVAL;
24872 + goto out_unlock;
24873 + }
24874 +#endif
24875 +
24876 fill_ldt(&ldt, &ldt_info);
24877 if (oldmode)
24878 ldt.avl = 0;
24879 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24880 index 5b19e4d..6476a76 100644
24881 --- a/arch/x86/kernel/machine_kexec_32.c
24882 +++ b/arch/x86/kernel/machine_kexec_32.c
24883 @@ -26,7 +26,7 @@
24884 #include <asm/cacheflush.h>
24885 #include <asm/debugreg.h>
24886
24887 -static void set_idt(void *newidt, __u16 limit)
24888 +static void set_idt(struct desc_struct *newidt, __u16 limit)
24889 {
24890 struct desc_ptr curidt;
24891
24892 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24893 }
24894
24895
24896 -static void set_gdt(void *newgdt, __u16 limit)
24897 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24898 {
24899 struct desc_ptr curgdt;
24900
24901 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24902 }
24903
24904 control_page = page_address(image->control_code_page);
24905 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24906 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24907
24908 relocate_kernel_ptr = control_page;
24909 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24910 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24911 index 15c9876..0a43909 100644
24912 --- a/arch/x86/kernel/microcode_core.c
24913 +++ b/arch/x86/kernel/microcode_core.c
24914 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24915 return NOTIFY_OK;
24916 }
24917
24918 -static struct notifier_block __refdata mc_cpu_notifier = {
24919 +static struct notifier_block mc_cpu_notifier = {
24920 .notifier_call = mc_cpu_callback,
24921 };
24922
24923 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24924 index 5fb2ceb..3ae90bb 100644
24925 --- a/arch/x86/kernel/microcode_intel.c
24926 +++ b/arch/x86/kernel/microcode_intel.c
24927 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24928
24929 static int get_ucode_user(void *to, const void *from, size_t n)
24930 {
24931 - return copy_from_user(to, from, n);
24932 + return copy_from_user(to, (const void __force_user *)from, n);
24933 }
24934
24935 static enum ucode_state
24936 request_microcode_user(int cpu, const void __user *buf, size_t size)
24937 {
24938 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24939 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24940 }
24941
24942 static void microcode_fini_cpu(int cpu)
24943 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24944 index 18be189..4a9fe40 100644
24945 --- a/arch/x86/kernel/module.c
24946 +++ b/arch/x86/kernel/module.c
24947 @@ -43,15 +43,60 @@ do { \
24948 } while (0)
24949 #endif
24950
24951 -void *module_alloc(unsigned long size)
24952 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24953 {
24954 - if (PAGE_ALIGN(size) > MODULES_LEN)
24955 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24956 return NULL;
24957 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24958 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24959 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24960 NUMA_NO_NODE, __builtin_return_address(0));
24961 }
24962
24963 +void *module_alloc(unsigned long size)
24964 +{
24965 +
24966 +#ifdef CONFIG_PAX_KERNEXEC
24967 + return __module_alloc(size, PAGE_KERNEL);
24968 +#else
24969 + return __module_alloc(size, PAGE_KERNEL_EXEC);
24970 +#endif
24971 +
24972 +}
24973 +
24974 +#ifdef CONFIG_PAX_KERNEXEC
24975 +#ifdef CONFIG_X86_32
24976 +void *module_alloc_exec(unsigned long size)
24977 +{
24978 + struct vm_struct *area;
24979 +
24980 + if (size == 0)
24981 + return NULL;
24982 +
24983 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24984 + return area ? area->addr : NULL;
24985 +}
24986 +EXPORT_SYMBOL(module_alloc_exec);
24987 +
24988 +void module_free_exec(struct module *mod, void *module_region)
24989 +{
24990 + vunmap(module_region);
24991 +}
24992 +EXPORT_SYMBOL(module_free_exec);
24993 +#else
24994 +void module_free_exec(struct module *mod, void *module_region)
24995 +{
24996 + module_free(mod, module_region);
24997 +}
24998 +EXPORT_SYMBOL(module_free_exec);
24999 +
25000 +void *module_alloc_exec(unsigned long size)
25001 +{
25002 + return __module_alloc(size, PAGE_KERNEL_RX);
25003 +}
25004 +EXPORT_SYMBOL(module_alloc_exec);
25005 +#endif
25006 +#endif
25007 +
25008 #ifdef CONFIG_X86_32
25009 int apply_relocate(Elf32_Shdr *sechdrs,
25010 const char *strtab,
25011 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25012 unsigned int i;
25013 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25014 Elf32_Sym *sym;
25015 - uint32_t *location;
25016 + uint32_t *plocation, location;
25017
25018 DEBUGP("Applying relocate section %u to %u\n",
25019 relsec, sechdrs[relsec].sh_info);
25020 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25021 /* This is where to make the change */
25022 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25023 - + rel[i].r_offset;
25024 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25025 + location = (uint32_t)plocation;
25026 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25027 + plocation = ktla_ktva((void *)plocation);
25028 /* This is the symbol it is referring to. Note that all
25029 undefined symbols have been resolved. */
25030 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25031 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25032 switch (ELF32_R_TYPE(rel[i].r_info)) {
25033 case R_386_32:
25034 /* We add the value into the location given */
25035 - *location += sym->st_value;
25036 + pax_open_kernel();
25037 + *plocation += sym->st_value;
25038 + pax_close_kernel();
25039 break;
25040 case R_386_PC32:
25041 /* Add the value, subtract its position */
25042 - *location += sym->st_value - (uint32_t)location;
25043 + pax_open_kernel();
25044 + *plocation += sym->st_value - location;
25045 + pax_close_kernel();
25046 break;
25047 default:
25048 pr_err("%s: Unknown relocation: %u\n",
25049 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25050 case R_X86_64_NONE:
25051 break;
25052 case R_X86_64_64:
25053 + pax_open_kernel();
25054 *(u64 *)loc = val;
25055 + pax_close_kernel();
25056 break;
25057 case R_X86_64_32:
25058 + pax_open_kernel();
25059 *(u32 *)loc = val;
25060 + pax_close_kernel();
25061 if (val != *(u32 *)loc)
25062 goto overflow;
25063 break;
25064 case R_X86_64_32S:
25065 + pax_open_kernel();
25066 *(s32 *)loc = val;
25067 + pax_close_kernel();
25068 if ((s64)val != *(s32 *)loc)
25069 goto overflow;
25070 break;
25071 case R_X86_64_PC32:
25072 val -= (u64)loc;
25073 + pax_open_kernel();
25074 *(u32 *)loc = val;
25075 + pax_close_kernel();
25076 +
25077 #if 0
25078 if ((s64)val != *(s32 *)loc)
25079 goto overflow;
25080 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25081 index 05266b5..1577fde 100644
25082 --- a/arch/x86/kernel/msr.c
25083 +++ b/arch/x86/kernel/msr.c
25084 @@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25085 return notifier_from_errno(err);
25086 }
25087
25088 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25089 +static struct notifier_block msr_class_cpu_notifier = {
25090 .notifier_call = msr_class_cpu_callback,
25091 };
25092
25093 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25094 index 6fcb49c..5b3f4ff 100644
25095 --- a/arch/x86/kernel/nmi.c
25096 +++ b/arch/x86/kernel/nmi.c
25097 @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25098 return handled;
25099 }
25100
25101 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25102 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25103 {
25104 struct nmi_desc *desc = nmi_to_desc(type);
25105 unsigned long flags;
25106 @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25107 * event confuses some handlers (kdump uses this flag)
25108 */
25109 if (action->flags & NMI_FLAG_FIRST)
25110 - list_add_rcu(&action->list, &desc->head);
25111 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25112 else
25113 - list_add_tail_rcu(&action->list, &desc->head);
25114 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25115
25116 spin_unlock_irqrestore(&desc->lock, flags);
25117 return 0;
25118 @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25119 if (!strcmp(n->name, name)) {
25120 WARN(in_nmi(),
25121 "Trying to free NMI (%s) from NMI context!\n", n->name);
25122 - list_del_rcu(&n->list);
25123 + pax_list_del_rcu((struct list_head *)&n->list);
25124 break;
25125 }
25126 }
25127 @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25128 dotraplinkage notrace __kprobes void
25129 do_nmi(struct pt_regs *regs, long error_code)
25130 {
25131 +
25132 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25133 + if (!user_mode(regs)) {
25134 + unsigned long cs = regs->cs & 0xFFFF;
25135 + unsigned long ip = ktva_ktla(regs->ip);
25136 +
25137 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25138 + regs->ip = ip;
25139 + }
25140 +#endif
25141 +
25142 nmi_nesting_preprocess(regs);
25143
25144 nmi_enter();
25145 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25146 index 6d9582e..f746287 100644
25147 --- a/arch/x86/kernel/nmi_selftest.c
25148 +++ b/arch/x86/kernel/nmi_selftest.c
25149 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25150 {
25151 /* trap all the unknown NMIs we may generate */
25152 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25153 - __initdata);
25154 + __initconst);
25155 }
25156
25157 static void __init cleanup_nmi_testsuite(void)
25158 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25159 unsigned long timeout;
25160
25161 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25162 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25163 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25164 nmi_fail = FAILURE;
25165 return;
25166 }
25167 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25168 index bbb6c73..24a58ef 100644
25169 --- a/arch/x86/kernel/paravirt-spinlocks.c
25170 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25171 @@ -8,7 +8,7 @@
25172
25173 #include <asm/paravirt.h>
25174
25175 -struct pv_lock_ops pv_lock_ops = {
25176 +struct pv_lock_ops pv_lock_ops __read_only = {
25177 #ifdef CONFIG_SMP
25178 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25179 .unlock_kick = paravirt_nop,
25180 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25181 index 1b10af8..0b58cbc 100644
25182 --- a/arch/x86/kernel/paravirt.c
25183 +++ b/arch/x86/kernel/paravirt.c
25184 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25185 {
25186 return x;
25187 }
25188 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25189 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25190 +#endif
25191
25192 void __init default_banner(void)
25193 {
25194 @@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25195 if (opfunc == NULL)
25196 /* If there's no function, patch it with a ud2a (BUG) */
25197 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25198 - else if (opfunc == _paravirt_nop)
25199 + else if (opfunc == (void *)_paravirt_nop)
25200 /* If the operation is a nop, then nop the callsite */
25201 ret = paravirt_patch_nop();
25202
25203 /* identity functions just return their single argument */
25204 - else if (opfunc == _paravirt_ident_32)
25205 + else if (opfunc == (void *)_paravirt_ident_32)
25206 ret = paravirt_patch_ident_32(insnbuf, len);
25207 - else if (opfunc == _paravirt_ident_64)
25208 + else if (opfunc == (void *)_paravirt_ident_64)
25209 ret = paravirt_patch_ident_64(insnbuf, len);
25210 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25211 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25212 + ret = paravirt_patch_ident_64(insnbuf, len);
25213 +#endif
25214
25215 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25216 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25217 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25218 if (insn_len > len || start == NULL)
25219 insn_len = len;
25220 else
25221 - memcpy(insnbuf, start, insn_len);
25222 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25223
25224 return insn_len;
25225 }
25226 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25227 return this_cpu_read(paravirt_lazy_mode);
25228 }
25229
25230 -struct pv_info pv_info = {
25231 +struct pv_info pv_info __read_only = {
25232 .name = "bare hardware",
25233 .paravirt_enabled = 0,
25234 .kernel_rpl = 0,
25235 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25236 #endif
25237 };
25238
25239 -struct pv_init_ops pv_init_ops = {
25240 +struct pv_init_ops pv_init_ops __read_only = {
25241 .patch = native_patch,
25242 };
25243
25244 -struct pv_time_ops pv_time_ops = {
25245 +struct pv_time_ops pv_time_ops __read_only = {
25246 .sched_clock = native_sched_clock,
25247 .steal_clock = native_steal_clock,
25248 };
25249
25250 -__visible struct pv_irq_ops pv_irq_ops = {
25251 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25252 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25253 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25254 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25255 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25256 #endif
25257 };
25258
25259 -__visible struct pv_cpu_ops pv_cpu_ops = {
25260 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25261 .cpuid = native_cpuid,
25262 .get_debugreg = native_get_debugreg,
25263 .set_debugreg = native_set_debugreg,
25264 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25265 .end_context_switch = paravirt_nop,
25266 };
25267
25268 -struct pv_apic_ops pv_apic_ops = {
25269 +struct pv_apic_ops pv_apic_ops __read_only= {
25270 #ifdef CONFIG_X86_LOCAL_APIC
25271 .startup_ipi_hook = paravirt_nop,
25272 #endif
25273 };
25274
25275 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25276 +#ifdef CONFIG_X86_32
25277 +#ifdef CONFIG_X86_PAE
25278 +/* 64-bit pagetable entries */
25279 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25280 +#else
25281 /* 32-bit pagetable entries */
25282 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25283 +#endif
25284 #else
25285 /* 64-bit pagetable entries */
25286 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25287 #endif
25288
25289 -struct pv_mmu_ops pv_mmu_ops = {
25290 +struct pv_mmu_ops pv_mmu_ops __read_only = {
25291
25292 .read_cr2 = native_read_cr2,
25293 .write_cr2 = native_write_cr2,
25294 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25295 .make_pud = PTE_IDENT,
25296
25297 .set_pgd = native_set_pgd,
25298 + .set_pgd_batched = native_set_pgd_batched,
25299 #endif
25300 #endif /* PAGETABLE_LEVELS >= 3 */
25301
25302 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25303 },
25304
25305 .set_fixmap = native_set_fixmap,
25306 +
25307 +#ifdef CONFIG_PAX_KERNEXEC
25308 + .pax_open_kernel = native_pax_open_kernel,
25309 + .pax_close_kernel = native_pax_close_kernel,
25310 +#endif
25311 +
25312 };
25313
25314 EXPORT_SYMBOL_GPL(pv_time_ops);
25315 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25316 index 299d493..2ccb0ee 100644
25317 --- a/arch/x86/kernel/pci-calgary_64.c
25318 +++ b/arch/x86/kernel/pci-calgary_64.c
25319 @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25320 tce_space = be64_to_cpu(readq(target));
25321 tce_space = tce_space & TAR_SW_BITS;
25322
25323 - tce_space = tce_space & (~specified_table_size);
25324 + tce_space = tce_space & (~(unsigned long)specified_table_size);
25325 info->tce_space = (u64 *)__va(tce_space);
25326 }
25327 }
25328 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25329 index 35ccf75..7a15747 100644
25330 --- a/arch/x86/kernel/pci-iommu_table.c
25331 +++ b/arch/x86/kernel/pci-iommu_table.c
25332 @@ -2,7 +2,7 @@
25333 #include <asm/iommu_table.h>
25334 #include <linux/string.h>
25335 #include <linux/kallsyms.h>
25336 -
25337 +#include <linux/sched.h>
25338
25339 #define DEBUG 1
25340
25341 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25342 index 6c483ba..d10ce2f 100644
25343 --- a/arch/x86/kernel/pci-swiotlb.c
25344 +++ b/arch/x86/kernel/pci-swiotlb.c
25345 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25346 void *vaddr, dma_addr_t dma_addr,
25347 struct dma_attrs *attrs)
25348 {
25349 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25350 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25351 }
25352
25353 static struct dma_map_ops swiotlb_dma_ops = {
25354 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25355 index ca7f0d5..8996469 100644
25356 --- a/arch/x86/kernel/preempt.S
25357 +++ b/arch/x86/kernel/preempt.S
25358 @@ -3,12 +3,14 @@
25359 #include <asm/dwarf2.h>
25360 #include <asm/asm.h>
25361 #include <asm/calling.h>
25362 +#include <asm/alternative-asm.h>
25363
25364 ENTRY(___preempt_schedule)
25365 CFI_STARTPROC
25366 SAVE_ALL
25367 call preempt_schedule
25368 RESTORE_ALL
25369 + pax_force_retaddr
25370 ret
25371 CFI_ENDPROC
25372
25373 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25374 SAVE_ALL
25375 call preempt_schedule_context
25376 RESTORE_ALL
25377 + pax_force_retaddr
25378 ret
25379 CFI_ENDPROC
25380
25381 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25382 index 3fb8d95..254dc51 100644
25383 --- a/arch/x86/kernel/process.c
25384 +++ b/arch/x86/kernel/process.c
25385 @@ -36,7 +36,8 @@
25386 * section. Since TSS's are completely CPU-local, we want them
25387 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25388 */
25389 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25390 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25391 +EXPORT_SYMBOL(init_tss);
25392
25393 #ifdef CONFIG_X86_64
25394 static DEFINE_PER_CPU(unsigned char, is_idle);
25395 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25396 task_xstate_cachep =
25397 kmem_cache_create("task_xstate", xstate_size,
25398 __alignof__(union thread_xstate),
25399 - SLAB_PANIC | SLAB_NOTRACK, NULL);
25400 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25401 }
25402
25403 /*
25404 @@ -105,7 +106,7 @@ void exit_thread(void)
25405 unsigned long *bp = t->io_bitmap_ptr;
25406
25407 if (bp) {
25408 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25409 + struct tss_struct *tss = init_tss + get_cpu();
25410
25411 t->io_bitmap_ptr = NULL;
25412 clear_thread_flag(TIF_IO_BITMAP);
25413 @@ -125,6 +126,9 @@ void flush_thread(void)
25414 {
25415 struct task_struct *tsk = current;
25416
25417 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25418 + loadsegment(gs, 0);
25419 +#endif
25420 flush_ptrace_hw_breakpoint(tsk);
25421 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25422 drop_init_fpu(tsk);
25423 @@ -271,7 +275,7 @@ static void __exit_idle(void)
25424 void exit_idle(void)
25425 {
25426 /* idle loop has pid 0 */
25427 - if (current->pid)
25428 + if (task_pid_nr(current))
25429 return;
25430 __exit_idle();
25431 }
25432 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25433 return ret;
25434 }
25435 #endif
25436 -void stop_this_cpu(void *dummy)
25437 +__noreturn void stop_this_cpu(void *dummy)
25438 {
25439 local_irq_disable();
25440 /*
25441 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25442 }
25443 early_param("idle", idle_setup);
25444
25445 -unsigned long arch_align_stack(unsigned long sp)
25446 +#ifdef CONFIG_PAX_RANDKSTACK
25447 +void pax_randomize_kstack(struct pt_regs *regs)
25448 {
25449 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
25450 - sp -= get_random_int() % 8192;
25451 - return sp & ~0xf;
25452 -}
25453 + struct thread_struct *thread = &current->thread;
25454 + unsigned long time;
25455
25456 -unsigned long arch_randomize_brk(struct mm_struct *mm)
25457 -{
25458 - unsigned long range_end = mm->brk + 0x02000000;
25459 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
25460 -}
25461 + if (!randomize_va_space)
25462 + return;
25463 +
25464 + if (v8086_mode(regs))
25465 + return;
25466
25467 + rdtscl(time);
25468 +
25469 + /* P4 seems to return a 0 LSB, ignore it */
25470 +#ifdef CONFIG_MPENTIUM4
25471 + time &= 0x3EUL;
25472 + time <<= 2;
25473 +#elif defined(CONFIG_X86_64)
25474 + time &= 0xFUL;
25475 + time <<= 4;
25476 +#else
25477 + time &= 0x1FUL;
25478 + time <<= 3;
25479 +#endif
25480 +
25481 + thread->sp0 ^= time;
25482 + load_sp0(init_tss + smp_processor_id(), thread);
25483 +
25484 +#ifdef CONFIG_X86_64
25485 + this_cpu_write(kernel_stack, thread->sp0);
25486 +#endif
25487 +}
25488 +#endif
25489 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
25490 index 6f1236c..fd448d4 100644
25491 --- a/arch/x86/kernel/process_32.c
25492 +++ b/arch/x86/kernel/process_32.c
25493 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
25494 unsigned long thread_saved_pc(struct task_struct *tsk)
25495 {
25496 return ((unsigned long *)tsk->thread.sp)[3];
25497 +//XXX return tsk->thread.eip;
25498 }
25499
25500 void __show_regs(struct pt_regs *regs, int all)
25501 @@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
25502 unsigned long sp;
25503 unsigned short ss, gs;
25504
25505 - if (user_mode_vm(regs)) {
25506 + if (user_mode(regs)) {
25507 sp = regs->sp;
25508 ss = regs->ss & 0xffff;
25509 - gs = get_user_gs(regs);
25510 } else {
25511 sp = kernel_stack_pointer(regs);
25512 savesegment(ss, ss);
25513 - savesegment(gs, gs);
25514 }
25515 + gs = get_user_gs(regs);
25516
25517 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
25518 (u16)regs->cs, regs->ip, regs->flags,
25519 - smp_processor_id());
25520 + raw_smp_processor_id());
25521 print_symbol("EIP is at %s\n", regs->ip);
25522
25523 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
25524 @@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
25525 int copy_thread(unsigned long clone_flags, unsigned long sp,
25526 unsigned long arg, struct task_struct *p)
25527 {
25528 - struct pt_regs *childregs = task_pt_regs(p);
25529 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
25530 struct task_struct *tsk;
25531 int err;
25532
25533 p->thread.sp = (unsigned long) childregs;
25534 p->thread.sp0 = (unsigned long) (childregs+1);
25535 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25536
25537 if (unlikely(p->flags & PF_KTHREAD)) {
25538 /* kernel thread */
25539 memset(childregs, 0, sizeof(struct pt_regs));
25540 p->thread.ip = (unsigned long) ret_from_kernel_thread;
25541 - task_user_gs(p) = __KERNEL_STACK_CANARY;
25542 - childregs->ds = __USER_DS;
25543 - childregs->es = __USER_DS;
25544 + savesegment(gs, childregs->gs);
25545 + childregs->ds = __KERNEL_DS;
25546 + childregs->es = __KERNEL_DS;
25547 childregs->fs = __KERNEL_PERCPU;
25548 childregs->bx = sp; /* function */
25549 childregs->bp = arg;
25550 @@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25551 struct thread_struct *prev = &prev_p->thread,
25552 *next = &next_p->thread;
25553 int cpu = smp_processor_id();
25554 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
25555 + struct tss_struct *tss = init_tss + cpu;
25556 fpu_switch_t fpu;
25557
25558 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
25559 @@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25560 */
25561 lazy_save_gs(prev->gs);
25562
25563 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25564 + __set_fs(task_thread_info(next_p)->addr_limit);
25565 +#endif
25566 +
25567 /*
25568 * Load the per-thread Thread-Local Storage descriptor.
25569 */
25570 @@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25571 */
25572 arch_end_context_switch(next_p);
25573
25574 + this_cpu_write(current_task, next_p);
25575 + this_cpu_write(current_tinfo, &next_p->tinfo);
25576 +
25577 /*
25578 * Restore %gs if needed (which is common)
25579 */
25580 @@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25581
25582 switch_fpu_finish(next_p, fpu);
25583
25584 - this_cpu_write(current_task, next_p);
25585 -
25586 return prev_p;
25587 }
25588
25589 @@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
25590 } while (count++ < 16);
25591 return 0;
25592 }
25593 -
25594 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
25595 index 9c0280f..5bbb1c0 100644
25596 --- a/arch/x86/kernel/process_64.c
25597 +++ b/arch/x86/kernel/process_64.c
25598 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25599 struct pt_regs *childregs;
25600 struct task_struct *me = current;
25601
25602 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
25603 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
25604 childregs = task_pt_regs(p);
25605 p->thread.sp = (unsigned long) childregs;
25606 p->thread.usersp = me->thread.usersp;
25607 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25608 set_tsk_thread_flag(p, TIF_FORK);
25609 p->thread.fpu_counter = 0;
25610 p->thread.io_bitmap_ptr = NULL;
25611 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25612 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
25613 savesegment(es, p->thread.es);
25614 savesegment(ds, p->thread.ds);
25615 + savesegment(ss, p->thread.ss);
25616 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
25617 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
25618
25619 if (unlikely(p->flags & PF_KTHREAD)) {
25620 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25621 struct thread_struct *prev = &prev_p->thread;
25622 struct thread_struct *next = &next_p->thread;
25623 int cpu = smp_processor_id();
25624 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
25625 + struct tss_struct *tss = init_tss + cpu;
25626 unsigned fsindex, gsindex;
25627 fpu_switch_t fpu;
25628
25629 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25630 if (unlikely(next->ds | prev->ds))
25631 loadsegment(ds, next->ds);
25632
25633 + savesegment(ss, prev->ss);
25634 + if (unlikely(next->ss != prev->ss))
25635 + loadsegment(ss, next->ss);
25636
25637 /* We must save %fs and %gs before load_TLS() because
25638 * %fs and %gs may be cleared by load_TLS().
25639 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25640 prev->usersp = this_cpu_read(old_rsp);
25641 this_cpu_write(old_rsp, next->usersp);
25642 this_cpu_write(current_task, next_p);
25643 + this_cpu_write(current_tinfo, &next_p->tinfo);
25644
25645 /*
25646 * If it were not for PREEMPT_ACTIVE we could guarantee that the
25647 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25648 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
25649 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
25650
25651 - this_cpu_write(kernel_stack,
25652 - (unsigned long)task_stack_page(next_p) +
25653 - THREAD_SIZE - KERNEL_STACK_OFFSET);
25654 + this_cpu_write(kernel_stack, next->sp0);
25655
25656 /*
25657 * Now maybe reload the debug registers and handle I/O bitmaps
25658 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
25659 if (!p || p == current || p->state == TASK_RUNNING)
25660 return 0;
25661 stack = (unsigned long)task_stack_page(p);
25662 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
25663 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
25664 return 0;
25665 fp = *(u64 *)(p->thread.sp);
25666 do {
25667 - if (fp < (unsigned long)stack ||
25668 - fp >= (unsigned long)stack+THREAD_SIZE)
25669 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
25670 return 0;
25671 ip = *(u64 *)(fp+8);
25672 if (!in_sched_functions(ip))
25673 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
25674 index 7461f50..1334029 100644
25675 --- a/arch/x86/kernel/ptrace.c
25676 +++ b/arch/x86/kernel/ptrace.c
25677 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
25678 {
25679 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
25680 unsigned long sp = (unsigned long)&regs->sp;
25681 - struct thread_info *tinfo;
25682
25683 - if (context == (sp & ~(THREAD_SIZE - 1)))
25684 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
25685 return sp;
25686
25687 - tinfo = (struct thread_info *)context;
25688 - if (tinfo->previous_esp)
25689 - return tinfo->previous_esp;
25690 + sp = *(unsigned long *)context;
25691 + if (sp)
25692 + return sp;
25693
25694 return (unsigned long)regs;
25695 }
25696 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
25697 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
25698 {
25699 int i;
25700 - int dr7 = 0;
25701 + unsigned long dr7 = 0;
25702 struct arch_hw_breakpoint *info;
25703
25704 for (i = 0; i < HBP_NUM; i++) {
25705 @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
25706 unsigned long addr, unsigned long data)
25707 {
25708 int ret;
25709 - unsigned long __user *datap = (unsigned long __user *)data;
25710 + unsigned long __user *datap = (__force unsigned long __user *)data;
25711
25712 switch (request) {
25713 /* read the word at location addr in the USER area. */
25714 @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
25715 if ((int) addr < 0)
25716 return -EIO;
25717 ret = do_get_thread_area(child, addr,
25718 - (struct user_desc __user *)data);
25719 + (__force struct user_desc __user *) data);
25720 break;
25721
25722 case PTRACE_SET_THREAD_AREA:
25723 if ((int) addr < 0)
25724 return -EIO;
25725 ret = do_set_thread_area(child, addr,
25726 - (struct user_desc __user *)data, 0);
25727 + (__force struct user_desc __user *) data, 0);
25728 break;
25729 #endif
25730
25731 @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
25732
25733 #ifdef CONFIG_X86_64
25734
25735 -static struct user_regset x86_64_regsets[] __read_mostly = {
25736 +static user_regset_no_const x86_64_regsets[] __read_only = {
25737 [REGSET_GENERAL] = {
25738 .core_note_type = NT_PRSTATUS,
25739 .n = sizeof(struct user_regs_struct) / sizeof(long),
25740 @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
25741 #endif /* CONFIG_X86_64 */
25742
25743 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
25744 -static struct user_regset x86_32_regsets[] __read_mostly = {
25745 +static user_regset_no_const x86_32_regsets[] __read_only = {
25746 [REGSET_GENERAL] = {
25747 .core_note_type = NT_PRSTATUS,
25748 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
25749 @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
25750 */
25751 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
25752
25753 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25754 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25755 {
25756 #ifdef CONFIG_X86_64
25757 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
25758 @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
25759 memset(info, 0, sizeof(*info));
25760 info->si_signo = SIGTRAP;
25761 info->si_code = si_code;
25762 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
25763 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
25764 }
25765
25766 void user_single_step_siginfo(struct task_struct *tsk,
25767 @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
25768 # define IS_IA32 0
25769 #endif
25770
25771 +#ifdef CONFIG_GRKERNSEC_SETXID
25772 +extern void gr_delayed_cred_worker(void);
25773 +#endif
25774 +
25775 /*
25776 * We must return the syscall number to actually look up in the table.
25777 * This can be -1L to skip running any syscall at all.
25778 @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
25779
25780 user_exit();
25781
25782 +#ifdef CONFIG_GRKERNSEC_SETXID
25783 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25784 + gr_delayed_cred_worker();
25785 +#endif
25786 +
25787 /*
25788 * If we stepped into a sysenter/syscall insn, it trapped in
25789 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
25790 @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
25791 */
25792 user_exit();
25793
25794 +#ifdef CONFIG_GRKERNSEC_SETXID
25795 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25796 + gr_delayed_cred_worker();
25797 +#endif
25798 +
25799 audit_syscall_exit(regs);
25800
25801 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
25802 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
25803 index 2f355d2..e75ed0a 100644
25804 --- a/arch/x86/kernel/pvclock.c
25805 +++ b/arch/x86/kernel/pvclock.c
25806 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
25807 reset_hung_task_detector();
25808 }
25809
25810 -static atomic64_t last_value = ATOMIC64_INIT(0);
25811 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
25812
25813 void pvclock_resume(void)
25814 {
25815 - atomic64_set(&last_value, 0);
25816 + atomic64_set_unchecked(&last_value, 0);
25817 }
25818
25819 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
25820 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
25821 * updating at the same time, and one of them could be slightly behind,
25822 * making the assumption that last_value always go forward fail to hold.
25823 */
25824 - last = atomic64_read(&last_value);
25825 + last = atomic64_read_unchecked(&last_value);
25826 do {
25827 if (ret < last)
25828 return last;
25829 - last = atomic64_cmpxchg(&last_value, last, ret);
25830 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
25831 } while (unlikely(last != ret));
25832
25833 return ret;
25834 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
25835 index c752cb4..866c432 100644
25836 --- a/arch/x86/kernel/reboot.c
25837 +++ b/arch/x86/kernel/reboot.c
25838 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
25839
25840 void __noreturn machine_real_restart(unsigned int type)
25841 {
25842 +
25843 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
25844 + struct desc_struct *gdt;
25845 +#endif
25846 +
25847 local_irq_disable();
25848
25849 /*
25850 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
25851
25852 /* Jump to the identity-mapped low memory code */
25853 #ifdef CONFIG_X86_32
25854 - asm volatile("jmpl *%0" : :
25855 +
25856 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
25857 + gdt = get_cpu_gdt_table(smp_processor_id());
25858 + pax_open_kernel();
25859 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25860 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
25861 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
25862 + loadsegment(ds, __KERNEL_DS);
25863 + loadsegment(es, __KERNEL_DS);
25864 + loadsegment(ss, __KERNEL_DS);
25865 +#endif
25866 +#ifdef CONFIG_PAX_KERNEXEC
25867 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
25868 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
25869 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
25870 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
25871 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
25872 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
25873 +#endif
25874 + pax_close_kernel();
25875 +#endif
25876 +
25877 + asm volatile("ljmpl *%0" : :
25878 "rm" (real_mode_header->machine_real_restart_asm),
25879 "a" (type));
25880 #else
25881 @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25882 * try to force a triple fault and then cycle between hitting the keyboard
25883 * controller and doing that
25884 */
25885 -static void native_machine_emergency_restart(void)
25886 +static void __noreturn native_machine_emergency_restart(void)
25887 {
25888 int i;
25889 int attempt = 0;
25890 @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
25891 #endif
25892 }
25893
25894 -static void __machine_emergency_restart(int emergency)
25895 +static void __noreturn __machine_emergency_restart(int emergency)
25896 {
25897 reboot_emergency = emergency;
25898 machine_ops.emergency_restart();
25899 }
25900
25901 -static void native_machine_restart(char *__unused)
25902 +static void __noreturn native_machine_restart(char *__unused)
25903 {
25904 pr_notice("machine restart\n");
25905
25906 @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
25907 __machine_emergency_restart(0);
25908 }
25909
25910 -static void native_machine_halt(void)
25911 +static void __noreturn native_machine_halt(void)
25912 {
25913 /* Stop other cpus and apics */
25914 machine_shutdown();
25915 @@ -618,7 +645,7 @@ static void native_machine_halt(void)
25916 stop_this_cpu(NULL);
25917 }
25918
25919 -static void native_machine_power_off(void)
25920 +static void __noreturn native_machine_power_off(void)
25921 {
25922 if (pm_power_off) {
25923 if (!reboot_force)
25924 @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
25925 }
25926 /* A fallback in case there is no PM info available */
25927 tboot_shutdown(TB_SHUTDOWN_HALT);
25928 + unreachable();
25929 }
25930
25931 -struct machine_ops machine_ops = {
25932 +struct machine_ops machine_ops __read_only = {
25933 .power_off = native_machine_power_off,
25934 .shutdown = native_machine_shutdown,
25935 .emergency_restart = native_machine_emergency_restart,
25936 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25937 index c8e41e9..64049ef 100644
25938 --- a/arch/x86/kernel/reboot_fixups_32.c
25939 +++ b/arch/x86/kernel/reboot_fixups_32.c
25940 @@ -57,7 +57,7 @@ struct device_fixup {
25941 unsigned int vendor;
25942 unsigned int device;
25943 void (*reboot_fixup)(struct pci_dev *);
25944 -};
25945 +} __do_const;
25946
25947 /*
25948 * PCI ids solely used for fixups_table go here
25949 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25950 index 3fd2c69..16ef367 100644
25951 --- a/arch/x86/kernel/relocate_kernel_64.S
25952 +++ b/arch/x86/kernel/relocate_kernel_64.S
25953 @@ -11,6 +11,7 @@
25954 #include <asm/kexec.h>
25955 #include <asm/processor-flags.h>
25956 #include <asm/pgtable_types.h>
25957 +#include <asm/alternative-asm.h>
25958
25959 /*
25960 * Must be relocatable PIC code callable as a C function
25961 @@ -96,8 +97,7 @@ relocate_kernel:
25962
25963 /* jump to identity mapped page */
25964 addq $(identity_mapped - relocate_kernel), %r8
25965 - pushq %r8
25966 - ret
25967 + jmp *%r8
25968
25969 identity_mapped:
25970 /* set return address to 0 if not preserving context */
25971 @@ -167,6 +167,7 @@ identity_mapped:
25972 xorl %r14d, %r14d
25973 xorl %r15d, %r15d
25974
25975 + pax_force_retaddr 0, 1
25976 ret
25977
25978 1:
25979 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25980 index cb233bc..23b4879 100644
25981 --- a/arch/x86/kernel/setup.c
25982 +++ b/arch/x86/kernel/setup.c
25983 @@ -110,6 +110,7 @@
25984 #include <asm/mce.h>
25985 #include <asm/alternative.h>
25986 #include <asm/prom.h>
25987 +#include <asm/boot.h>
25988
25989 /*
25990 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25991 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25992 #endif
25993
25994
25995 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25996 -__visible unsigned long mmu_cr4_features;
25997 +#ifdef CONFIG_X86_64
25998 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25999 +#elif defined(CONFIG_X86_PAE)
26000 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26001 #else
26002 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26003 +__visible unsigned long mmu_cr4_features __read_only;
26004 #endif
26005
26006 +void set_in_cr4(unsigned long mask)
26007 +{
26008 + unsigned long cr4 = read_cr4();
26009 +
26010 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26011 + return;
26012 +
26013 + pax_open_kernel();
26014 + mmu_cr4_features |= mask;
26015 + pax_close_kernel();
26016 +
26017 + if (trampoline_cr4_features)
26018 + *trampoline_cr4_features = mmu_cr4_features;
26019 + cr4 |= mask;
26020 + write_cr4(cr4);
26021 +}
26022 +EXPORT_SYMBOL(set_in_cr4);
26023 +
26024 +void clear_in_cr4(unsigned long mask)
26025 +{
26026 + unsigned long cr4 = read_cr4();
26027 +
26028 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26029 + return;
26030 +
26031 + pax_open_kernel();
26032 + mmu_cr4_features &= ~mask;
26033 + pax_close_kernel();
26034 +
26035 + if (trampoline_cr4_features)
26036 + *trampoline_cr4_features = mmu_cr4_features;
26037 + cr4 &= ~mask;
26038 + write_cr4(cr4);
26039 +}
26040 +EXPORT_SYMBOL(clear_in_cr4);
26041 +
26042 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26043 int bootloader_type, bootloader_version;
26044
26045 @@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26046 * area (640->1Mb) as ram even though it is not.
26047 * take them out.
26048 */
26049 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26050 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26051
26052 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26053 }
26054 @@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26055 /* called before trim_bios_range() to spare extra sanitize */
26056 static void __init e820_add_kernel_range(void)
26057 {
26058 - u64 start = __pa_symbol(_text);
26059 + u64 start = __pa_symbol(ktla_ktva(_text));
26060 u64 size = __pa_symbol(_end) - start;
26061
26062 /*
26063 @@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26064
26065 void __init setup_arch(char **cmdline_p)
26066 {
26067 +#ifdef CONFIG_X86_32
26068 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26069 +#else
26070 memblock_reserve(__pa_symbol(_text),
26071 (unsigned long)__bss_stop - (unsigned long)_text);
26072 +#endif
26073
26074 early_reserve_initrd();
26075
26076 @@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26077
26078 if (!boot_params.hdr.root_flags)
26079 root_mountflags &= ~MS_RDONLY;
26080 - init_mm.start_code = (unsigned long) _text;
26081 - init_mm.end_code = (unsigned long) _etext;
26082 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26083 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26084 init_mm.end_data = (unsigned long) _edata;
26085 init_mm.brk = _brk_end;
26086
26087 - code_resource.start = __pa_symbol(_text);
26088 - code_resource.end = __pa_symbol(_etext)-1;
26089 - data_resource.start = __pa_symbol(_etext);
26090 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26091 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26092 + data_resource.start = __pa_symbol(_sdata);
26093 data_resource.end = __pa_symbol(_edata)-1;
26094 bss_resource.start = __pa_symbol(__bss_start);
26095 bss_resource.end = __pa_symbol(__bss_stop)-1;
26096 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26097 index 5cdff03..80fa283 100644
26098 --- a/arch/x86/kernel/setup_percpu.c
26099 +++ b/arch/x86/kernel/setup_percpu.c
26100 @@ -21,19 +21,17 @@
26101 #include <asm/cpu.h>
26102 #include <asm/stackprotector.h>
26103
26104 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26105 +#ifdef CONFIG_SMP
26106 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26107 EXPORT_PER_CPU_SYMBOL(cpu_number);
26108 +#endif
26109
26110 -#ifdef CONFIG_X86_64
26111 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26112 -#else
26113 -#define BOOT_PERCPU_OFFSET 0
26114 -#endif
26115
26116 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26117 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26118
26119 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26120 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26121 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26122 };
26123 EXPORT_SYMBOL(__per_cpu_offset);
26124 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26125 {
26126 #ifdef CONFIG_NEED_MULTIPLE_NODES
26127 pg_data_t *last = NULL;
26128 - unsigned int cpu;
26129 + int cpu;
26130
26131 for_each_possible_cpu(cpu) {
26132 int node = early_cpu_to_node(cpu);
26133 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26134 {
26135 #ifdef CONFIG_X86_32
26136 struct desc_struct gdt;
26137 + unsigned long base = per_cpu_offset(cpu);
26138
26139 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26140 - 0x2 | DESCTYPE_S, 0x8);
26141 - gdt.s = 1;
26142 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26143 + 0x83 | DESCTYPE_S, 0xC);
26144 write_gdt_entry(get_cpu_gdt_table(cpu),
26145 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26146 #endif
26147 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26148 /* alrighty, percpu areas up and running */
26149 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26150 for_each_possible_cpu(cpu) {
26151 +#ifdef CONFIG_CC_STACKPROTECTOR
26152 +#ifdef CONFIG_X86_32
26153 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26154 +#endif
26155 +#endif
26156 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26157 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26158 per_cpu(cpu_number, cpu) = cpu;
26159 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26160 */
26161 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26162 #endif
26163 +#ifdef CONFIG_CC_STACKPROTECTOR
26164 +#ifdef CONFIG_X86_32
26165 + if (!cpu)
26166 + per_cpu(stack_canary.canary, cpu) = canary;
26167 +#endif
26168 +#endif
26169 /*
26170 * Up to this point, the boot CPU has been using .init.data
26171 * area. Reload any changed state for the boot CPU.
26172 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26173 index 9e5de68..16c53cb 100644
26174 --- a/arch/x86/kernel/signal.c
26175 +++ b/arch/x86/kernel/signal.c
26176 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26177 * Align the stack pointer according to the i386 ABI,
26178 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26179 */
26180 - sp = ((sp + 4) & -16ul) - 4;
26181 + sp = ((sp - 12) & -16ul) - 4;
26182 #else /* !CONFIG_X86_32 */
26183 sp = round_down(sp, 16) - 8;
26184 #endif
26185 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26186 }
26187
26188 if (current->mm->context.vdso)
26189 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26190 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26191 else
26192 - restorer = &frame->retcode;
26193 + restorer = (void __user *)&frame->retcode;
26194 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26195 restorer = ksig->ka.sa.sa_restorer;
26196
26197 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26198 * reasons and because gdb uses it as a signature to notice
26199 * signal handler stack frames.
26200 */
26201 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26202 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26203
26204 if (err)
26205 return -EFAULT;
26206 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26207 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26208
26209 /* Set up to return from userspace. */
26210 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26211 + if (current->mm->context.vdso)
26212 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26213 + else
26214 + restorer = (void __user *)&frame->retcode;
26215 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26216 restorer = ksig->ka.sa.sa_restorer;
26217 put_user_ex(restorer, &frame->pretcode);
26218 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26219 * reasons and because gdb uses it as a signature to notice
26220 * signal handler stack frames.
26221 */
26222 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26223 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26224 } put_user_catch(err);
26225
26226 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26227 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26228 {
26229 int usig = signr_convert(ksig->sig);
26230 sigset_t *set = sigmask_to_save();
26231 - compat_sigset_t *cset = (compat_sigset_t *) set;
26232 + sigset_t sigcopy;
26233 + compat_sigset_t *cset;
26234 +
26235 + sigcopy = *set;
26236 +
26237 + cset = (compat_sigset_t *) &sigcopy;
26238
26239 /* Set up the stack frame */
26240 if (is_ia32_frame()) {
26241 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26242 } else if (is_x32_frame()) {
26243 return x32_setup_rt_frame(ksig, cset, regs);
26244 } else {
26245 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26246 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26247 }
26248 }
26249
26250 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26251 index 7c3a5a6..f0a8961 100644
26252 --- a/arch/x86/kernel/smp.c
26253 +++ b/arch/x86/kernel/smp.c
26254 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26255
26256 __setup("nonmi_ipi", nonmi_ipi_setup);
26257
26258 -struct smp_ops smp_ops = {
26259 +struct smp_ops smp_ops __read_only = {
26260 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26261 .smp_prepare_cpus = native_smp_prepare_cpus,
26262 .smp_cpus_done = native_smp_cpus_done,
26263 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26264 index 85dc05a..1241266 100644
26265 --- a/arch/x86/kernel/smpboot.c
26266 +++ b/arch/x86/kernel/smpboot.c
26267 @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26268
26269 enable_start_cpu0 = 0;
26270
26271 -#ifdef CONFIG_X86_32
26272 - /* switch away from the initial page table */
26273 - load_cr3(swapper_pg_dir);
26274 - __flush_tlb_all();
26275 -#endif
26276 -
26277 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26278 barrier();
26279 +
26280 + /* switch away from the initial page table */
26281 +#ifdef CONFIG_PAX_PER_CPU_PGD
26282 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26283 + __flush_tlb_all();
26284 +#elif defined(CONFIG_X86_32)
26285 + load_cr3(swapper_pg_dir);
26286 + __flush_tlb_all();
26287 +#endif
26288 +
26289 /*
26290 * Check TSC synchronization with the BP:
26291 */
26292 @@ -751,6 +755,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26293 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26294 (THREAD_SIZE + task_stack_page(idle))) - 1);
26295 per_cpu(current_task, cpu) = idle;
26296 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26297
26298 #ifdef CONFIG_X86_32
26299 /* Stack for startup_32 can be just as for start_secondary onwards */
26300 @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26301 #else
26302 clear_tsk_thread_flag(idle, TIF_FORK);
26303 initial_gs = per_cpu_offset(cpu);
26304 - per_cpu(kernel_stack, cpu) =
26305 - (unsigned long)task_stack_page(idle) -
26306 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26307 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26308 #endif
26309 +
26310 + pax_open_kernel();
26311 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26312 + pax_close_kernel();
26313 +
26314 initial_code = (unsigned long)start_secondary;
26315 stack_start = idle->thread.sp;
26316
26317 @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26318 /* the FPU context is blank, nobody can own it */
26319 __cpu_disable_lazy_restore(cpu);
26320
26321 +#ifdef CONFIG_PAX_PER_CPU_PGD
26322 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26323 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26324 + KERNEL_PGD_PTRS);
26325 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26326 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26327 + KERNEL_PGD_PTRS);
26328 +#endif
26329 +
26330 err = do_boot_cpu(apicid, cpu, tidle);
26331 if (err) {
26332 pr_debug("do_boot_cpu failed %d\n", err);
26333 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26334 index 9b4d51d..5d28b58 100644
26335 --- a/arch/x86/kernel/step.c
26336 +++ b/arch/x86/kernel/step.c
26337 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26338 struct desc_struct *desc;
26339 unsigned long base;
26340
26341 - seg &= ~7UL;
26342 + seg >>= 3;
26343
26344 mutex_lock(&child->mm->context.lock);
26345 - if (unlikely((seg >> 3) >= child->mm->context.size))
26346 + if (unlikely(seg >= child->mm->context.size))
26347 addr = -1L; /* bogus selector, access would fault */
26348 else {
26349 desc = child->mm->context.ldt + seg;
26350 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26351 addr += base;
26352 }
26353 mutex_unlock(&child->mm->context.lock);
26354 - }
26355 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26356 + addr = ktla_ktva(addr);
26357
26358 return addr;
26359 }
26360 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26361 unsigned char opcode[15];
26362 unsigned long addr = convert_ip_to_linear(child, regs);
26363
26364 + if (addr == -EINVAL)
26365 + return 0;
26366 +
26367 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26368 for (i = 0; i < copied; i++) {
26369 switch (opcode[i]) {
26370 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26371 new file mode 100644
26372 index 0000000..5877189
26373 --- /dev/null
26374 +++ b/arch/x86/kernel/sys_i386_32.c
26375 @@ -0,0 +1,189 @@
26376 +/*
26377 + * This file contains various random system calls that
26378 + * have a non-standard calling sequence on the Linux/i386
26379 + * platform.
26380 + */
26381 +
26382 +#include <linux/errno.h>
26383 +#include <linux/sched.h>
26384 +#include <linux/mm.h>
26385 +#include <linux/fs.h>
26386 +#include <linux/smp.h>
26387 +#include <linux/sem.h>
26388 +#include <linux/msg.h>
26389 +#include <linux/shm.h>
26390 +#include <linux/stat.h>
26391 +#include <linux/syscalls.h>
26392 +#include <linux/mman.h>
26393 +#include <linux/file.h>
26394 +#include <linux/utsname.h>
26395 +#include <linux/ipc.h>
26396 +#include <linux/elf.h>
26397 +
26398 +#include <linux/uaccess.h>
26399 +#include <linux/unistd.h>
26400 +
26401 +#include <asm/syscalls.h>
26402 +
26403 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26404 +{
26405 + unsigned long pax_task_size = TASK_SIZE;
26406 +
26407 +#ifdef CONFIG_PAX_SEGMEXEC
26408 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26409 + pax_task_size = SEGMEXEC_TASK_SIZE;
26410 +#endif
26411 +
26412 + if (flags & MAP_FIXED)
26413 + if (len > pax_task_size || addr > pax_task_size - len)
26414 + return -EINVAL;
26415 +
26416 + return 0;
26417 +}
26418 +
26419 +/*
26420 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26421 + */
26422 +static unsigned long get_align_mask(void)
26423 +{
26424 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26425 + return 0;
26426 +
26427 + if (!(current->flags & PF_RANDOMIZE))
26428 + return 0;
26429 +
26430 + return va_align.mask;
26431 +}
26432 +
26433 +unsigned long
26434 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
26435 + unsigned long len, unsigned long pgoff, unsigned long flags)
26436 +{
26437 + struct mm_struct *mm = current->mm;
26438 + struct vm_area_struct *vma;
26439 + unsigned long pax_task_size = TASK_SIZE;
26440 + struct vm_unmapped_area_info info;
26441 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26442 +
26443 +#ifdef CONFIG_PAX_SEGMEXEC
26444 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26445 + pax_task_size = SEGMEXEC_TASK_SIZE;
26446 +#endif
26447 +
26448 + pax_task_size -= PAGE_SIZE;
26449 +
26450 + if (len > pax_task_size)
26451 + return -ENOMEM;
26452 +
26453 + if (flags & MAP_FIXED)
26454 + return addr;
26455 +
26456 +#ifdef CONFIG_PAX_RANDMMAP
26457 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26458 +#endif
26459 +
26460 + if (addr) {
26461 + addr = PAGE_ALIGN(addr);
26462 + if (pax_task_size - len >= addr) {
26463 + vma = find_vma(mm, addr);
26464 + if (check_heap_stack_gap(vma, addr, len, offset))
26465 + return addr;
26466 + }
26467 + }
26468 +
26469 + info.flags = 0;
26470 + info.length = len;
26471 + info.align_mask = filp ? get_align_mask() : 0;
26472 + info.align_offset = pgoff << PAGE_SHIFT;
26473 + info.threadstack_offset = offset;
26474 +
26475 +#ifdef CONFIG_PAX_PAGEEXEC
26476 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
26477 + info.low_limit = 0x00110000UL;
26478 + info.high_limit = mm->start_code;
26479 +
26480 +#ifdef CONFIG_PAX_RANDMMAP
26481 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26482 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
26483 +#endif
26484 +
26485 + if (info.low_limit < info.high_limit) {
26486 + addr = vm_unmapped_area(&info);
26487 + if (!IS_ERR_VALUE(addr))
26488 + return addr;
26489 + }
26490 + } else
26491 +#endif
26492 +
26493 + info.low_limit = mm->mmap_base;
26494 + info.high_limit = pax_task_size;
26495 +
26496 + return vm_unmapped_area(&info);
26497 +}
26498 +
26499 +unsigned long
26500 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26501 + const unsigned long len, const unsigned long pgoff,
26502 + const unsigned long flags)
26503 +{
26504 + struct vm_area_struct *vma;
26505 + struct mm_struct *mm = current->mm;
26506 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
26507 + struct vm_unmapped_area_info info;
26508 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26509 +
26510 +#ifdef CONFIG_PAX_SEGMEXEC
26511 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26512 + pax_task_size = SEGMEXEC_TASK_SIZE;
26513 +#endif
26514 +
26515 + pax_task_size -= PAGE_SIZE;
26516 +
26517 + /* requested length too big for entire address space */
26518 + if (len > pax_task_size)
26519 + return -ENOMEM;
26520 +
26521 + if (flags & MAP_FIXED)
26522 + return addr;
26523 +
26524 +#ifdef CONFIG_PAX_PAGEEXEC
26525 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
26526 + goto bottomup;
26527 +#endif
26528 +
26529 +#ifdef CONFIG_PAX_RANDMMAP
26530 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26531 +#endif
26532 +
26533 + /* requesting a specific address */
26534 + if (addr) {
26535 + addr = PAGE_ALIGN(addr);
26536 + if (pax_task_size - len >= addr) {
26537 + vma = find_vma(mm, addr);
26538 + if (check_heap_stack_gap(vma, addr, len, offset))
26539 + return addr;
26540 + }
26541 + }
26542 +
26543 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
26544 + info.length = len;
26545 + info.low_limit = PAGE_SIZE;
26546 + info.high_limit = mm->mmap_base;
26547 + info.align_mask = filp ? get_align_mask() : 0;
26548 + info.align_offset = pgoff << PAGE_SHIFT;
26549 + info.threadstack_offset = offset;
26550 +
26551 + addr = vm_unmapped_area(&info);
26552 + if (!(addr & ~PAGE_MASK))
26553 + return addr;
26554 + VM_BUG_ON(addr != -ENOMEM);
26555 +
26556 +bottomup:
26557 + /*
26558 + * A failed mmap() very likely causes application failure,
26559 + * so fall back to the bottom-up function here. This scenario
26560 + * can happen with large stack limits and large mmap()
26561 + * allocations.
26562 + */
26563 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
26564 +}
26565 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
26566 index 30277e2..5664a29 100644
26567 --- a/arch/x86/kernel/sys_x86_64.c
26568 +++ b/arch/x86/kernel/sys_x86_64.c
26569 @@ -81,8 +81,8 @@ out:
26570 return error;
26571 }
26572
26573 -static void find_start_end(unsigned long flags, unsigned long *begin,
26574 - unsigned long *end)
26575 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
26576 + unsigned long *begin, unsigned long *end)
26577 {
26578 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
26579 unsigned long new_begin;
26580 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
26581 *begin = new_begin;
26582 }
26583 } else {
26584 - *begin = current->mm->mmap_legacy_base;
26585 + *begin = mm->mmap_legacy_base;
26586 *end = TASK_SIZE;
26587 }
26588 }
26589 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26590 struct vm_area_struct *vma;
26591 struct vm_unmapped_area_info info;
26592 unsigned long begin, end;
26593 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26594
26595 if (flags & MAP_FIXED)
26596 return addr;
26597
26598 - find_start_end(flags, &begin, &end);
26599 + find_start_end(mm, flags, &begin, &end);
26600
26601 if (len > end)
26602 return -ENOMEM;
26603
26604 +#ifdef CONFIG_PAX_RANDMMAP
26605 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26606 +#endif
26607 +
26608 if (addr) {
26609 addr = PAGE_ALIGN(addr);
26610 vma = find_vma(mm, addr);
26611 - if (end - len >= addr &&
26612 - (!vma || addr + len <= vma->vm_start))
26613 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26614 return addr;
26615 }
26616
26617 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26618 info.high_limit = end;
26619 info.align_mask = filp ? get_align_mask() : 0;
26620 info.align_offset = pgoff << PAGE_SHIFT;
26621 + info.threadstack_offset = offset;
26622 return vm_unmapped_area(&info);
26623 }
26624
26625 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26626 struct mm_struct *mm = current->mm;
26627 unsigned long addr = addr0;
26628 struct vm_unmapped_area_info info;
26629 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26630
26631 /* requested length too big for entire address space */
26632 if (len > TASK_SIZE)
26633 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26634 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
26635 goto bottomup;
26636
26637 +#ifdef CONFIG_PAX_RANDMMAP
26638 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26639 +#endif
26640 +
26641 /* requesting a specific address */
26642 if (addr) {
26643 addr = PAGE_ALIGN(addr);
26644 vma = find_vma(mm, addr);
26645 - if (TASK_SIZE - len >= addr &&
26646 - (!vma || addr + len <= vma->vm_start))
26647 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26648 return addr;
26649 }
26650
26651 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26652 info.high_limit = mm->mmap_base;
26653 info.align_mask = filp ? get_align_mask() : 0;
26654 info.align_offset = pgoff << PAGE_SHIFT;
26655 + info.threadstack_offset = offset;
26656 addr = vm_unmapped_area(&info);
26657 if (!(addr & ~PAGE_MASK))
26658 return addr;
26659 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
26660 index 91a4496..bb87552 100644
26661 --- a/arch/x86/kernel/tboot.c
26662 +++ b/arch/x86/kernel/tboot.c
26663 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
26664
26665 void tboot_shutdown(u32 shutdown_type)
26666 {
26667 - void (*shutdown)(void);
26668 + void (* __noreturn shutdown)(void);
26669
26670 if (!tboot_enabled())
26671 return;
26672 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
26673
26674 switch_to_tboot_pt();
26675
26676 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
26677 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
26678 shutdown();
26679
26680 /* should not reach here */
26681 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
26682 return -ENODEV;
26683 }
26684
26685 -static atomic_t ap_wfs_count;
26686 +static atomic_unchecked_t ap_wfs_count;
26687
26688 static int tboot_wait_for_aps(int num_aps)
26689 {
26690 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
26691 {
26692 switch (action) {
26693 case CPU_DYING:
26694 - atomic_inc(&ap_wfs_count);
26695 + atomic_inc_unchecked(&ap_wfs_count);
26696 if (num_online_cpus() == 1)
26697 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
26698 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
26699 return NOTIFY_BAD;
26700 break;
26701 }
26702 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
26703
26704 tboot_create_trampoline();
26705
26706 - atomic_set(&ap_wfs_count, 0);
26707 + atomic_set_unchecked(&ap_wfs_count, 0);
26708 register_hotcpu_notifier(&tboot_cpu_notifier);
26709
26710 #ifdef CONFIG_DEBUG_FS
26711 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
26712 index 24d3c91..d06b473 100644
26713 --- a/arch/x86/kernel/time.c
26714 +++ b/arch/x86/kernel/time.c
26715 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
26716 {
26717 unsigned long pc = instruction_pointer(regs);
26718
26719 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
26720 + if (!user_mode(regs) && in_lock_functions(pc)) {
26721 #ifdef CONFIG_FRAME_POINTER
26722 - return *(unsigned long *)(regs->bp + sizeof(long));
26723 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
26724 #else
26725 unsigned long *sp =
26726 (unsigned long *)kernel_stack_pointer(regs);
26727 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
26728 * or above a saved flags. Eflags has bits 22-31 zero,
26729 * kernel addresses don't.
26730 */
26731 +
26732 +#ifdef CONFIG_PAX_KERNEXEC
26733 + return ktla_ktva(sp[0]);
26734 +#else
26735 if (sp[0] >> 22)
26736 return sp[0];
26737 if (sp[1] >> 22)
26738 return sp[1];
26739 #endif
26740 +
26741 +#endif
26742 }
26743 return pc;
26744 }
26745 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
26746 index f7fec09..9991981 100644
26747 --- a/arch/x86/kernel/tls.c
26748 +++ b/arch/x86/kernel/tls.c
26749 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
26750 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
26751 return -EINVAL;
26752
26753 +#ifdef CONFIG_PAX_SEGMEXEC
26754 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
26755 + return -EINVAL;
26756 +#endif
26757 +
26758 set_tls_desc(p, idx, &info, 1);
26759
26760 return 0;
26761 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
26762
26763 if (kbuf)
26764 info = kbuf;
26765 - else if (__copy_from_user(infobuf, ubuf, count))
26766 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
26767 return -EFAULT;
26768 else
26769 info = infobuf;
26770 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
26771 index 1c113db..287b42e 100644
26772 --- a/arch/x86/kernel/tracepoint.c
26773 +++ b/arch/x86/kernel/tracepoint.c
26774 @@ -9,11 +9,11 @@
26775 #include <linux/atomic.h>
26776
26777 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
26778 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26779 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26780 (unsigned long) trace_idt_table };
26781
26782 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26783 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
26784 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
26785
26786 static int trace_irq_vector_refcount;
26787 static DEFINE_MUTEX(irq_vector_mutex);
26788 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
26789 index b857ed8..51ae4cb 100644
26790 --- a/arch/x86/kernel/traps.c
26791 +++ b/arch/x86/kernel/traps.c
26792 @@ -66,7 +66,7 @@
26793 #include <asm/proto.h>
26794
26795 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26796 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
26797 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
26798 #else
26799 #include <asm/processor-flags.h>
26800 #include <asm/setup.h>
26801 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
26802 #endif
26803
26804 /* Must be page-aligned because the real IDT is used in a fixmap. */
26805 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
26806 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
26807
26808 DECLARE_BITMAP(used_vectors, NR_VECTORS);
26809 EXPORT_SYMBOL_GPL(used_vectors);
26810 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
26811 }
26812
26813 static int __kprobes
26814 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26815 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
26816 struct pt_regs *regs, long error_code)
26817 {
26818 #ifdef CONFIG_X86_32
26819 - if (regs->flags & X86_VM_MASK) {
26820 + if (v8086_mode(regs)) {
26821 /*
26822 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
26823 * On nmi (interrupt 2), do_trap should not be called.
26824 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26825 return -1;
26826 }
26827 #endif
26828 - if (!user_mode(regs)) {
26829 + if (!user_mode_novm(regs)) {
26830 if (!fixup_exception(regs)) {
26831 tsk->thread.error_code = error_code;
26832 tsk->thread.trap_nr = trapnr;
26833 +
26834 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26835 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
26836 + str = "PAX: suspicious stack segment fault";
26837 +#endif
26838 +
26839 die(str, regs, error_code);
26840 }
26841 +
26842 +#ifdef CONFIG_PAX_REFCOUNT
26843 + if (trapnr == 4)
26844 + pax_report_refcount_overflow(regs);
26845 +#endif
26846 +
26847 return 0;
26848 }
26849
26850 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26851 }
26852
26853 static void __kprobes
26854 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26855 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
26856 long error_code, siginfo_t *info)
26857 {
26858 struct task_struct *tsk = current;
26859 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26860 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
26861 printk_ratelimit()) {
26862 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
26863 - tsk->comm, tsk->pid, str,
26864 + tsk->comm, task_pid_nr(tsk), str,
26865 regs->ip, regs->sp, error_code);
26866 print_vma_addr(" in ", regs->ip);
26867 pr_cont("\n");
26868 @@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26869 conditional_sti(regs);
26870
26871 #ifdef CONFIG_X86_32
26872 - if (regs->flags & X86_VM_MASK) {
26873 + if (v8086_mode(regs)) {
26874 local_irq_enable();
26875 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26876 goto exit;
26877 @@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26878 #endif
26879
26880 tsk = current;
26881 - if (!user_mode(regs)) {
26882 + if (!user_mode_novm(regs)) {
26883 if (fixup_exception(regs))
26884 goto exit;
26885
26886 tsk->thread.error_code = error_code;
26887 tsk->thread.trap_nr = X86_TRAP_GP;
26888 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26889 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26890 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26891 +
26892 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26893 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26894 + die("PAX: suspicious general protection fault", regs, error_code);
26895 + else
26896 +#endif
26897 +
26898 die("general protection fault", regs, error_code);
26899 + }
26900 goto exit;
26901 }
26902
26903 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26904 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26905 + struct mm_struct *mm = tsk->mm;
26906 + unsigned long limit;
26907 +
26908 + down_write(&mm->mmap_sem);
26909 + limit = mm->context.user_cs_limit;
26910 + if (limit < TASK_SIZE) {
26911 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26912 + up_write(&mm->mmap_sem);
26913 + return;
26914 + }
26915 + up_write(&mm->mmap_sem);
26916 + }
26917 +#endif
26918 +
26919 tsk->thread.error_code = error_code;
26920 tsk->thread.trap_nr = X86_TRAP_GP;
26921
26922 @@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26923 /* It's safe to allow irq's after DR6 has been saved */
26924 preempt_conditional_sti(regs);
26925
26926 - if (regs->flags & X86_VM_MASK) {
26927 + if (v8086_mode(regs)) {
26928 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26929 X86_TRAP_DB);
26930 preempt_conditional_cli(regs);
26931 @@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26932 * We already checked v86 mode above, so we can check for kernel mode
26933 * by just checking the CPL of CS.
26934 */
26935 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
26936 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26937 tsk->thread.debugreg6 &= ~DR_STEP;
26938 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26939 regs->flags &= ~X86_EFLAGS_TF;
26940 @@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26941 return;
26942 conditional_sti(regs);
26943
26944 - if (!user_mode_vm(regs))
26945 + if (!user_mode(regs))
26946 {
26947 if (!fixup_exception(regs)) {
26948 task->thread.error_code = error_code;
26949 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26950 index 2ed8459..7cf329f 100644
26951 --- a/arch/x86/kernel/uprobes.c
26952 +++ b/arch/x86/kernel/uprobes.c
26953 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26954 int ret = NOTIFY_DONE;
26955
26956 /* We are only interested in userspace traps */
26957 - if (regs && !user_mode_vm(regs))
26958 + if (regs && !user_mode(regs))
26959 return NOTIFY_DONE;
26960
26961 switch (val) {
26962 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26963
26964 if (ncopied != rasize) {
26965 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26966 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26967 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26968
26969 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26970 }
26971 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26972 index b9242ba..50c5edd 100644
26973 --- a/arch/x86/kernel/verify_cpu.S
26974 +++ b/arch/x86/kernel/verify_cpu.S
26975 @@ -20,6 +20,7 @@
26976 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26977 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26978 * arch/x86/kernel/head_32.S: processor startup
26979 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26980 *
26981 * verify_cpu, returns the status of longmode and SSE in register %eax.
26982 * 0: Success 1: Failure
26983 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26984 index e8edcf5..27f9344 100644
26985 --- a/arch/x86/kernel/vm86_32.c
26986 +++ b/arch/x86/kernel/vm86_32.c
26987 @@ -44,6 +44,7 @@
26988 #include <linux/ptrace.h>
26989 #include <linux/audit.h>
26990 #include <linux/stddef.h>
26991 +#include <linux/grsecurity.h>
26992
26993 #include <asm/uaccess.h>
26994 #include <asm/io.h>
26995 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26996 do_exit(SIGSEGV);
26997 }
26998
26999 - tss = &per_cpu(init_tss, get_cpu());
27000 + tss = init_tss + get_cpu();
27001 current->thread.sp0 = current->thread.saved_sp0;
27002 current->thread.sysenter_cs = __KERNEL_CS;
27003 load_sp0(tss, &current->thread);
27004 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27005
27006 if (tsk->thread.saved_sp0)
27007 return -EPERM;
27008 +
27009 +#ifdef CONFIG_GRKERNSEC_VM86
27010 + if (!capable(CAP_SYS_RAWIO)) {
27011 + gr_handle_vm86();
27012 + return -EPERM;
27013 + }
27014 +#endif
27015 +
27016 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27017 offsetof(struct kernel_vm86_struct, vm86plus) -
27018 sizeof(info.regs));
27019 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27020 int tmp;
27021 struct vm86plus_struct __user *v86;
27022
27023 +#ifdef CONFIG_GRKERNSEC_VM86
27024 + if (!capable(CAP_SYS_RAWIO)) {
27025 + gr_handle_vm86();
27026 + return -EPERM;
27027 + }
27028 +#endif
27029 +
27030 tsk = current;
27031 switch (cmd) {
27032 case VM86_REQUEST_IRQ:
27033 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27034 tsk->thread.saved_fs = info->regs32->fs;
27035 tsk->thread.saved_gs = get_user_gs(info->regs32);
27036
27037 - tss = &per_cpu(init_tss, get_cpu());
27038 + tss = init_tss + get_cpu();
27039 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27040 if (cpu_has_sep)
27041 tsk->thread.sysenter_cs = 0;
27042 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27043 goto cannot_handle;
27044 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27045 goto cannot_handle;
27046 - intr_ptr = (unsigned long __user *) (i << 2);
27047 + intr_ptr = (__force unsigned long __user *) (i << 2);
27048 if (get_user(segoffs, intr_ptr))
27049 goto cannot_handle;
27050 if ((segoffs >> 16) == BIOSSEG)
27051 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27052 index da6b35a..977e9cf 100644
27053 --- a/arch/x86/kernel/vmlinux.lds.S
27054 +++ b/arch/x86/kernel/vmlinux.lds.S
27055 @@ -26,6 +26,13 @@
27056 #include <asm/page_types.h>
27057 #include <asm/cache.h>
27058 #include <asm/boot.h>
27059 +#include <asm/segment.h>
27060 +
27061 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27062 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27063 +#else
27064 +#define __KERNEL_TEXT_OFFSET 0
27065 +#endif
27066
27067 #undef i386 /* in case the preprocessor is a 32bit one */
27068
27069 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27070
27071 PHDRS {
27072 text PT_LOAD FLAGS(5); /* R_E */
27073 +#ifdef CONFIG_X86_32
27074 + module PT_LOAD FLAGS(5); /* R_E */
27075 +#endif
27076 +#ifdef CONFIG_XEN
27077 + rodata PT_LOAD FLAGS(5); /* R_E */
27078 +#else
27079 + rodata PT_LOAD FLAGS(4); /* R__ */
27080 +#endif
27081 data PT_LOAD FLAGS(6); /* RW_ */
27082 -#ifdef CONFIG_X86_64
27083 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27084 #ifdef CONFIG_SMP
27085 percpu PT_LOAD FLAGS(6); /* RW_ */
27086 #endif
27087 + text.init PT_LOAD FLAGS(5); /* R_E */
27088 + text.exit PT_LOAD FLAGS(5); /* R_E */
27089 init PT_LOAD FLAGS(7); /* RWE */
27090 -#endif
27091 note PT_NOTE FLAGS(0); /* ___ */
27092 }
27093
27094 SECTIONS
27095 {
27096 #ifdef CONFIG_X86_32
27097 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27098 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27099 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27100 #else
27101 - . = __START_KERNEL;
27102 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27103 + . = __START_KERNEL;
27104 #endif
27105
27106 /* Text and read-only data */
27107 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27108 - _text = .;
27109 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27110 /* bootstrapping code */
27111 +#ifdef CONFIG_X86_32
27112 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27113 +#else
27114 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27115 +#endif
27116 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27117 + _text = .;
27118 HEAD_TEXT
27119 . = ALIGN(8);
27120 _stext = .;
27121 @@ -104,13 +124,47 @@ SECTIONS
27122 IRQENTRY_TEXT
27123 *(.fixup)
27124 *(.gnu.warning)
27125 - /* End of text section */
27126 - _etext = .;
27127 } :text = 0x9090
27128
27129 - NOTES :text :note
27130 + . += __KERNEL_TEXT_OFFSET;
27131
27132 - EXCEPTION_TABLE(16) :text = 0x9090
27133 +#ifdef CONFIG_X86_32
27134 + . = ALIGN(PAGE_SIZE);
27135 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27136 +
27137 +#ifdef CONFIG_PAX_KERNEXEC
27138 + MODULES_EXEC_VADDR = .;
27139 + BYTE(0)
27140 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27141 + . = ALIGN(HPAGE_SIZE) - 1;
27142 + MODULES_EXEC_END = .;
27143 +#endif
27144 +
27145 + } :module
27146 +#endif
27147 +
27148 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27149 + /* End of text section */
27150 + BYTE(0)
27151 + _etext = . - __KERNEL_TEXT_OFFSET;
27152 + }
27153 +
27154 +#ifdef CONFIG_X86_32
27155 + . = ALIGN(PAGE_SIZE);
27156 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27157 + . = ALIGN(PAGE_SIZE);
27158 + *(.empty_zero_page)
27159 + *(.initial_pg_fixmap)
27160 + *(.initial_pg_pmd)
27161 + *(.initial_page_table)
27162 + *(.swapper_pg_dir)
27163 + } :rodata
27164 +#endif
27165 +
27166 + . = ALIGN(PAGE_SIZE);
27167 + NOTES :rodata :note
27168 +
27169 + EXCEPTION_TABLE(16) :rodata
27170
27171 #if defined(CONFIG_DEBUG_RODATA)
27172 /* .text should occupy whole number of pages */
27173 @@ -122,16 +176,20 @@ SECTIONS
27174
27175 /* Data */
27176 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27177 +
27178 +#ifdef CONFIG_PAX_KERNEXEC
27179 + . = ALIGN(HPAGE_SIZE);
27180 +#else
27181 + . = ALIGN(PAGE_SIZE);
27182 +#endif
27183 +
27184 /* Start of data section */
27185 _sdata = .;
27186
27187 /* init_task */
27188 INIT_TASK_DATA(THREAD_SIZE)
27189
27190 -#ifdef CONFIG_X86_32
27191 - /* 32 bit has nosave before _edata */
27192 NOSAVE_DATA
27193 -#endif
27194
27195 PAGE_ALIGNED_DATA(PAGE_SIZE)
27196
27197 @@ -172,12 +230,19 @@ SECTIONS
27198 #endif /* CONFIG_X86_64 */
27199
27200 /* Init code and data - will be freed after init */
27201 - . = ALIGN(PAGE_SIZE);
27202 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27203 + BYTE(0)
27204 +
27205 +#ifdef CONFIG_PAX_KERNEXEC
27206 + . = ALIGN(HPAGE_SIZE);
27207 +#else
27208 + . = ALIGN(PAGE_SIZE);
27209 +#endif
27210 +
27211 __init_begin = .; /* paired with __init_end */
27212 - }
27213 + } :init.begin
27214
27215 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27216 +#ifdef CONFIG_SMP
27217 /*
27218 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27219 * output PHDR, so the next output section - .init.text - should
27220 @@ -186,12 +251,27 @@ SECTIONS
27221 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27222 #endif
27223
27224 - INIT_TEXT_SECTION(PAGE_SIZE)
27225 -#ifdef CONFIG_X86_64
27226 - :init
27227 -#endif
27228 + . = ALIGN(PAGE_SIZE);
27229 + init_begin = .;
27230 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27231 + VMLINUX_SYMBOL(_sinittext) = .;
27232 + INIT_TEXT
27233 + VMLINUX_SYMBOL(_einittext) = .;
27234 + . = ALIGN(PAGE_SIZE);
27235 + } :text.init
27236
27237 - INIT_DATA_SECTION(16)
27238 + /*
27239 + * .exit.text is discard at runtime, not link time, to deal with
27240 + * references from .altinstructions and .eh_frame
27241 + */
27242 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27243 + EXIT_TEXT
27244 + . = ALIGN(16);
27245 + } :text.exit
27246 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27247 +
27248 + . = ALIGN(PAGE_SIZE);
27249 + INIT_DATA_SECTION(16) :init
27250
27251 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27252 __x86_cpu_dev_start = .;
27253 @@ -262,19 +342,12 @@ SECTIONS
27254 }
27255
27256 . = ALIGN(8);
27257 - /*
27258 - * .exit.text is discard at runtime, not link time, to deal with
27259 - * references from .altinstructions and .eh_frame
27260 - */
27261 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27262 - EXIT_TEXT
27263 - }
27264
27265 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27266 EXIT_DATA
27267 }
27268
27269 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27270 +#ifndef CONFIG_SMP
27271 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27272 #endif
27273
27274 @@ -293,16 +366,10 @@ SECTIONS
27275 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27276 __smp_locks = .;
27277 *(.smp_locks)
27278 - . = ALIGN(PAGE_SIZE);
27279 __smp_locks_end = .;
27280 + . = ALIGN(PAGE_SIZE);
27281 }
27282
27283 -#ifdef CONFIG_X86_64
27284 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27285 - NOSAVE_DATA
27286 - }
27287 -#endif
27288 -
27289 /* BSS */
27290 . = ALIGN(PAGE_SIZE);
27291 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27292 @@ -318,6 +385,7 @@ SECTIONS
27293 __brk_base = .;
27294 . += 64 * 1024; /* 64k alignment slop space */
27295 *(.brk_reservation) /* areas brk users have reserved */
27296 + . = ALIGN(HPAGE_SIZE);
27297 __brk_limit = .;
27298 }
27299
27300 @@ -344,13 +412,12 @@ SECTIONS
27301 * for the boot processor.
27302 */
27303 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27304 -INIT_PER_CPU(gdt_page);
27305 INIT_PER_CPU(irq_stack_union);
27306
27307 /*
27308 * Build-time check on the image size:
27309 */
27310 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27311 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27312 "kernel image bigger than KERNEL_IMAGE_SIZE");
27313
27314 #ifdef CONFIG_SMP
27315 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27316 index 1f96f93..d5c8f7a 100644
27317 --- a/arch/x86/kernel/vsyscall_64.c
27318 +++ b/arch/x86/kernel/vsyscall_64.c
27319 @@ -56,15 +56,13 @@
27320 DEFINE_VVAR(int, vgetcpu_mode);
27321 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27322
27323 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27324 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27325
27326 static int __init vsyscall_setup(char *str)
27327 {
27328 if (str) {
27329 if (!strcmp("emulate", str))
27330 vsyscall_mode = EMULATE;
27331 - else if (!strcmp("native", str))
27332 - vsyscall_mode = NATIVE;
27333 else if (!strcmp("none", str))
27334 vsyscall_mode = NONE;
27335 else
27336 @@ -323,8 +321,7 @@ do_ret:
27337 return true;
27338
27339 sigsegv:
27340 - force_sig(SIGSEGV, current);
27341 - return true;
27342 + do_group_exit(SIGKILL);
27343 }
27344
27345 /*
27346 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27347 extern char __vvar_page;
27348 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27349
27350 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27351 - vsyscall_mode == NATIVE
27352 - ? PAGE_KERNEL_VSYSCALL
27353 - : PAGE_KERNEL_VVAR);
27354 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27355 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27356 (unsigned long)VSYSCALL_START);
27357
27358 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27359 index 04068192..4d75aa6 100644
27360 --- a/arch/x86/kernel/x8664_ksyms_64.c
27361 +++ b/arch/x86/kernel/x8664_ksyms_64.c
27362 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27363 EXPORT_SYMBOL(copy_user_generic_unrolled);
27364 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27365 EXPORT_SYMBOL(__copy_user_nocache);
27366 -EXPORT_SYMBOL(_copy_from_user);
27367 -EXPORT_SYMBOL(_copy_to_user);
27368
27369 EXPORT_SYMBOL(copy_page);
27370 EXPORT_SYMBOL(clear_page);
27371 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27372 EXPORT_SYMBOL(___preempt_schedule_context);
27373 #endif
27374 #endif
27375 +
27376 +#ifdef CONFIG_PAX_PER_CPU_PGD
27377 +EXPORT_SYMBOL(cpu_pgd);
27378 +#endif
27379 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27380 index 021783b..6511282 100644
27381 --- a/arch/x86/kernel/x86_init.c
27382 +++ b/arch/x86/kernel/x86_init.c
27383 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27384 static void default_nmi_init(void) { };
27385 static int default_i8042_detect(void) { return 1; };
27386
27387 -struct x86_platform_ops x86_platform = {
27388 +struct x86_platform_ops x86_platform __read_only = {
27389 .calibrate_tsc = native_calibrate_tsc,
27390 .get_wallclock = mach_get_cmos_time,
27391 .set_wallclock = mach_set_rtc_mmss,
27392 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27393 EXPORT_SYMBOL_GPL(x86_platform);
27394
27395 #if defined(CONFIG_PCI_MSI)
27396 -struct x86_msi_ops x86_msi = {
27397 +struct x86_msi_ops x86_msi __read_only = {
27398 .setup_msi_irqs = native_setup_msi_irqs,
27399 .compose_msi_msg = native_compose_msi_msg,
27400 .teardown_msi_irq = native_teardown_msi_irq,
27401 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27402 }
27403 #endif
27404
27405 -struct x86_io_apic_ops x86_io_apic_ops = {
27406 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27407 .init = native_io_apic_init_mappings,
27408 .read = native_io_apic_read,
27409 .write = native_io_apic_write,
27410 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27411 index 422fd82..b2d262e 100644
27412 --- a/arch/x86/kernel/xsave.c
27413 +++ b/arch/x86/kernel/xsave.c
27414 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27415
27416 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27417 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27418 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27419 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27420
27421 if (!use_xsave())
27422 return err;
27423
27424 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27425 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27426
27427 /*
27428 * Read the xstate_bv which we copied (directly from the cpu or
27429 * from the state in task struct) to the user buffers.
27430 */
27431 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27432 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27433
27434 /*
27435 * For legacy compatible, we always set FP/SSE bits in the bit
27436 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27437 */
27438 xstate_bv |= XSTATE_FPSSE;
27439
27440 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27441 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27442
27443 return err;
27444 }
27445 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27446 {
27447 int err;
27448
27449 + buf = (struct xsave_struct __user *)____m(buf);
27450 if (use_xsave())
27451 err = xsave_user(buf);
27452 else if (use_fxsr())
27453 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
27454 */
27455 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
27456 {
27457 + buf = (void __user *)____m(buf);
27458 if (use_xsave()) {
27459 if ((unsigned long)buf % 64 || fx_only) {
27460 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
27461 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
27462 index c697625..a032162 100644
27463 --- a/arch/x86/kvm/cpuid.c
27464 +++ b/arch/x86/kvm/cpuid.c
27465 @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
27466 struct kvm_cpuid2 *cpuid,
27467 struct kvm_cpuid_entry2 __user *entries)
27468 {
27469 - int r;
27470 + int r, i;
27471
27472 r = -E2BIG;
27473 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
27474 goto out;
27475 r = -EFAULT;
27476 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
27477 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27478 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27479 goto out;
27480 + for (i = 0; i < cpuid->nent; ++i) {
27481 + struct kvm_cpuid_entry2 cpuid_entry;
27482 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
27483 + goto out;
27484 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
27485 + }
27486 vcpu->arch.cpuid_nent = cpuid->nent;
27487 kvm_apic_set_version(vcpu);
27488 kvm_x86_ops->cpuid_update(vcpu);
27489 @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
27490 struct kvm_cpuid2 *cpuid,
27491 struct kvm_cpuid_entry2 __user *entries)
27492 {
27493 - int r;
27494 + int r, i;
27495
27496 r = -E2BIG;
27497 if (cpuid->nent < vcpu->arch.cpuid_nent)
27498 goto out;
27499 r = -EFAULT;
27500 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
27501 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27502 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27503 goto out;
27504 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
27505 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
27506 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
27507 + goto out;
27508 + }
27509 return 0;
27510
27511 out:
27512 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
27513 index 775702f..737d4a9 100644
27514 --- a/arch/x86/kvm/lapic.c
27515 +++ b/arch/x86/kvm/lapic.c
27516 @@ -55,7 +55,7 @@
27517 #define APIC_BUS_CYCLE_NS 1
27518
27519 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
27520 -#define apic_debug(fmt, arg...)
27521 +#define apic_debug(fmt, arg...) do {} while (0)
27522
27523 #define APIC_LVT_NUM 6
27524 /* 14 is the version for Xeon and Pentium 8.4.8*/
27525 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
27526 index ad75d77..a679d32 100644
27527 --- a/arch/x86/kvm/paging_tmpl.h
27528 +++ b/arch/x86/kvm/paging_tmpl.h
27529 @@ -331,7 +331,7 @@ retry_walk:
27530 if (unlikely(kvm_is_error_hva(host_addr)))
27531 goto error;
27532
27533 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
27534 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
27535 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
27536 goto error;
27537 walker->ptep_user[walker->level - 1] = ptep_user;
27538 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
27539 index c7168a5..09070fc 100644
27540 --- a/arch/x86/kvm/svm.c
27541 +++ b/arch/x86/kvm/svm.c
27542 @@ -3497,7 +3497,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
27543 int cpu = raw_smp_processor_id();
27544
27545 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
27546 +
27547 + pax_open_kernel();
27548 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
27549 + pax_close_kernel();
27550 +
27551 load_TR_desc();
27552 }
27553
27554 @@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
27555 #endif
27556 #endif
27557
27558 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27559 + __set_fs(current_thread_info()->addr_limit);
27560 +#endif
27561 +
27562 reload_tss(vcpu);
27563
27564 local_irq_disable();
27565 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
27566 index da7837e..86c6ebf 100644
27567 --- a/arch/x86/kvm/vmx.c
27568 +++ b/arch/x86/kvm/vmx.c
27569 @@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
27570 #endif
27571 }
27572
27573 -static void vmcs_clear_bits(unsigned long field, u32 mask)
27574 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
27575 {
27576 vmcs_writel(field, vmcs_readl(field) & ~mask);
27577 }
27578
27579 -static void vmcs_set_bits(unsigned long field, u32 mask)
27580 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
27581 {
27582 vmcs_writel(field, vmcs_readl(field) | mask);
27583 }
27584 @@ -1522,7 +1522,11 @@ static void reload_tss(void)
27585 struct desc_struct *descs;
27586
27587 descs = (void *)gdt->address;
27588 +
27589 + pax_open_kernel();
27590 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
27591 + pax_close_kernel();
27592 +
27593 load_TR_desc();
27594 }
27595
27596 @@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
27597 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
27598 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
27599
27600 +#ifdef CONFIG_PAX_PER_CPU_PGD
27601 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27602 +#endif
27603 +
27604 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
27605 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
27606 vmx->loaded_vmcs->cpu = cpu;
27607 @@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
27608 * reads and returns guest's timestamp counter "register"
27609 * guest_tsc = host_tsc + tsc_offset -- 21.3
27610 */
27611 -static u64 guest_read_tsc(void)
27612 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
27613 {
27614 u64 host_tsc, tsc_offset;
27615
27616 @@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
27617 if (!cpu_has_vmx_flexpriority())
27618 flexpriority_enabled = 0;
27619
27620 - if (!cpu_has_vmx_tpr_shadow())
27621 - kvm_x86_ops->update_cr8_intercept = NULL;
27622 + if (!cpu_has_vmx_tpr_shadow()) {
27623 + pax_open_kernel();
27624 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27625 + pax_close_kernel();
27626 + }
27627
27628 if (enable_ept && !cpu_has_vmx_ept_2m_page())
27629 kvm_disable_largepages();
27630 @@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
27631 if (!cpu_has_vmx_apicv())
27632 enable_apicv = 0;
27633
27634 + pax_open_kernel();
27635 if (enable_apicv)
27636 - kvm_x86_ops->update_cr8_intercept = NULL;
27637 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27638 else {
27639 - kvm_x86_ops->hwapic_irr_update = NULL;
27640 - kvm_x86_ops->deliver_posted_interrupt = NULL;
27641 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27642 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
27643 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
27644 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27645 }
27646 + pax_close_kernel();
27647
27648 if (nested)
27649 nested_vmx_setup_ctls_msrs();
27650 @@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27651
27652 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
27653 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
27654 +
27655 +#ifndef CONFIG_PAX_PER_CPU_PGD
27656 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27657 +#endif
27658
27659 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
27660 #ifdef CONFIG_X86_64
27661 @@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27662 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
27663 vmx->host_idt_base = dt.address;
27664
27665 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
27666 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
27667
27668 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
27669 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
27670 @@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27671 "jmp 2f \n\t"
27672 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
27673 "2: "
27674 +
27675 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27676 + "ljmp %[cs],$3f\n\t"
27677 + "3: "
27678 +#endif
27679 +
27680 /* Save guest registers, load host registers, keep flags */
27681 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
27682 "pop %0 \n\t"
27683 @@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27684 #endif
27685 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
27686 [wordsize]"i"(sizeof(ulong))
27687 +
27688 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27689 + ,[cs]"i"(__KERNEL_CS)
27690 +#endif
27691 +
27692 : "cc", "memory"
27693 #ifdef CONFIG_X86_64
27694 , "rax", "rbx", "rdi", "rsi"
27695 @@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27696 if (debugctlmsr)
27697 update_debugctlmsr(debugctlmsr);
27698
27699 -#ifndef CONFIG_X86_64
27700 +#ifdef CONFIG_X86_32
27701 /*
27702 * The sysexit path does not restore ds/es, so we must set them to
27703 * a reasonable value ourselves.
27704 @@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27705 * may be executed in interrupt context, which saves and restore segments
27706 * around it, nullifying its effect.
27707 */
27708 - loadsegment(ds, __USER_DS);
27709 - loadsegment(es, __USER_DS);
27710 + loadsegment(ds, __KERNEL_DS);
27711 + loadsegment(es, __KERNEL_DS);
27712 + loadsegment(ss, __KERNEL_DS);
27713 +
27714 +#ifdef CONFIG_PAX_KERNEXEC
27715 + loadsegment(fs, __KERNEL_PERCPU);
27716 +#endif
27717 +
27718 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27719 + __set_fs(current_thread_info()->addr_limit);
27720 +#endif
27721 +
27722 #endif
27723
27724 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
27725 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
27726 index 5d004da..0802480 100644
27727 --- a/arch/x86/kvm/x86.c
27728 +++ b/arch/x86/kvm/x86.c
27729 @@ -1788,8 +1788,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
27730 {
27731 struct kvm *kvm = vcpu->kvm;
27732 int lm = is_long_mode(vcpu);
27733 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27734 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27735 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27736 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27737 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
27738 : kvm->arch.xen_hvm_config.blob_size_32;
27739 u32 page_num = data & ~PAGE_MASK;
27740 @@ -2673,6 +2673,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
27741 if (n < msr_list.nmsrs)
27742 goto out;
27743 r = -EFAULT;
27744 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
27745 + goto out;
27746 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
27747 num_msrs_to_save * sizeof(u32)))
27748 goto out;
27749 @@ -5482,7 +5484,7 @@ static struct notifier_block pvclock_gtod_notifier = {
27750 };
27751 #endif
27752
27753 -int kvm_arch_init(void *opaque)
27754 +int kvm_arch_init(const void *opaque)
27755 {
27756 int r;
27757 struct kvm_x86_ops *ops = opaque;
27758 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
27759 index bdf8532..f63c587 100644
27760 --- a/arch/x86/lguest/boot.c
27761 +++ b/arch/x86/lguest/boot.c
27762 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
27763 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
27764 * Launcher to reboot us.
27765 */
27766 -static void lguest_restart(char *reason)
27767 +static __noreturn void lguest_restart(char *reason)
27768 {
27769 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
27770 + BUG();
27771 }
27772
27773 /*G:050
27774 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
27775 index 00933d5..3a64af9 100644
27776 --- a/arch/x86/lib/atomic64_386_32.S
27777 +++ b/arch/x86/lib/atomic64_386_32.S
27778 @@ -48,6 +48,10 @@ BEGIN(read)
27779 movl (v), %eax
27780 movl 4(v), %edx
27781 RET_ENDP
27782 +BEGIN(read_unchecked)
27783 + movl (v), %eax
27784 + movl 4(v), %edx
27785 +RET_ENDP
27786 #undef v
27787
27788 #define v %esi
27789 @@ -55,6 +59,10 @@ BEGIN(set)
27790 movl %ebx, (v)
27791 movl %ecx, 4(v)
27792 RET_ENDP
27793 +BEGIN(set_unchecked)
27794 + movl %ebx, (v)
27795 + movl %ecx, 4(v)
27796 +RET_ENDP
27797 #undef v
27798
27799 #define v %esi
27800 @@ -70,6 +78,20 @@ RET_ENDP
27801 BEGIN(add)
27802 addl %eax, (v)
27803 adcl %edx, 4(v)
27804 +
27805 +#ifdef CONFIG_PAX_REFCOUNT
27806 + jno 0f
27807 + subl %eax, (v)
27808 + sbbl %edx, 4(v)
27809 + int $4
27810 +0:
27811 + _ASM_EXTABLE(0b, 0b)
27812 +#endif
27813 +
27814 +RET_ENDP
27815 +BEGIN(add_unchecked)
27816 + addl %eax, (v)
27817 + adcl %edx, 4(v)
27818 RET_ENDP
27819 #undef v
27820
27821 @@ -77,6 +99,24 @@ RET_ENDP
27822 BEGIN(add_return)
27823 addl (v), %eax
27824 adcl 4(v), %edx
27825 +
27826 +#ifdef CONFIG_PAX_REFCOUNT
27827 + into
27828 +1234:
27829 + _ASM_EXTABLE(1234b, 2f)
27830 +#endif
27831 +
27832 + movl %eax, (v)
27833 + movl %edx, 4(v)
27834 +
27835 +#ifdef CONFIG_PAX_REFCOUNT
27836 +2:
27837 +#endif
27838 +
27839 +RET_ENDP
27840 +BEGIN(add_return_unchecked)
27841 + addl (v), %eax
27842 + adcl 4(v), %edx
27843 movl %eax, (v)
27844 movl %edx, 4(v)
27845 RET_ENDP
27846 @@ -86,6 +126,20 @@ RET_ENDP
27847 BEGIN(sub)
27848 subl %eax, (v)
27849 sbbl %edx, 4(v)
27850 +
27851 +#ifdef CONFIG_PAX_REFCOUNT
27852 + jno 0f
27853 + addl %eax, (v)
27854 + adcl %edx, 4(v)
27855 + int $4
27856 +0:
27857 + _ASM_EXTABLE(0b, 0b)
27858 +#endif
27859 +
27860 +RET_ENDP
27861 +BEGIN(sub_unchecked)
27862 + subl %eax, (v)
27863 + sbbl %edx, 4(v)
27864 RET_ENDP
27865 #undef v
27866
27867 @@ -96,6 +150,27 @@ BEGIN(sub_return)
27868 sbbl $0, %edx
27869 addl (v), %eax
27870 adcl 4(v), %edx
27871 +
27872 +#ifdef CONFIG_PAX_REFCOUNT
27873 + into
27874 +1234:
27875 + _ASM_EXTABLE(1234b, 2f)
27876 +#endif
27877 +
27878 + movl %eax, (v)
27879 + movl %edx, 4(v)
27880 +
27881 +#ifdef CONFIG_PAX_REFCOUNT
27882 +2:
27883 +#endif
27884 +
27885 +RET_ENDP
27886 +BEGIN(sub_return_unchecked)
27887 + negl %edx
27888 + negl %eax
27889 + sbbl $0, %edx
27890 + addl (v), %eax
27891 + adcl 4(v), %edx
27892 movl %eax, (v)
27893 movl %edx, 4(v)
27894 RET_ENDP
27895 @@ -105,6 +180,20 @@ RET_ENDP
27896 BEGIN(inc)
27897 addl $1, (v)
27898 adcl $0, 4(v)
27899 +
27900 +#ifdef CONFIG_PAX_REFCOUNT
27901 + jno 0f
27902 + subl $1, (v)
27903 + sbbl $0, 4(v)
27904 + int $4
27905 +0:
27906 + _ASM_EXTABLE(0b, 0b)
27907 +#endif
27908 +
27909 +RET_ENDP
27910 +BEGIN(inc_unchecked)
27911 + addl $1, (v)
27912 + adcl $0, 4(v)
27913 RET_ENDP
27914 #undef v
27915
27916 @@ -114,6 +203,26 @@ BEGIN(inc_return)
27917 movl 4(v), %edx
27918 addl $1, %eax
27919 adcl $0, %edx
27920 +
27921 +#ifdef CONFIG_PAX_REFCOUNT
27922 + into
27923 +1234:
27924 + _ASM_EXTABLE(1234b, 2f)
27925 +#endif
27926 +
27927 + movl %eax, (v)
27928 + movl %edx, 4(v)
27929 +
27930 +#ifdef CONFIG_PAX_REFCOUNT
27931 +2:
27932 +#endif
27933 +
27934 +RET_ENDP
27935 +BEGIN(inc_return_unchecked)
27936 + movl (v), %eax
27937 + movl 4(v), %edx
27938 + addl $1, %eax
27939 + adcl $0, %edx
27940 movl %eax, (v)
27941 movl %edx, 4(v)
27942 RET_ENDP
27943 @@ -123,6 +232,20 @@ RET_ENDP
27944 BEGIN(dec)
27945 subl $1, (v)
27946 sbbl $0, 4(v)
27947 +
27948 +#ifdef CONFIG_PAX_REFCOUNT
27949 + jno 0f
27950 + addl $1, (v)
27951 + adcl $0, 4(v)
27952 + int $4
27953 +0:
27954 + _ASM_EXTABLE(0b, 0b)
27955 +#endif
27956 +
27957 +RET_ENDP
27958 +BEGIN(dec_unchecked)
27959 + subl $1, (v)
27960 + sbbl $0, 4(v)
27961 RET_ENDP
27962 #undef v
27963
27964 @@ -132,6 +255,26 @@ BEGIN(dec_return)
27965 movl 4(v), %edx
27966 subl $1, %eax
27967 sbbl $0, %edx
27968 +
27969 +#ifdef CONFIG_PAX_REFCOUNT
27970 + into
27971 +1234:
27972 + _ASM_EXTABLE(1234b, 2f)
27973 +#endif
27974 +
27975 + movl %eax, (v)
27976 + movl %edx, 4(v)
27977 +
27978 +#ifdef CONFIG_PAX_REFCOUNT
27979 +2:
27980 +#endif
27981 +
27982 +RET_ENDP
27983 +BEGIN(dec_return_unchecked)
27984 + movl (v), %eax
27985 + movl 4(v), %edx
27986 + subl $1, %eax
27987 + sbbl $0, %edx
27988 movl %eax, (v)
27989 movl %edx, 4(v)
27990 RET_ENDP
27991 @@ -143,6 +286,13 @@ BEGIN(add_unless)
27992 adcl %edx, %edi
27993 addl (v), %eax
27994 adcl 4(v), %edx
27995 +
27996 +#ifdef CONFIG_PAX_REFCOUNT
27997 + into
27998 +1234:
27999 + _ASM_EXTABLE(1234b, 2f)
28000 +#endif
28001 +
28002 cmpl %eax, %ecx
28003 je 3f
28004 1:
28005 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28006 1:
28007 addl $1, %eax
28008 adcl $0, %edx
28009 +
28010 +#ifdef CONFIG_PAX_REFCOUNT
28011 + into
28012 +1234:
28013 + _ASM_EXTABLE(1234b, 2f)
28014 +#endif
28015 +
28016 movl %eax, (v)
28017 movl %edx, 4(v)
28018 movl $1, %eax
28019 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28020 movl 4(v), %edx
28021 subl $1, %eax
28022 sbbl $0, %edx
28023 +
28024 +#ifdef CONFIG_PAX_REFCOUNT
28025 + into
28026 +1234:
28027 + _ASM_EXTABLE(1234b, 1f)
28028 +#endif
28029 +
28030 js 1f
28031 movl %eax, (v)
28032 movl %edx, 4(v)
28033 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28034 index f5cc9eb..51fa319 100644
28035 --- a/arch/x86/lib/atomic64_cx8_32.S
28036 +++ b/arch/x86/lib/atomic64_cx8_32.S
28037 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28038 CFI_STARTPROC
28039
28040 read64 %ecx
28041 + pax_force_retaddr
28042 ret
28043 CFI_ENDPROC
28044 ENDPROC(atomic64_read_cx8)
28045
28046 +ENTRY(atomic64_read_unchecked_cx8)
28047 + CFI_STARTPROC
28048 +
28049 + read64 %ecx
28050 + pax_force_retaddr
28051 + ret
28052 + CFI_ENDPROC
28053 +ENDPROC(atomic64_read_unchecked_cx8)
28054 +
28055 ENTRY(atomic64_set_cx8)
28056 CFI_STARTPROC
28057
28058 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28059 cmpxchg8b (%esi)
28060 jne 1b
28061
28062 + pax_force_retaddr
28063 ret
28064 CFI_ENDPROC
28065 ENDPROC(atomic64_set_cx8)
28066
28067 +ENTRY(atomic64_set_unchecked_cx8)
28068 + CFI_STARTPROC
28069 +
28070 +1:
28071 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28072 + * are atomic on 586 and newer */
28073 + cmpxchg8b (%esi)
28074 + jne 1b
28075 +
28076 + pax_force_retaddr
28077 + ret
28078 + CFI_ENDPROC
28079 +ENDPROC(atomic64_set_unchecked_cx8)
28080 +
28081 ENTRY(atomic64_xchg_cx8)
28082 CFI_STARTPROC
28083
28084 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28085 cmpxchg8b (%esi)
28086 jne 1b
28087
28088 + pax_force_retaddr
28089 ret
28090 CFI_ENDPROC
28091 ENDPROC(atomic64_xchg_cx8)
28092
28093 -.macro addsub_return func ins insc
28094 -ENTRY(atomic64_\func\()_return_cx8)
28095 +.macro addsub_return func ins insc unchecked=""
28096 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28097 CFI_STARTPROC
28098 SAVE ebp
28099 SAVE ebx
28100 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28101 movl %edx, %ecx
28102 \ins\()l %esi, %ebx
28103 \insc\()l %edi, %ecx
28104 +
28105 +.ifb \unchecked
28106 +#ifdef CONFIG_PAX_REFCOUNT
28107 + into
28108 +2:
28109 + _ASM_EXTABLE(2b, 3f)
28110 +#endif
28111 +.endif
28112 +
28113 LOCK_PREFIX
28114 cmpxchg8b (%ebp)
28115 jne 1b
28116 -
28117 -10:
28118 movl %ebx, %eax
28119 movl %ecx, %edx
28120 +
28121 +.ifb \unchecked
28122 +#ifdef CONFIG_PAX_REFCOUNT
28123 +3:
28124 +#endif
28125 +.endif
28126 +
28127 RESTORE edi
28128 RESTORE esi
28129 RESTORE ebx
28130 RESTORE ebp
28131 + pax_force_retaddr
28132 ret
28133 CFI_ENDPROC
28134 -ENDPROC(atomic64_\func\()_return_cx8)
28135 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28136 .endm
28137
28138 addsub_return add add adc
28139 addsub_return sub sub sbb
28140 +addsub_return add add adc _unchecked
28141 +addsub_return sub sub sbb _unchecked
28142
28143 -.macro incdec_return func ins insc
28144 -ENTRY(atomic64_\func\()_return_cx8)
28145 +.macro incdec_return func ins insc unchecked=""
28146 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28147 CFI_STARTPROC
28148 SAVE ebx
28149
28150 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28151 movl %edx, %ecx
28152 \ins\()l $1, %ebx
28153 \insc\()l $0, %ecx
28154 +
28155 +.ifb \unchecked
28156 +#ifdef CONFIG_PAX_REFCOUNT
28157 + into
28158 +2:
28159 + _ASM_EXTABLE(2b, 3f)
28160 +#endif
28161 +.endif
28162 +
28163 LOCK_PREFIX
28164 cmpxchg8b (%esi)
28165 jne 1b
28166
28167 -10:
28168 movl %ebx, %eax
28169 movl %ecx, %edx
28170 +
28171 +.ifb \unchecked
28172 +#ifdef CONFIG_PAX_REFCOUNT
28173 +3:
28174 +#endif
28175 +.endif
28176 +
28177 RESTORE ebx
28178 + pax_force_retaddr
28179 ret
28180 CFI_ENDPROC
28181 -ENDPROC(atomic64_\func\()_return_cx8)
28182 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28183 .endm
28184
28185 incdec_return inc add adc
28186 incdec_return dec sub sbb
28187 +incdec_return inc add adc _unchecked
28188 +incdec_return dec sub sbb _unchecked
28189
28190 ENTRY(atomic64_dec_if_positive_cx8)
28191 CFI_STARTPROC
28192 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28193 movl %edx, %ecx
28194 subl $1, %ebx
28195 sbb $0, %ecx
28196 +
28197 +#ifdef CONFIG_PAX_REFCOUNT
28198 + into
28199 +1234:
28200 + _ASM_EXTABLE(1234b, 2f)
28201 +#endif
28202 +
28203 js 2f
28204 LOCK_PREFIX
28205 cmpxchg8b (%esi)
28206 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28207 movl %ebx, %eax
28208 movl %ecx, %edx
28209 RESTORE ebx
28210 + pax_force_retaddr
28211 ret
28212 CFI_ENDPROC
28213 ENDPROC(atomic64_dec_if_positive_cx8)
28214 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28215 movl %edx, %ecx
28216 addl %ebp, %ebx
28217 adcl %edi, %ecx
28218 +
28219 +#ifdef CONFIG_PAX_REFCOUNT
28220 + into
28221 +1234:
28222 + _ASM_EXTABLE(1234b, 3f)
28223 +#endif
28224 +
28225 LOCK_PREFIX
28226 cmpxchg8b (%esi)
28227 jne 1b
28228 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28229 CFI_ADJUST_CFA_OFFSET -8
28230 RESTORE ebx
28231 RESTORE ebp
28232 + pax_force_retaddr
28233 ret
28234 4:
28235 cmpl %edx, 4(%esp)
28236 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28237 xorl %ecx, %ecx
28238 addl $1, %ebx
28239 adcl %edx, %ecx
28240 +
28241 +#ifdef CONFIG_PAX_REFCOUNT
28242 + into
28243 +1234:
28244 + _ASM_EXTABLE(1234b, 3f)
28245 +#endif
28246 +
28247 LOCK_PREFIX
28248 cmpxchg8b (%esi)
28249 jne 1b
28250 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28251 movl $1, %eax
28252 3:
28253 RESTORE ebx
28254 + pax_force_retaddr
28255 ret
28256 CFI_ENDPROC
28257 ENDPROC(atomic64_inc_not_zero_cx8)
28258 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28259 index e78b8ee..7e173a8 100644
28260 --- a/arch/x86/lib/checksum_32.S
28261 +++ b/arch/x86/lib/checksum_32.S
28262 @@ -29,7 +29,8 @@
28263 #include <asm/dwarf2.h>
28264 #include <asm/errno.h>
28265 #include <asm/asm.h>
28266 -
28267 +#include <asm/segment.h>
28268 +
28269 /*
28270 * computes a partial checksum, e.g. for TCP/UDP fragments
28271 */
28272 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28273
28274 #define ARGBASE 16
28275 #define FP 12
28276 -
28277 -ENTRY(csum_partial_copy_generic)
28278 +
28279 +ENTRY(csum_partial_copy_generic_to_user)
28280 CFI_STARTPROC
28281 +
28282 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28283 + pushl_cfi %gs
28284 + popl_cfi %es
28285 + jmp csum_partial_copy_generic
28286 +#endif
28287 +
28288 +ENTRY(csum_partial_copy_generic_from_user)
28289 +
28290 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28291 + pushl_cfi %gs
28292 + popl_cfi %ds
28293 +#endif
28294 +
28295 +ENTRY(csum_partial_copy_generic)
28296 subl $4,%esp
28297 CFI_ADJUST_CFA_OFFSET 4
28298 pushl_cfi %edi
28299 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28300 jmp 4f
28301 SRC(1: movw (%esi), %bx )
28302 addl $2, %esi
28303 -DST( movw %bx, (%edi) )
28304 +DST( movw %bx, %es:(%edi) )
28305 addl $2, %edi
28306 addw %bx, %ax
28307 adcl $0, %eax
28308 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28309 SRC(1: movl (%esi), %ebx )
28310 SRC( movl 4(%esi), %edx )
28311 adcl %ebx, %eax
28312 -DST( movl %ebx, (%edi) )
28313 +DST( movl %ebx, %es:(%edi) )
28314 adcl %edx, %eax
28315 -DST( movl %edx, 4(%edi) )
28316 +DST( movl %edx, %es:4(%edi) )
28317
28318 SRC( movl 8(%esi), %ebx )
28319 SRC( movl 12(%esi), %edx )
28320 adcl %ebx, %eax
28321 -DST( movl %ebx, 8(%edi) )
28322 +DST( movl %ebx, %es:8(%edi) )
28323 adcl %edx, %eax
28324 -DST( movl %edx, 12(%edi) )
28325 +DST( movl %edx, %es:12(%edi) )
28326
28327 SRC( movl 16(%esi), %ebx )
28328 SRC( movl 20(%esi), %edx )
28329 adcl %ebx, %eax
28330 -DST( movl %ebx, 16(%edi) )
28331 +DST( movl %ebx, %es:16(%edi) )
28332 adcl %edx, %eax
28333 -DST( movl %edx, 20(%edi) )
28334 +DST( movl %edx, %es:20(%edi) )
28335
28336 SRC( movl 24(%esi), %ebx )
28337 SRC( movl 28(%esi), %edx )
28338 adcl %ebx, %eax
28339 -DST( movl %ebx, 24(%edi) )
28340 +DST( movl %ebx, %es:24(%edi) )
28341 adcl %edx, %eax
28342 -DST( movl %edx, 28(%edi) )
28343 +DST( movl %edx, %es:28(%edi) )
28344
28345 lea 32(%esi), %esi
28346 lea 32(%edi), %edi
28347 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28348 shrl $2, %edx # This clears CF
28349 SRC(3: movl (%esi), %ebx )
28350 adcl %ebx, %eax
28351 -DST( movl %ebx, (%edi) )
28352 +DST( movl %ebx, %es:(%edi) )
28353 lea 4(%esi), %esi
28354 lea 4(%edi), %edi
28355 dec %edx
28356 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28357 jb 5f
28358 SRC( movw (%esi), %cx )
28359 leal 2(%esi), %esi
28360 -DST( movw %cx, (%edi) )
28361 +DST( movw %cx, %es:(%edi) )
28362 leal 2(%edi), %edi
28363 je 6f
28364 shll $16,%ecx
28365 SRC(5: movb (%esi), %cl )
28366 -DST( movb %cl, (%edi) )
28367 +DST( movb %cl, %es:(%edi) )
28368 6: addl %ecx, %eax
28369 adcl $0, %eax
28370 7:
28371 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28372
28373 6001:
28374 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28375 - movl $-EFAULT, (%ebx)
28376 + movl $-EFAULT, %ss:(%ebx)
28377
28378 # zero the complete destination - computing the rest
28379 # is too much work
28380 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28381
28382 6002:
28383 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28384 - movl $-EFAULT,(%ebx)
28385 + movl $-EFAULT,%ss:(%ebx)
28386 jmp 5000b
28387
28388 .previous
28389
28390 + pushl_cfi %ss
28391 + popl_cfi %ds
28392 + pushl_cfi %ss
28393 + popl_cfi %es
28394 popl_cfi %ebx
28395 CFI_RESTORE ebx
28396 popl_cfi %esi
28397 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28398 popl_cfi %ecx # equivalent to addl $4,%esp
28399 ret
28400 CFI_ENDPROC
28401 -ENDPROC(csum_partial_copy_generic)
28402 +ENDPROC(csum_partial_copy_generic_to_user)
28403
28404 #else
28405
28406 /* Version for PentiumII/PPro */
28407
28408 #define ROUND1(x) \
28409 + nop; nop; nop; \
28410 SRC(movl x(%esi), %ebx ) ; \
28411 addl %ebx, %eax ; \
28412 - DST(movl %ebx, x(%edi) ) ;
28413 + DST(movl %ebx, %es:x(%edi)) ;
28414
28415 #define ROUND(x) \
28416 + nop; nop; nop; \
28417 SRC(movl x(%esi), %ebx ) ; \
28418 adcl %ebx, %eax ; \
28419 - DST(movl %ebx, x(%edi) ) ;
28420 + DST(movl %ebx, %es:x(%edi)) ;
28421
28422 #define ARGBASE 12
28423 -
28424 -ENTRY(csum_partial_copy_generic)
28425 +
28426 +ENTRY(csum_partial_copy_generic_to_user)
28427 CFI_STARTPROC
28428 +
28429 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28430 + pushl_cfi %gs
28431 + popl_cfi %es
28432 + jmp csum_partial_copy_generic
28433 +#endif
28434 +
28435 +ENTRY(csum_partial_copy_generic_from_user)
28436 +
28437 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28438 + pushl_cfi %gs
28439 + popl_cfi %ds
28440 +#endif
28441 +
28442 +ENTRY(csum_partial_copy_generic)
28443 pushl_cfi %ebx
28444 CFI_REL_OFFSET ebx, 0
28445 pushl_cfi %edi
28446 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28447 subl %ebx, %edi
28448 lea -1(%esi),%edx
28449 andl $-32,%edx
28450 - lea 3f(%ebx,%ebx), %ebx
28451 + lea 3f(%ebx,%ebx,2), %ebx
28452 testl %esi, %esi
28453 jmp *%ebx
28454 1: addl $64,%esi
28455 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
28456 jb 5f
28457 SRC( movw (%esi), %dx )
28458 leal 2(%esi), %esi
28459 -DST( movw %dx, (%edi) )
28460 +DST( movw %dx, %es:(%edi) )
28461 leal 2(%edi), %edi
28462 je 6f
28463 shll $16,%edx
28464 5:
28465 SRC( movb (%esi), %dl )
28466 -DST( movb %dl, (%edi) )
28467 +DST( movb %dl, %es:(%edi) )
28468 6: addl %edx, %eax
28469 adcl $0, %eax
28470 7:
28471 .section .fixup, "ax"
28472 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
28473 - movl $-EFAULT, (%ebx)
28474 + movl $-EFAULT, %ss:(%ebx)
28475 # zero the complete destination (computing the rest is too much work)
28476 movl ARGBASE+8(%esp),%edi # dst
28477 movl ARGBASE+12(%esp),%ecx # len
28478 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
28479 rep; stosb
28480 jmp 7b
28481 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28482 - movl $-EFAULT, (%ebx)
28483 + movl $-EFAULT, %ss:(%ebx)
28484 jmp 7b
28485 .previous
28486
28487 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28488 + pushl_cfi %ss
28489 + popl_cfi %ds
28490 + pushl_cfi %ss
28491 + popl_cfi %es
28492 +#endif
28493 +
28494 popl_cfi %esi
28495 CFI_RESTORE esi
28496 popl_cfi %edi
28497 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
28498 CFI_RESTORE ebx
28499 ret
28500 CFI_ENDPROC
28501 -ENDPROC(csum_partial_copy_generic)
28502 +ENDPROC(csum_partial_copy_generic_to_user)
28503
28504 #undef ROUND
28505 #undef ROUND1
28506 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
28507 index f2145cf..cea889d 100644
28508 --- a/arch/x86/lib/clear_page_64.S
28509 +++ b/arch/x86/lib/clear_page_64.S
28510 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
28511 movl $4096/8,%ecx
28512 xorl %eax,%eax
28513 rep stosq
28514 + pax_force_retaddr
28515 ret
28516 CFI_ENDPROC
28517 ENDPROC(clear_page_c)
28518 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
28519 movl $4096,%ecx
28520 xorl %eax,%eax
28521 rep stosb
28522 + pax_force_retaddr
28523 ret
28524 CFI_ENDPROC
28525 ENDPROC(clear_page_c_e)
28526 @@ -43,6 +45,7 @@ ENTRY(clear_page)
28527 leaq 64(%rdi),%rdi
28528 jnz .Lloop
28529 nop
28530 + pax_force_retaddr
28531 ret
28532 CFI_ENDPROC
28533 .Lclear_page_end:
28534 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
28535
28536 #include <asm/cpufeature.h>
28537
28538 - .section .altinstr_replacement,"ax"
28539 + .section .altinstr_replacement,"a"
28540 1: .byte 0xeb /* jmp <disp8> */
28541 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
28542 2: .byte 0xeb /* jmp <disp8> */
28543 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
28544 index 1e572c5..2a162cd 100644
28545 --- a/arch/x86/lib/cmpxchg16b_emu.S
28546 +++ b/arch/x86/lib/cmpxchg16b_emu.S
28547 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
28548
28549 popf
28550 mov $1, %al
28551 + pax_force_retaddr
28552 ret
28553
28554 not_same:
28555 popf
28556 xor %al,%al
28557 + pax_force_retaddr
28558 ret
28559
28560 CFI_ENDPROC
28561 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
28562 index 176cca6..e0d658e 100644
28563 --- a/arch/x86/lib/copy_page_64.S
28564 +++ b/arch/x86/lib/copy_page_64.S
28565 @@ -9,6 +9,7 @@ copy_page_rep:
28566 CFI_STARTPROC
28567 movl $4096/8, %ecx
28568 rep movsq
28569 + pax_force_retaddr
28570 ret
28571 CFI_ENDPROC
28572 ENDPROC(copy_page_rep)
28573 @@ -24,8 +25,8 @@ ENTRY(copy_page)
28574 CFI_ADJUST_CFA_OFFSET 2*8
28575 movq %rbx, (%rsp)
28576 CFI_REL_OFFSET rbx, 0
28577 - movq %r12, 1*8(%rsp)
28578 - CFI_REL_OFFSET r12, 1*8
28579 + movq %r13, 1*8(%rsp)
28580 + CFI_REL_OFFSET r13, 1*8
28581
28582 movl $(4096/64)-5, %ecx
28583 .p2align 4
28584 @@ -38,7 +39,7 @@ ENTRY(copy_page)
28585 movq 0x8*4(%rsi), %r9
28586 movq 0x8*5(%rsi), %r10
28587 movq 0x8*6(%rsi), %r11
28588 - movq 0x8*7(%rsi), %r12
28589 + movq 0x8*7(%rsi), %r13
28590
28591 prefetcht0 5*64(%rsi)
28592
28593 @@ -49,7 +50,7 @@ ENTRY(copy_page)
28594 movq %r9, 0x8*4(%rdi)
28595 movq %r10, 0x8*5(%rdi)
28596 movq %r11, 0x8*6(%rdi)
28597 - movq %r12, 0x8*7(%rdi)
28598 + movq %r13, 0x8*7(%rdi)
28599
28600 leaq 64 (%rsi), %rsi
28601 leaq 64 (%rdi), %rdi
28602 @@ -68,7 +69,7 @@ ENTRY(copy_page)
28603 movq 0x8*4(%rsi), %r9
28604 movq 0x8*5(%rsi), %r10
28605 movq 0x8*6(%rsi), %r11
28606 - movq 0x8*7(%rsi), %r12
28607 + movq 0x8*7(%rsi), %r13
28608
28609 movq %rax, 0x8*0(%rdi)
28610 movq %rbx, 0x8*1(%rdi)
28611 @@ -77,7 +78,7 @@ ENTRY(copy_page)
28612 movq %r9, 0x8*4(%rdi)
28613 movq %r10, 0x8*5(%rdi)
28614 movq %r11, 0x8*6(%rdi)
28615 - movq %r12, 0x8*7(%rdi)
28616 + movq %r13, 0x8*7(%rdi)
28617
28618 leaq 64(%rdi), %rdi
28619 leaq 64(%rsi), %rsi
28620 @@ -85,10 +86,11 @@ ENTRY(copy_page)
28621
28622 movq (%rsp), %rbx
28623 CFI_RESTORE rbx
28624 - movq 1*8(%rsp), %r12
28625 - CFI_RESTORE r12
28626 + movq 1*8(%rsp), %r13
28627 + CFI_RESTORE r13
28628 addq $2*8, %rsp
28629 CFI_ADJUST_CFA_OFFSET -2*8
28630 + pax_force_retaddr
28631 ret
28632 .Lcopy_page_end:
28633 CFI_ENDPROC
28634 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
28635
28636 #include <asm/cpufeature.h>
28637
28638 - .section .altinstr_replacement,"ax"
28639 + .section .altinstr_replacement,"a"
28640 1: .byte 0xeb /* jmp <disp8> */
28641 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
28642 2:
28643 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
28644 index a30ca15..407412b 100644
28645 --- a/arch/x86/lib/copy_user_64.S
28646 +++ b/arch/x86/lib/copy_user_64.S
28647 @@ -18,31 +18,7 @@
28648 #include <asm/alternative-asm.h>
28649 #include <asm/asm.h>
28650 #include <asm/smap.h>
28651 -
28652 -/*
28653 - * By placing feature2 after feature1 in altinstructions section, we logically
28654 - * implement:
28655 - * If CPU has feature2, jmp to alt2 is used
28656 - * else if CPU has feature1, jmp to alt1 is used
28657 - * else jmp to orig is used.
28658 - */
28659 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
28660 -0:
28661 - .byte 0xe9 /* 32bit jump */
28662 - .long \orig-1f /* by default jump to orig */
28663 -1:
28664 - .section .altinstr_replacement,"ax"
28665 -2: .byte 0xe9 /* near jump with 32bit immediate */
28666 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
28667 -3: .byte 0xe9 /* near jump with 32bit immediate */
28668 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
28669 - .previous
28670 -
28671 - .section .altinstructions,"a"
28672 - altinstruction_entry 0b,2b,\feature1,5,5
28673 - altinstruction_entry 0b,3b,\feature2,5,5
28674 - .previous
28675 - .endm
28676 +#include <asm/pgtable.h>
28677
28678 .macro ALIGN_DESTINATION
28679 #ifdef FIX_ALIGNMENT
28680 @@ -70,52 +46,6 @@
28681 #endif
28682 .endm
28683
28684 -/* Standard copy_to_user with segment limit checking */
28685 -ENTRY(_copy_to_user)
28686 - CFI_STARTPROC
28687 - GET_THREAD_INFO(%rax)
28688 - movq %rdi,%rcx
28689 - addq %rdx,%rcx
28690 - jc bad_to_user
28691 - cmpq TI_addr_limit(%rax),%rcx
28692 - ja bad_to_user
28693 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28694 - copy_user_generic_unrolled,copy_user_generic_string, \
28695 - copy_user_enhanced_fast_string
28696 - CFI_ENDPROC
28697 -ENDPROC(_copy_to_user)
28698 -
28699 -/* Standard copy_from_user with segment limit checking */
28700 -ENTRY(_copy_from_user)
28701 - CFI_STARTPROC
28702 - GET_THREAD_INFO(%rax)
28703 - movq %rsi,%rcx
28704 - addq %rdx,%rcx
28705 - jc bad_from_user
28706 - cmpq TI_addr_limit(%rax),%rcx
28707 - ja bad_from_user
28708 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28709 - copy_user_generic_unrolled,copy_user_generic_string, \
28710 - copy_user_enhanced_fast_string
28711 - CFI_ENDPROC
28712 -ENDPROC(_copy_from_user)
28713 -
28714 - .section .fixup,"ax"
28715 - /* must zero dest */
28716 -ENTRY(bad_from_user)
28717 -bad_from_user:
28718 - CFI_STARTPROC
28719 - movl %edx,%ecx
28720 - xorl %eax,%eax
28721 - rep
28722 - stosb
28723 -bad_to_user:
28724 - movl %edx,%eax
28725 - ret
28726 - CFI_ENDPROC
28727 -ENDPROC(bad_from_user)
28728 - .previous
28729 -
28730 /*
28731 * copy_user_generic_unrolled - memory copy with exception handling.
28732 * This version is for CPUs like P4 that don't have efficient micro
28733 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
28734 */
28735 ENTRY(copy_user_generic_unrolled)
28736 CFI_STARTPROC
28737 + ASM_PAX_OPEN_USERLAND
28738 ASM_STAC
28739 cmpl $8,%edx
28740 jb 20f /* less then 8 bytes, go to byte copy loop */
28741 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
28742 jnz 21b
28743 23: xor %eax,%eax
28744 ASM_CLAC
28745 + ASM_PAX_CLOSE_USERLAND
28746 + pax_force_retaddr
28747 ret
28748
28749 .section .fixup,"ax"
28750 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
28751 */
28752 ENTRY(copy_user_generic_string)
28753 CFI_STARTPROC
28754 + ASM_PAX_OPEN_USERLAND
28755 ASM_STAC
28756 andl %edx,%edx
28757 jz 4f
28758 @@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
28759 movsb
28760 4: xorl %eax,%eax
28761 ASM_CLAC
28762 + ASM_PAX_CLOSE_USERLAND
28763 + pax_force_retaddr
28764 ret
28765
28766 .section .fixup,"ax"
28767 @@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
28768 */
28769 ENTRY(copy_user_enhanced_fast_string)
28770 CFI_STARTPROC
28771 + ASM_PAX_OPEN_USERLAND
28772 ASM_STAC
28773 andl %edx,%edx
28774 jz 2f
28775 @@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
28776 movsb
28777 2: xorl %eax,%eax
28778 ASM_CLAC
28779 + ASM_PAX_CLOSE_USERLAND
28780 + pax_force_retaddr
28781 ret
28782
28783 .section .fixup,"ax"
28784 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
28785 index 6a4f43c..c70fb52 100644
28786 --- a/arch/x86/lib/copy_user_nocache_64.S
28787 +++ b/arch/x86/lib/copy_user_nocache_64.S
28788 @@ -8,6 +8,7 @@
28789
28790 #include <linux/linkage.h>
28791 #include <asm/dwarf2.h>
28792 +#include <asm/alternative-asm.h>
28793
28794 #define FIX_ALIGNMENT 1
28795
28796 @@ -16,6 +17,7 @@
28797 #include <asm/thread_info.h>
28798 #include <asm/asm.h>
28799 #include <asm/smap.h>
28800 +#include <asm/pgtable.h>
28801
28802 .macro ALIGN_DESTINATION
28803 #ifdef FIX_ALIGNMENT
28804 @@ -49,6 +51,16 @@
28805 */
28806 ENTRY(__copy_user_nocache)
28807 CFI_STARTPROC
28808 +
28809 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28810 + mov pax_user_shadow_base,%rcx
28811 + cmp %rcx,%rsi
28812 + jae 1f
28813 + add %rcx,%rsi
28814 +1:
28815 +#endif
28816 +
28817 + ASM_PAX_OPEN_USERLAND
28818 ASM_STAC
28819 cmpl $8,%edx
28820 jb 20f /* less then 8 bytes, go to byte copy loop */
28821 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
28822 jnz 21b
28823 23: xorl %eax,%eax
28824 ASM_CLAC
28825 + ASM_PAX_CLOSE_USERLAND
28826 sfence
28827 + pax_force_retaddr
28828 ret
28829
28830 .section .fixup,"ax"
28831 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
28832 index 2419d5f..fe52d0e 100644
28833 --- a/arch/x86/lib/csum-copy_64.S
28834 +++ b/arch/x86/lib/csum-copy_64.S
28835 @@ -9,6 +9,7 @@
28836 #include <asm/dwarf2.h>
28837 #include <asm/errno.h>
28838 #include <asm/asm.h>
28839 +#include <asm/alternative-asm.h>
28840
28841 /*
28842 * Checksum copy with exception handling.
28843 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
28844 CFI_ADJUST_CFA_OFFSET 7*8
28845 movq %rbx, 2*8(%rsp)
28846 CFI_REL_OFFSET rbx, 2*8
28847 - movq %r12, 3*8(%rsp)
28848 - CFI_REL_OFFSET r12, 3*8
28849 + movq %r15, 3*8(%rsp)
28850 + CFI_REL_OFFSET r15, 3*8
28851 movq %r14, 4*8(%rsp)
28852 CFI_REL_OFFSET r14, 4*8
28853 movq %r13, 5*8(%rsp)
28854 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
28855 movl %edx, %ecx
28856
28857 xorl %r9d, %r9d
28858 - movq %rcx, %r12
28859 + movq %rcx, %r15
28860
28861 - shrq $6, %r12
28862 + shrq $6, %r15
28863 jz .Lhandle_tail /* < 64 */
28864
28865 clc
28866
28867 /* main loop. clear in 64 byte blocks */
28868 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
28869 - /* r11: temp3, rdx: temp4, r12 loopcnt */
28870 + /* r11: temp3, rdx: temp4, r15 loopcnt */
28871 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
28872 .p2align 4
28873 .Lloop:
28874 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
28875 adcq %r14, %rax
28876 adcq %r13, %rax
28877
28878 - decl %r12d
28879 + decl %r15d
28880
28881 dest
28882 movq %rbx, (%rsi)
28883 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
28884 .Lende:
28885 movq 2*8(%rsp), %rbx
28886 CFI_RESTORE rbx
28887 - movq 3*8(%rsp), %r12
28888 - CFI_RESTORE r12
28889 + movq 3*8(%rsp), %r15
28890 + CFI_RESTORE r15
28891 movq 4*8(%rsp), %r14
28892 CFI_RESTORE r14
28893 movq 5*8(%rsp), %r13
28894 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
28895 CFI_RESTORE rbp
28896 addq $7*8, %rsp
28897 CFI_ADJUST_CFA_OFFSET -7*8
28898 + pax_force_retaddr
28899 ret
28900 CFI_RESTORE_STATE
28901
28902 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28903 index 7609e0e..b449b98 100644
28904 --- a/arch/x86/lib/csum-wrappers_64.c
28905 +++ b/arch/x86/lib/csum-wrappers_64.c
28906 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28907 len -= 2;
28908 }
28909 }
28910 + pax_open_userland();
28911 stac();
28912 - isum = csum_partial_copy_generic((__force const void *)src,
28913 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28914 dst, len, isum, errp, NULL);
28915 clac();
28916 + pax_close_userland();
28917 if (unlikely(*errp))
28918 goto out_err;
28919
28920 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28921 }
28922
28923 *errp = 0;
28924 + pax_open_userland();
28925 stac();
28926 - ret = csum_partial_copy_generic(src, (void __force *)dst,
28927 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
28928 len, isum, NULL, errp);
28929 clac();
28930 + pax_close_userland();
28931 return ret;
28932 }
28933 EXPORT_SYMBOL(csum_partial_copy_to_user);
28934 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28935 index a451235..1daa956 100644
28936 --- a/arch/x86/lib/getuser.S
28937 +++ b/arch/x86/lib/getuser.S
28938 @@ -33,17 +33,40 @@
28939 #include <asm/thread_info.h>
28940 #include <asm/asm.h>
28941 #include <asm/smap.h>
28942 +#include <asm/segment.h>
28943 +#include <asm/pgtable.h>
28944 +#include <asm/alternative-asm.h>
28945 +
28946 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28947 +#define __copyuser_seg gs;
28948 +#else
28949 +#define __copyuser_seg
28950 +#endif
28951
28952 .text
28953 ENTRY(__get_user_1)
28954 CFI_STARTPROC
28955 +
28956 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28957 GET_THREAD_INFO(%_ASM_DX)
28958 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28959 jae bad_get_user
28960 ASM_STAC
28961 -1: movzbl (%_ASM_AX),%edx
28962 +
28963 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28964 + mov pax_user_shadow_base,%_ASM_DX
28965 + cmp %_ASM_DX,%_ASM_AX
28966 + jae 1234f
28967 + add %_ASM_DX,%_ASM_AX
28968 +1234:
28969 +#endif
28970 +
28971 +#endif
28972 +
28973 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
28974 xor %eax,%eax
28975 ASM_CLAC
28976 + pax_force_retaddr
28977 ret
28978 CFI_ENDPROC
28979 ENDPROC(__get_user_1)
28980 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28981 ENTRY(__get_user_2)
28982 CFI_STARTPROC
28983 add $1,%_ASM_AX
28984 +
28985 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28986 jc bad_get_user
28987 GET_THREAD_INFO(%_ASM_DX)
28988 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28989 jae bad_get_user
28990 ASM_STAC
28991 -2: movzwl -1(%_ASM_AX),%edx
28992 +
28993 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28994 + mov pax_user_shadow_base,%_ASM_DX
28995 + cmp %_ASM_DX,%_ASM_AX
28996 + jae 1234f
28997 + add %_ASM_DX,%_ASM_AX
28998 +1234:
28999 +#endif
29000 +
29001 +#endif
29002 +
29003 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29004 xor %eax,%eax
29005 ASM_CLAC
29006 + pax_force_retaddr
29007 ret
29008 CFI_ENDPROC
29009 ENDPROC(__get_user_2)
29010 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29011 ENTRY(__get_user_4)
29012 CFI_STARTPROC
29013 add $3,%_ASM_AX
29014 +
29015 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29016 jc bad_get_user
29017 GET_THREAD_INFO(%_ASM_DX)
29018 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29019 jae bad_get_user
29020 ASM_STAC
29021 -3: movl -3(%_ASM_AX),%edx
29022 +
29023 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29024 + mov pax_user_shadow_base,%_ASM_DX
29025 + cmp %_ASM_DX,%_ASM_AX
29026 + jae 1234f
29027 + add %_ASM_DX,%_ASM_AX
29028 +1234:
29029 +#endif
29030 +
29031 +#endif
29032 +
29033 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29034 xor %eax,%eax
29035 ASM_CLAC
29036 + pax_force_retaddr
29037 ret
29038 CFI_ENDPROC
29039 ENDPROC(__get_user_4)
29040 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29041 GET_THREAD_INFO(%_ASM_DX)
29042 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29043 jae bad_get_user
29044 +
29045 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29046 + mov pax_user_shadow_base,%_ASM_DX
29047 + cmp %_ASM_DX,%_ASM_AX
29048 + jae 1234f
29049 + add %_ASM_DX,%_ASM_AX
29050 +1234:
29051 +#endif
29052 +
29053 ASM_STAC
29054 4: movq -7(%_ASM_AX),%rdx
29055 xor %eax,%eax
29056 ASM_CLAC
29057 + pax_force_retaddr
29058 ret
29059 #else
29060 add $7,%_ASM_AX
29061 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29062 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29063 jae bad_get_user_8
29064 ASM_STAC
29065 -4: movl -7(%_ASM_AX),%edx
29066 -5: movl -3(%_ASM_AX),%ecx
29067 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29068 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29069 xor %eax,%eax
29070 ASM_CLAC
29071 + pax_force_retaddr
29072 ret
29073 #endif
29074 CFI_ENDPROC
29075 @@ -113,6 +175,7 @@ bad_get_user:
29076 xor %edx,%edx
29077 mov $(-EFAULT),%_ASM_AX
29078 ASM_CLAC
29079 + pax_force_retaddr
29080 ret
29081 CFI_ENDPROC
29082 END(bad_get_user)
29083 @@ -124,6 +187,7 @@ bad_get_user_8:
29084 xor %ecx,%ecx
29085 mov $(-EFAULT),%_ASM_AX
29086 ASM_CLAC
29087 + pax_force_retaddr
29088 ret
29089 CFI_ENDPROC
29090 END(bad_get_user_8)
29091 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29092 index 54fcffe..7be149e 100644
29093 --- a/arch/x86/lib/insn.c
29094 +++ b/arch/x86/lib/insn.c
29095 @@ -20,8 +20,10 @@
29096
29097 #ifdef __KERNEL__
29098 #include <linux/string.h>
29099 +#include <asm/pgtable_types.h>
29100 #else
29101 #include <string.h>
29102 +#define ktla_ktva(addr) addr
29103 #endif
29104 #include <asm/inat.h>
29105 #include <asm/insn.h>
29106 @@ -53,8 +55,8 @@
29107 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29108 {
29109 memset(insn, 0, sizeof(*insn));
29110 - insn->kaddr = kaddr;
29111 - insn->next_byte = kaddr;
29112 + insn->kaddr = ktla_ktva(kaddr);
29113 + insn->next_byte = ktla_ktva(kaddr);
29114 insn->x86_64 = x86_64 ? 1 : 0;
29115 insn->opnd_bytes = 4;
29116 if (x86_64)
29117 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29118 index 05a95e7..326f2fa 100644
29119 --- a/arch/x86/lib/iomap_copy_64.S
29120 +++ b/arch/x86/lib/iomap_copy_64.S
29121 @@ -17,6 +17,7 @@
29122
29123 #include <linux/linkage.h>
29124 #include <asm/dwarf2.h>
29125 +#include <asm/alternative-asm.h>
29126
29127 /*
29128 * override generic version in lib/iomap_copy.c
29129 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29130 CFI_STARTPROC
29131 movl %edx,%ecx
29132 rep movsd
29133 + pax_force_retaddr
29134 ret
29135 CFI_ENDPROC
29136 ENDPROC(__iowrite32_copy)
29137 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29138 index 56313a3..0db417e 100644
29139 --- a/arch/x86/lib/memcpy_64.S
29140 +++ b/arch/x86/lib/memcpy_64.S
29141 @@ -24,7 +24,7 @@
29142 * This gets patched over the unrolled variant (below) via the
29143 * alternative instructions framework:
29144 */
29145 - .section .altinstr_replacement, "ax", @progbits
29146 + .section .altinstr_replacement, "a", @progbits
29147 .Lmemcpy_c:
29148 movq %rdi, %rax
29149 movq %rdx, %rcx
29150 @@ -33,6 +33,7 @@
29151 rep movsq
29152 movl %edx, %ecx
29153 rep movsb
29154 + pax_force_retaddr
29155 ret
29156 .Lmemcpy_e:
29157 .previous
29158 @@ -44,11 +45,12 @@
29159 * This gets patched over the unrolled variant (below) via the
29160 * alternative instructions framework:
29161 */
29162 - .section .altinstr_replacement, "ax", @progbits
29163 + .section .altinstr_replacement, "a", @progbits
29164 .Lmemcpy_c_e:
29165 movq %rdi, %rax
29166 movq %rdx, %rcx
29167 rep movsb
29168 + pax_force_retaddr
29169 ret
29170 .Lmemcpy_e_e:
29171 .previous
29172 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29173 movq %r9, 1*8(%rdi)
29174 movq %r10, -2*8(%rdi, %rdx)
29175 movq %r11, -1*8(%rdi, %rdx)
29176 + pax_force_retaddr
29177 retq
29178 .p2align 4
29179 .Lless_16bytes:
29180 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29181 movq -1*8(%rsi, %rdx), %r9
29182 movq %r8, 0*8(%rdi)
29183 movq %r9, -1*8(%rdi, %rdx)
29184 + pax_force_retaddr
29185 retq
29186 .p2align 4
29187 .Lless_8bytes:
29188 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29189 movl -4(%rsi, %rdx), %r8d
29190 movl %ecx, (%rdi)
29191 movl %r8d, -4(%rdi, %rdx)
29192 + pax_force_retaddr
29193 retq
29194 .p2align 4
29195 .Lless_3bytes:
29196 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29197 movb %cl, (%rdi)
29198
29199 .Lend:
29200 + pax_force_retaddr
29201 retq
29202 CFI_ENDPROC
29203 ENDPROC(memcpy)
29204 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29205 index 65268a6..dd1de11 100644
29206 --- a/arch/x86/lib/memmove_64.S
29207 +++ b/arch/x86/lib/memmove_64.S
29208 @@ -202,14 +202,16 @@ ENTRY(memmove)
29209 movb (%rsi), %r11b
29210 movb %r11b, (%rdi)
29211 13:
29212 + pax_force_retaddr
29213 retq
29214 CFI_ENDPROC
29215
29216 - .section .altinstr_replacement,"ax"
29217 + .section .altinstr_replacement,"a"
29218 .Lmemmove_begin_forward_efs:
29219 /* Forward moving data. */
29220 movq %rdx, %rcx
29221 rep movsb
29222 + pax_force_retaddr
29223 retq
29224 .Lmemmove_end_forward_efs:
29225 .previous
29226 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29227 index 2dcb380..2eb79fe 100644
29228 --- a/arch/x86/lib/memset_64.S
29229 +++ b/arch/x86/lib/memset_64.S
29230 @@ -16,7 +16,7 @@
29231 *
29232 * rax original destination
29233 */
29234 - .section .altinstr_replacement, "ax", @progbits
29235 + .section .altinstr_replacement, "a", @progbits
29236 .Lmemset_c:
29237 movq %rdi,%r9
29238 movq %rdx,%rcx
29239 @@ -30,6 +30,7 @@
29240 movl %edx,%ecx
29241 rep stosb
29242 movq %r9,%rax
29243 + pax_force_retaddr
29244 ret
29245 .Lmemset_e:
29246 .previous
29247 @@ -45,13 +46,14 @@
29248 *
29249 * rax original destination
29250 */
29251 - .section .altinstr_replacement, "ax", @progbits
29252 + .section .altinstr_replacement, "a", @progbits
29253 .Lmemset_c_e:
29254 movq %rdi,%r9
29255 movb %sil,%al
29256 movq %rdx,%rcx
29257 rep stosb
29258 movq %r9,%rax
29259 + pax_force_retaddr
29260 ret
29261 .Lmemset_e_e:
29262 .previous
29263 @@ -118,6 +120,7 @@ ENTRY(__memset)
29264
29265 .Lende:
29266 movq %r10,%rax
29267 + pax_force_retaddr
29268 ret
29269
29270 CFI_RESTORE_STATE
29271 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29272 index c9f2d9b..e7fd2c0 100644
29273 --- a/arch/x86/lib/mmx_32.c
29274 +++ b/arch/x86/lib/mmx_32.c
29275 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29276 {
29277 void *p;
29278 int i;
29279 + unsigned long cr0;
29280
29281 if (unlikely(in_interrupt()))
29282 return __memcpy(to, from, len);
29283 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29284 kernel_fpu_begin();
29285
29286 __asm__ __volatile__ (
29287 - "1: prefetch (%0)\n" /* This set is 28 bytes */
29288 - " prefetch 64(%0)\n"
29289 - " prefetch 128(%0)\n"
29290 - " prefetch 192(%0)\n"
29291 - " prefetch 256(%0)\n"
29292 + "1: prefetch (%1)\n" /* This set is 28 bytes */
29293 + " prefetch 64(%1)\n"
29294 + " prefetch 128(%1)\n"
29295 + " prefetch 192(%1)\n"
29296 + " prefetch 256(%1)\n"
29297 "2: \n"
29298 ".section .fixup, \"ax\"\n"
29299 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29300 + "3: \n"
29301 +
29302 +#ifdef CONFIG_PAX_KERNEXEC
29303 + " movl %%cr0, %0\n"
29304 + " movl %0, %%eax\n"
29305 + " andl $0xFFFEFFFF, %%eax\n"
29306 + " movl %%eax, %%cr0\n"
29307 +#endif
29308 +
29309 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29310 +
29311 +#ifdef CONFIG_PAX_KERNEXEC
29312 + " movl %0, %%cr0\n"
29313 +#endif
29314 +
29315 " jmp 2b\n"
29316 ".previous\n"
29317 _ASM_EXTABLE(1b, 3b)
29318 - : : "r" (from));
29319 + : "=&r" (cr0) : "r" (from) : "ax");
29320
29321 for ( ; i > 5; i--) {
29322 __asm__ __volatile__ (
29323 - "1: prefetch 320(%0)\n"
29324 - "2: movq (%0), %%mm0\n"
29325 - " movq 8(%0), %%mm1\n"
29326 - " movq 16(%0), %%mm2\n"
29327 - " movq 24(%0), %%mm3\n"
29328 - " movq %%mm0, (%1)\n"
29329 - " movq %%mm1, 8(%1)\n"
29330 - " movq %%mm2, 16(%1)\n"
29331 - " movq %%mm3, 24(%1)\n"
29332 - " movq 32(%0), %%mm0\n"
29333 - " movq 40(%0), %%mm1\n"
29334 - " movq 48(%0), %%mm2\n"
29335 - " movq 56(%0), %%mm3\n"
29336 - " movq %%mm0, 32(%1)\n"
29337 - " movq %%mm1, 40(%1)\n"
29338 - " movq %%mm2, 48(%1)\n"
29339 - " movq %%mm3, 56(%1)\n"
29340 + "1: prefetch 320(%1)\n"
29341 + "2: movq (%1), %%mm0\n"
29342 + " movq 8(%1), %%mm1\n"
29343 + " movq 16(%1), %%mm2\n"
29344 + " movq 24(%1), %%mm3\n"
29345 + " movq %%mm0, (%2)\n"
29346 + " movq %%mm1, 8(%2)\n"
29347 + " movq %%mm2, 16(%2)\n"
29348 + " movq %%mm3, 24(%2)\n"
29349 + " movq 32(%1), %%mm0\n"
29350 + " movq 40(%1), %%mm1\n"
29351 + " movq 48(%1), %%mm2\n"
29352 + " movq 56(%1), %%mm3\n"
29353 + " movq %%mm0, 32(%2)\n"
29354 + " movq %%mm1, 40(%2)\n"
29355 + " movq %%mm2, 48(%2)\n"
29356 + " movq %%mm3, 56(%2)\n"
29357 ".section .fixup, \"ax\"\n"
29358 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29359 + "3:\n"
29360 +
29361 +#ifdef CONFIG_PAX_KERNEXEC
29362 + " movl %%cr0, %0\n"
29363 + " movl %0, %%eax\n"
29364 + " andl $0xFFFEFFFF, %%eax\n"
29365 + " movl %%eax, %%cr0\n"
29366 +#endif
29367 +
29368 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29369 +
29370 +#ifdef CONFIG_PAX_KERNEXEC
29371 + " movl %0, %%cr0\n"
29372 +#endif
29373 +
29374 " jmp 2b\n"
29375 ".previous\n"
29376 _ASM_EXTABLE(1b, 3b)
29377 - : : "r" (from), "r" (to) : "memory");
29378 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29379
29380 from += 64;
29381 to += 64;
29382 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29383 static void fast_copy_page(void *to, void *from)
29384 {
29385 int i;
29386 + unsigned long cr0;
29387
29388 kernel_fpu_begin();
29389
29390 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29391 * but that is for later. -AV
29392 */
29393 __asm__ __volatile__(
29394 - "1: prefetch (%0)\n"
29395 - " prefetch 64(%0)\n"
29396 - " prefetch 128(%0)\n"
29397 - " prefetch 192(%0)\n"
29398 - " prefetch 256(%0)\n"
29399 + "1: prefetch (%1)\n"
29400 + " prefetch 64(%1)\n"
29401 + " prefetch 128(%1)\n"
29402 + " prefetch 192(%1)\n"
29403 + " prefetch 256(%1)\n"
29404 "2: \n"
29405 ".section .fixup, \"ax\"\n"
29406 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29407 + "3: \n"
29408 +
29409 +#ifdef CONFIG_PAX_KERNEXEC
29410 + " movl %%cr0, %0\n"
29411 + " movl %0, %%eax\n"
29412 + " andl $0xFFFEFFFF, %%eax\n"
29413 + " movl %%eax, %%cr0\n"
29414 +#endif
29415 +
29416 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29417 +
29418 +#ifdef CONFIG_PAX_KERNEXEC
29419 + " movl %0, %%cr0\n"
29420 +#endif
29421 +
29422 " jmp 2b\n"
29423 ".previous\n"
29424 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
29425 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29426
29427 for (i = 0; i < (4096-320)/64; i++) {
29428 __asm__ __volatile__ (
29429 - "1: prefetch 320(%0)\n"
29430 - "2: movq (%0), %%mm0\n"
29431 - " movntq %%mm0, (%1)\n"
29432 - " movq 8(%0), %%mm1\n"
29433 - " movntq %%mm1, 8(%1)\n"
29434 - " movq 16(%0), %%mm2\n"
29435 - " movntq %%mm2, 16(%1)\n"
29436 - " movq 24(%0), %%mm3\n"
29437 - " movntq %%mm3, 24(%1)\n"
29438 - " movq 32(%0), %%mm4\n"
29439 - " movntq %%mm4, 32(%1)\n"
29440 - " movq 40(%0), %%mm5\n"
29441 - " movntq %%mm5, 40(%1)\n"
29442 - " movq 48(%0), %%mm6\n"
29443 - " movntq %%mm6, 48(%1)\n"
29444 - " movq 56(%0), %%mm7\n"
29445 - " movntq %%mm7, 56(%1)\n"
29446 + "1: prefetch 320(%1)\n"
29447 + "2: movq (%1), %%mm0\n"
29448 + " movntq %%mm0, (%2)\n"
29449 + " movq 8(%1), %%mm1\n"
29450 + " movntq %%mm1, 8(%2)\n"
29451 + " movq 16(%1), %%mm2\n"
29452 + " movntq %%mm2, 16(%2)\n"
29453 + " movq 24(%1), %%mm3\n"
29454 + " movntq %%mm3, 24(%2)\n"
29455 + " movq 32(%1), %%mm4\n"
29456 + " movntq %%mm4, 32(%2)\n"
29457 + " movq 40(%1), %%mm5\n"
29458 + " movntq %%mm5, 40(%2)\n"
29459 + " movq 48(%1), %%mm6\n"
29460 + " movntq %%mm6, 48(%2)\n"
29461 + " movq 56(%1), %%mm7\n"
29462 + " movntq %%mm7, 56(%2)\n"
29463 ".section .fixup, \"ax\"\n"
29464 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29465 + "3:\n"
29466 +
29467 +#ifdef CONFIG_PAX_KERNEXEC
29468 + " movl %%cr0, %0\n"
29469 + " movl %0, %%eax\n"
29470 + " andl $0xFFFEFFFF, %%eax\n"
29471 + " movl %%eax, %%cr0\n"
29472 +#endif
29473 +
29474 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29475 +
29476 +#ifdef CONFIG_PAX_KERNEXEC
29477 + " movl %0, %%cr0\n"
29478 +#endif
29479 +
29480 " jmp 2b\n"
29481 ".previous\n"
29482 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
29483 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29484
29485 from += 64;
29486 to += 64;
29487 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
29488 static void fast_copy_page(void *to, void *from)
29489 {
29490 int i;
29491 + unsigned long cr0;
29492
29493 kernel_fpu_begin();
29494
29495 __asm__ __volatile__ (
29496 - "1: prefetch (%0)\n"
29497 - " prefetch 64(%0)\n"
29498 - " prefetch 128(%0)\n"
29499 - " prefetch 192(%0)\n"
29500 - " prefetch 256(%0)\n"
29501 + "1: prefetch (%1)\n"
29502 + " prefetch 64(%1)\n"
29503 + " prefetch 128(%1)\n"
29504 + " prefetch 192(%1)\n"
29505 + " prefetch 256(%1)\n"
29506 "2: \n"
29507 ".section .fixup, \"ax\"\n"
29508 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29509 + "3: \n"
29510 +
29511 +#ifdef CONFIG_PAX_KERNEXEC
29512 + " movl %%cr0, %0\n"
29513 + " movl %0, %%eax\n"
29514 + " andl $0xFFFEFFFF, %%eax\n"
29515 + " movl %%eax, %%cr0\n"
29516 +#endif
29517 +
29518 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29519 +
29520 +#ifdef CONFIG_PAX_KERNEXEC
29521 + " movl %0, %%cr0\n"
29522 +#endif
29523 +
29524 " jmp 2b\n"
29525 ".previous\n"
29526 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
29527 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29528
29529 for (i = 0; i < 4096/64; i++) {
29530 __asm__ __volatile__ (
29531 - "1: prefetch 320(%0)\n"
29532 - "2: movq (%0), %%mm0\n"
29533 - " movq 8(%0), %%mm1\n"
29534 - " movq 16(%0), %%mm2\n"
29535 - " movq 24(%0), %%mm3\n"
29536 - " movq %%mm0, (%1)\n"
29537 - " movq %%mm1, 8(%1)\n"
29538 - " movq %%mm2, 16(%1)\n"
29539 - " movq %%mm3, 24(%1)\n"
29540 - " movq 32(%0), %%mm0\n"
29541 - " movq 40(%0), %%mm1\n"
29542 - " movq 48(%0), %%mm2\n"
29543 - " movq 56(%0), %%mm3\n"
29544 - " movq %%mm0, 32(%1)\n"
29545 - " movq %%mm1, 40(%1)\n"
29546 - " movq %%mm2, 48(%1)\n"
29547 - " movq %%mm3, 56(%1)\n"
29548 + "1: prefetch 320(%1)\n"
29549 + "2: movq (%1), %%mm0\n"
29550 + " movq 8(%1), %%mm1\n"
29551 + " movq 16(%1), %%mm2\n"
29552 + " movq 24(%1), %%mm3\n"
29553 + " movq %%mm0, (%2)\n"
29554 + " movq %%mm1, 8(%2)\n"
29555 + " movq %%mm2, 16(%2)\n"
29556 + " movq %%mm3, 24(%2)\n"
29557 + " movq 32(%1), %%mm0\n"
29558 + " movq 40(%1), %%mm1\n"
29559 + " movq 48(%1), %%mm2\n"
29560 + " movq 56(%1), %%mm3\n"
29561 + " movq %%mm0, 32(%2)\n"
29562 + " movq %%mm1, 40(%2)\n"
29563 + " movq %%mm2, 48(%2)\n"
29564 + " movq %%mm3, 56(%2)\n"
29565 ".section .fixup, \"ax\"\n"
29566 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29567 + "3:\n"
29568 +
29569 +#ifdef CONFIG_PAX_KERNEXEC
29570 + " movl %%cr0, %0\n"
29571 + " movl %0, %%eax\n"
29572 + " andl $0xFFFEFFFF, %%eax\n"
29573 + " movl %%eax, %%cr0\n"
29574 +#endif
29575 +
29576 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29577 +
29578 +#ifdef CONFIG_PAX_KERNEXEC
29579 + " movl %0, %%cr0\n"
29580 +#endif
29581 +
29582 " jmp 2b\n"
29583 ".previous\n"
29584 _ASM_EXTABLE(1b, 3b)
29585 - : : "r" (from), "r" (to) : "memory");
29586 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29587
29588 from += 64;
29589 to += 64;
29590 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
29591 index f6d13ee..d789440 100644
29592 --- a/arch/x86/lib/msr-reg.S
29593 +++ b/arch/x86/lib/msr-reg.S
29594 @@ -3,6 +3,7 @@
29595 #include <asm/dwarf2.h>
29596 #include <asm/asm.h>
29597 #include <asm/msr.h>
29598 +#include <asm/alternative-asm.h>
29599
29600 #ifdef CONFIG_X86_64
29601 /*
29602 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
29603 movl %edi, 28(%r10)
29604 popq_cfi %rbp
29605 popq_cfi %rbx
29606 + pax_force_retaddr
29607 ret
29608 3:
29609 CFI_RESTORE_STATE
29610 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
29611 index fc6ba17..d4d989d 100644
29612 --- a/arch/x86/lib/putuser.S
29613 +++ b/arch/x86/lib/putuser.S
29614 @@ -16,7 +16,9 @@
29615 #include <asm/errno.h>
29616 #include <asm/asm.h>
29617 #include <asm/smap.h>
29618 -
29619 +#include <asm/segment.h>
29620 +#include <asm/pgtable.h>
29621 +#include <asm/alternative-asm.h>
29622
29623 /*
29624 * __put_user_X
29625 @@ -30,57 +32,125 @@
29626 * as they get called from within inline assembly.
29627 */
29628
29629 -#define ENTER CFI_STARTPROC ; \
29630 - GET_THREAD_INFO(%_ASM_BX)
29631 -#define EXIT ASM_CLAC ; \
29632 - ret ; \
29633 +#define ENTER CFI_STARTPROC
29634 +#define EXIT ASM_CLAC ; \
29635 + pax_force_retaddr ; \
29636 + ret ; \
29637 CFI_ENDPROC
29638
29639 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29640 +#define _DEST %_ASM_CX,%_ASM_BX
29641 +#else
29642 +#define _DEST %_ASM_CX
29643 +#endif
29644 +
29645 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29646 +#define __copyuser_seg gs;
29647 +#else
29648 +#define __copyuser_seg
29649 +#endif
29650 +
29651 .text
29652 ENTRY(__put_user_1)
29653 ENTER
29654 +
29655 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29656 + GET_THREAD_INFO(%_ASM_BX)
29657 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
29658 jae bad_put_user
29659 ASM_STAC
29660 -1: movb %al,(%_ASM_CX)
29661 +
29662 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29663 + mov pax_user_shadow_base,%_ASM_BX
29664 + cmp %_ASM_BX,%_ASM_CX
29665 + jb 1234f
29666 + xor %ebx,%ebx
29667 +1234:
29668 +#endif
29669 +
29670 +#endif
29671 +
29672 +1: __copyuser_seg movb %al,(_DEST)
29673 xor %eax,%eax
29674 EXIT
29675 ENDPROC(__put_user_1)
29676
29677 ENTRY(__put_user_2)
29678 ENTER
29679 +
29680 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29681 + GET_THREAD_INFO(%_ASM_BX)
29682 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29683 sub $1,%_ASM_BX
29684 cmp %_ASM_BX,%_ASM_CX
29685 jae bad_put_user
29686 ASM_STAC
29687 -2: movw %ax,(%_ASM_CX)
29688 +
29689 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29690 + mov pax_user_shadow_base,%_ASM_BX
29691 + cmp %_ASM_BX,%_ASM_CX
29692 + jb 1234f
29693 + xor %ebx,%ebx
29694 +1234:
29695 +#endif
29696 +
29697 +#endif
29698 +
29699 +2: __copyuser_seg movw %ax,(_DEST)
29700 xor %eax,%eax
29701 EXIT
29702 ENDPROC(__put_user_2)
29703
29704 ENTRY(__put_user_4)
29705 ENTER
29706 +
29707 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29708 + GET_THREAD_INFO(%_ASM_BX)
29709 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29710 sub $3,%_ASM_BX
29711 cmp %_ASM_BX,%_ASM_CX
29712 jae bad_put_user
29713 ASM_STAC
29714 -3: movl %eax,(%_ASM_CX)
29715 +
29716 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29717 + mov pax_user_shadow_base,%_ASM_BX
29718 + cmp %_ASM_BX,%_ASM_CX
29719 + jb 1234f
29720 + xor %ebx,%ebx
29721 +1234:
29722 +#endif
29723 +
29724 +#endif
29725 +
29726 +3: __copyuser_seg movl %eax,(_DEST)
29727 xor %eax,%eax
29728 EXIT
29729 ENDPROC(__put_user_4)
29730
29731 ENTRY(__put_user_8)
29732 ENTER
29733 +
29734 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29735 + GET_THREAD_INFO(%_ASM_BX)
29736 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29737 sub $7,%_ASM_BX
29738 cmp %_ASM_BX,%_ASM_CX
29739 jae bad_put_user
29740 ASM_STAC
29741 -4: mov %_ASM_AX,(%_ASM_CX)
29742 +
29743 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29744 + mov pax_user_shadow_base,%_ASM_BX
29745 + cmp %_ASM_BX,%_ASM_CX
29746 + jb 1234f
29747 + xor %ebx,%ebx
29748 +1234:
29749 +#endif
29750 +
29751 +#endif
29752 +
29753 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
29754 #ifdef CONFIG_X86_32
29755 -5: movl %edx,4(%_ASM_CX)
29756 +5: __copyuser_seg movl %edx,4(_DEST)
29757 #endif
29758 xor %eax,%eax
29759 EXIT
29760 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29761 index 1cad221..de671ee 100644
29762 --- a/arch/x86/lib/rwlock.S
29763 +++ b/arch/x86/lib/rwlock.S
29764 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29765 FRAME
29766 0: LOCK_PREFIX
29767 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29768 +
29769 +#ifdef CONFIG_PAX_REFCOUNT
29770 + jno 1234f
29771 + LOCK_PREFIX
29772 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29773 + int $4
29774 +1234:
29775 + _ASM_EXTABLE(1234b, 1234b)
29776 +#endif
29777 +
29778 1: rep; nop
29779 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29780 jne 1b
29781 LOCK_PREFIX
29782 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29783 +
29784 +#ifdef CONFIG_PAX_REFCOUNT
29785 + jno 1234f
29786 + LOCK_PREFIX
29787 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29788 + int $4
29789 +1234:
29790 + _ASM_EXTABLE(1234b, 1234b)
29791 +#endif
29792 +
29793 jnz 0b
29794 ENDFRAME
29795 + pax_force_retaddr
29796 ret
29797 CFI_ENDPROC
29798 END(__write_lock_failed)
29799 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29800 FRAME
29801 0: LOCK_PREFIX
29802 READ_LOCK_SIZE(inc) (%__lock_ptr)
29803 +
29804 +#ifdef CONFIG_PAX_REFCOUNT
29805 + jno 1234f
29806 + LOCK_PREFIX
29807 + READ_LOCK_SIZE(dec) (%__lock_ptr)
29808 + int $4
29809 +1234:
29810 + _ASM_EXTABLE(1234b, 1234b)
29811 +#endif
29812 +
29813 1: rep; nop
29814 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29815 js 1b
29816 LOCK_PREFIX
29817 READ_LOCK_SIZE(dec) (%__lock_ptr)
29818 +
29819 +#ifdef CONFIG_PAX_REFCOUNT
29820 + jno 1234f
29821 + LOCK_PREFIX
29822 + READ_LOCK_SIZE(inc) (%__lock_ptr)
29823 + int $4
29824 +1234:
29825 + _ASM_EXTABLE(1234b, 1234b)
29826 +#endif
29827 +
29828 js 0b
29829 ENDFRAME
29830 + pax_force_retaddr
29831 ret
29832 CFI_ENDPROC
29833 END(__read_lock_failed)
29834 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29835 index 5dff5f0..cadebf4 100644
29836 --- a/arch/x86/lib/rwsem.S
29837 +++ b/arch/x86/lib/rwsem.S
29838 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29839 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29840 CFI_RESTORE __ASM_REG(dx)
29841 restore_common_regs
29842 + pax_force_retaddr
29843 ret
29844 CFI_ENDPROC
29845 ENDPROC(call_rwsem_down_read_failed)
29846 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29847 movq %rax,%rdi
29848 call rwsem_down_write_failed
29849 restore_common_regs
29850 + pax_force_retaddr
29851 ret
29852 CFI_ENDPROC
29853 ENDPROC(call_rwsem_down_write_failed)
29854 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29855 movq %rax,%rdi
29856 call rwsem_wake
29857 restore_common_regs
29858 -1: ret
29859 +1: pax_force_retaddr
29860 + ret
29861 CFI_ENDPROC
29862 ENDPROC(call_rwsem_wake)
29863
29864 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29865 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29866 CFI_RESTORE __ASM_REG(dx)
29867 restore_common_regs
29868 + pax_force_retaddr
29869 ret
29870 CFI_ENDPROC
29871 ENDPROC(call_rwsem_downgrade_wake)
29872 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29873 index a63efd6..8149fbe 100644
29874 --- a/arch/x86/lib/thunk_64.S
29875 +++ b/arch/x86/lib/thunk_64.S
29876 @@ -8,6 +8,7 @@
29877 #include <linux/linkage.h>
29878 #include <asm/dwarf2.h>
29879 #include <asm/calling.h>
29880 +#include <asm/alternative-asm.h>
29881
29882 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29883 .macro THUNK name, func, put_ret_addr_in_rdi=0
29884 @@ -15,11 +16,11 @@
29885 \name:
29886 CFI_STARTPROC
29887
29888 - /* this one pushes 9 elems, the next one would be %rIP */
29889 - SAVE_ARGS
29890 + /* this one pushes 15+1 elems, the next one would be %rIP */
29891 + SAVE_ARGS 8
29892
29893 .if \put_ret_addr_in_rdi
29894 - movq_cfi_restore 9*8, rdi
29895 + movq_cfi_restore RIP, rdi
29896 .endif
29897
29898 call \func
29899 @@ -38,8 +39,9 @@
29900
29901 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
29902 CFI_STARTPROC
29903 - SAVE_ARGS
29904 + SAVE_ARGS 8
29905 restore:
29906 - RESTORE_ARGS
29907 + RESTORE_ARGS 1,8
29908 + pax_force_retaddr
29909 ret
29910 CFI_ENDPROC
29911 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29912 index e2f5e21..4b22130 100644
29913 --- a/arch/x86/lib/usercopy_32.c
29914 +++ b/arch/x86/lib/usercopy_32.c
29915 @@ -42,11 +42,13 @@ do { \
29916 int __d0; \
29917 might_fault(); \
29918 __asm__ __volatile__( \
29919 + __COPYUSER_SET_ES \
29920 ASM_STAC "\n" \
29921 "0: rep; stosl\n" \
29922 " movl %2,%0\n" \
29923 "1: rep; stosb\n" \
29924 "2: " ASM_CLAC "\n" \
29925 + __COPYUSER_RESTORE_ES \
29926 ".section .fixup,\"ax\"\n" \
29927 "3: lea 0(%2,%0,4),%0\n" \
29928 " jmp 2b\n" \
29929 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29930
29931 #ifdef CONFIG_X86_INTEL_USERCOPY
29932 static unsigned long
29933 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
29934 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29935 {
29936 int d0, d1;
29937 __asm__ __volatile__(
29938 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29939 " .align 2,0x90\n"
29940 "3: movl 0(%4), %%eax\n"
29941 "4: movl 4(%4), %%edx\n"
29942 - "5: movl %%eax, 0(%3)\n"
29943 - "6: movl %%edx, 4(%3)\n"
29944 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29945 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29946 "7: movl 8(%4), %%eax\n"
29947 "8: movl 12(%4),%%edx\n"
29948 - "9: movl %%eax, 8(%3)\n"
29949 - "10: movl %%edx, 12(%3)\n"
29950 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29951 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29952 "11: movl 16(%4), %%eax\n"
29953 "12: movl 20(%4), %%edx\n"
29954 - "13: movl %%eax, 16(%3)\n"
29955 - "14: movl %%edx, 20(%3)\n"
29956 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29957 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29958 "15: movl 24(%4), %%eax\n"
29959 "16: movl 28(%4), %%edx\n"
29960 - "17: movl %%eax, 24(%3)\n"
29961 - "18: movl %%edx, 28(%3)\n"
29962 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29963 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29964 "19: movl 32(%4), %%eax\n"
29965 "20: movl 36(%4), %%edx\n"
29966 - "21: movl %%eax, 32(%3)\n"
29967 - "22: movl %%edx, 36(%3)\n"
29968 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29969 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29970 "23: movl 40(%4), %%eax\n"
29971 "24: movl 44(%4), %%edx\n"
29972 - "25: movl %%eax, 40(%3)\n"
29973 - "26: movl %%edx, 44(%3)\n"
29974 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29975 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29976 "27: movl 48(%4), %%eax\n"
29977 "28: movl 52(%4), %%edx\n"
29978 - "29: movl %%eax, 48(%3)\n"
29979 - "30: movl %%edx, 52(%3)\n"
29980 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29981 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29982 "31: movl 56(%4), %%eax\n"
29983 "32: movl 60(%4), %%edx\n"
29984 - "33: movl %%eax, 56(%3)\n"
29985 - "34: movl %%edx, 60(%3)\n"
29986 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29987 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29988 " addl $-64, %0\n"
29989 " addl $64, %4\n"
29990 " addl $64, %3\n"
29991 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29992 " shrl $2, %0\n"
29993 " andl $3, %%eax\n"
29994 " cld\n"
29995 + __COPYUSER_SET_ES
29996 "99: rep; movsl\n"
29997 "36: movl %%eax, %0\n"
29998 "37: rep; movsb\n"
29999 "100:\n"
30000 + __COPYUSER_RESTORE_ES
30001 + ".section .fixup,\"ax\"\n"
30002 + "101: lea 0(%%eax,%0,4),%0\n"
30003 + " jmp 100b\n"
30004 + ".previous\n"
30005 + _ASM_EXTABLE(1b,100b)
30006 + _ASM_EXTABLE(2b,100b)
30007 + _ASM_EXTABLE(3b,100b)
30008 + _ASM_EXTABLE(4b,100b)
30009 + _ASM_EXTABLE(5b,100b)
30010 + _ASM_EXTABLE(6b,100b)
30011 + _ASM_EXTABLE(7b,100b)
30012 + _ASM_EXTABLE(8b,100b)
30013 + _ASM_EXTABLE(9b,100b)
30014 + _ASM_EXTABLE(10b,100b)
30015 + _ASM_EXTABLE(11b,100b)
30016 + _ASM_EXTABLE(12b,100b)
30017 + _ASM_EXTABLE(13b,100b)
30018 + _ASM_EXTABLE(14b,100b)
30019 + _ASM_EXTABLE(15b,100b)
30020 + _ASM_EXTABLE(16b,100b)
30021 + _ASM_EXTABLE(17b,100b)
30022 + _ASM_EXTABLE(18b,100b)
30023 + _ASM_EXTABLE(19b,100b)
30024 + _ASM_EXTABLE(20b,100b)
30025 + _ASM_EXTABLE(21b,100b)
30026 + _ASM_EXTABLE(22b,100b)
30027 + _ASM_EXTABLE(23b,100b)
30028 + _ASM_EXTABLE(24b,100b)
30029 + _ASM_EXTABLE(25b,100b)
30030 + _ASM_EXTABLE(26b,100b)
30031 + _ASM_EXTABLE(27b,100b)
30032 + _ASM_EXTABLE(28b,100b)
30033 + _ASM_EXTABLE(29b,100b)
30034 + _ASM_EXTABLE(30b,100b)
30035 + _ASM_EXTABLE(31b,100b)
30036 + _ASM_EXTABLE(32b,100b)
30037 + _ASM_EXTABLE(33b,100b)
30038 + _ASM_EXTABLE(34b,100b)
30039 + _ASM_EXTABLE(35b,100b)
30040 + _ASM_EXTABLE(36b,100b)
30041 + _ASM_EXTABLE(37b,100b)
30042 + _ASM_EXTABLE(99b,101b)
30043 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30044 + : "1"(to), "2"(from), "0"(size)
30045 + : "eax", "edx", "memory");
30046 + return size;
30047 +}
30048 +
30049 +static unsigned long
30050 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30051 +{
30052 + int d0, d1;
30053 + __asm__ __volatile__(
30054 + " .align 2,0x90\n"
30055 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30056 + " cmpl $67, %0\n"
30057 + " jbe 3f\n"
30058 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30059 + " .align 2,0x90\n"
30060 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30061 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30062 + "5: movl %%eax, 0(%3)\n"
30063 + "6: movl %%edx, 4(%3)\n"
30064 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30065 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30066 + "9: movl %%eax, 8(%3)\n"
30067 + "10: movl %%edx, 12(%3)\n"
30068 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30069 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30070 + "13: movl %%eax, 16(%3)\n"
30071 + "14: movl %%edx, 20(%3)\n"
30072 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30073 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30074 + "17: movl %%eax, 24(%3)\n"
30075 + "18: movl %%edx, 28(%3)\n"
30076 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30077 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30078 + "21: movl %%eax, 32(%3)\n"
30079 + "22: movl %%edx, 36(%3)\n"
30080 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30081 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30082 + "25: movl %%eax, 40(%3)\n"
30083 + "26: movl %%edx, 44(%3)\n"
30084 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30085 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30086 + "29: movl %%eax, 48(%3)\n"
30087 + "30: movl %%edx, 52(%3)\n"
30088 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30089 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30090 + "33: movl %%eax, 56(%3)\n"
30091 + "34: movl %%edx, 60(%3)\n"
30092 + " addl $-64, %0\n"
30093 + " addl $64, %4\n"
30094 + " addl $64, %3\n"
30095 + " cmpl $63, %0\n"
30096 + " ja 1b\n"
30097 + "35: movl %0, %%eax\n"
30098 + " shrl $2, %0\n"
30099 + " andl $3, %%eax\n"
30100 + " cld\n"
30101 + "99: rep; "__copyuser_seg" movsl\n"
30102 + "36: movl %%eax, %0\n"
30103 + "37: rep; "__copyuser_seg" movsb\n"
30104 + "100:\n"
30105 ".section .fixup,\"ax\"\n"
30106 "101: lea 0(%%eax,%0,4),%0\n"
30107 " jmp 100b\n"
30108 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30109 int d0, d1;
30110 __asm__ __volatile__(
30111 " .align 2,0x90\n"
30112 - "0: movl 32(%4), %%eax\n"
30113 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30114 " cmpl $67, %0\n"
30115 " jbe 2f\n"
30116 - "1: movl 64(%4), %%eax\n"
30117 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30118 " .align 2,0x90\n"
30119 - "2: movl 0(%4), %%eax\n"
30120 - "21: movl 4(%4), %%edx\n"
30121 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30122 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30123 " movl %%eax, 0(%3)\n"
30124 " movl %%edx, 4(%3)\n"
30125 - "3: movl 8(%4), %%eax\n"
30126 - "31: movl 12(%4),%%edx\n"
30127 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30128 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30129 " movl %%eax, 8(%3)\n"
30130 " movl %%edx, 12(%3)\n"
30131 - "4: movl 16(%4), %%eax\n"
30132 - "41: movl 20(%4), %%edx\n"
30133 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30134 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30135 " movl %%eax, 16(%3)\n"
30136 " movl %%edx, 20(%3)\n"
30137 - "10: movl 24(%4), %%eax\n"
30138 - "51: movl 28(%4), %%edx\n"
30139 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30140 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30141 " movl %%eax, 24(%3)\n"
30142 " movl %%edx, 28(%3)\n"
30143 - "11: movl 32(%4), %%eax\n"
30144 - "61: movl 36(%4), %%edx\n"
30145 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30146 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30147 " movl %%eax, 32(%3)\n"
30148 " movl %%edx, 36(%3)\n"
30149 - "12: movl 40(%4), %%eax\n"
30150 - "71: movl 44(%4), %%edx\n"
30151 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30152 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30153 " movl %%eax, 40(%3)\n"
30154 " movl %%edx, 44(%3)\n"
30155 - "13: movl 48(%4), %%eax\n"
30156 - "81: movl 52(%4), %%edx\n"
30157 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30158 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30159 " movl %%eax, 48(%3)\n"
30160 " movl %%edx, 52(%3)\n"
30161 - "14: movl 56(%4), %%eax\n"
30162 - "91: movl 60(%4), %%edx\n"
30163 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30164 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30165 " movl %%eax, 56(%3)\n"
30166 " movl %%edx, 60(%3)\n"
30167 " addl $-64, %0\n"
30168 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30169 " shrl $2, %0\n"
30170 " andl $3, %%eax\n"
30171 " cld\n"
30172 - "6: rep; movsl\n"
30173 + "6: rep; "__copyuser_seg" movsl\n"
30174 " movl %%eax,%0\n"
30175 - "7: rep; movsb\n"
30176 + "7: rep; "__copyuser_seg" movsb\n"
30177 "8:\n"
30178 ".section .fixup,\"ax\"\n"
30179 "9: lea 0(%%eax,%0,4),%0\n"
30180 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30181
30182 __asm__ __volatile__(
30183 " .align 2,0x90\n"
30184 - "0: movl 32(%4), %%eax\n"
30185 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30186 " cmpl $67, %0\n"
30187 " jbe 2f\n"
30188 - "1: movl 64(%4), %%eax\n"
30189 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30190 " .align 2,0x90\n"
30191 - "2: movl 0(%4), %%eax\n"
30192 - "21: movl 4(%4), %%edx\n"
30193 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30194 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30195 " movnti %%eax, 0(%3)\n"
30196 " movnti %%edx, 4(%3)\n"
30197 - "3: movl 8(%4), %%eax\n"
30198 - "31: movl 12(%4),%%edx\n"
30199 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30200 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30201 " movnti %%eax, 8(%3)\n"
30202 " movnti %%edx, 12(%3)\n"
30203 - "4: movl 16(%4), %%eax\n"
30204 - "41: movl 20(%4), %%edx\n"
30205 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30206 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30207 " movnti %%eax, 16(%3)\n"
30208 " movnti %%edx, 20(%3)\n"
30209 - "10: movl 24(%4), %%eax\n"
30210 - "51: movl 28(%4), %%edx\n"
30211 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30212 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30213 " movnti %%eax, 24(%3)\n"
30214 " movnti %%edx, 28(%3)\n"
30215 - "11: movl 32(%4), %%eax\n"
30216 - "61: movl 36(%4), %%edx\n"
30217 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30218 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30219 " movnti %%eax, 32(%3)\n"
30220 " movnti %%edx, 36(%3)\n"
30221 - "12: movl 40(%4), %%eax\n"
30222 - "71: movl 44(%4), %%edx\n"
30223 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30224 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30225 " movnti %%eax, 40(%3)\n"
30226 " movnti %%edx, 44(%3)\n"
30227 - "13: movl 48(%4), %%eax\n"
30228 - "81: movl 52(%4), %%edx\n"
30229 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30230 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30231 " movnti %%eax, 48(%3)\n"
30232 " movnti %%edx, 52(%3)\n"
30233 - "14: movl 56(%4), %%eax\n"
30234 - "91: movl 60(%4), %%edx\n"
30235 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30236 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30237 " movnti %%eax, 56(%3)\n"
30238 " movnti %%edx, 60(%3)\n"
30239 " addl $-64, %0\n"
30240 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30241 " shrl $2, %0\n"
30242 " andl $3, %%eax\n"
30243 " cld\n"
30244 - "6: rep; movsl\n"
30245 + "6: rep; "__copyuser_seg" movsl\n"
30246 " movl %%eax,%0\n"
30247 - "7: rep; movsb\n"
30248 + "7: rep; "__copyuser_seg" movsb\n"
30249 "8:\n"
30250 ".section .fixup,\"ax\"\n"
30251 "9: lea 0(%%eax,%0,4),%0\n"
30252 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30253
30254 __asm__ __volatile__(
30255 " .align 2,0x90\n"
30256 - "0: movl 32(%4), %%eax\n"
30257 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30258 " cmpl $67, %0\n"
30259 " jbe 2f\n"
30260 - "1: movl 64(%4), %%eax\n"
30261 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30262 " .align 2,0x90\n"
30263 - "2: movl 0(%4), %%eax\n"
30264 - "21: movl 4(%4), %%edx\n"
30265 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30266 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30267 " movnti %%eax, 0(%3)\n"
30268 " movnti %%edx, 4(%3)\n"
30269 - "3: movl 8(%4), %%eax\n"
30270 - "31: movl 12(%4),%%edx\n"
30271 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30272 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30273 " movnti %%eax, 8(%3)\n"
30274 " movnti %%edx, 12(%3)\n"
30275 - "4: movl 16(%4), %%eax\n"
30276 - "41: movl 20(%4), %%edx\n"
30277 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30278 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30279 " movnti %%eax, 16(%3)\n"
30280 " movnti %%edx, 20(%3)\n"
30281 - "10: movl 24(%4), %%eax\n"
30282 - "51: movl 28(%4), %%edx\n"
30283 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30284 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30285 " movnti %%eax, 24(%3)\n"
30286 " movnti %%edx, 28(%3)\n"
30287 - "11: movl 32(%4), %%eax\n"
30288 - "61: movl 36(%4), %%edx\n"
30289 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30290 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30291 " movnti %%eax, 32(%3)\n"
30292 " movnti %%edx, 36(%3)\n"
30293 - "12: movl 40(%4), %%eax\n"
30294 - "71: movl 44(%4), %%edx\n"
30295 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30296 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30297 " movnti %%eax, 40(%3)\n"
30298 " movnti %%edx, 44(%3)\n"
30299 - "13: movl 48(%4), %%eax\n"
30300 - "81: movl 52(%4), %%edx\n"
30301 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30302 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30303 " movnti %%eax, 48(%3)\n"
30304 " movnti %%edx, 52(%3)\n"
30305 - "14: movl 56(%4), %%eax\n"
30306 - "91: movl 60(%4), %%edx\n"
30307 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30308 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30309 " movnti %%eax, 56(%3)\n"
30310 " movnti %%edx, 60(%3)\n"
30311 " addl $-64, %0\n"
30312 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30313 " shrl $2, %0\n"
30314 " andl $3, %%eax\n"
30315 " cld\n"
30316 - "6: rep; movsl\n"
30317 + "6: rep; "__copyuser_seg" movsl\n"
30318 " movl %%eax,%0\n"
30319 - "7: rep; movsb\n"
30320 + "7: rep; "__copyuser_seg" movsb\n"
30321 "8:\n"
30322 ".section .fixup,\"ax\"\n"
30323 "9: lea 0(%%eax,%0,4),%0\n"
30324 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30325 */
30326 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30327 unsigned long size);
30328 -unsigned long __copy_user_intel(void __user *to, const void *from,
30329 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30330 + unsigned long size);
30331 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30332 unsigned long size);
30333 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30334 const void __user *from, unsigned long size);
30335 #endif /* CONFIG_X86_INTEL_USERCOPY */
30336
30337 /* Generic arbitrary sized copy. */
30338 -#define __copy_user(to, from, size) \
30339 +#define __copy_user(to, from, size, prefix, set, restore) \
30340 do { \
30341 int __d0, __d1, __d2; \
30342 __asm__ __volatile__( \
30343 + set \
30344 " cmp $7,%0\n" \
30345 " jbe 1f\n" \
30346 " movl %1,%0\n" \
30347 " negl %0\n" \
30348 " andl $7,%0\n" \
30349 " subl %0,%3\n" \
30350 - "4: rep; movsb\n" \
30351 + "4: rep; "prefix"movsb\n" \
30352 " movl %3,%0\n" \
30353 " shrl $2,%0\n" \
30354 " andl $3,%3\n" \
30355 " .align 2,0x90\n" \
30356 - "0: rep; movsl\n" \
30357 + "0: rep; "prefix"movsl\n" \
30358 " movl %3,%0\n" \
30359 - "1: rep; movsb\n" \
30360 + "1: rep; "prefix"movsb\n" \
30361 "2:\n" \
30362 + restore \
30363 ".section .fixup,\"ax\"\n" \
30364 "5: addl %3,%0\n" \
30365 " jmp 2b\n" \
30366 @@ -538,14 +650,14 @@ do { \
30367 " negl %0\n" \
30368 " andl $7,%0\n" \
30369 " subl %0,%3\n" \
30370 - "4: rep; movsb\n" \
30371 + "4: rep; "__copyuser_seg"movsb\n" \
30372 " movl %3,%0\n" \
30373 " shrl $2,%0\n" \
30374 " andl $3,%3\n" \
30375 " .align 2,0x90\n" \
30376 - "0: rep; movsl\n" \
30377 + "0: rep; "__copyuser_seg"movsl\n" \
30378 " movl %3,%0\n" \
30379 - "1: rep; movsb\n" \
30380 + "1: rep; "__copyuser_seg"movsb\n" \
30381 "2:\n" \
30382 ".section .fixup,\"ax\"\n" \
30383 "5: addl %3,%0\n" \
30384 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30385 {
30386 stac();
30387 if (movsl_is_ok(to, from, n))
30388 - __copy_user(to, from, n);
30389 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30390 else
30391 - n = __copy_user_intel(to, from, n);
30392 + n = __generic_copy_to_user_intel(to, from, n);
30393 clac();
30394 return n;
30395 }
30396 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30397 {
30398 stac();
30399 if (movsl_is_ok(to, from, n))
30400 - __copy_user(to, from, n);
30401 + __copy_user(to, from, n, __copyuser_seg, "", "");
30402 else
30403 - n = __copy_user_intel((void __user *)to,
30404 - (const void *)from, n);
30405 + n = __generic_copy_from_user_intel(to, from, n);
30406 clac();
30407 return n;
30408 }
30409 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30410 if (n > 64 && cpu_has_xmm2)
30411 n = __copy_user_intel_nocache(to, from, n);
30412 else
30413 - __copy_user(to, from, n);
30414 + __copy_user(to, from, n, __copyuser_seg, "", "");
30415 #else
30416 - __copy_user(to, from, n);
30417 + __copy_user(to, from, n, __copyuser_seg, "", "");
30418 #endif
30419 clac();
30420 return n;
30421 }
30422 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30423
30424 -/**
30425 - * copy_to_user: - Copy a block of data into user space.
30426 - * @to: Destination address, in user space.
30427 - * @from: Source address, in kernel space.
30428 - * @n: Number of bytes to copy.
30429 - *
30430 - * Context: User context only. This function may sleep.
30431 - *
30432 - * Copy data from kernel space to user space.
30433 - *
30434 - * Returns number of bytes that could not be copied.
30435 - * On success, this will be zero.
30436 - */
30437 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
30438 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30439 +void __set_fs(mm_segment_t x)
30440 {
30441 - if (access_ok(VERIFY_WRITE, to, n))
30442 - n = __copy_to_user(to, from, n);
30443 - return n;
30444 + switch (x.seg) {
30445 + case 0:
30446 + loadsegment(gs, 0);
30447 + break;
30448 + case TASK_SIZE_MAX:
30449 + loadsegment(gs, __USER_DS);
30450 + break;
30451 + case -1UL:
30452 + loadsegment(gs, __KERNEL_DS);
30453 + break;
30454 + default:
30455 + BUG();
30456 + }
30457 }
30458 -EXPORT_SYMBOL(_copy_to_user);
30459 +EXPORT_SYMBOL(__set_fs);
30460
30461 -/**
30462 - * copy_from_user: - Copy a block of data from user space.
30463 - * @to: Destination address, in kernel space.
30464 - * @from: Source address, in user space.
30465 - * @n: Number of bytes to copy.
30466 - *
30467 - * Context: User context only. This function may sleep.
30468 - *
30469 - * Copy data from user space to kernel space.
30470 - *
30471 - * Returns number of bytes that could not be copied.
30472 - * On success, this will be zero.
30473 - *
30474 - * If some data could not be copied, this function will pad the copied
30475 - * data to the requested size using zero bytes.
30476 - */
30477 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
30478 +void set_fs(mm_segment_t x)
30479 {
30480 - if (access_ok(VERIFY_READ, from, n))
30481 - n = __copy_from_user(to, from, n);
30482 - else
30483 - memset(to, 0, n);
30484 - return n;
30485 + current_thread_info()->addr_limit = x;
30486 + __set_fs(x);
30487 }
30488 -EXPORT_SYMBOL(_copy_from_user);
30489 +EXPORT_SYMBOL(set_fs);
30490 +#endif
30491 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
30492 index c905e89..01ab928 100644
30493 --- a/arch/x86/lib/usercopy_64.c
30494 +++ b/arch/x86/lib/usercopy_64.c
30495 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30496 might_fault();
30497 /* no memory constraint because it doesn't change any memory gcc knows
30498 about */
30499 + pax_open_userland();
30500 stac();
30501 asm volatile(
30502 " testq %[size8],%[size8]\n"
30503 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30504 _ASM_EXTABLE(0b,3b)
30505 _ASM_EXTABLE(1b,2b)
30506 : [size8] "=&c"(size), [dst] "=&D" (__d0)
30507 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
30508 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
30509 [zero] "r" (0UL), [eight] "r" (8UL));
30510 clac();
30511 + pax_close_userland();
30512 return size;
30513 }
30514 EXPORT_SYMBOL(__clear_user);
30515 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
30516 }
30517 EXPORT_SYMBOL(clear_user);
30518
30519 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
30520 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
30521 {
30522 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
30523 - return copy_user_generic((__force void *)to, (__force void *)from, len);
30524 - }
30525 - return len;
30526 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
30527 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
30528 + return len;
30529 }
30530 EXPORT_SYMBOL(copy_in_user);
30531
30532 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
30533 * it is not necessary to optimize tail handling.
30534 */
30535 __visible unsigned long
30536 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30537 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
30538 {
30539 char c;
30540 unsigned zero_len;
30541
30542 + clac();
30543 + pax_close_userland();
30544 for (; len; --len, to++) {
30545 if (__get_user_nocheck(c, from++, sizeof(char)))
30546 break;
30547 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30548 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
30549 if (__put_user_nocheck(c, to++, sizeof(char)))
30550 break;
30551 - clac();
30552 return len;
30553 }
30554 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
30555 index 6a19ad9..1c48f9a 100644
30556 --- a/arch/x86/mm/Makefile
30557 +++ b/arch/x86/mm/Makefile
30558 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
30559 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
30560
30561 obj-$(CONFIG_MEMTEST) += memtest.o
30562 +
30563 +quote:="
30564 +obj-$(CONFIG_X86_64) += uderef_64.o
30565 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
30566 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
30567 index 903ec1e..c4166b2 100644
30568 --- a/arch/x86/mm/extable.c
30569 +++ b/arch/x86/mm/extable.c
30570 @@ -6,12 +6,24 @@
30571 static inline unsigned long
30572 ex_insn_addr(const struct exception_table_entry *x)
30573 {
30574 - return (unsigned long)&x->insn + x->insn;
30575 + unsigned long reloc = 0;
30576 +
30577 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30578 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30579 +#endif
30580 +
30581 + return (unsigned long)&x->insn + x->insn + reloc;
30582 }
30583 static inline unsigned long
30584 ex_fixup_addr(const struct exception_table_entry *x)
30585 {
30586 - return (unsigned long)&x->fixup + x->fixup;
30587 + unsigned long reloc = 0;
30588 +
30589 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30590 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30591 +#endif
30592 +
30593 + return (unsigned long)&x->fixup + x->fixup + reloc;
30594 }
30595
30596 int fixup_exception(struct pt_regs *regs)
30597 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
30598 unsigned long new_ip;
30599
30600 #ifdef CONFIG_PNPBIOS
30601 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
30602 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
30603 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
30604 extern u32 pnp_bios_is_utter_crap;
30605 pnp_bios_is_utter_crap = 1;
30606 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
30607 i += 4;
30608 p->fixup -= i;
30609 i += 4;
30610 +
30611 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30612 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
30613 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30614 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30615 +#endif
30616 +
30617 }
30618 }
30619
30620 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
30621 index 9d591c8..2e61790 100644
30622 --- a/arch/x86/mm/fault.c
30623 +++ b/arch/x86/mm/fault.c
30624 @@ -14,11 +14,18 @@
30625 #include <linux/hugetlb.h> /* hstate_index_to_shift */
30626 #include <linux/prefetch.h> /* prefetchw */
30627 #include <linux/context_tracking.h> /* exception_enter(), ... */
30628 +#include <linux/unistd.h>
30629 +#include <linux/compiler.h>
30630
30631 #include <asm/traps.h> /* dotraplinkage, ... */
30632 #include <asm/pgalloc.h> /* pgd_*(), ... */
30633 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
30634 #include <asm/fixmap.h> /* VSYSCALL_START */
30635 +#include <asm/tlbflush.h>
30636 +
30637 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30638 +#include <asm/stacktrace.h>
30639 +#endif
30640
30641 #define CREATE_TRACE_POINTS
30642 #include <asm/trace/exceptions.h>
30643 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
30644 int ret = 0;
30645
30646 /* kprobe_running() needs smp_processor_id() */
30647 - if (kprobes_built_in() && !user_mode_vm(regs)) {
30648 + if (kprobes_built_in() && !user_mode(regs)) {
30649 preempt_disable();
30650 if (kprobe_running() && kprobe_fault_handler(regs, 14))
30651 ret = 1;
30652 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
30653 return !instr_lo || (instr_lo>>1) == 1;
30654 case 0x00:
30655 /* Prefetch instruction is 0x0F0D or 0x0F18 */
30656 - if (probe_kernel_address(instr, opcode))
30657 + if (user_mode(regs)) {
30658 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30659 + return 0;
30660 + } else if (probe_kernel_address(instr, opcode))
30661 return 0;
30662
30663 *prefetch = (instr_lo == 0xF) &&
30664 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
30665 while (instr < max_instr) {
30666 unsigned char opcode;
30667
30668 - if (probe_kernel_address(instr, opcode))
30669 + if (user_mode(regs)) {
30670 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30671 + break;
30672 + } else if (probe_kernel_address(instr, opcode))
30673 break;
30674
30675 instr++;
30676 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
30677 force_sig_info(si_signo, &info, tsk);
30678 }
30679
30680 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30681 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
30682 +#endif
30683 +
30684 +#ifdef CONFIG_PAX_EMUTRAMP
30685 +static int pax_handle_fetch_fault(struct pt_regs *regs);
30686 +#endif
30687 +
30688 +#ifdef CONFIG_PAX_PAGEEXEC
30689 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
30690 +{
30691 + pgd_t *pgd;
30692 + pud_t *pud;
30693 + pmd_t *pmd;
30694 +
30695 + pgd = pgd_offset(mm, address);
30696 + if (!pgd_present(*pgd))
30697 + return NULL;
30698 + pud = pud_offset(pgd, address);
30699 + if (!pud_present(*pud))
30700 + return NULL;
30701 + pmd = pmd_offset(pud, address);
30702 + if (!pmd_present(*pmd))
30703 + return NULL;
30704 + return pmd;
30705 +}
30706 +#endif
30707 +
30708 DEFINE_SPINLOCK(pgd_lock);
30709 LIST_HEAD(pgd_list);
30710
30711 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
30712 for (address = VMALLOC_START & PMD_MASK;
30713 address >= TASK_SIZE && address < FIXADDR_TOP;
30714 address += PMD_SIZE) {
30715 +
30716 +#ifdef CONFIG_PAX_PER_CPU_PGD
30717 + unsigned long cpu;
30718 +#else
30719 struct page *page;
30720 +#endif
30721
30722 spin_lock(&pgd_lock);
30723 +
30724 +#ifdef CONFIG_PAX_PER_CPU_PGD
30725 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30726 + pgd_t *pgd = get_cpu_pgd(cpu, user);
30727 + pmd_t *ret;
30728 +
30729 + ret = vmalloc_sync_one(pgd, address);
30730 + if (!ret)
30731 + break;
30732 + pgd = get_cpu_pgd(cpu, kernel);
30733 +#else
30734 list_for_each_entry(page, &pgd_list, lru) {
30735 + pgd_t *pgd;
30736 spinlock_t *pgt_lock;
30737 pmd_t *ret;
30738
30739 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
30740 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30741
30742 spin_lock(pgt_lock);
30743 - ret = vmalloc_sync_one(page_address(page), address);
30744 + pgd = page_address(page);
30745 +#endif
30746 +
30747 + ret = vmalloc_sync_one(pgd, address);
30748 +
30749 +#ifndef CONFIG_PAX_PER_CPU_PGD
30750 spin_unlock(pgt_lock);
30751 +#endif
30752
30753 if (!ret)
30754 break;
30755 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30756 * an interrupt in the middle of a task switch..
30757 */
30758 pgd_paddr = read_cr3();
30759 +
30760 +#ifdef CONFIG_PAX_PER_CPU_PGD
30761 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30762 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30763 +#endif
30764 +
30765 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30766 if (!pmd_k)
30767 return -1;
30768 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30769 * happen within a race in page table update. In the later
30770 * case just flush:
30771 */
30772 - pgd = pgd_offset(current->active_mm, address);
30773 +
30774 pgd_ref = pgd_offset_k(address);
30775 if (pgd_none(*pgd_ref))
30776 return -1;
30777
30778 +#ifdef CONFIG_PAX_PER_CPU_PGD
30779 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30780 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30781 + if (pgd_none(*pgd)) {
30782 + set_pgd(pgd, *pgd_ref);
30783 + arch_flush_lazy_mmu_mode();
30784 + } else {
30785 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30786 + }
30787 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30788 +#else
30789 + pgd = pgd_offset(current->active_mm, address);
30790 +#endif
30791 +
30792 if (pgd_none(*pgd)) {
30793 set_pgd(pgd, *pgd_ref);
30794 arch_flush_lazy_mmu_mode();
30795 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30796 static int is_errata100(struct pt_regs *regs, unsigned long address)
30797 {
30798 #ifdef CONFIG_X86_64
30799 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30800 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30801 return 1;
30802 #endif
30803 return 0;
30804 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30805 }
30806
30807 static const char nx_warning[] = KERN_CRIT
30808 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30809 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30810
30811 static void
30812 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30813 @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30814 if (!oops_may_print())
30815 return;
30816
30817 - if (error_code & PF_INSTR) {
30818 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30819 unsigned int level;
30820
30821 pte_t *pte = lookup_address(address, &level);
30822
30823 if (pte && pte_present(*pte) && !pte_exec(*pte))
30824 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30825 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30826 }
30827
30828 +#ifdef CONFIG_PAX_KERNEXEC
30829 + if (init_mm.start_code <= address && address < init_mm.end_code) {
30830 + if (current->signal->curr_ip)
30831 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30832 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
30833 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30834 + else
30835 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30836 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30837 + }
30838 +#endif
30839 +
30840 printk(KERN_ALERT "BUG: unable to handle kernel ");
30841 if (address < PAGE_SIZE)
30842 printk(KERN_CONT "NULL pointer dereference");
30843 @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30844 return;
30845 }
30846 #endif
30847 +
30848 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30849 + if (pax_is_fetch_fault(regs, error_code, address)) {
30850 +
30851 +#ifdef CONFIG_PAX_EMUTRAMP
30852 + switch (pax_handle_fetch_fault(regs)) {
30853 + case 2:
30854 + return;
30855 + }
30856 +#endif
30857 +
30858 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30859 + do_group_exit(SIGKILL);
30860 + }
30861 +#endif
30862 +
30863 /* Kernel addresses are always protection faults: */
30864 if (address >= TASK_SIZE)
30865 error_code |= PF_PROT;
30866 @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30867 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30868 printk(KERN_ERR
30869 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30870 - tsk->comm, tsk->pid, address);
30871 + tsk->comm, task_pid_nr(tsk), address);
30872 code = BUS_MCEERR_AR;
30873 }
30874 #endif
30875 @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30876 return 1;
30877 }
30878
30879 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30880 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30881 +{
30882 + pte_t *pte;
30883 + pmd_t *pmd;
30884 + spinlock_t *ptl;
30885 + unsigned char pte_mask;
30886 +
30887 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30888 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
30889 + return 0;
30890 +
30891 + /* PaX: it's our fault, let's handle it if we can */
30892 +
30893 + /* PaX: take a look at read faults before acquiring any locks */
30894 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30895 + /* instruction fetch attempt from a protected page in user mode */
30896 + up_read(&mm->mmap_sem);
30897 +
30898 +#ifdef CONFIG_PAX_EMUTRAMP
30899 + switch (pax_handle_fetch_fault(regs)) {
30900 + case 2:
30901 + return 1;
30902 + }
30903 +#endif
30904 +
30905 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30906 + do_group_exit(SIGKILL);
30907 + }
30908 +
30909 + pmd = pax_get_pmd(mm, address);
30910 + if (unlikely(!pmd))
30911 + return 0;
30912 +
30913 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30914 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30915 + pte_unmap_unlock(pte, ptl);
30916 + return 0;
30917 + }
30918 +
30919 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30920 + /* write attempt to a protected page in user mode */
30921 + pte_unmap_unlock(pte, ptl);
30922 + return 0;
30923 + }
30924 +
30925 +#ifdef CONFIG_SMP
30926 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30927 +#else
30928 + if (likely(address > get_limit(regs->cs)))
30929 +#endif
30930 + {
30931 + set_pte(pte, pte_mkread(*pte));
30932 + __flush_tlb_one(address);
30933 + pte_unmap_unlock(pte, ptl);
30934 + up_read(&mm->mmap_sem);
30935 + return 1;
30936 + }
30937 +
30938 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30939 +
30940 + /*
30941 + * PaX: fill DTLB with user rights and retry
30942 + */
30943 + __asm__ __volatile__ (
30944 + "orb %2,(%1)\n"
30945 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30946 +/*
30947 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30948 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30949 + * page fault when examined during a TLB load attempt. this is true not only
30950 + * for PTEs holding a non-present entry but also present entries that will
30951 + * raise a page fault (such as those set up by PaX, or the copy-on-write
30952 + * mechanism). in effect it means that we do *not* need to flush the TLBs
30953 + * for our target pages since their PTEs are simply not in the TLBs at all.
30954 +
30955 + * the best thing in omitting it is that we gain around 15-20% speed in the
30956 + * fast path of the page fault handler and can get rid of tracing since we
30957 + * can no longer flush unintended entries.
30958 + */
30959 + "invlpg (%0)\n"
30960 +#endif
30961 + __copyuser_seg"testb $0,(%0)\n"
30962 + "xorb %3,(%1)\n"
30963 + :
30964 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30965 + : "memory", "cc");
30966 + pte_unmap_unlock(pte, ptl);
30967 + up_read(&mm->mmap_sem);
30968 + return 1;
30969 +}
30970 +#endif
30971 +
30972 /*
30973 * Handle a spurious fault caused by a stale TLB entry.
30974 *
30975 @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
30976 static inline int
30977 access_error(unsigned long error_code, struct vm_area_struct *vma)
30978 {
30979 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30980 + return 1;
30981 +
30982 if (error_code & PF_WRITE) {
30983 /* write, present and write, not present: */
30984 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30985 @@ -1004,7 +1212,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30986 if (error_code & PF_USER)
30987 return false;
30988
30989 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30990 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30991 return false;
30992
30993 return true;
30994 @@ -1031,6 +1239,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30995 /* Get the faulting address: */
30996 address = read_cr2();
30997
30998 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30999 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31000 + if (!search_exception_tables(regs->ip)) {
31001 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31002 + bad_area_nosemaphore(regs, error_code, address);
31003 + return;
31004 + }
31005 + if (address < pax_user_shadow_base) {
31006 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31007 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31008 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31009 + } else
31010 + address -= pax_user_shadow_base;
31011 + }
31012 +#endif
31013 +
31014 /*
31015 * Detect and handle instructions that would cause a page fault for
31016 * both a tracked kernel page and a userspace page.
31017 @@ -1110,7 +1334,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31018 * User-mode registers count as a user access even for any
31019 * potential system fault or CPU buglet:
31020 */
31021 - if (user_mode_vm(regs)) {
31022 + if (user_mode(regs)) {
31023 local_irq_enable();
31024 error_code |= PF_USER;
31025 flags |= FAULT_FLAG_USER;
31026 @@ -1157,6 +1381,11 @@ retry:
31027 might_sleep();
31028 }
31029
31030 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31031 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31032 + return;
31033 +#endif
31034 +
31035 vma = find_vma(mm, address);
31036 if (unlikely(!vma)) {
31037 bad_area(regs, error_code, address);
31038 @@ -1168,18 +1397,24 @@ retry:
31039 bad_area(regs, error_code, address);
31040 return;
31041 }
31042 - if (error_code & PF_USER) {
31043 - /*
31044 - * Accessing the stack below %sp is always a bug.
31045 - * The large cushion allows instructions like enter
31046 - * and pusha to work. ("enter $65535, $31" pushes
31047 - * 32 pointers and then decrements %sp by 65535.)
31048 - */
31049 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31050 - bad_area(regs, error_code, address);
31051 - return;
31052 - }
31053 + /*
31054 + * Accessing the stack below %sp is always a bug.
31055 + * The large cushion allows instructions like enter
31056 + * and pusha to work. ("enter $65535, $31" pushes
31057 + * 32 pointers and then decrements %sp by 65535.)
31058 + */
31059 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31060 + bad_area(regs, error_code, address);
31061 + return;
31062 }
31063 +
31064 +#ifdef CONFIG_PAX_SEGMEXEC
31065 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31066 + bad_area(regs, error_code, address);
31067 + return;
31068 + }
31069 +#endif
31070 +
31071 if (unlikely(expand_stack(vma, address))) {
31072 bad_area(regs, error_code, address);
31073 return;
31074 @@ -1273,3 +1508,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31075 __do_page_fault(regs, error_code);
31076 exception_exit(prev_state);
31077 }
31078 +
31079 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31080 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31081 +{
31082 + struct mm_struct *mm = current->mm;
31083 + unsigned long ip = regs->ip;
31084 +
31085 + if (v8086_mode(regs))
31086 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31087 +
31088 +#ifdef CONFIG_PAX_PAGEEXEC
31089 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31090 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31091 + return true;
31092 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31093 + return true;
31094 + return false;
31095 + }
31096 +#endif
31097 +
31098 +#ifdef CONFIG_PAX_SEGMEXEC
31099 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31100 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31101 + return true;
31102 + return false;
31103 + }
31104 +#endif
31105 +
31106 + return false;
31107 +}
31108 +#endif
31109 +
31110 +#ifdef CONFIG_PAX_EMUTRAMP
31111 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31112 +{
31113 + int err;
31114 +
31115 + do { /* PaX: libffi trampoline emulation */
31116 + unsigned char mov, jmp;
31117 + unsigned int addr1, addr2;
31118 +
31119 +#ifdef CONFIG_X86_64
31120 + if ((regs->ip + 9) >> 32)
31121 + break;
31122 +#endif
31123 +
31124 + err = get_user(mov, (unsigned char __user *)regs->ip);
31125 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31126 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31127 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31128 +
31129 + if (err)
31130 + break;
31131 +
31132 + if (mov == 0xB8 && jmp == 0xE9) {
31133 + regs->ax = addr1;
31134 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31135 + return 2;
31136 + }
31137 + } while (0);
31138 +
31139 + do { /* PaX: gcc trampoline emulation #1 */
31140 + unsigned char mov1, mov2;
31141 + unsigned short jmp;
31142 + unsigned int addr1, addr2;
31143 +
31144 +#ifdef CONFIG_X86_64
31145 + if ((regs->ip + 11) >> 32)
31146 + break;
31147 +#endif
31148 +
31149 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31150 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31151 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31152 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31153 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31154 +
31155 + if (err)
31156 + break;
31157 +
31158 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31159 + regs->cx = addr1;
31160 + regs->ax = addr2;
31161 + regs->ip = addr2;
31162 + return 2;
31163 + }
31164 + } while (0);
31165 +
31166 + do { /* PaX: gcc trampoline emulation #2 */
31167 + unsigned char mov, jmp;
31168 + unsigned int addr1, addr2;
31169 +
31170 +#ifdef CONFIG_X86_64
31171 + if ((regs->ip + 9) >> 32)
31172 + break;
31173 +#endif
31174 +
31175 + err = get_user(mov, (unsigned char __user *)regs->ip);
31176 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31177 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31178 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31179 +
31180 + if (err)
31181 + break;
31182 +
31183 + if (mov == 0xB9 && jmp == 0xE9) {
31184 + regs->cx = addr1;
31185 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31186 + return 2;
31187 + }
31188 + } while (0);
31189 +
31190 + return 1; /* PaX in action */
31191 +}
31192 +
31193 +#ifdef CONFIG_X86_64
31194 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31195 +{
31196 + int err;
31197 +
31198 + do { /* PaX: libffi trampoline emulation */
31199 + unsigned short mov1, mov2, jmp1;
31200 + unsigned char stcclc, jmp2;
31201 + unsigned long addr1, addr2;
31202 +
31203 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31204 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31205 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31206 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31207 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31208 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31209 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31210 +
31211 + if (err)
31212 + break;
31213 +
31214 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31215 + regs->r11 = addr1;
31216 + regs->r10 = addr2;
31217 + if (stcclc == 0xF8)
31218 + regs->flags &= ~X86_EFLAGS_CF;
31219 + else
31220 + regs->flags |= X86_EFLAGS_CF;
31221 + regs->ip = addr1;
31222 + return 2;
31223 + }
31224 + } while (0);
31225 +
31226 + do { /* PaX: gcc trampoline emulation #1 */
31227 + unsigned short mov1, mov2, jmp1;
31228 + unsigned char jmp2;
31229 + unsigned int addr1;
31230 + unsigned long addr2;
31231 +
31232 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31233 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31234 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31235 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31236 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31237 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31238 +
31239 + if (err)
31240 + break;
31241 +
31242 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31243 + regs->r11 = addr1;
31244 + regs->r10 = addr2;
31245 + regs->ip = addr1;
31246 + return 2;
31247 + }
31248 + } while (0);
31249 +
31250 + do { /* PaX: gcc trampoline emulation #2 */
31251 + unsigned short mov1, mov2, jmp1;
31252 + unsigned char jmp2;
31253 + unsigned long addr1, addr2;
31254 +
31255 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31256 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31257 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31258 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31259 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31260 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31261 +
31262 + if (err)
31263 + break;
31264 +
31265 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31266 + regs->r11 = addr1;
31267 + regs->r10 = addr2;
31268 + regs->ip = addr1;
31269 + return 2;
31270 + }
31271 + } while (0);
31272 +
31273 + return 1; /* PaX in action */
31274 +}
31275 +#endif
31276 +
31277 +/*
31278 + * PaX: decide what to do with offenders (regs->ip = fault address)
31279 + *
31280 + * returns 1 when task should be killed
31281 + * 2 when gcc trampoline was detected
31282 + */
31283 +static int pax_handle_fetch_fault(struct pt_regs *regs)
31284 +{
31285 + if (v8086_mode(regs))
31286 + return 1;
31287 +
31288 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31289 + return 1;
31290 +
31291 +#ifdef CONFIG_X86_32
31292 + return pax_handle_fetch_fault_32(regs);
31293 +#else
31294 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31295 + return pax_handle_fetch_fault_32(regs);
31296 + else
31297 + return pax_handle_fetch_fault_64(regs);
31298 +#endif
31299 +}
31300 +#endif
31301 +
31302 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31303 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31304 +{
31305 + long i;
31306 +
31307 + printk(KERN_ERR "PAX: bytes at PC: ");
31308 + for (i = 0; i < 20; i++) {
31309 + unsigned char c;
31310 + if (get_user(c, (unsigned char __force_user *)pc+i))
31311 + printk(KERN_CONT "?? ");
31312 + else
31313 + printk(KERN_CONT "%02x ", c);
31314 + }
31315 + printk("\n");
31316 +
31317 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31318 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
31319 + unsigned long c;
31320 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
31321 +#ifdef CONFIG_X86_32
31322 + printk(KERN_CONT "???????? ");
31323 +#else
31324 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31325 + printk(KERN_CONT "???????? ???????? ");
31326 + else
31327 + printk(KERN_CONT "???????????????? ");
31328 +#endif
31329 + } else {
31330 +#ifdef CONFIG_X86_64
31331 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31332 + printk(KERN_CONT "%08x ", (unsigned int)c);
31333 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31334 + } else
31335 +#endif
31336 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31337 + }
31338 + }
31339 + printk("\n");
31340 +}
31341 +#endif
31342 +
31343 +/**
31344 + * probe_kernel_write(): safely attempt to write to a location
31345 + * @dst: address to write to
31346 + * @src: pointer to the data that shall be written
31347 + * @size: size of the data chunk
31348 + *
31349 + * Safely write to address @dst from the buffer at @src. If a kernel fault
31350 + * happens, handle that and return -EFAULT.
31351 + */
31352 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31353 +{
31354 + long ret;
31355 + mm_segment_t old_fs = get_fs();
31356 +
31357 + set_fs(KERNEL_DS);
31358 + pagefault_disable();
31359 + pax_open_kernel();
31360 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31361 + pax_close_kernel();
31362 + pagefault_enable();
31363 + set_fs(old_fs);
31364 +
31365 + return ret ? -EFAULT : 0;
31366 +}
31367 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31368 index 0596e8e..9de0b1c 100644
31369 --- a/arch/x86/mm/gup.c
31370 +++ b/arch/x86/mm/gup.c
31371 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31372 addr = start;
31373 len = (unsigned long) nr_pages << PAGE_SHIFT;
31374 end = start + len;
31375 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31376 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31377 (void __user *)start, len)))
31378 return 0;
31379
31380 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31381 goto slow_irqon;
31382 #endif
31383
31384 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31385 + (void __user *)start, len)))
31386 + return 0;
31387 +
31388 /*
31389 * XXX: batch / limit 'nr', to avoid large irq off latency
31390 * needs some instrumenting to determine the common sizes used by
31391 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31392 index 4500142..53a363c 100644
31393 --- a/arch/x86/mm/highmem_32.c
31394 +++ b/arch/x86/mm/highmem_32.c
31395 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31396 idx = type + KM_TYPE_NR*smp_processor_id();
31397 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31398 BUG_ON(!pte_none(*(kmap_pte-idx)));
31399 +
31400 + pax_open_kernel();
31401 set_pte(kmap_pte-idx, mk_pte(page, prot));
31402 + pax_close_kernel();
31403 +
31404 arch_flush_lazy_mmu_mode();
31405
31406 return (void *)vaddr;
31407 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31408 index 9d980d8..6bbfacb 100644
31409 --- a/arch/x86/mm/hugetlbpage.c
31410 +++ b/arch/x86/mm/hugetlbpage.c
31411 @@ -92,23 +92,30 @@ int pmd_huge_support(void)
31412 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31413 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31414 unsigned long addr, unsigned long len,
31415 - unsigned long pgoff, unsigned long flags)
31416 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31417 {
31418 struct hstate *h = hstate_file(file);
31419 struct vm_unmapped_area_info info;
31420 -
31421 +
31422 info.flags = 0;
31423 info.length = len;
31424 info.low_limit = TASK_UNMAPPED_BASE;
31425 +
31426 +#ifdef CONFIG_PAX_RANDMMAP
31427 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31428 + info.low_limit += current->mm->delta_mmap;
31429 +#endif
31430 +
31431 info.high_limit = TASK_SIZE;
31432 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31433 info.align_offset = 0;
31434 + info.threadstack_offset = offset;
31435 return vm_unmapped_area(&info);
31436 }
31437
31438 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31439 unsigned long addr0, unsigned long len,
31440 - unsigned long pgoff, unsigned long flags)
31441 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31442 {
31443 struct hstate *h = hstate_file(file);
31444 struct vm_unmapped_area_info info;
31445 @@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31446 info.high_limit = current->mm->mmap_base;
31447 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31448 info.align_offset = 0;
31449 + info.threadstack_offset = offset;
31450 addr = vm_unmapped_area(&info);
31451
31452 /*
31453 @@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31454 VM_BUG_ON(addr != -ENOMEM);
31455 info.flags = 0;
31456 info.low_limit = TASK_UNMAPPED_BASE;
31457 +
31458 +#ifdef CONFIG_PAX_RANDMMAP
31459 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31460 + info.low_limit += current->mm->delta_mmap;
31461 +#endif
31462 +
31463 info.high_limit = TASK_SIZE;
31464 addr = vm_unmapped_area(&info);
31465 }
31466 @@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31467 struct hstate *h = hstate_file(file);
31468 struct mm_struct *mm = current->mm;
31469 struct vm_area_struct *vma;
31470 + unsigned long pax_task_size = TASK_SIZE;
31471 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
31472
31473 if (len & ~huge_page_mask(h))
31474 return -EINVAL;
31475 - if (len > TASK_SIZE)
31476 +
31477 +#ifdef CONFIG_PAX_SEGMEXEC
31478 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
31479 + pax_task_size = SEGMEXEC_TASK_SIZE;
31480 +#endif
31481 +
31482 + pax_task_size -= PAGE_SIZE;
31483 +
31484 + if (len > pax_task_size)
31485 return -ENOMEM;
31486
31487 if (flags & MAP_FIXED) {
31488 @@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31489 return addr;
31490 }
31491
31492 +#ifdef CONFIG_PAX_RANDMMAP
31493 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31494 +#endif
31495 +
31496 if (addr) {
31497 addr = ALIGN(addr, huge_page_size(h));
31498 vma = find_vma(mm, addr);
31499 - if (TASK_SIZE - len >= addr &&
31500 - (!vma || addr + len <= vma->vm_start))
31501 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
31502 return addr;
31503 }
31504 if (mm->get_unmapped_area == arch_get_unmapped_area)
31505 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
31506 - pgoff, flags);
31507 + pgoff, flags, offset);
31508 else
31509 return hugetlb_get_unmapped_area_topdown(file, addr, len,
31510 - pgoff, flags);
31511 + pgoff, flags, offset);
31512 }
31513
31514 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
31515 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
31516 index f971306..e83e0f6 100644
31517 --- a/arch/x86/mm/init.c
31518 +++ b/arch/x86/mm/init.c
31519 @@ -4,6 +4,7 @@
31520 #include <linux/swap.h>
31521 #include <linux/memblock.h>
31522 #include <linux/bootmem.h> /* for max_low_pfn */
31523 +#include <linux/tboot.h>
31524
31525 #include <asm/cacheflush.h>
31526 #include <asm/e820.h>
31527 @@ -17,6 +18,8 @@
31528 #include <asm/proto.h>
31529 #include <asm/dma.h> /* for MAX_DMA_PFN */
31530 #include <asm/microcode.h>
31531 +#include <asm/desc.h>
31532 +#include <asm/bios_ebda.h>
31533
31534 #include "mm_internal.h"
31535
31536 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
31537 early_ioremap_page_table_range_init();
31538 #endif
31539
31540 +#ifdef CONFIG_PAX_PER_CPU_PGD
31541 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
31542 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31543 + KERNEL_PGD_PTRS);
31544 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
31545 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31546 + KERNEL_PGD_PTRS);
31547 + load_cr3(get_cpu_pgd(0, kernel));
31548 +#else
31549 load_cr3(swapper_pg_dir);
31550 +#endif
31551 +
31552 __flush_tlb_all();
31553
31554 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
31555 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
31556 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
31557 * mmio resources as well as potential bios/acpi data regions.
31558 */
31559 +
31560 +#ifdef CONFIG_GRKERNSEC_KMEM
31561 +static unsigned int ebda_start __read_only;
31562 +static unsigned int ebda_end __read_only;
31563 +#endif
31564 +
31565 int devmem_is_allowed(unsigned long pagenr)
31566 {
31567 - if (pagenr < 256)
31568 +#ifdef CONFIG_GRKERNSEC_KMEM
31569 + /* allow BDA */
31570 + if (!pagenr)
31571 return 1;
31572 + /* allow EBDA */
31573 + if (pagenr >= ebda_start && pagenr < ebda_end)
31574 + return 1;
31575 + /* if tboot is in use, allow access to its hardcoded serial log range */
31576 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
31577 + return 1;
31578 +#else
31579 + if (!pagenr)
31580 + return 1;
31581 +#ifdef CONFIG_VM86
31582 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
31583 + return 1;
31584 +#endif
31585 +#endif
31586 +
31587 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
31588 + return 1;
31589 +#ifdef CONFIG_GRKERNSEC_KMEM
31590 + /* throw out everything else below 1MB */
31591 + if (pagenr <= 256)
31592 + return 0;
31593 +#endif
31594 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
31595 return 0;
31596 if (!page_is_ram(pagenr))
31597 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
31598 #endif
31599 }
31600
31601 +#ifdef CONFIG_GRKERNSEC_KMEM
31602 +static inline void gr_init_ebda(void)
31603 +{
31604 + unsigned int ebda_addr;
31605 + unsigned int ebda_size = 0;
31606 +
31607 + ebda_addr = get_bios_ebda();
31608 + if (ebda_addr) {
31609 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
31610 + ebda_size <<= 10;
31611 + }
31612 + if (ebda_addr && ebda_size) {
31613 + ebda_start = ebda_addr >> PAGE_SHIFT;
31614 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
31615 + } else {
31616 + ebda_start = 0x9f000 >> PAGE_SHIFT;
31617 + ebda_end = 0xa0000 >> PAGE_SHIFT;
31618 + }
31619 +}
31620 +#else
31621 +static inline void gr_init_ebda(void) { }
31622 +#endif
31623 +
31624 void free_initmem(void)
31625 {
31626 +#ifdef CONFIG_PAX_KERNEXEC
31627 +#ifdef CONFIG_X86_32
31628 + /* PaX: limit KERNEL_CS to actual size */
31629 + unsigned long addr, limit;
31630 + struct desc_struct d;
31631 + int cpu;
31632 +#else
31633 + pgd_t *pgd;
31634 + pud_t *pud;
31635 + pmd_t *pmd;
31636 + unsigned long addr, end;
31637 +#endif
31638 +#endif
31639 +
31640 + gr_init_ebda();
31641 +
31642 +#ifdef CONFIG_PAX_KERNEXEC
31643 +#ifdef CONFIG_X86_32
31644 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
31645 + limit = (limit - 1UL) >> PAGE_SHIFT;
31646 +
31647 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
31648 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
31649 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
31650 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
31651 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
31652 + }
31653 +
31654 + /* PaX: make KERNEL_CS read-only */
31655 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
31656 + if (!paravirt_enabled())
31657 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
31658 +/*
31659 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
31660 + pgd = pgd_offset_k(addr);
31661 + pud = pud_offset(pgd, addr);
31662 + pmd = pmd_offset(pud, addr);
31663 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31664 + }
31665 +*/
31666 +#ifdef CONFIG_X86_PAE
31667 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
31668 +/*
31669 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
31670 + pgd = pgd_offset_k(addr);
31671 + pud = pud_offset(pgd, addr);
31672 + pmd = pmd_offset(pud, addr);
31673 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31674 + }
31675 +*/
31676 +#endif
31677 +
31678 +#ifdef CONFIG_MODULES
31679 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
31680 +#endif
31681 +
31682 +#else
31683 + /* PaX: make kernel code/rodata read-only, rest non-executable */
31684 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
31685 + pgd = pgd_offset_k(addr);
31686 + pud = pud_offset(pgd, addr);
31687 + pmd = pmd_offset(pud, addr);
31688 + if (!pmd_present(*pmd))
31689 + continue;
31690 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
31691 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31692 + else
31693 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31694 + }
31695 +
31696 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
31697 + end = addr + KERNEL_IMAGE_SIZE;
31698 + for (; addr < end; addr += PMD_SIZE) {
31699 + pgd = pgd_offset_k(addr);
31700 + pud = pud_offset(pgd, addr);
31701 + pmd = pmd_offset(pud, addr);
31702 + if (!pmd_present(*pmd))
31703 + continue;
31704 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
31705 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31706 + }
31707 +#endif
31708 +
31709 + flush_tlb_all();
31710 +#endif
31711 +
31712 free_init_pages("unused kernel",
31713 (unsigned long)(&__init_begin),
31714 (unsigned long)(&__init_end));
31715 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31716 index 4287f1f..3b99c71 100644
31717 --- a/arch/x86/mm/init_32.c
31718 +++ b/arch/x86/mm/init_32.c
31719 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31720 bool __read_mostly __vmalloc_start_set = false;
31721
31722 /*
31723 - * Creates a middle page table and puts a pointer to it in the
31724 - * given global directory entry. This only returns the gd entry
31725 - * in non-PAE compilation mode, since the middle layer is folded.
31726 - */
31727 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
31728 -{
31729 - pud_t *pud;
31730 - pmd_t *pmd_table;
31731 -
31732 -#ifdef CONFIG_X86_PAE
31733 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31734 - pmd_table = (pmd_t *)alloc_low_page();
31735 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31736 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31737 - pud = pud_offset(pgd, 0);
31738 - BUG_ON(pmd_table != pmd_offset(pud, 0));
31739 -
31740 - return pmd_table;
31741 - }
31742 -#endif
31743 - pud = pud_offset(pgd, 0);
31744 - pmd_table = pmd_offset(pud, 0);
31745 -
31746 - return pmd_table;
31747 -}
31748 -
31749 -/*
31750 * Create a page table and place a pointer to it in a middle page
31751 * directory entry:
31752 */
31753 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31754 pte_t *page_table = (pte_t *)alloc_low_page();
31755
31756 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31757 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31758 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31759 +#else
31760 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31761 +#endif
31762 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31763 }
31764
31765 return pte_offset_kernel(pmd, 0);
31766 }
31767
31768 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
31769 +{
31770 + pud_t *pud;
31771 + pmd_t *pmd_table;
31772 +
31773 + pud = pud_offset(pgd, 0);
31774 + pmd_table = pmd_offset(pud, 0);
31775 +
31776 + return pmd_table;
31777 +}
31778 +
31779 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31780 {
31781 int pgd_idx = pgd_index(vaddr);
31782 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31783 int pgd_idx, pmd_idx;
31784 unsigned long vaddr;
31785 pgd_t *pgd;
31786 + pud_t *pud;
31787 pmd_t *pmd;
31788 pte_t *pte = NULL;
31789 unsigned long count = page_table_range_init_count(start, end);
31790 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31791 pgd = pgd_base + pgd_idx;
31792
31793 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31794 - pmd = one_md_table_init(pgd);
31795 - pmd = pmd + pmd_index(vaddr);
31796 + pud = pud_offset(pgd, vaddr);
31797 + pmd = pmd_offset(pud, vaddr);
31798 +
31799 +#ifdef CONFIG_X86_PAE
31800 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31801 +#endif
31802 +
31803 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31804 pmd++, pmd_idx++) {
31805 pte = page_table_kmap_check(one_page_table_init(pmd),
31806 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31807 }
31808 }
31809
31810 -static inline int is_kernel_text(unsigned long addr)
31811 +static inline int is_kernel_text(unsigned long start, unsigned long end)
31812 {
31813 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31814 - return 1;
31815 - return 0;
31816 + if ((start > ktla_ktva((unsigned long)_etext) ||
31817 + end <= ktla_ktva((unsigned long)_stext)) &&
31818 + (start > ktla_ktva((unsigned long)_einittext) ||
31819 + end <= ktla_ktva((unsigned long)_sinittext)) &&
31820 +
31821 +#ifdef CONFIG_ACPI_SLEEP
31822 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31823 +#endif
31824 +
31825 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31826 + return 0;
31827 + return 1;
31828 }
31829
31830 /*
31831 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31832 unsigned long last_map_addr = end;
31833 unsigned long start_pfn, end_pfn;
31834 pgd_t *pgd_base = swapper_pg_dir;
31835 - int pgd_idx, pmd_idx, pte_ofs;
31836 + unsigned int pgd_idx, pmd_idx, pte_ofs;
31837 unsigned long pfn;
31838 pgd_t *pgd;
31839 + pud_t *pud;
31840 pmd_t *pmd;
31841 pte_t *pte;
31842 unsigned pages_2m, pages_4k;
31843 @@ -291,8 +295,13 @@ repeat:
31844 pfn = start_pfn;
31845 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31846 pgd = pgd_base + pgd_idx;
31847 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31848 - pmd = one_md_table_init(pgd);
31849 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31850 + pud = pud_offset(pgd, 0);
31851 + pmd = pmd_offset(pud, 0);
31852 +
31853 +#ifdef CONFIG_X86_PAE
31854 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31855 +#endif
31856
31857 if (pfn >= end_pfn)
31858 continue;
31859 @@ -304,14 +313,13 @@ repeat:
31860 #endif
31861 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31862 pmd++, pmd_idx++) {
31863 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31864 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31865
31866 /*
31867 * Map with big pages if possible, otherwise
31868 * create normal page tables:
31869 */
31870 if (use_pse) {
31871 - unsigned int addr2;
31872 pgprot_t prot = PAGE_KERNEL_LARGE;
31873 /*
31874 * first pass will use the same initial
31875 @@ -322,11 +330,7 @@ repeat:
31876 _PAGE_PSE);
31877
31878 pfn &= PMD_MASK >> PAGE_SHIFT;
31879 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31880 - PAGE_OFFSET + PAGE_SIZE-1;
31881 -
31882 - if (is_kernel_text(addr) ||
31883 - is_kernel_text(addr2))
31884 + if (is_kernel_text(address, address + PMD_SIZE))
31885 prot = PAGE_KERNEL_LARGE_EXEC;
31886
31887 pages_2m++;
31888 @@ -343,7 +347,7 @@ repeat:
31889 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31890 pte += pte_ofs;
31891 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31892 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31893 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31894 pgprot_t prot = PAGE_KERNEL;
31895 /*
31896 * first pass will use the same initial
31897 @@ -351,7 +355,7 @@ repeat:
31898 */
31899 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31900
31901 - if (is_kernel_text(addr))
31902 + if (is_kernel_text(address, address + PAGE_SIZE))
31903 prot = PAGE_KERNEL_EXEC;
31904
31905 pages_4k++;
31906 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31907
31908 pud = pud_offset(pgd, va);
31909 pmd = pmd_offset(pud, va);
31910 - if (!pmd_present(*pmd))
31911 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31912 break;
31913
31914 /* should not be large page here */
31915 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31916
31917 static void __init pagetable_init(void)
31918 {
31919 - pgd_t *pgd_base = swapper_pg_dir;
31920 -
31921 - permanent_kmaps_init(pgd_base);
31922 + permanent_kmaps_init(swapper_pg_dir);
31923 }
31924
31925 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31926 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31927 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31928
31929 /* user-defined highmem size */
31930 @@ -787,10 +789,10 @@ void __init mem_init(void)
31931 ((unsigned long)&__init_end -
31932 (unsigned long)&__init_begin) >> 10,
31933
31934 - (unsigned long)&_etext, (unsigned long)&_edata,
31935 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31936 + (unsigned long)&_sdata, (unsigned long)&_edata,
31937 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31938
31939 - (unsigned long)&_text, (unsigned long)&_etext,
31940 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31941 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31942
31943 /*
31944 @@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31945 if (!kernel_set_to_readonly)
31946 return;
31947
31948 + start = ktla_ktva(start);
31949 pr_debug("Set kernel text: %lx - %lx for read write\n",
31950 start, start+size);
31951
31952 @@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31953 if (!kernel_set_to_readonly)
31954 return;
31955
31956 + start = ktla_ktva(start);
31957 pr_debug("Set kernel text: %lx - %lx for read only\n",
31958 start, start+size);
31959
31960 @@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31961 unsigned long start = PFN_ALIGN(_text);
31962 unsigned long size = PFN_ALIGN(_etext) - start;
31963
31964 + start = ktla_ktva(start);
31965 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31966 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31967 size >> 10);
31968 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31969 index 104d56a..62ba13f1 100644
31970 --- a/arch/x86/mm/init_64.c
31971 +++ b/arch/x86/mm/init_64.c
31972 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31973 * around without checking the pgd every time.
31974 */
31975
31976 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31977 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31978 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31979
31980 int force_personality32;
31981 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31982
31983 for (address = start; address <= end; address += PGDIR_SIZE) {
31984 const pgd_t *pgd_ref = pgd_offset_k(address);
31985 +
31986 +#ifdef CONFIG_PAX_PER_CPU_PGD
31987 + unsigned long cpu;
31988 +#else
31989 struct page *page;
31990 +#endif
31991
31992 if (pgd_none(*pgd_ref))
31993 continue;
31994
31995 spin_lock(&pgd_lock);
31996 +
31997 +#ifdef CONFIG_PAX_PER_CPU_PGD
31998 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31999 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32000 +
32001 + if (pgd_none(*pgd))
32002 + set_pgd(pgd, *pgd_ref);
32003 + else
32004 + BUG_ON(pgd_page_vaddr(*pgd)
32005 + != pgd_page_vaddr(*pgd_ref));
32006 + pgd = pgd_offset_cpu(cpu, kernel, address);
32007 +#else
32008 list_for_each_entry(page, &pgd_list, lru) {
32009 pgd_t *pgd;
32010 spinlock_t *pgt_lock;
32011 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32012 /* the pgt_lock only for Xen */
32013 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32014 spin_lock(pgt_lock);
32015 +#endif
32016
32017 if (pgd_none(*pgd))
32018 set_pgd(pgd, *pgd_ref);
32019 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32020 BUG_ON(pgd_page_vaddr(*pgd)
32021 != pgd_page_vaddr(*pgd_ref));
32022
32023 +#ifndef CONFIG_PAX_PER_CPU_PGD
32024 spin_unlock(pgt_lock);
32025 +#endif
32026 +
32027 }
32028 spin_unlock(&pgd_lock);
32029 }
32030 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32031 {
32032 if (pgd_none(*pgd)) {
32033 pud_t *pud = (pud_t *)spp_getpage();
32034 - pgd_populate(&init_mm, pgd, pud);
32035 + pgd_populate_kernel(&init_mm, pgd, pud);
32036 if (pud != pud_offset(pgd, 0))
32037 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32038 pud, pud_offset(pgd, 0));
32039 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32040 {
32041 if (pud_none(*pud)) {
32042 pmd_t *pmd = (pmd_t *) spp_getpage();
32043 - pud_populate(&init_mm, pud, pmd);
32044 + pud_populate_kernel(&init_mm, pud, pmd);
32045 if (pmd != pmd_offset(pud, 0))
32046 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32047 pmd, pmd_offset(pud, 0));
32048 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32049 pmd = fill_pmd(pud, vaddr);
32050 pte = fill_pte(pmd, vaddr);
32051
32052 + pax_open_kernel();
32053 set_pte(pte, new_pte);
32054 + pax_close_kernel();
32055
32056 /*
32057 * It's enough to flush this one mapping.
32058 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32059 pgd = pgd_offset_k((unsigned long)__va(phys));
32060 if (pgd_none(*pgd)) {
32061 pud = (pud_t *) spp_getpage();
32062 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32063 - _PAGE_USER));
32064 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32065 }
32066 pud = pud_offset(pgd, (unsigned long)__va(phys));
32067 if (pud_none(*pud)) {
32068 pmd = (pmd_t *) spp_getpage();
32069 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32070 - _PAGE_USER));
32071 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32072 }
32073 pmd = pmd_offset(pud, phys);
32074 BUG_ON(!pmd_none(*pmd));
32075 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32076 prot);
32077
32078 spin_lock(&init_mm.page_table_lock);
32079 - pud_populate(&init_mm, pud, pmd);
32080 + pud_populate_kernel(&init_mm, pud, pmd);
32081 spin_unlock(&init_mm.page_table_lock);
32082 }
32083 __flush_tlb_all();
32084 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32085 page_size_mask);
32086
32087 spin_lock(&init_mm.page_table_lock);
32088 - pgd_populate(&init_mm, pgd, pud);
32089 + pgd_populate_kernel(&init_mm, pgd, pud);
32090 spin_unlock(&init_mm.page_table_lock);
32091 pgd_changed = true;
32092 }
32093 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32094 static struct vm_area_struct gate_vma = {
32095 .vm_start = VSYSCALL_START,
32096 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32097 - .vm_page_prot = PAGE_READONLY_EXEC,
32098 - .vm_flags = VM_READ | VM_EXEC
32099 + .vm_page_prot = PAGE_READONLY,
32100 + .vm_flags = VM_READ
32101 };
32102
32103 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32104 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32105
32106 const char *arch_vma_name(struct vm_area_struct *vma)
32107 {
32108 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32109 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32110 return "[vdso]";
32111 if (vma == &gate_vma)
32112 return "[vsyscall]";
32113 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32114 index 7b179b4..6bd17777 100644
32115 --- a/arch/x86/mm/iomap_32.c
32116 +++ b/arch/x86/mm/iomap_32.c
32117 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32118 type = kmap_atomic_idx_push();
32119 idx = type + KM_TYPE_NR * smp_processor_id();
32120 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32121 +
32122 + pax_open_kernel();
32123 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32124 + pax_close_kernel();
32125 +
32126 arch_flush_lazy_mmu_mode();
32127
32128 return (void *)vaddr;
32129 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32130 index 799580c..72f9fe0 100644
32131 --- a/arch/x86/mm/ioremap.c
32132 +++ b/arch/x86/mm/ioremap.c
32133 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32134 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32135 int is_ram = page_is_ram(pfn);
32136
32137 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32138 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32139 return NULL;
32140 WARN_ON_ONCE(is_ram);
32141 }
32142 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32143 *
32144 * Caller must ensure there is only one unmapping for the same pointer.
32145 */
32146 -void iounmap(volatile void __iomem *addr)
32147 +void iounmap(const volatile void __iomem *addr)
32148 {
32149 struct vm_struct *p, *o;
32150
32151 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32152
32153 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32154 if (page_is_ram(start >> PAGE_SHIFT))
32155 +#ifdef CONFIG_HIGHMEM
32156 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32157 +#endif
32158 return __va(phys);
32159
32160 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32161 @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32162 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32163 {
32164 if (page_is_ram(phys >> PAGE_SHIFT))
32165 +#ifdef CONFIG_HIGHMEM
32166 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32167 +#endif
32168 return;
32169
32170 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32171 @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32172 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32173
32174 static __initdata int after_paging_init;
32175 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32176 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32177
32178 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32179 {
32180 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32181 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32182
32183 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32184 - memset(bm_pte, 0, sizeof(bm_pte));
32185 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32186 + pmd_populate_user(&init_mm, pmd, bm_pte);
32187
32188 /*
32189 * The boot-ioremap range spans multiple pmds, for which
32190 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32191 index d87dd6d..bf3fa66 100644
32192 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32193 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32194 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32195 * memory (e.g. tracked pages)? For now, we need this to avoid
32196 * invoking kmemcheck for PnP BIOS calls.
32197 */
32198 - if (regs->flags & X86_VM_MASK)
32199 + if (v8086_mode(regs))
32200 return false;
32201 - if (regs->cs != __KERNEL_CS)
32202 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32203 return false;
32204
32205 pte = kmemcheck_pte_lookup(address);
32206 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32207 index 25e7e13..1964579 100644
32208 --- a/arch/x86/mm/mmap.c
32209 +++ b/arch/x86/mm/mmap.c
32210 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32211 * Leave an at least ~128 MB hole with possible stack randomization.
32212 */
32213 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32214 -#define MAX_GAP (TASK_SIZE/6*5)
32215 +#define MAX_GAP (pax_task_size/6*5)
32216
32217 static int mmap_is_legacy(void)
32218 {
32219 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32220 return rnd << PAGE_SHIFT;
32221 }
32222
32223 -static unsigned long mmap_base(void)
32224 +static unsigned long mmap_base(struct mm_struct *mm)
32225 {
32226 unsigned long gap = rlimit(RLIMIT_STACK);
32227 + unsigned long pax_task_size = TASK_SIZE;
32228 +
32229 +#ifdef CONFIG_PAX_SEGMEXEC
32230 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32231 + pax_task_size = SEGMEXEC_TASK_SIZE;
32232 +#endif
32233
32234 if (gap < MIN_GAP)
32235 gap = MIN_GAP;
32236 else if (gap > MAX_GAP)
32237 gap = MAX_GAP;
32238
32239 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32240 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32241 }
32242
32243 /*
32244 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32245 * does, but not when emulating X86_32
32246 */
32247 -static unsigned long mmap_legacy_base(void)
32248 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
32249 {
32250 - if (mmap_is_ia32())
32251 + if (mmap_is_ia32()) {
32252 +
32253 +#ifdef CONFIG_PAX_SEGMEXEC
32254 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32255 + return SEGMEXEC_TASK_UNMAPPED_BASE;
32256 + else
32257 +#endif
32258 +
32259 return TASK_UNMAPPED_BASE;
32260 - else
32261 + } else
32262 return TASK_UNMAPPED_BASE + mmap_rnd();
32263 }
32264
32265 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32266 */
32267 void arch_pick_mmap_layout(struct mm_struct *mm)
32268 {
32269 - mm->mmap_legacy_base = mmap_legacy_base();
32270 - mm->mmap_base = mmap_base();
32271 + mm->mmap_legacy_base = mmap_legacy_base(mm);
32272 + mm->mmap_base = mmap_base(mm);
32273 +
32274 +#ifdef CONFIG_PAX_RANDMMAP
32275 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
32276 + mm->mmap_legacy_base += mm->delta_mmap;
32277 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32278 + }
32279 +#endif
32280
32281 if (mmap_is_legacy()) {
32282 mm->mmap_base = mm->mmap_legacy_base;
32283 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32284 index 0057a7a..95c7edd 100644
32285 --- a/arch/x86/mm/mmio-mod.c
32286 +++ b/arch/x86/mm/mmio-mod.c
32287 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32288 break;
32289 default:
32290 {
32291 - unsigned char *ip = (unsigned char *)instptr;
32292 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32293 my_trace->opcode = MMIO_UNKNOWN_OP;
32294 my_trace->width = 0;
32295 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32296 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32297 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32298 void __iomem *addr)
32299 {
32300 - static atomic_t next_id;
32301 + static atomic_unchecked_t next_id;
32302 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32303 /* These are page-unaligned. */
32304 struct mmiotrace_map map = {
32305 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32306 .private = trace
32307 },
32308 .phys = offset,
32309 - .id = atomic_inc_return(&next_id)
32310 + .id = atomic_inc_return_unchecked(&next_id)
32311 };
32312 map.map_id = trace->id;
32313
32314 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32315 ioremap_trace_core(offset, size, addr);
32316 }
32317
32318 -static void iounmap_trace_core(volatile void __iomem *addr)
32319 +static void iounmap_trace_core(const volatile void __iomem *addr)
32320 {
32321 struct mmiotrace_map map = {
32322 .phys = 0,
32323 @@ -328,7 +328,7 @@ not_enabled:
32324 }
32325 }
32326
32327 -void mmiotrace_iounmap(volatile void __iomem *addr)
32328 +void mmiotrace_iounmap(const volatile void __iomem *addr)
32329 {
32330 might_sleep();
32331 if (is_enabled()) /* recheck and proper locking in *_core() */
32332 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32333 index 24aec58..c39fe8b 100644
32334 --- a/arch/x86/mm/numa.c
32335 +++ b/arch/x86/mm/numa.c
32336 @@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32337 return true;
32338 }
32339
32340 -static int __init numa_register_memblks(struct numa_meminfo *mi)
32341 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32342 {
32343 unsigned long uninitialized_var(pfn_align);
32344 int i, nid;
32345 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32346 index d0b1773..4c3327c 100644
32347 --- a/arch/x86/mm/pageattr-test.c
32348 +++ b/arch/x86/mm/pageattr-test.c
32349 @@ -36,7 +36,7 @@ enum {
32350
32351 static int pte_testbit(pte_t pte)
32352 {
32353 - return pte_flags(pte) & _PAGE_UNUSED1;
32354 + return pte_flags(pte) & _PAGE_CPA_TEST;
32355 }
32356
32357 struct split_state {
32358 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32359 index bb32480..75f2f5e 100644
32360 --- a/arch/x86/mm/pageattr.c
32361 +++ b/arch/x86/mm/pageattr.c
32362 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32363 */
32364 #ifdef CONFIG_PCI_BIOS
32365 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32366 - pgprot_val(forbidden) |= _PAGE_NX;
32367 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32368 #endif
32369
32370 /*
32371 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32372 * Does not cover __inittext since that is gone later on. On
32373 * 64bit we do not enforce !NX on the low mapping
32374 */
32375 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
32376 - pgprot_val(forbidden) |= _PAGE_NX;
32377 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32378 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32379
32380 +#ifdef CONFIG_DEBUG_RODATA
32381 /*
32382 * The .rodata section needs to be read-only. Using the pfn
32383 * catches all aliases.
32384 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32385 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32386 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32387 pgprot_val(forbidden) |= _PAGE_RW;
32388 +#endif
32389
32390 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32391 /*
32392 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32393 }
32394 #endif
32395
32396 +#ifdef CONFIG_PAX_KERNEXEC
32397 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32398 + pgprot_val(forbidden) |= _PAGE_RW;
32399 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32400 + }
32401 +#endif
32402 +
32403 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32404
32405 return prot;
32406 @@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32407 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32408 {
32409 /* change init_mm */
32410 + pax_open_kernel();
32411 set_pte_atomic(kpte, pte);
32412 +
32413 #ifdef CONFIG_X86_32
32414 if (!SHARED_KERNEL_PMD) {
32415 +
32416 +#ifdef CONFIG_PAX_PER_CPU_PGD
32417 + unsigned long cpu;
32418 +#else
32419 struct page *page;
32420 +#endif
32421
32422 +#ifdef CONFIG_PAX_PER_CPU_PGD
32423 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32424 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32425 +#else
32426 list_for_each_entry(page, &pgd_list, lru) {
32427 - pgd_t *pgd;
32428 + pgd_t *pgd = (pgd_t *)page_address(page);
32429 +#endif
32430 +
32431 pud_t *pud;
32432 pmd_t *pmd;
32433
32434 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
32435 + pgd += pgd_index(address);
32436 pud = pud_offset(pgd, address);
32437 pmd = pmd_offset(pud, address);
32438 set_pte_atomic((pte_t *)pmd, pte);
32439 }
32440 }
32441 #endif
32442 + pax_close_kernel();
32443 }
32444
32445 static int
32446 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32447 index 6574388..87e9bef 100644
32448 --- a/arch/x86/mm/pat.c
32449 +++ b/arch/x86/mm/pat.c
32450 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32451
32452 if (!entry) {
32453 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32454 - current->comm, current->pid, start, end - 1);
32455 + current->comm, task_pid_nr(current), start, end - 1);
32456 return -EINVAL;
32457 }
32458
32459 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32460
32461 while (cursor < to) {
32462 if (!devmem_is_allowed(pfn)) {
32463 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
32464 - current->comm, from, to - 1);
32465 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
32466 + current->comm, from, to - 1, cursor);
32467 return 0;
32468 }
32469 cursor += PAGE_SIZE;
32470 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
32471 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
32472 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
32473 "for [mem %#010Lx-%#010Lx]\n",
32474 - current->comm, current->pid,
32475 + current->comm, task_pid_nr(current),
32476 cattr_name(flags),
32477 base, (unsigned long long)(base + size-1));
32478 return -EINVAL;
32479 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32480 flags = lookup_memtype(paddr);
32481 if (want_flags != flags) {
32482 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
32483 - current->comm, current->pid,
32484 + current->comm, task_pid_nr(current),
32485 cattr_name(want_flags),
32486 (unsigned long long)paddr,
32487 (unsigned long long)(paddr + size - 1),
32488 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32489 free_memtype(paddr, paddr + size);
32490 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
32491 " for [mem %#010Lx-%#010Lx], got %s\n",
32492 - current->comm, current->pid,
32493 + current->comm, task_pid_nr(current),
32494 cattr_name(want_flags),
32495 (unsigned long long)paddr,
32496 (unsigned long long)(paddr + size - 1),
32497 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
32498 index 415f6c4..d319983 100644
32499 --- a/arch/x86/mm/pat_rbtree.c
32500 +++ b/arch/x86/mm/pat_rbtree.c
32501 @@ -160,7 +160,7 @@ success:
32502
32503 failure:
32504 printk(KERN_INFO "%s:%d conflicting memory types "
32505 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
32506 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
32507 end, cattr_name(found_type), cattr_name(match->type));
32508 return -EBUSY;
32509 }
32510 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
32511 index 9f0614d..92ae64a 100644
32512 --- a/arch/x86/mm/pf_in.c
32513 +++ b/arch/x86/mm/pf_in.c
32514 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
32515 int i;
32516 enum reason_type rv = OTHERS;
32517
32518 - p = (unsigned char *)ins_addr;
32519 + p = (unsigned char *)ktla_ktva(ins_addr);
32520 p += skip_prefix(p, &prf);
32521 p += get_opcode(p, &opcode);
32522
32523 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
32524 struct prefix_bits prf;
32525 int i;
32526
32527 - p = (unsigned char *)ins_addr;
32528 + p = (unsigned char *)ktla_ktva(ins_addr);
32529 p += skip_prefix(p, &prf);
32530 p += get_opcode(p, &opcode);
32531
32532 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
32533 struct prefix_bits prf;
32534 int i;
32535
32536 - p = (unsigned char *)ins_addr;
32537 + p = (unsigned char *)ktla_ktva(ins_addr);
32538 p += skip_prefix(p, &prf);
32539 p += get_opcode(p, &opcode);
32540
32541 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
32542 struct prefix_bits prf;
32543 int i;
32544
32545 - p = (unsigned char *)ins_addr;
32546 + p = (unsigned char *)ktla_ktva(ins_addr);
32547 p += skip_prefix(p, &prf);
32548 p += get_opcode(p, &opcode);
32549 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
32550 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
32551 struct prefix_bits prf;
32552 int i;
32553
32554 - p = (unsigned char *)ins_addr;
32555 + p = (unsigned char *)ktla_ktva(ins_addr);
32556 p += skip_prefix(p, &prf);
32557 p += get_opcode(p, &opcode);
32558 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
32559 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
32560 index c96314a..433b127 100644
32561 --- a/arch/x86/mm/pgtable.c
32562 +++ b/arch/x86/mm/pgtable.c
32563 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
32564 list_del(&page->lru);
32565 }
32566
32567 -#define UNSHARED_PTRS_PER_PGD \
32568 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32569 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32570 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
32571
32572 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
32573 +{
32574 + unsigned int count = USER_PGD_PTRS;
32575
32576 + if (!pax_user_shadow_base)
32577 + return;
32578 +
32579 + while (count--)
32580 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
32581 +}
32582 +#endif
32583 +
32584 +#ifdef CONFIG_PAX_PER_CPU_PGD
32585 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
32586 +{
32587 + unsigned int count = USER_PGD_PTRS;
32588 +
32589 + while (count--) {
32590 + pgd_t pgd;
32591 +
32592 +#ifdef CONFIG_X86_64
32593 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
32594 +#else
32595 + pgd = *src++;
32596 +#endif
32597 +
32598 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32599 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
32600 +#endif
32601 +
32602 + *dst++ = pgd;
32603 + }
32604 +
32605 +}
32606 +#endif
32607 +
32608 +#ifdef CONFIG_X86_64
32609 +#define pxd_t pud_t
32610 +#define pyd_t pgd_t
32611 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
32612 +#define pgtable_pxd_page_ctor(page) true
32613 +#define pgtable_pxd_page_dtor(page)
32614 +#define pxd_free(mm, pud) pud_free((mm), (pud))
32615 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
32616 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
32617 +#define PYD_SIZE PGDIR_SIZE
32618 +#else
32619 +#define pxd_t pmd_t
32620 +#define pyd_t pud_t
32621 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
32622 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
32623 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
32624 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
32625 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
32626 +#define pyd_offset(mm, address) pud_offset((mm), (address))
32627 +#define PYD_SIZE PUD_SIZE
32628 +#endif
32629 +
32630 +#ifdef CONFIG_PAX_PER_CPU_PGD
32631 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
32632 +static inline void pgd_dtor(pgd_t *pgd) {}
32633 +#else
32634 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
32635 {
32636 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
32637 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
32638 pgd_list_del(pgd);
32639 spin_unlock(&pgd_lock);
32640 }
32641 +#endif
32642
32643 /*
32644 * List of all pgd's needed for non-PAE so it can invalidate entries
32645 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
32646 * -- nyc
32647 */
32648
32649 -#ifdef CONFIG_X86_PAE
32650 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
32651 /*
32652 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
32653 * updating the top-level pagetable entries to guarantee the
32654 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
32655 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
32656 * and initialize the kernel pmds here.
32657 */
32658 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
32659 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32660
32661 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32662 {
32663 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32664 */
32665 flush_tlb_mm(mm);
32666 }
32667 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
32668 +#define PREALLOCATED_PXDS USER_PGD_PTRS
32669 #else /* !CONFIG_X86_PAE */
32670
32671 /* No need to prepopulate any pagetable entries in non-PAE modes. */
32672 -#define PREALLOCATED_PMDS 0
32673 +#define PREALLOCATED_PXDS 0
32674
32675 #endif /* CONFIG_X86_PAE */
32676
32677 -static void free_pmds(pmd_t *pmds[])
32678 +static void free_pxds(pxd_t *pxds[])
32679 {
32680 int i;
32681
32682 - for(i = 0; i < PREALLOCATED_PMDS; i++)
32683 - if (pmds[i]) {
32684 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
32685 - free_page((unsigned long)pmds[i]);
32686 + for(i = 0; i < PREALLOCATED_PXDS; i++)
32687 + if (pxds[i]) {
32688 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
32689 + free_page((unsigned long)pxds[i]);
32690 }
32691 }
32692
32693 -static int preallocate_pmds(pmd_t *pmds[])
32694 +static int preallocate_pxds(pxd_t *pxds[])
32695 {
32696 int i;
32697 bool failed = false;
32698
32699 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
32700 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
32701 - if (!pmd)
32702 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
32703 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
32704 + if (!pxd)
32705 failed = true;
32706 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
32707 - free_page((unsigned long)pmd);
32708 - pmd = NULL;
32709 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
32710 + free_page((unsigned long)pxd);
32711 + pxd = NULL;
32712 failed = true;
32713 }
32714 - pmds[i] = pmd;
32715 + pxds[i] = pxd;
32716 }
32717
32718 if (failed) {
32719 - free_pmds(pmds);
32720 + free_pxds(pxds);
32721 return -ENOMEM;
32722 }
32723
32724 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
32725 * preallocate which never got a corresponding vma will need to be
32726 * freed manually.
32727 */
32728 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32729 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32730 {
32731 int i;
32732
32733 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
32734 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
32735 pgd_t pgd = pgdp[i];
32736
32737 if (pgd_val(pgd) != 0) {
32738 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32739 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32740
32741 - pgdp[i] = native_make_pgd(0);
32742 + set_pgd(pgdp + i, native_make_pgd(0));
32743
32744 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32745 - pmd_free(mm, pmd);
32746 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32747 + pxd_free(mm, pxd);
32748 }
32749 }
32750 }
32751
32752 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32753 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32754 {
32755 - pud_t *pud;
32756 + pyd_t *pyd;
32757 int i;
32758
32759 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32760 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32761 return;
32762
32763 - pud = pud_offset(pgd, 0);
32764 -
32765 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32766 - pmd_t *pmd = pmds[i];
32767 +#ifdef CONFIG_X86_64
32768 + pyd = pyd_offset(mm, 0L);
32769 +#else
32770 + pyd = pyd_offset(pgd, 0L);
32771 +#endif
32772
32773 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32774 + pxd_t *pxd = pxds[i];
32775 if (i >= KERNEL_PGD_BOUNDARY)
32776 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32777 - sizeof(pmd_t) * PTRS_PER_PMD);
32778 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32779 + sizeof(pxd_t) * PTRS_PER_PMD);
32780
32781 - pud_populate(mm, pud, pmd);
32782 + pyd_populate(mm, pyd, pxd);
32783 }
32784 }
32785
32786 pgd_t *pgd_alloc(struct mm_struct *mm)
32787 {
32788 pgd_t *pgd;
32789 - pmd_t *pmds[PREALLOCATED_PMDS];
32790 + pxd_t *pxds[PREALLOCATED_PXDS];
32791
32792 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32793
32794 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32795
32796 mm->pgd = pgd;
32797
32798 - if (preallocate_pmds(pmds) != 0)
32799 + if (preallocate_pxds(pxds) != 0)
32800 goto out_free_pgd;
32801
32802 if (paravirt_pgd_alloc(mm) != 0)
32803 - goto out_free_pmds;
32804 + goto out_free_pxds;
32805
32806 /*
32807 * Make sure that pre-populating the pmds is atomic with
32808 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32809 spin_lock(&pgd_lock);
32810
32811 pgd_ctor(mm, pgd);
32812 - pgd_prepopulate_pmd(mm, pgd, pmds);
32813 + pgd_prepopulate_pxd(mm, pgd, pxds);
32814
32815 spin_unlock(&pgd_lock);
32816
32817 return pgd;
32818
32819 -out_free_pmds:
32820 - free_pmds(pmds);
32821 +out_free_pxds:
32822 + free_pxds(pxds);
32823 out_free_pgd:
32824 free_page((unsigned long)pgd);
32825 out:
32826 @@ -313,7 +380,7 @@ out:
32827
32828 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32829 {
32830 - pgd_mop_up_pmds(mm, pgd);
32831 + pgd_mop_up_pxds(mm, pgd);
32832 pgd_dtor(pgd);
32833 paravirt_pgd_free(mm, pgd);
32834 free_page((unsigned long)pgd);
32835 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32836 index a69bcb8..19068ab 100644
32837 --- a/arch/x86/mm/pgtable_32.c
32838 +++ b/arch/x86/mm/pgtable_32.c
32839 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32840 return;
32841 }
32842 pte = pte_offset_kernel(pmd, vaddr);
32843 +
32844 + pax_open_kernel();
32845 if (pte_val(pteval))
32846 set_pte_at(&init_mm, vaddr, pte, pteval);
32847 else
32848 pte_clear(&init_mm, vaddr, pte);
32849 + pax_close_kernel();
32850
32851 /*
32852 * It's enough to flush this one mapping.
32853 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32854 index e666cbb..61788c45 100644
32855 --- a/arch/x86/mm/physaddr.c
32856 +++ b/arch/x86/mm/physaddr.c
32857 @@ -10,7 +10,7 @@
32858 #ifdef CONFIG_X86_64
32859
32860 #ifdef CONFIG_DEBUG_VIRTUAL
32861 -unsigned long __phys_addr(unsigned long x)
32862 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32863 {
32864 unsigned long y = x - __START_KERNEL_map;
32865
32866 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32867 #else
32868
32869 #ifdef CONFIG_DEBUG_VIRTUAL
32870 -unsigned long __phys_addr(unsigned long x)
32871 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32872 {
32873 unsigned long phys_addr = x - PAGE_OFFSET;
32874 /* VMALLOC_* aren't constants */
32875 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32876 index 90555bf..f5f1828 100644
32877 --- a/arch/x86/mm/setup_nx.c
32878 +++ b/arch/x86/mm/setup_nx.c
32879 @@ -5,8 +5,10 @@
32880 #include <asm/pgtable.h>
32881 #include <asm/proto.h>
32882
32883 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32884 static int disable_nx;
32885
32886 +#ifndef CONFIG_PAX_PAGEEXEC
32887 /*
32888 * noexec = on|off
32889 *
32890 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32891 return 0;
32892 }
32893 early_param("noexec", noexec_setup);
32894 +#endif
32895 +
32896 +#endif
32897
32898 void x86_configure_nx(void)
32899 {
32900 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32901 if (cpu_has_nx && !disable_nx)
32902 __supported_pte_mask |= _PAGE_NX;
32903 else
32904 +#endif
32905 __supported_pte_mask &= ~_PAGE_NX;
32906 }
32907
32908 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32909 index ae699b3..f1b2ad2 100644
32910 --- a/arch/x86/mm/tlb.c
32911 +++ b/arch/x86/mm/tlb.c
32912 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
32913 BUG();
32914 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32915 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32916 +
32917 +#ifndef CONFIG_PAX_PER_CPU_PGD
32918 load_cr3(swapper_pg_dir);
32919 +#endif
32920 +
32921 }
32922 }
32923 EXPORT_SYMBOL_GPL(leave_mm);
32924 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32925 new file mode 100644
32926 index 0000000..dace51c
32927 --- /dev/null
32928 +++ b/arch/x86/mm/uderef_64.c
32929 @@ -0,0 +1,37 @@
32930 +#include <linux/mm.h>
32931 +#include <asm/pgtable.h>
32932 +#include <asm/uaccess.h>
32933 +
32934 +#ifdef CONFIG_PAX_MEMORY_UDEREF
32935 +/* PaX: due to the special call convention these functions must
32936 + * - remain leaf functions under all configurations,
32937 + * - never be called directly, only dereferenced from the wrappers.
32938 + */
32939 +void __pax_open_userland(void)
32940 +{
32941 + unsigned int cpu;
32942 +
32943 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
32944 + return;
32945 +
32946 + cpu = raw_get_cpu();
32947 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32948 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32949 + raw_put_cpu_no_resched();
32950 +}
32951 +EXPORT_SYMBOL(__pax_open_userland);
32952 +
32953 +void __pax_close_userland(void)
32954 +{
32955 + unsigned int cpu;
32956 +
32957 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
32958 + return;
32959 +
32960 + cpu = raw_get_cpu();
32961 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32962 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32963 + raw_put_cpu_no_resched();
32964 +}
32965 +EXPORT_SYMBOL(__pax_close_userland);
32966 +#endif
32967 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32968 index 877b9a1..a8ecf42 100644
32969 --- a/arch/x86/net/bpf_jit.S
32970 +++ b/arch/x86/net/bpf_jit.S
32971 @@ -9,6 +9,7 @@
32972 */
32973 #include <linux/linkage.h>
32974 #include <asm/dwarf2.h>
32975 +#include <asm/alternative-asm.h>
32976
32977 /*
32978 * Calling convention :
32979 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32980 jle bpf_slow_path_word
32981 mov (SKBDATA,%rsi),%eax
32982 bswap %eax /* ntohl() */
32983 + pax_force_retaddr
32984 ret
32985
32986 sk_load_half:
32987 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32988 jle bpf_slow_path_half
32989 movzwl (SKBDATA,%rsi),%eax
32990 rol $8,%ax # ntohs()
32991 + pax_force_retaddr
32992 ret
32993
32994 sk_load_byte:
32995 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32996 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32997 jle bpf_slow_path_byte
32998 movzbl (SKBDATA,%rsi),%eax
32999 + pax_force_retaddr
33000 ret
33001
33002 /**
33003 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33004 movzbl (SKBDATA,%rsi),%ebx
33005 and $15,%bl
33006 shl $2,%bl
33007 + pax_force_retaddr
33008 ret
33009
33010 /* rsi contains offset and can be scratched */
33011 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33012 js bpf_error
33013 mov -12(%rbp),%eax
33014 bswap %eax
33015 + pax_force_retaddr
33016 ret
33017
33018 bpf_slow_path_half:
33019 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33020 mov -12(%rbp),%ax
33021 rol $8,%ax
33022 movzwl %ax,%eax
33023 + pax_force_retaddr
33024 ret
33025
33026 bpf_slow_path_byte:
33027 bpf_slow_path_common(1)
33028 js bpf_error
33029 movzbl -12(%rbp),%eax
33030 + pax_force_retaddr
33031 ret
33032
33033 bpf_slow_path_byte_msh:
33034 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33035 and $15,%al
33036 shl $2,%al
33037 xchg %eax,%ebx
33038 + pax_force_retaddr
33039 ret
33040
33041 #define sk_negative_common(SIZE) \
33042 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33043 sk_negative_common(4)
33044 mov (%rax), %eax
33045 bswap %eax
33046 + pax_force_retaddr
33047 ret
33048
33049 bpf_slow_path_half_neg:
33050 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33051 mov (%rax),%ax
33052 rol $8,%ax
33053 movzwl %ax,%eax
33054 + pax_force_retaddr
33055 ret
33056
33057 bpf_slow_path_byte_neg:
33058 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33059 .globl sk_load_byte_negative_offset
33060 sk_negative_common(1)
33061 movzbl (%rax), %eax
33062 + pax_force_retaddr
33063 ret
33064
33065 bpf_slow_path_byte_msh_neg:
33066 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33067 and $15,%al
33068 shl $2,%al
33069 xchg %eax,%ebx
33070 + pax_force_retaddr
33071 ret
33072
33073 bpf_error:
33074 @@ -197,4 +210,5 @@ bpf_error:
33075 xor %eax,%eax
33076 mov -8(%rbp),%rbx
33077 leaveq
33078 + pax_force_retaddr
33079 ret
33080 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33081 index 4ed75dd..8dfe0d5 100644
33082 --- a/arch/x86/net/bpf_jit_comp.c
33083 +++ b/arch/x86/net/bpf_jit_comp.c
33084 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33085 return ptr + len;
33086 }
33087
33088 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33089 +#define MAX_INSTR_CODE_SIZE 96
33090 +#else
33091 +#define MAX_INSTR_CODE_SIZE 64
33092 +#endif
33093 +
33094 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33095
33096 #define EMIT1(b1) EMIT(b1, 1)
33097 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33098 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33099 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33100 +
33101 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33102 +/* original constant will appear in ecx */
33103 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33104 +do { \
33105 + /* mov ecx, randkey */ \
33106 + EMIT1(0xb9); \
33107 + EMIT(_key, 4); \
33108 + /* xor ecx, randkey ^ off */ \
33109 + EMIT2(0x81, 0xf1); \
33110 + EMIT((_key) ^ (_off), 4); \
33111 +} while (0)
33112 +
33113 +#define EMIT1_off32(b1, _off) \
33114 +do { \
33115 + switch (b1) { \
33116 + case 0x05: /* add eax, imm32 */ \
33117 + case 0x2d: /* sub eax, imm32 */ \
33118 + case 0x25: /* and eax, imm32 */ \
33119 + case 0x0d: /* or eax, imm32 */ \
33120 + case 0xb8: /* mov eax, imm32 */ \
33121 + case 0x35: /* xor eax, imm32 */ \
33122 + case 0x3d: /* cmp eax, imm32 */ \
33123 + case 0xa9: /* test eax, imm32 */ \
33124 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33125 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33126 + break; \
33127 + case 0xbb: /* mov ebx, imm32 */ \
33128 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33129 + /* mov ebx, ecx */ \
33130 + EMIT2(0x89, 0xcb); \
33131 + break; \
33132 + case 0xbe: /* mov esi, imm32 */ \
33133 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33134 + /* mov esi, ecx */ \
33135 + EMIT2(0x89, 0xce); \
33136 + break; \
33137 + case 0xe8: /* call rel imm32, always to known funcs */ \
33138 + EMIT1(b1); \
33139 + EMIT(_off, 4); \
33140 + break; \
33141 + case 0xe9: /* jmp rel imm32 */ \
33142 + EMIT1(b1); \
33143 + EMIT(_off, 4); \
33144 + /* prevent fall-through, we're not called if off = 0 */ \
33145 + EMIT(0xcccccccc, 4); \
33146 + EMIT(0xcccccccc, 4); \
33147 + break; \
33148 + default: \
33149 + BUILD_BUG(); \
33150 + } \
33151 +} while (0)
33152 +
33153 +#define EMIT2_off32(b1, b2, _off) \
33154 +do { \
33155 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33156 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33157 + EMIT(randkey, 4); \
33158 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33159 + EMIT((_off) - randkey, 4); \
33160 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33161 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33162 + /* imul eax, ecx */ \
33163 + EMIT3(0x0f, 0xaf, 0xc1); \
33164 + } else { \
33165 + BUILD_BUG(); \
33166 + } \
33167 +} while (0)
33168 +#else
33169 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33170 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33171 +#endif
33172
33173 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33174 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33175 @@ -91,6 +168,24 @@ do { \
33176 #define X86_JBE 0x76
33177 #define X86_JA 0x77
33178
33179 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33180 +#define APPEND_FLOW_VERIFY() \
33181 +do { \
33182 + /* mov ecx, randkey */ \
33183 + EMIT1(0xb9); \
33184 + EMIT(randkey, 4); \
33185 + /* cmp ecx, randkey */ \
33186 + EMIT2(0x81, 0xf9); \
33187 + EMIT(randkey, 4); \
33188 + /* jz after 8 int 3s */ \
33189 + EMIT2(0x74, 0x08); \
33190 + EMIT(0xcccccccc, 4); \
33191 + EMIT(0xcccccccc, 4); \
33192 +} while (0)
33193 +#else
33194 +#define APPEND_FLOW_VERIFY() do { } while (0)
33195 +#endif
33196 +
33197 #define EMIT_COND_JMP(op, offset) \
33198 do { \
33199 if (is_near(offset)) \
33200 @@ -98,6 +193,7 @@ do { \
33201 else { \
33202 EMIT2(0x0f, op + 0x10); \
33203 EMIT(offset, 4); /* jxx .+off32 */ \
33204 + APPEND_FLOW_VERIFY(); \
33205 } \
33206 } while (0)
33207
33208 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33209 return -1;
33210 }
33211
33212 -struct bpf_binary_header {
33213 - unsigned int pages;
33214 - /* Note : for security reasons, bpf code will follow a randomly
33215 - * sized amount of int3 instructions
33216 - */
33217 - u8 image[];
33218 -};
33219 -
33220 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33221 +/* Note : for security reasons, bpf code will follow a randomly
33222 + * sized amount of int3 instructions
33223 + */
33224 +static u8 *bpf_alloc_binary(unsigned int proglen,
33225 u8 **image_ptr)
33226 {
33227 unsigned int sz, hole;
33228 - struct bpf_binary_header *header;
33229 + u8 *header;
33230
33231 /* Most of BPF filters are really small,
33232 * but if some of them fill a page, allow at least
33233 * 128 extra bytes to insert a random section of int3
33234 */
33235 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33236 - header = module_alloc(sz);
33237 + sz = round_up(proglen + 128, PAGE_SIZE);
33238 + header = module_alloc_exec(sz);
33239 if (!header)
33240 return NULL;
33241
33242 + pax_open_kernel();
33243 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33244 + pax_close_kernel();
33245
33246 - header->pages = sz / PAGE_SIZE;
33247 - hole = sz - (proglen + sizeof(*header));
33248 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33249
33250 /* insert a random number of int3 instructions before BPF code */
33251 - *image_ptr = &header->image[prandom_u32() % hole];
33252 + *image_ptr = &header[prandom_u32() % hole];
33253 return header;
33254 }
33255
33256 void bpf_jit_compile(struct sk_filter *fp)
33257 {
33258 - u8 temp[64];
33259 + u8 temp[MAX_INSTR_CODE_SIZE];
33260 u8 *prog;
33261 unsigned int proglen, oldproglen = 0;
33262 int ilen, i;
33263 int t_offset, f_offset;
33264 u8 t_op, f_op, seen = 0, pass;
33265 u8 *image = NULL;
33266 - struct bpf_binary_header *header = NULL;
33267 + u8 *header = NULL;
33268 u8 *func;
33269 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33270 unsigned int cleanup_addr; /* epilogue code offset */
33271 unsigned int *addrs;
33272 const struct sock_filter *filter = fp->insns;
33273 int flen = fp->len;
33274 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33275 + unsigned int randkey;
33276 +#endif
33277
33278 if (!bpf_jit_enable)
33279 return;
33280 @@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
33281 if (addrs == NULL)
33282 return;
33283
33284 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33285 + randkey = get_random_int();
33286 +#endif
33287 +
33288 /* Before first pass, make a rough estimation of addrs[]
33289 - * each bpf instruction is translated to less than 64 bytes
33290 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33291 */
33292 for (proglen = 0, i = 0; i < flen; i++) {
33293 - proglen += 64;
33294 + proglen += MAX_INSTR_CODE_SIZE;
33295 addrs[i] = proglen;
33296 }
33297 cleanup_addr = proglen; /* epilogue address */
33298 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33299 case BPF_S_ALU_MUL_K: /* A *= K */
33300 if (is_imm8(K))
33301 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33302 - else {
33303 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33304 - EMIT(K, 4);
33305 - }
33306 + else
33307 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33308 break;
33309 case BPF_S_ALU_DIV_X: /* A /= X; */
33310 seen |= SEEN_XREG;
33311 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33312 break;
33313 }
33314 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33315 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33316 + DILUTE_CONST_SEQUENCE(K, randkey);
33317 +#else
33318 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33319 +#endif
33320 EMIT2(0xf7, 0xf1); /* div %ecx */
33321 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33322 break;
33323 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33324 if (K == 1)
33325 break;
33326 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33327 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33328 + DILUTE_CONST_SEQUENCE(K, randkey);
33329 +#else
33330 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33331 +#endif
33332 EMIT2(0xf7, 0xf1); /* div %ecx */
33333 break;
33334 case BPF_S_ALU_AND_X:
33335 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33336 if (is_imm8(K)) {
33337 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33338 } else {
33339 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33340 - EMIT(K, 4);
33341 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33342 }
33343 } else {
33344 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33345 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33346 if (unlikely(proglen + ilen > oldproglen)) {
33347 pr_err("bpb_jit_compile fatal error\n");
33348 kfree(addrs);
33349 - module_free(NULL, header);
33350 + module_free_exec(NULL, image);
33351 return;
33352 }
33353 + pax_open_kernel();
33354 memcpy(image + proglen, temp, ilen);
33355 + pax_close_kernel();
33356 }
33357 proglen += ilen;
33358 addrs[i] = proglen;
33359 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33360
33361 if (image) {
33362 bpf_flush_icache(header, image + proglen);
33363 - set_memory_ro((unsigned long)header, header->pages);
33364 fp->bpf_func = (void *)image;
33365 }
33366 out:
33367 @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33368 {
33369 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33370 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33371 - struct bpf_binary_header *header = (void *)addr;
33372
33373 - set_memory_rw(addr, header->pages);
33374 - module_free(NULL, header);
33375 + set_memory_rw(addr, 1);
33376 + module_free_exec(NULL, (void *)addr);
33377 kfree(fp);
33378 }
33379
33380 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33381 index 5d04be5..2beeaa2 100644
33382 --- a/arch/x86/oprofile/backtrace.c
33383 +++ b/arch/x86/oprofile/backtrace.c
33384 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33385 struct stack_frame_ia32 *fp;
33386 unsigned long bytes;
33387
33388 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33389 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33390 if (bytes != 0)
33391 return NULL;
33392
33393 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33394 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33395
33396 oprofile_add_trace(bufhead[0].return_address);
33397
33398 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33399 struct stack_frame bufhead[2];
33400 unsigned long bytes;
33401
33402 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33403 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33404 if (bytes != 0)
33405 return NULL;
33406
33407 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33408 {
33409 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33410
33411 - if (!user_mode_vm(regs)) {
33412 + if (!user_mode(regs)) {
33413 unsigned long stack = kernel_stack_pointer(regs);
33414 if (depth)
33415 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33416 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33417 index 6890d84..1dad1f1 100644
33418 --- a/arch/x86/oprofile/nmi_int.c
33419 +++ b/arch/x86/oprofile/nmi_int.c
33420 @@ -23,6 +23,7 @@
33421 #include <asm/nmi.h>
33422 #include <asm/msr.h>
33423 #include <asm/apic.h>
33424 +#include <asm/pgtable.h>
33425
33426 #include "op_counter.h"
33427 #include "op_x86_model.h"
33428 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33429 if (ret)
33430 return ret;
33431
33432 - if (!model->num_virt_counters)
33433 - model->num_virt_counters = model->num_counters;
33434 + if (!model->num_virt_counters) {
33435 + pax_open_kernel();
33436 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
33437 + pax_close_kernel();
33438 + }
33439
33440 mux_init(ops);
33441
33442 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33443 index 50d86c0..7985318 100644
33444 --- a/arch/x86/oprofile/op_model_amd.c
33445 +++ b/arch/x86/oprofile/op_model_amd.c
33446 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33447 num_counters = AMD64_NUM_COUNTERS;
33448 }
33449
33450 - op_amd_spec.num_counters = num_counters;
33451 - op_amd_spec.num_controls = num_counters;
33452 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33453 + pax_open_kernel();
33454 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
33455 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
33456 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33457 + pax_close_kernel();
33458
33459 return 0;
33460 }
33461 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
33462 index d90528e..0127e2b 100644
33463 --- a/arch/x86/oprofile/op_model_ppro.c
33464 +++ b/arch/x86/oprofile/op_model_ppro.c
33465 @@ -19,6 +19,7 @@
33466 #include <asm/msr.h>
33467 #include <asm/apic.h>
33468 #include <asm/nmi.h>
33469 +#include <asm/pgtable.h>
33470
33471 #include "op_x86_model.h"
33472 #include "op_counter.h"
33473 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
33474
33475 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
33476
33477 - op_arch_perfmon_spec.num_counters = num_counters;
33478 - op_arch_perfmon_spec.num_controls = num_counters;
33479 + pax_open_kernel();
33480 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
33481 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
33482 + pax_close_kernel();
33483 }
33484
33485 static int arch_perfmon_init(struct oprofile_operations *ignore)
33486 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
33487 index 71e8a67..6a313bb 100644
33488 --- a/arch/x86/oprofile/op_x86_model.h
33489 +++ b/arch/x86/oprofile/op_x86_model.h
33490 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
33491 void (*switch_ctrl)(struct op_x86_model_spec const *model,
33492 struct op_msrs const * const msrs);
33493 #endif
33494 -};
33495 +} __do_const;
33496
33497 struct op_counter_config;
33498
33499 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
33500 index 51384ca..a25f51e 100644
33501 --- a/arch/x86/pci/intel_mid_pci.c
33502 +++ b/arch/x86/pci/intel_mid_pci.c
33503 @@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
33504 pr_info("Intel MID platform detected, using MID PCI ops\n");
33505 pci_mmcfg_late_init();
33506 pcibios_enable_irq = intel_mid_pci_irq_enable;
33507 - pci_root_ops = intel_mid_pci_ops;
33508 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
33509 pci_soc_mode = 1;
33510 /* Continue with standard init */
33511 return 1;
33512 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
33513 index 372e9b8..e775a6c 100644
33514 --- a/arch/x86/pci/irq.c
33515 +++ b/arch/x86/pci/irq.c
33516 @@ -50,7 +50,7 @@ struct irq_router {
33517 struct irq_router_handler {
33518 u16 vendor;
33519 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
33520 -};
33521 +} __do_const;
33522
33523 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
33524 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
33525 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
33526 return 0;
33527 }
33528
33529 -static __initdata struct irq_router_handler pirq_routers[] = {
33530 +static __initconst const struct irq_router_handler pirq_routers[] = {
33531 { PCI_VENDOR_ID_INTEL, intel_router_probe },
33532 { PCI_VENDOR_ID_AL, ali_router_probe },
33533 { PCI_VENDOR_ID_ITE, ite_router_probe },
33534 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
33535 static void __init pirq_find_router(struct irq_router *r)
33536 {
33537 struct irq_routing_table *rt = pirq_table;
33538 - struct irq_router_handler *h;
33539 + const struct irq_router_handler *h;
33540
33541 #ifdef CONFIG_PCI_BIOS
33542 if (!rt->signature) {
33543 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
33544 return 0;
33545 }
33546
33547 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
33548 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
33549 {
33550 .callback = fix_broken_hp_bios_irq9,
33551 .ident = "HP Pavilion N5400 Series Laptop",
33552 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
33553 index c77b24a..c979855 100644
33554 --- a/arch/x86/pci/pcbios.c
33555 +++ b/arch/x86/pci/pcbios.c
33556 @@ -79,7 +79,7 @@ union bios32 {
33557 static struct {
33558 unsigned long address;
33559 unsigned short segment;
33560 -} bios32_indirect = { 0, __KERNEL_CS };
33561 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
33562
33563 /*
33564 * Returns the entry point for the given service, NULL on error
33565 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
33566 unsigned long length; /* %ecx */
33567 unsigned long entry; /* %edx */
33568 unsigned long flags;
33569 + struct desc_struct d, *gdt;
33570
33571 local_irq_save(flags);
33572 - __asm__("lcall *(%%edi); cld"
33573 +
33574 + gdt = get_cpu_gdt_table(smp_processor_id());
33575 +
33576 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
33577 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33578 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
33579 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33580 +
33581 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
33582 : "=a" (return_code),
33583 "=b" (address),
33584 "=c" (length),
33585 "=d" (entry)
33586 : "0" (service),
33587 "1" (0),
33588 - "D" (&bios32_indirect));
33589 + "D" (&bios32_indirect),
33590 + "r"(__PCIBIOS_DS)
33591 + : "memory");
33592 +
33593 + pax_open_kernel();
33594 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
33595 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
33596 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
33597 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
33598 + pax_close_kernel();
33599 +
33600 local_irq_restore(flags);
33601
33602 switch (return_code) {
33603 - case 0:
33604 - return address + entry;
33605 - case 0x80: /* Not present */
33606 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33607 - return 0;
33608 - default: /* Shouldn't happen */
33609 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33610 - service, return_code);
33611 + case 0: {
33612 + int cpu;
33613 + unsigned char flags;
33614 +
33615 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
33616 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
33617 + printk(KERN_WARNING "bios32_service: not valid\n");
33618 return 0;
33619 + }
33620 + address = address + PAGE_OFFSET;
33621 + length += 16UL; /* some BIOSs underreport this... */
33622 + flags = 4;
33623 + if (length >= 64*1024*1024) {
33624 + length >>= PAGE_SHIFT;
33625 + flags |= 8;
33626 + }
33627 +
33628 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33629 + gdt = get_cpu_gdt_table(cpu);
33630 + pack_descriptor(&d, address, length, 0x9b, flags);
33631 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33632 + pack_descriptor(&d, address, length, 0x93, flags);
33633 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33634 + }
33635 + return entry;
33636 + }
33637 + case 0x80: /* Not present */
33638 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33639 + return 0;
33640 + default: /* Shouldn't happen */
33641 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33642 + service, return_code);
33643 + return 0;
33644 }
33645 }
33646
33647 static struct {
33648 unsigned long address;
33649 unsigned short segment;
33650 -} pci_indirect = { 0, __KERNEL_CS };
33651 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
33652
33653 -static int pci_bios_present;
33654 +static int pci_bios_present __read_only;
33655
33656 static int check_pcibios(void)
33657 {
33658 @@ -131,11 +174,13 @@ static int check_pcibios(void)
33659 unsigned long flags, pcibios_entry;
33660
33661 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
33662 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
33663 + pci_indirect.address = pcibios_entry;
33664
33665 local_irq_save(flags);
33666 - __asm__(
33667 - "lcall *(%%edi); cld\n\t"
33668 + __asm__("movw %w6, %%ds\n\t"
33669 + "lcall *%%ss:(%%edi); cld\n\t"
33670 + "push %%ss\n\t"
33671 + "pop %%ds\n\t"
33672 "jc 1f\n\t"
33673 "xor %%ah, %%ah\n"
33674 "1:"
33675 @@ -144,7 +189,8 @@ static int check_pcibios(void)
33676 "=b" (ebx),
33677 "=c" (ecx)
33678 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
33679 - "D" (&pci_indirect)
33680 + "D" (&pci_indirect),
33681 + "r" (__PCIBIOS_DS)
33682 : "memory");
33683 local_irq_restore(flags);
33684
33685 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33686
33687 switch (len) {
33688 case 1:
33689 - __asm__("lcall *(%%esi); cld\n\t"
33690 + __asm__("movw %w6, %%ds\n\t"
33691 + "lcall *%%ss:(%%esi); cld\n\t"
33692 + "push %%ss\n\t"
33693 + "pop %%ds\n\t"
33694 "jc 1f\n\t"
33695 "xor %%ah, %%ah\n"
33696 "1:"
33697 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33698 : "1" (PCIBIOS_READ_CONFIG_BYTE),
33699 "b" (bx),
33700 "D" ((long)reg),
33701 - "S" (&pci_indirect));
33702 + "S" (&pci_indirect),
33703 + "r" (__PCIBIOS_DS));
33704 /*
33705 * Zero-extend the result beyond 8 bits, do not trust the
33706 * BIOS having done it:
33707 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33708 *value &= 0xff;
33709 break;
33710 case 2:
33711 - __asm__("lcall *(%%esi); cld\n\t"
33712 + __asm__("movw %w6, %%ds\n\t"
33713 + "lcall *%%ss:(%%esi); cld\n\t"
33714 + "push %%ss\n\t"
33715 + "pop %%ds\n\t"
33716 "jc 1f\n\t"
33717 "xor %%ah, %%ah\n"
33718 "1:"
33719 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33720 : "1" (PCIBIOS_READ_CONFIG_WORD),
33721 "b" (bx),
33722 "D" ((long)reg),
33723 - "S" (&pci_indirect));
33724 + "S" (&pci_indirect),
33725 + "r" (__PCIBIOS_DS));
33726 /*
33727 * Zero-extend the result beyond 16 bits, do not trust the
33728 * BIOS having done it:
33729 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33730 *value &= 0xffff;
33731 break;
33732 case 4:
33733 - __asm__("lcall *(%%esi); cld\n\t"
33734 + __asm__("movw %w6, %%ds\n\t"
33735 + "lcall *%%ss:(%%esi); cld\n\t"
33736 + "push %%ss\n\t"
33737 + "pop %%ds\n\t"
33738 "jc 1f\n\t"
33739 "xor %%ah, %%ah\n"
33740 "1:"
33741 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33742 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33743 "b" (bx),
33744 "D" ((long)reg),
33745 - "S" (&pci_indirect));
33746 + "S" (&pci_indirect),
33747 + "r" (__PCIBIOS_DS));
33748 break;
33749 }
33750
33751 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33752
33753 switch (len) {
33754 case 1:
33755 - __asm__("lcall *(%%esi); cld\n\t"
33756 + __asm__("movw %w6, %%ds\n\t"
33757 + "lcall *%%ss:(%%esi); cld\n\t"
33758 + "push %%ss\n\t"
33759 + "pop %%ds\n\t"
33760 "jc 1f\n\t"
33761 "xor %%ah, %%ah\n"
33762 "1:"
33763 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33764 "c" (value),
33765 "b" (bx),
33766 "D" ((long)reg),
33767 - "S" (&pci_indirect));
33768 + "S" (&pci_indirect),
33769 + "r" (__PCIBIOS_DS));
33770 break;
33771 case 2:
33772 - __asm__("lcall *(%%esi); cld\n\t"
33773 + __asm__("movw %w6, %%ds\n\t"
33774 + "lcall *%%ss:(%%esi); cld\n\t"
33775 + "push %%ss\n\t"
33776 + "pop %%ds\n\t"
33777 "jc 1f\n\t"
33778 "xor %%ah, %%ah\n"
33779 "1:"
33780 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33781 "c" (value),
33782 "b" (bx),
33783 "D" ((long)reg),
33784 - "S" (&pci_indirect));
33785 + "S" (&pci_indirect),
33786 + "r" (__PCIBIOS_DS));
33787 break;
33788 case 4:
33789 - __asm__("lcall *(%%esi); cld\n\t"
33790 + __asm__("movw %w6, %%ds\n\t"
33791 + "lcall *%%ss:(%%esi); cld\n\t"
33792 + "push %%ss\n\t"
33793 + "pop %%ds\n\t"
33794 "jc 1f\n\t"
33795 "xor %%ah, %%ah\n"
33796 "1:"
33797 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33798 "c" (value),
33799 "b" (bx),
33800 "D" ((long)reg),
33801 - "S" (&pci_indirect));
33802 + "S" (&pci_indirect),
33803 + "r" (__PCIBIOS_DS));
33804 break;
33805 }
33806
33807 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33808
33809 DBG("PCI: Fetching IRQ routing table... ");
33810 __asm__("push %%es\n\t"
33811 + "movw %w8, %%ds\n\t"
33812 "push %%ds\n\t"
33813 "pop %%es\n\t"
33814 - "lcall *(%%esi); cld\n\t"
33815 + "lcall *%%ss:(%%esi); cld\n\t"
33816 "pop %%es\n\t"
33817 + "push %%ss\n\t"
33818 + "pop %%ds\n"
33819 "jc 1f\n\t"
33820 "xor %%ah, %%ah\n"
33821 "1:"
33822 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33823 "1" (0),
33824 "D" ((long) &opt),
33825 "S" (&pci_indirect),
33826 - "m" (opt)
33827 + "m" (opt),
33828 + "r" (__PCIBIOS_DS)
33829 : "memory");
33830 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33831 if (ret & 0xff00)
33832 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33833 {
33834 int ret;
33835
33836 - __asm__("lcall *(%%esi); cld\n\t"
33837 + __asm__("movw %w5, %%ds\n\t"
33838 + "lcall *%%ss:(%%esi); cld\n\t"
33839 + "push %%ss\n\t"
33840 + "pop %%ds\n"
33841 "jc 1f\n\t"
33842 "xor %%ah, %%ah\n"
33843 "1:"
33844 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33845 : "0" (PCIBIOS_SET_PCI_HW_INT),
33846 "b" ((dev->bus->number << 8) | dev->devfn),
33847 "c" ((irq << 8) | (pin + 10)),
33848 - "S" (&pci_indirect));
33849 + "S" (&pci_indirect),
33850 + "r" (__PCIBIOS_DS));
33851 return !(ret & 0xff00);
33852 }
33853 EXPORT_SYMBOL(pcibios_set_irq_routing);
33854 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33855 index 40e4469..d915bf9 100644
33856 --- a/arch/x86/platform/efi/efi_32.c
33857 +++ b/arch/x86/platform/efi/efi_32.c
33858 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33859 {
33860 struct desc_ptr gdt_descr;
33861
33862 +#ifdef CONFIG_PAX_KERNEXEC
33863 + struct desc_struct d;
33864 +#endif
33865 +
33866 local_irq_save(efi_rt_eflags);
33867
33868 load_cr3(initial_page_table);
33869 __flush_tlb_all();
33870
33871 +#ifdef CONFIG_PAX_KERNEXEC
33872 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33873 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33874 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33875 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33876 +#endif
33877 +
33878 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33879 gdt_descr.size = GDT_SIZE - 1;
33880 load_gdt(&gdt_descr);
33881 @@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33882 {
33883 struct desc_ptr gdt_descr;
33884
33885 +#ifdef CONFIG_PAX_KERNEXEC
33886 + struct desc_struct d;
33887 +
33888 + memset(&d, 0, sizeof d);
33889 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33890 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33891 +#endif
33892 +
33893 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33894 gdt_descr.size = GDT_SIZE - 1;
33895 load_gdt(&gdt_descr);
33896
33897 +#ifdef CONFIG_PAX_PER_CPU_PGD
33898 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33899 +#else
33900 load_cr3(swapper_pg_dir);
33901 +#endif
33902 +
33903 __flush_tlb_all();
33904
33905 local_irq_restore(efi_rt_eflags);
33906 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33907 index 39a0e7f1..872396e 100644
33908 --- a/arch/x86/platform/efi/efi_64.c
33909 +++ b/arch/x86/platform/efi/efi_64.c
33910 @@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33911 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33912 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33913 }
33914 +
33915 +#ifdef CONFIG_PAX_PER_CPU_PGD
33916 + load_cr3(swapper_pg_dir);
33917 +#endif
33918 +
33919 __flush_tlb_all();
33920 }
33921
33922 @@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33923 for (pgd = 0; pgd < n_pgds; pgd++)
33924 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33925 kfree(save_pgd);
33926 +
33927 +#ifdef CONFIG_PAX_PER_CPU_PGD
33928 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33929 +#endif
33930 +
33931 __flush_tlb_all();
33932 local_irq_restore(efi_flags);
33933 early_code_mapping_set_exec(0);
33934 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33935 index fbe66e6..eae5e38 100644
33936 --- a/arch/x86/platform/efi/efi_stub_32.S
33937 +++ b/arch/x86/platform/efi/efi_stub_32.S
33938 @@ -6,7 +6,9 @@
33939 */
33940
33941 #include <linux/linkage.h>
33942 +#include <linux/init.h>
33943 #include <asm/page_types.h>
33944 +#include <asm/segment.h>
33945
33946 /*
33947 * efi_call_phys(void *, ...) is a function with variable parameters.
33948 @@ -20,7 +22,7 @@
33949 * service functions will comply with gcc calling convention, too.
33950 */
33951
33952 -.text
33953 +__INIT
33954 ENTRY(efi_call_phys)
33955 /*
33956 * 0. The function can only be called in Linux kernel. So CS has been
33957 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33958 * The mapping of lower virtual memory has been created in prelog and
33959 * epilog.
33960 */
33961 - movl $1f, %edx
33962 - subl $__PAGE_OFFSET, %edx
33963 - jmp *%edx
33964 +#ifdef CONFIG_PAX_KERNEXEC
33965 + movl $(__KERNEXEC_EFI_DS), %edx
33966 + mov %edx, %ds
33967 + mov %edx, %es
33968 + mov %edx, %ss
33969 + addl $2f,(1f)
33970 + ljmp *(1f)
33971 +
33972 +__INITDATA
33973 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33974 +.previous
33975 +
33976 +2:
33977 + subl $2b,(1b)
33978 +#else
33979 + jmp 1f-__PAGE_OFFSET
33980 1:
33981 +#endif
33982
33983 /*
33984 * 2. Now on the top of stack is the return
33985 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33986 * parameter 2, ..., param n. To make things easy, we save the return
33987 * address of efi_call_phys in a global variable.
33988 */
33989 - popl %edx
33990 - movl %edx, saved_return_addr
33991 - /* get the function pointer into ECX*/
33992 - popl %ecx
33993 - movl %ecx, efi_rt_function_ptr
33994 - movl $2f, %edx
33995 - subl $__PAGE_OFFSET, %edx
33996 - pushl %edx
33997 + popl (saved_return_addr)
33998 + popl (efi_rt_function_ptr)
33999
34000 /*
34001 * 3. Clear PG bit in %CR0.
34002 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34003 /*
34004 * 5. Call the physical function.
34005 */
34006 - jmp *%ecx
34007 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34008
34009 -2:
34010 /*
34011 * 6. After EFI runtime service returns, control will return to
34012 * following instruction. We'd better readjust stack pointer first.
34013 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34014 movl %cr0, %edx
34015 orl $0x80000000, %edx
34016 movl %edx, %cr0
34017 - jmp 1f
34018 -1:
34019 +
34020 /*
34021 * 8. Now restore the virtual mode from flat mode by
34022 * adding EIP with PAGE_OFFSET.
34023 */
34024 - movl $1f, %edx
34025 - jmp *%edx
34026 +#ifdef CONFIG_PAX_KERNEXEC
34027 + movl $(__KERNEL_DS), %edx
34028 + mov %edx, %ds
34029 + mov %edx, %es
34030 + mov %edx, %ss
34031 + ljmp $(__KERNEL_CS),$1f
34032 +#else
34033 + jmp 1f+__PAGE_OFFSET
34034 +#endif
34035 1:
34036
34037 /*
34038 * 9. Balance the stack. And because EAX contain the return value,
34039 * we'd better not clobber it.
34040 */
34041 - leal efi_rt_function_ptr, %edx
34042 - movl (%edx), %ecx
34043 - pushl %ecx
34044 + pushl (efi_rt_function_ptr)
34045
34046 /*
34047 - * 10. Push the saved return address onto the stack and return.
34048 + * 10. Return to the saved return address.
34049 */
34050 - leal saved_return_addr, %edx
34051 - movl (%edx), %ecx
34052 - pushl %ecx
34053 - ret
34054 + jmpl *(saved_return_addr)
34055 ENDPROC(efi_call_phys)
34056 .previous
34057
34058 -.data
34059 +__INITDATA
34060 saved_return_addr:
34061 .long 0
34062 efi_rt_function_ptr:
34063 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34064 index 4c07cca..2c8427d 100644
34065 --- a/arch/x86/platform/efi/efi_stub_64.S
34066 +++ b/arch/x86/platform/efi/efi_stub_64.S
34067 @@ -7,6 +7,7 @@
34068 */
34069
34070 #include <linux/linkage.h>
34071 +#include <asm/alternative-asm.h>
34072
34073 #define SAVE_XMM \
34074 mov %rsp, %rax; \
34075 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
34076 call *%rdi
34077 addq $32, %rsp
34078 RESTORE_XMM
34079 + pax_force_retaddr 0, 1
34080 ret
34081 ENDPROC(efi_call0)
34082
34083 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
34084 call *%rdi
34085 addq $32, %rsp
34086 RESTORE_XMM
34087 + pax_force_retaddr 0, 1
34088 ret
34089 ENDPROC(efi_call1)
34090
34091 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
34092 call *%rdi
34093 addq $32, %rsp
34094 RESTORE_XMM
34095 + pax_force_retaddr 0, 1
34096 ret
34097 ENDPROC(efi_call2)
34098
34099 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
34100 call *%rdi
34101 addq $32, %rsp
34102 RESTORE_XMM
34103 + pax_force_retaddr 0, 1
34104 ret
34105 ENDPROC(efi_call3)
34106
34107 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
34108 call *%rdi
34109 addq $32, %rsp
34110 RESTORE_XMM
34111 + pax_force_retaddr 0, 1
34112 ret
34113 ENDPROC(efi_call4)
34114
34115 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
34116 call *%rdi
34117 addq $48, %rsp
34118 RESTORE_XMM
34119 + pax_force_retaddr 0, 1
34120 ret
34121 ENDPROC(efi_call5)
34122
34123 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
34124 call *%rdi
34125 addq $48, %rsp
34126 RESTORE_XMM
34127 + pax_force_retaddr 0, 1
34128 ret
34129 ENDPROC(efi_call6)
34130 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34131 index f90e290..435f0dd 100644
34132 --- a/arch/x86/platform/intel-mid/intel-mid.c
34133 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34134 @@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34135 {
34136 }
34137
34138 -static void intel_mid_reboot(void)
34139 +static void __noreturn intel_mid_reboot(void)
34140 {
34141 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34142 + BUG();
34143 }
34144
34145 static unsigned long __init intel_mid_calibrate_tsc(void)
34146 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34147 index d6ee929..3637cb5 100644
34148 --- a/arch/x86/platform/olpc/olpc_dt.c
34149 +++ b/arch/x86/platform/olpc/olpc_dt.c
34150 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34151 return res;
34152 }
34153
34154 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34155 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34156 .nextprop = olpc_dt_nextprop,
34157 .getproplen = olpc_dt_getproplen,
34158 .getproperty = olpc_dt_getproperty,
34159 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34160 index 424f4c9..f2a2988 100644
34161 --- a/arch/x86/power/cpu.c
34162 +++ b/arch/x86/power/cpu.c
34163 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34164 static void fix_processor_context(void)
34165 {
34166 int cpu = smp_processor_id();
34167 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34168 -#ifdef CONFIG_X86_64
34169 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34170 - tss_desc tss;
34171 -#endif
34172 + struct tss_struct *t = init_tss + cpu;
34173 +
34174 set_tss_desc(cpu, t); /*
34175 * This just modifies memory; should not be
34176 * necessary. But... This is necessary, because
34177 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34178 */
34179
34180 #ifdef CONFIG_X86_64
34181 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34182 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34183 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34184 -
34185 syscall_init(); /* This sets MSR_*STAR and related */
34186 #endif
34187 load_TR_desc(); /* This does ltr */
34188 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34189 index a44f457..9140171 100644
34190 --- a/arch/x86/realmode/init.c
34191 +++ b/arch/x86/realmode/init.c
34192 @@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34193 __va(real_mode_header->trampoline_header);
34194
34195 #ifdef CONFIG_X86_32
34196 - trampoline_header->start = __pa_symbol(startup_32_smp);
34197 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34198 +
34199 +#ifdef CONFIG_PAX_KERNEXEC
34200 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34201 +#endif
34202 +
34203 + trampoline_header->boot_cs = __BOOT_CS;
34204 trampoline_header->gdt_limit = __BOOT_DS + 7;
34205 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34206 #else
34207 @@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34208 *trampoline_cr4_features = read_cr4();
34209
34210 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34211 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34212 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34213 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34214 #endif
34215 }
34216 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34217 index 9cac825..4890b25 100644
34218 --- a/arch/x86/realmode/rm/Makefile
34219 +++ b/arch/x86/realmode/rm/Makefile
34220 @@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34221 $(call cc-option, -fno-unit-at-a-time)) \
34222 $(call cc-option, -fno-stack-protector) \
34223 $(call cc-option, -mpreferred-stack-boundary=2)
34224 +ifdef CONSTIFY_PLUGIN
34225 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34226 +endif
34227 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34228 GCOV_PROFILE := n
34229 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34230 index a28221d..93c40f1 100644
34231 --- a/arch/x86/realmode/rm/header.S
34232 +++ b/arch/x86/realmode/rm/header.S
34233 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34234 #endif
34235 /* APM/BIOS reboot */
34236 .long pa_machine_real_restart_asm
34237 -#ifdef CONFIG_X86_64
34238 +#ifdef CONFIG_X86_32
34239 + .long __KERNEL_CS
34240 +#else
34241 .long __KERNEL32_CS
34242 #endif
34243 END(real_mode_header)
34244 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34245 index c1b2791..f9e31c7 100644
34246 --- a/arch/x86/realmode/rm/trampoline_32.S
34247 +++ b/arch/x86/realmode/rm/trampoline_32.S
34248 @@ -25,6 +25,12 @@
34249 #include <asm/page_types.h>
34250 #include "realmode.h"
34251
34252 +#ifdef CONFIG_PAX_KERNEXEC
34253 +#define ta(X) (X)
34254 +#else
34255 +#define ta(X) (pa_ ## X)
34256 +#endif
34257 +
34258 .text
34259 .code16
34260
34261 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34262
34263 cli # We should be safe anyway
34264
34265 - movl tr_start, %eax # where we need to go
34266 -
34267 movl $0xA5A5A5A5, trampoline_status
34268 # write marker for master knows we're running
34269
34270 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34271 movw $1, %dx # protected mode (PE) bit
34272 lmsw %dx # into protected mode
34273
34274 - ljmpl $__BOOT_CS, $pa_startup_32
34275 + ljmpl *(trampoline_header)
34276
34277 .section ".text32","ax"
34278 .code32
34279 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34280 .balign 8
34281 GLOBAL(trampoline_header)
34282 tr_start: .space 4
34283 - tr_gdt_pad: .space 2
34284 + tr_boot_cs: .space 2
34285 tr_gdt: .space 6
34286 END(trampoline_header)
34287
34288 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34289 index bb360dc..d0fd8f8 100644
34290 --- a/arch/x86/realmode/rm/trampoline_64.S
34291 +++ b/arch/x86/realmode/rm/trampoline_64.S
34292 @@ -94,6 +94,7 @@ ENTRY(startup_32)
34293 movl %edx, %gs
34294
34295 movl pa_tr_cr4, %eax
34296 + andl $~X86_CR4_PCIDE, %eax
34297 movl %eax, %cr4 # Enable PAE mode
34298
34299 # Setup trampoline 4 level pagetables
34300 @@ -107,7 +108,7 @@ ENTRY(startup_32)
34301 wrmsr
34302
34303 # Enable paging and in turn activate Long Mode
34304 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34305 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
34306 movl %eax, %cr0
34307
34308 /*
34309 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34310 index e812034..c747134 100644
34311 --- a/arch/x86/tools/Makefile
34312 +++ b/arch/x86/tools/Makefile
34313 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34314
34315 $(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
34316
34317 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34318 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34319 hostprogs-y += relocs
34320 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34321 relocs: $(obj)/relocs
34322 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34323 index f7bab68..b6d9886 100644
34324 --- a/arch/x86/tools/relocs.c
34325 +++ b/arch/x86/tools/relocs.c
34326 @@ -1,5 +1,7 @@
34327 /* This is included from relocs_32/64.c */
34328
34329 +#include "../../../include/generated/autoconf.h"
34330 +
34331 #define ElfW(type) _ElfW(ELF_BITS, type)
34332 #define _ElfW(bits, type) __ElfW(bits, type)
34333 #define __ElfW(bits, type) Elf##bits##_##type
34334 @@ -11,6 +13,7 @@
34335 #define Elf_Sym ElfW(Sym)
34336
34337 static Elf_Ehdr ehdr;
34338 +static Elf_Phdr *phdr;
34339
34340 struct relocs {
34341 uint32_t *offset;
34342 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34343 }
34344 }
34345
34346 +static void read_phdrs(FILE *fp)
34347 +{
34348 + unsigned int i;
34349 +
34350 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34351 + if (!phdr) {
34352 + die("Unable to allocate %d program headers\n",
34353 + ehdr.e_phnum);
34354 + }
34355 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34356 + die("Seek to %d failed: %s\n",
34357 + ehdr.e_phoff, strerror(errno));
34358 + }
34359 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34360 + die("Cannot read ELF program headers: %s\n",
34361 + strerror(errno));
34362 + }
34363 + for(i = 0; i < ehdr.e_phnum; i++) {
34364 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34365 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34366 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34367 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34368 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34369 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34370 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34371 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34372 + }
34373 +
34374 +}
34375 +
34376 static void read_shdrs(FILE *fp)
34377 {
34378 - int i;
34379 + unsigned int i;
34380 Elf_Shdr shdr;
34381
34382 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34383 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34384
34385 static void read_strtabs(FILE *fp)
34386 {
34387 - int i;
34388 + unsigned int i;
34389 for (i = 0; i < ehdr.e_shnum; i++) {
34390 struct section *sec = &secs[i];
34391 if (sec->shdr.sh_type != SHT_STRTAB) {
34392 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34393
34394 static void read_symtabs(FILE *fp)
34395 {
34396 - int i,j;
34397 + unsigned int i,j;
34398 for (i = 0; i < ehdr.e_shnum; i++) {
34399 struct section *sec = &secs[i];
34400 if (sec->shdr.sh_type != SHT_SYMTAB) {
34401 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34402 }
34403
34404
34405 -static void read_relocs(FILE *fp)
34406 +static void read_relocs(FILE *fp, int use_real_mode)
34407 {
34408 - int i,j;
34409 + unsigned int i,j;
34410 + uint32_t base;
34411 +
34412 for (i = 0; i < ehdr.e_shnum; i++) {
34413 struct section *sec = &secs[i];
34414 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34415 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34416 die("Cannot read symbol table: %s\n",
34417 strerror(errno));
34418 }
34419 + base = 0;
34420 +
34421 +#ifdef CONFIG_X86_32
34422 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34423 + if (phdr[j].p_type != PT_LOAD )
34424 + continue;
34425 + 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)
34426 + continue;
34427 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34428 + break;
34429 + }
34430 +#endif
34431 +
34432 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34433 Elf_Rel *rel = &sec->reltab[j];
34434 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34435 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34436 rel->r_info = elf_xword_to_cpu(rel->r_info);
34437 #if (SHT_REL_TYPE == SHT_RELA)
34438 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34439 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34440
34441 static void print_absolute_symbols(void)
34442 {
34443 - int i;
34444 + unsigned int i;
34445 const char *format;
34446
34447 if (ELF_BITS == 64)
34448 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
34449 for (i = 0; i < ehdr.e_shnum; i++) {
34450 struct section *sec = &secs[i];
34451 char *sym_strtab;
34452 - int j;
34453 + unsigned int j;
34454
34455 if (sec->shdr.sh_type != SHT_SYMTAB) {
34456 continue;
34457 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
34458
34459 static void print_absolute_relocs(void)
34460 {
34461 - int i, printed = 0;
34462 + unsigned int i, printed = 0;
34463 const char *format;
34464
34465 if (ELF_BITS == 64)
34466 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
34467 struct section *sec_applies, *sec_symtab;
34468 char *sym_strtab;
34469 Elf_Sym *sh_symtab;
34470 - int j;
34471 + unsigned int j;
34472 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34473 continue;
34474 }
34475 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
34476 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
34477 Elf_Sym *sym, const char *symname))
34478 {
34479 - int i;
34480 + unsigned int i;
34481 /* Walk through the relocations */
34482 for (i = 0; i < ehdr.e_shnum; i++) {
34483 char *sym_strtab;
34484 Elf_Sym *sh_symtab;
34485 struct section *sec_applies, *sec_symtab;
34486 - int j;
34487 + unsigned int j;
34488 struct section *sec = &secs[i];
34489
34490 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34491 @@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34492 {
34493 unsigned r_type = ELF32_R_TYPE(rel->r_info);
34494 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
34495 + char *sym_strtab = sec->link->link->strtab;
34496 +
34497 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
34498 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
34499 + return 0;
34500 +
34501 +#ifdef CONFIG_PAX_KERNEXEC
34502 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
34503 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
34504 + return 0;
34505 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
34506 + return 0;
34507 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
34508 + return 0;
34509 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
34510 + return 0;
34511 +#endif
34512
34513 switch (r_type) {
34514 case R_386_NONE:
34515 @@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
34516
34517 static void emit_relocs(int as_text, int use_real_mode)
34518 {
34519 - int i;
34520 + unsigned int i;
34521 int (*write_reloc)(uint32_t, FILE *) = write32;
34522 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34523 const char *symname);
34524 @@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
34525 {
34526 regex_init(use_real_mode);
34527 read_ehdr(fp);
34528 + read_phdrs(fp);
34529 read_shdrs(fp);
34530 read_strtabs(fp);
34531 read_symtabs(fp);
34532 - read_relocs(fp);
34533 + read_relocs(fp, use_real_mode);
34534 if (ELF_BITS == 64)
34535 percpu_init();
34536 if (show_absolute_syms) {
34537 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
34538 index 80ffa5b..a33bd15 100644
34539 --- a/arch/x86/um/tls_32.c
34540 +++ b/arch/x86/um/tls_32.c
34541 @@ -260,7 +260,7 @@ out:
34542 if (unlikely(task == current &&
34543 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
34544 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
34545 - "without flushed TLS.", current->pid);
34546 + "without flushed TLS.", task_pid_nr(current));
34547 }
34548
34549 return 0;
34550 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
34551 index fd14be1..e3c79c0 100644
34552 --- a/arch/x86/vdso/Makefile
34553 +++ b/arch/x86/vdso/Makefile
34554 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
34555 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
34556 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
34557
34558 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34559 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34560 GCOV_PROFILE := n
34561
34562 #
34563 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
34564 index d6bfb87..876ee18 100644
34565 --- a/arch/x86/vdso/vdso32-setup.c
34566 +++ b/arch/x86/vdso/vdso32-setup.c
34567 @@ -25,6 +25,7 @@
34568 #include <asm/tlbflush.h>
34569 #include <asm/vdso.h>
34570 #include <asm/proto.h>
34571 +#include <asm/mman.h>
34572
34573 enum {
34574 VDSO_DISABLED = 0,
34575 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
34576 void enable_sep_cpu(void)
34577 {
34578 int cpu = get_cpu();
34579 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
34580 + struct tss_struct *tss = init_tss + cpu;
34581
34582 if (!boot_cpu_has(X86_FEATURE_SEP)) {
34583 put_cpu();
34584 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
34585 gate_vma.vm_start = FIXADDR_USER_START;
34586 gate_vma.vm_end = FIXADDR_USER_END;
34587 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34588 - gate_vma.vm_page_prot = __P101;
34589 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34590
34591 return 0;
34592 }
34593 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34594 if (compat)
34595 addr = VDSO_HIGH_BASE;
34596 else {
34597 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
34598 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
34599 if (IS_ERR_VALUE(addr)) {
34600 ret = addr;
34601 goto up_fail;
34602 }
34603 }
34604
34605 - current->mm->context.vdso = (void *)addr;
34606 + current->mm->context.vdso = addr;
34607
34608 if (compat_uses_vma || !compat) {
34609 /*
34610 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34611 }
34612
34613 current_thread_info()->sysenter_return =
34614 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34615 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34616
34617 up_fail:
34618 if (ret)
34619 - current->mm->context.vdso = NULL;
34620 + current->mm->context.vdso = 0;
34621
34622 up_write(&mm->mmap_sem);
34623
34624 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
34625
34626 const char *arch_vma_name(struct vm_area_struct *vma)
34627 {
34628 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
34629 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
34630 return "[vdso]";
34631 +
34632 +#ifdef CONFIG_PAX_SEGMEXEC
34633 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
34634 + return "[vdso]";
34635 +#endif
34636 +
34637 return NULL;
34638 }
34639
34640 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
34641 * Check to see if the corresponding task was created in compat vdso
34642 * mode.
34643 */
34644 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
34645 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
34646 return &gate_vma;
34647 return NULL;
34648 }
34649 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
34650 index 431e875..cbb23f3 100644
34651 --- a/arch/x86/vdso/vma.c
34652 +++ b/arch/x86/vdso/vma.c
34653 @@ -16,8 +16,6 @@
34654 #include <asm/vdso.h>
34655 #include <asm/page.h>
34656
34657 -unsigned int __read_mostly vdso_enabled = 1;
34658 -
34659 extern char vdso_start[], vdso_end[];
34660 extern unsigned short vdso_sync_cpuid;
34661
34662 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
34663 * unaligned here as a result of stack start randomization.
34664 */
34665 addr = PAGE_ALIGN(addr);
34666 - addr = align_vdso_addr(addr);
34667
34668 return addr;
34669 }
34670 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
34671 unsigned size)
34672 {
34673 struct mm_struct *mm = current->mm;
34674 - unsigned long addr;
34675 + unsigned long addr = 0;
34676 int ret;
34677
34678 - if (!vdso_enabled)
34679 - return 0;
34680 -
34681 down_write(&mm->mmap_sem);
34682 +
34683 +#ifdef CONFIG_PAX_RANDMMAP
34684 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34685 +#endif
34686 +
34687 addr = vdso_addr(mm->start_stack, size);
34688 + addr = align_vdso_addr(addr);
34689 addr = get_unmapped_area(NULL, addr, size, 0, 0);
34690 if (IS_ERR_VALUE(addr)) {
34691 ret = addr;
34692 goto up_fail;
34693 }
34694
34695 - current->mm->context.vdso = (void *)addr;
34696 + mm->context.vdso = addr;
34697
34698 ret = install_special_mapping(mm, addr, size,
34699 VM_READ|VM_EXEC|
34700 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
34701 pages);
34702 - if (ret) {
34703 - current->mm->context.vdso = NULL;
34704 - goto up_fail;
34705 - }
34706 + if (ret)
34707 + mm->context.vdso = 0;
34708
34709 up_fail:
34710 up_write(&mm->mmap_sem);
34711 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34712 vdsox32_size);
34713 }
34714 #endif
34715 -
34716 -static __init int vdso_setup(char *s)
34717 -{
34718 - vdso_enabled = simple_strtoul(s, NULL, 0);
34719 - return 0;
34720 -}
34721 -__setup("vdso=", vdso_setup);
34722 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34723 index fa6ade7..73da73a5 100644
34724 --- a/arch/x86/xen/enlighten.c
34725 +++ b/arch/x86/xen/enlighten.c
34726 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34727
34728 struct shared_info xen_dummy_shared_info;
34729
34730 -void *xen_initial_gdt;
34731 -
34732 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34733 __read_mostly int xen_have_vector_callback;
34734 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34735 @@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34736 {
34737 unsigned long va = dtr->address;
34738 unsigned int size = dtr->size + 1;
34739 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34740 - unsigned long frames[pages];
34741 + unsigned long frames[65536 / PAGE_SIZE];
34742 int f;
34743
34744 /*
34745 @@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34746 {
34747 unsigned long va = dtr->address;
34748 unsigned int size = dtr->size + 1;
34749 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34750 - unsigned long frames[pages];
34751 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34752 int f;
34753
34754 /*
34755 @@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34756 * 8-byte entries, or 16 4k pages..
34757 */
34758
34759 - BUG_ON(size > 65536);
34760 + BUG_ON(size > GDT_SIZE);
34761 BUG_ON(va & ~PAGE_MASK);
34762
34763 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34764 @@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34765 return 0;
34766 }
34767
34768 -static void set_xen_basic_apic_ops(void)
34769 +static void __init set_xen_basic_apic_ops(void)
34770 {
34771 apic->read = xen_apic_read;
34772 apic->write = xen_apic_write;
34773 @@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34774 #endif
34775 };
34776
34777 -static void xen_reboot(int reason)
34778 +static __noreturn void xen_reboot(int reason)
34779 {
34780 struct sched_shutdown r = { .reason = reason };
34781
34782 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34783 - BUG();
34784 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34785 + BUG();
34786 }
34787
34788 -static void xen_restart(char *msg)
34789 +static __noreturn void xen_restart(char *msg)
34790 {
34791 xen_reboot(SHUTDOWN_reboot);
34792 }
34793
34794 -static void xen_emergency_restart(void)
34795 +static __noreturn void xen_emergency_restart(void)
34796 {
34797 xen_reboot(SHUTDOWN_reboot);
34798 }
34799
34800 -static void xen_machine_halt(void)
34801 +static __noreturn void xen_machine_halt(void)
34802 {
34803 xen_reboot(SHUTDOWN_poweroff);
34804 }
34805
34806 -static void xen_machine_power_off(void)
34807 +static __noreturn void xen_machine_power_off(void)
34808 {
34809 if (pm_power_off)
34810 pm_power_off();
34811 @@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
34812 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34813
34814 /* Work out if we support NX */
34815 - x86_configure_nx();
34816 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34817 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34818 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34819 + unsigned l, h;
34820 +
34821 + __supported_pte_mask |= _PAGE_NX;
34822 + rdmsr(MSR_EFER, l, h);
34823 + l |= EFER_NX;
34824 + wrmsr(MSR_EFER, l, h);
34825 + }
34826 +#endif
34827
34828 xen_setup_features();
34829
34830 @@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
34831
34832 machine_ops = xen_machine_ops;
34833
34834 - /*
34835 - * The only reliable way to retain the initial address of the
34836 - * percpu gdt_page is to remember it here, so we can go and
34837 - * mark it RW later, when the initial percpu area is freed.
34838 - */
34839 - xen_initial_gdt = &per_cpu(gdt_page, 0);
34840 -
34841 xen_smp_init();
34842
34843 #ifdef CONFIG_ACPI_NUMA
34844 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34845 index ce563be..7327d91 100644
34846 --- a/arch/x86/xen/mmu.c
34847 +++ b/arch/x86/xen/mmu.c
34848 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
34849 return val;
34850 }
34851
34852 -static pteval_t pte_pfn_to_mfn(pteval_t val)
34853 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
34854 {
34855 if (val & _PAGE_PRESENT) {
34856 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
34857 @@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34858 /* L3_k[510] -> level2_kernel_pgt
34859 * L3_i[511] -> level2_fixmap_pgt */
34860 convert_pfn_mfn(level3_kernel_pgt);
34861 + convert_pfn_mfn(level3_vmalloc_start_pgt);
34862 + convert_pfn_mfn(level3_vmalloc_end_pgt);
34863 + convert_pfn_mfn(level3_vmemmap_pgt);
34864
34865 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34866 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34867 @@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34868 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34869 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34870 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34871 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34872 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34873 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34874 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34875 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34876 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34877 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34878 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34879
34880 @@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34881 pv_mmu_ops.set_pud = xen_set_pud;
34882 #if PAGETABLE_LEVELS == 4
34883 pv_mmu_ops.set_pgd = xen_set_pgd;
34884 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34885 #endif
34886
34887 /* This will work as long as patching hasn't happened yet
34888 @@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34889 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34890 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34891 .set_pgd = xen_set_pgd_hyper,
34892 + .set_pgd_batched = xen_set_pgd_hyper,
34893
34894 .alloc_pud = xen_alloc_pmd_init,
34895 .release_pud = xen_release_pmd_init,
34896 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34897 index c36b325..b0f1518 100644
34898 --- a/arch/x86/xen/smp.c
34899 +++ b/arch/x86/xen/smp.c
34900 @@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
34901 native_smp_prepare_boot_cpu();
34902
34903 if (xen_pv_domain()) {
34904 - /* We've switched to the "real" per-cpu gdt, so make sure the
34905 - old memory can be recycled */
34906 - make_lowmem_page_readwrite(xen_initial_gdt);
34907 -
34908 #ifdef CONFIG_X86_32
34909 /*
34910 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
34911 * expects __USER_DS
34912 */
34913 - loadsegment(ds, __USER_DS);
34914 - loadsegment(es, __USER_DS);
34915 + loadsegment(ds, __KERNEL_DS);
34916 + loadsegment(es, __KERNEL_DS);
34917 #endif
34918
34919 xen_filter_cpu_maps();
34920 @@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34921 ctxt->user_regs.ss = __KERNEL_DS;
34922 #ifdef CONFIG_X86_32
34923 ctxt->user_regs.fs = __KERNEL_PERCPU;
34924 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34925 + savesegment(gs, ctxt->user_regs.gs);
34926 #else
34927 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34928 #endif
34929 @@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34930
34931 {
34932 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34933 - ctxt->user_regs.ds = __USER_DS;
34934 - ctxt->user_regs.es = __USER_DS;
34935 + ctxt->user_regs.ds = __KERNEL_DS;
34936 + ctxt->user_regs.es = __KERNEL_DS;
34937
34938 xen_copy_trap_info(ctxt->trap_ctxt);
34939
34940 @@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34941 int rc;
34942
34943 per_cpu(current_task, cpu) = idle;
34944 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
34945 #ifdef CONFIG_X86_32
34946 irq_ctx_init(cpu);
34947 #else
34948 clear_tsk_thread_flag(idle, TIF_FORK);
34949 - per_cpu(kernel_stack, cpu) =
34950 - (unsigned long)task_stack_page(idle) -
34951 - KERNEL_STACK_OFFSET + THREAD_SIZE;
34952 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34953 #endif
34954 xen_setup_runstate_info(cpu);
34955 xen_setup_timer(cpu);
34956 @@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34957
34958 void __init xen_smp_init(void)
34959 {
34960 - smp_ops = xen_smp_ops;
34961 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34962 xen_fill_possible_map();
34963 }
34964
34965 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34966 index 33ca6e4..0ded929 100644
34967 --- a/arch/x86/xen/xen-asm_32.S
34968 +++ b/arch/x86/xen/xen-asm_32.S
34969 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
34970 ESP_OFFSET=4 # bytes pushed onto stack
34971
34972 /*
34973 - * Store vcpu_info pointer for easy access. Do it this way to
34974 - * avoid having to reload %fs
34975 + * Store vcpu_info pointer for easy access.
34976 */
34977 #ifdef CONFIG_SMP
34978 - GET_THREAD_INFO(%eax)
34979 - movl %ss:TI_cpu(%eax), %eax
34980 - movl %ss:__per_cpu_offset(,%eax,4), %eax
34981 - mov %ss:xen_vcpu(%eax), %eax
34982 + push %fs
34983 + mov $(__KERNEL_PERCPU), %eax
34984 + mov %eax, %fs
34985 + mov PER_CPU_VAR(xen_vcpu), %eax
34986 + pop %fs
34987 #else
34988 movl %ss:xen_vcpu, %eax
34989 #endif
34990 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34991 index 7faed58..ba4427c 100644
34992 --- a/arch/x86/xen/xen-head.S
34993 +++ b/arch/x86/xen/xen-head.S
34994 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
34995 #ifdef CONFIG_X86_32
34996 mov %esi,xen_start_info
34997 mov $init_thread_union+THREAD_SIZE,%esp
34998 +#ifdef CONFIG_SMP
34999 + movl $cpu_gdt_table,%edi
35000 + movl $__per_cpu_load,%eax
35001 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35002 + rorl $16,%eax
35003 + movb %al,__KERNEL_PERCPU + 4(%edi)
35004 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35005 + movl $__per_cpu_end - 1,%eax
35006 + subl $__per_cpu_start,%eax
35007 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35008 +#endif
35009 #else
35010 mov %rsi,xen_start_info
35011 mov $init_thread_union+THREAD_SIZE,%rsp
35012 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35013 index 95f8c61..611d6e8 100644
35014 --- a/arch/x86/xen/xen-ops.h
35015 +++ b/arch/x86/xen/xen-ops.h
35016 @@ -10,8 +10,6 @@
35017 extern const char xen_hypervisor_callback[];
35018 extern const char xen_failsafe_callback[];
35019
35020 -extern void *xen_initial_gdt;
35021 -
35022 struct trap_info;
35023 void xen_copy_trap_info(struct trap_info *traps);
35024
35025 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35026 index 525bd3d..ef888b1 100644
35027 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35028 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35029 @@ -119,9 +119,9 @@
35030 ----------------------------------------------------------------------*/
35031
35032 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35033 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35034 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35035 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35036 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35037
35038 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35039 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35040 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35041 index 2f33760..835e50a 100644
35042 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35043 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35044 @@ -11,6 +11,7 @@
35045 #ifndef _XTENSA_CORE_H
35046 #define _XTENSA_CORE_H
35047
35048 +#include <linux/const.h>
35049
35050 /****************************************************************************
35051 Parameters Useful for Any Code, USER or PRIVILEGED
35052 @@ -112,9 +113,9 @@
35053 ----------------------------------------------------------------------*/
35054
35055 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35056 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35057 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35058 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35059 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35060
35061 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35062 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35063 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35064 index af00795..2bb8105 100644
35065 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35066 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35067 @@ -11,6 +11,7 @@
35068 #ifndef _XTENSA_CORE_CONFIGURATION_H
35069 #define _XTENSA_CORE_CONFIGURATION_H
35070
35071 +#include <linux/const.h>
35072
35073 /****************************************************************************
35074 Parameters Useful for Any Code, USER or PRIVILEGED
35075 @@ -118,9 +119,9 @@
35076 ----------------------------------------------------------------------*/
35077
35078 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35079 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35080 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35081 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35082 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35083
35084 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35085 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35086 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35087 index 4e491d9..c8e18e4 100644
35088 --- a/block/blk-cgroup.c
35089 +++ b/block/blk-cgroup.c
35090 @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35091 static struct cgroup_subsys_state *
35092 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35093 {
35094 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35095 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35096 struct blkcg *blkcg;
35097
35098 if (!parent_css) {
35099 @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35100
35101 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35102 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35103 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35104 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35105 done:
35106 spin_lock_init(&blkcg->lock);
35107 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35108 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35109 index 1855bf5..af12b06 100644
35110 --- a/block/blk-iopoll.c
35111 +++ b/block/blk-iopoll.c
35112 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35113 }
35114 EXPORT_SYMBOL(blk_iopoll_complete);
35115
35116 -static void blk_iopoll_softirq(struct softirq_action *h)
35117 +static __latent_entropy void blk_iopoll_softirq(void)
35118 {
35119 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35120 int rearm = 0, budget = blk_iopoll_budget;
35121 diff --git a/block/blk-map.c b/block/blk-map.c
35122 index 623e1cd..ca1e109 100644
35123 --- a/block/blk-map.c
35124 +++ b/block/blk-map.c
35125 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35126 if (!len || !kbuf)
35127 return -EINVAL;
35128
35129 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35130 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35131 if (do_copy)
35132 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35133 else
35134 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35135 index 57790c1..5e988dd 100644
35136 --- a/block/blk-softirq.c
35137 +++ b/block/blk-softirq.c
35138 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35139 * Softirq action handler - move entries to local list and loop over them
35140 * while passing them to the queue registered handler.
35141 */
35142 -static void blk_done_softirq(struct softirq_action *h)
35143 +static __latent_entropy void blk_done_softirq(void)
35144 {
35145 struct list_head *cpu_list, local_list;
35146
35147 diff --git a/block/bsg.c b/block/bsg.c
35148 index 420a5a9..23834aa 100644
35149 --- a/block/bsg.c
35150 +++ b/block/bsg.c
35151 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35152 struct sg_io_v4 *hdr, struct bsg_device *bd,
35153 fmode_t has_write_perm)
35154 {
35155 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35156 + unsigned char *cmdptr;
35157 +
35158 if (hdr->request_len > BLK_MAX_CDB) {
35159 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35160 if (!rq->cmd)
35161 return -ENOMEM;
35162 - }
35163 + cmdptr = rq->cmd;
35164 + } else
35165 + cmdptr = tmpcmd;
35166
35167 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35168 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35169 hdr->request_len))
35170 return -EFAULT;
35171
35172 + if (cmdptr != rq->cmd)
35173 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35174 +
35175 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35176 if (blk_verify_command(rq->cmd, has_write_perm))
35177 return -EPERM;
35178 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35179 index fbd5a67..f24fd95 100644
35180 --- a/block/compat_ioctl.c
35181 +++ b/block/compat_ioctl.c
35182 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35183 cgc = compat_alloc_user_space(sizeof(*cgc));
35184 cgc32 = compat_ptr(arg);
35185
35186 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35187 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35188 get_user(data, &cgc32->buffer) ||
35189 put_user(compat_ptr(data), &cgc->buffer) ||
35190 copy_in_user(&cgc->buflen, &cgc32->buflen,
35191 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35192 err |= __get_user(f->spec1, &uf->spec1);
35193 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35194 err |= __get_user(name, &uf->name);
35195 - f->name = compat_ptr(name);
35196 + f->name = (void __force_kernel *)compat_ptr(name);
35197 if (err) {
35198 err = -EFAULT;
35199 goto out;
35200 diff --git a/block/genhd.c b/block/genhd.c
35201 index 791f419..89f21c4 100644
35202 --- a/block/genhd.c
35203 +++ b/block/genhd.c
35204 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35205
35206 /*
35207 * Register device numbers dev..(dev+range-1)
35208 - * range must be nonzero
35209 + * Noop if @range is zero.
35210 * The hash chain is sorted on range, so that subranges can override.
35211 */
35212 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35213 struct kobject *(*probe)(dev_t, int *, void *),
35214 int (*lock)(dev_t, void *), void *data)
35215 {
35216 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35217 + if (range)
35218 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35219 }
35220
35221 EXPORT_SYMBOL(blk_register_region);
35222
35223 +/* undo blk_register_region(), noop if @range is zero */
35224 void blk_unregister_region(dev_t devt, unsigned long range)
35225 {
35226 - kobj_unmap(bdev_map, devt, range);
35227 + if (range)
35228 + kobj_unmap(bdev_map, devt, range);
35229 }
35230
35231 EXPORT_SYMBOL(blk_unregister_region);
35232 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35233 index dc51f46..d5446a8 100644
35234 --- a/block/partitions/efi.c
35235 +++ b/block/partitions/efi.c
35236 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35237 if (!gpt)
35238 return NULL;
35239
35240 + if (!le32_to_cpu(gpt->num_partition_entries))
35241 + return NULL;
35242 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35243 + if (!pte)
35244 + return NULL;
35245 +
35246 count = le32_to_cpu(gpt->num_partition_entries) *
35247 le32_to_cpu(gpt->sizeof_partition_entry);
35248 - if (!count)
35249 - return NULL;
35250 - pte = kmalloc(count, GFP_KERNEL);
35251 - if (!pte)
35252 - return NULL;
35253 -
35254 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35255 (u8 *) pte, count) < count) {
35256 kfree(pte);
35257 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35258 index 625e3e4..b5339f9 100644
35259 --- a/block/scsi_ioctl.c
35260 +++ b/block/scsi_ioctl.c
35261 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35262 return put_user(0, p);
35263 }
35264
35265 -static int sg_get_timeout(struct request_queue *q)
35266 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35267 {
35268 return jiffies_to_clock_t(q->sg_timeout);
35269 }
35270 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35271 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35272 struct sg_io_hdr *hdr, fmode_t mode)
35273 {
35274 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35275 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35276 + unsigned char *cmdptr;
35277 +
35278 + if (rq->cmd != rq->__cmd)
35279 + cmdptr = rq->cmd;
35280 + else
35281 + cmdptr = tmpcmd;
35282 +
35283 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35284 return -EFAULT;
35285 +
35286 + if (cmdptr != rq->cmd)
35287 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35288 +
35289 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35290 return -EPERM;
35291
35292 @@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35293 int err;
35294 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35295 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35296 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35297 + unsigned char *cmdptr;
35298
35299 if (!sic)
35300 return -EINVAL;
35301 @@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35302 */
35303 err = -EFAULT;
35304 rq->cmd_len = cmdlen;
35305 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
35306 +
35307 + if (rq->cmd != rq->__cmd)
35308 + cmdptr = rq->cmd;
35309 + else
35310 + cmdptr = tmpcmd;
35311 +
35312 + if (copy_from_user(cmdptr, sic->data, cmdlen))
35313 goto error;
35314
35315 + if (rq->cmd != cmdptr)
35316 + memcpy(rq->cmd, cmdptr, cmdlen);
35317 +
35318 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35319 goto error;
35320
35321 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35322 index 7bdd61b..afec999 100644
35323 --- a/crypto/cryptd.c
35324 +++ b/crypto/cryptd.c
35325 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35326
35327 struct cryptd_blkcipher_request_ctx {
35328 crypto_completion_t complete;
35329 -};
35330 +} __no_const;
35331
35332 struct cryptd_hash_ctx {
35333 struct crypto_shash *child;
35334 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35335
35336 struct cryptd_aead_request_ctx {
35337 crypto_completion_t complete;
35338 -};
35339 +} __no_const;
35340
35341 static void cryptd_queue_worker(struct work_struct *work);
35342
35343 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35344 index f8c920c..ab2cb5a 100644
35345 --- a/crypto/pcrypt.c
35346 +++ b/crypto/pcrypt.c
35347 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35348 int ret;
35349
35350 pinst->kobj.kset = pcrypt_kset;
35351 - ret = kobject_add(&pinst->kobj, NULL, name);
35352 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35353 if (!ret)
35354 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35355
35356 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35357 index 15dddc1..b61cf0c 100644
35358 --- a/drivers/acpi/acpica/hwxfsleep.c
35359 +++ b/drivers/acpi/acpica/hwxfsleep.c
35360 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35361 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35362
35363 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35364 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35365 - acpi_hw_extended_sleep},
35366 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35367 - acpi_hw_extended_wake_prep},
35368 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35369 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35370 + .extended_function = acpi_hw_extended_sleep},
35371 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35372 + .extended_function = acpi_hw_extended_wake_prep},
35373 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35374 + .extended_function = acpi_hw_extended_wake}
35375 };
35376
35377 /*
35378 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35379 index 21ba34a..cb05966 100644
35380 --- a/drivers/acpi/apei/apei-internal.h
35381 +++ b/drivers/acpi/apei/apei-internal.h
35382 @@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35383 struct apei_exec_ins_type {
35384 u32 flags;
35385 apei_exec_ins_func_t run;
35386 -};
35387 +} __do_const;
35388
35389 struct apei_exec_context {
35390 u32 ip;
35391 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35392 index a30bc31..b91c4d5 100644
35393 --- a/drivers/acpi/apei/ghes.c
35394 +++ b/drivers/acpi/apei/ghes.c
35395 @@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35396 const struct acpi_hest_generic *generic,
35397 const struct acpi_generic_status *estatus)
35398 {
35399 - static atomic_t seqno;
35400 + static atomic_unchecked_t seqno;
35401 unsigned int curr_seqno;
35402 char pfx_seq[64];
35403
35404 @@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
35405 else
35406 pfx = KERN_ERR;
35407 }
35408 - curr_seqno = atomic_inc_return(&seqno);
35409 + curr_seqno = atomic_inc_return_unchecked(&seqno);
35410 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35411 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35412 pfx_seq, generic->header.source_id);
35413 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35414 index a83e3c6..c3d617f 100644
35415 --- a/drivers/acpi/bgrt.c
35416 +++ b/drivers/acpi/bgrt.c
35417 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35418 if (!bgrt_image)
35419 return -ENODEV;
35420
35421 - bin_attr_image.private = bgrt_image;
35422 - bin_attr_image.size = bgrt_image_size;
35423 + pax_open_kernel();
35424 + *(void **)&bin_attr_image.private = bgrt_image;
35425 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
35426 + pax_close_kernel();
35427
35428 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35429 if (!bgrt_kobj)
35430 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35431 index 078c4f7..410e272 100644
35432 --- a/drivers/acpi/blacklist.c
35433 +++ b/drivers/acpi/blacklist.c
35434 @@ -52,7 +52,7 @@ struct acpi_blacklist_item {
35435 u32 is_critical_error;
35436 };
35437
35438 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
35439 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
35440
35441 /*
35442 * POLICY: If *anything* doesn't work, put it on the blacklist.
35443 @@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
35444 return 0;
35445 }
35446
35447 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
35448 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
35449 {
35450 .callback = dmi_disable_osi_vista,
35451 .ident = "Fujitsu Siemens",
35452 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
35453 index 12b62f2..dc2aac8 100644
35454 --- a/drivers/acpi/custom_method.c
35455 +++ b/drivers/acpi/custom_method.c
35456 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
35457 struct acpi_table_header table;
35458 acpi_status status;
35459
35460 +#ifdef CONFIG_GRKERNSEC_KMEM
35461 + return -EPERM;
35462 +#endif
35463 +
35464 if (!(*ppos)) {
35465 /* parse the table header to get the table length */
35466 if (count <= sizeof(struct acpi_table_header))
35467 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
35468 index 644516d..643937e 100644
35469 --- a/drivers/acpi/processor_idle.c
35470 +++ b/drivers/acpi/processor_idle.c
35471 @@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
35472 {
35473 int i, count = CPUIDLE_DRIVER_STATE_START;
35474 struct acpi_processor_cx *cx;
35475 - struct cpuidle_state *state;
35476 + cpuidle_state_no_const *state;
35477 struct cpuidle_driver *drv = &acpi_idle_driver;
35478
35479 if (!pr->flags.power_setup_done)
35480 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
35481 index 6dbc3ca..b8b59a0 100644
35482 --- a/drivers/acpi/sysfs.c
35483 +++ b/drivers/acpi/sysfs.c
35484 @@ -425,11 +425,11 @@ static u32 num_counters;
35485 static struct attribute **all_attrs;
35486 static u32 acpi_gpe_count;
35487
35488 -static struct attribute_group interrupt_stats_attr_group = {
35489 +static attribute_group_no_const interrupt_stats_attr_group = {
35490 .name = "interrupts",
35491 };
35492
35493 -static struct kobj_attribute *counter_attrs;
35494 +static kobj_attribute_no_const *counter_attrs;
35495
35496 static void delete_gpe_attr_array(void)
35497 {
35498 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
35499 index c482f8c..c832240 100644
35500 --- a/drivers/ata/libahci.c
35501 +++ b/drivers/ata/libahci.c
35502 @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
35503 }
35504 EXPORT_SYMBOL_GPL(ahci_kick_engine);
35505
35506 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35507 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35508 struct ata_taskfile *tf, int is_cmd, u16 flags,
35509 unsigned long timeout_msec)
35510 {
35511 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
35512 index 1393a58..3bf8cbe 100644
35513 --- a/drivers/ata/libata-core.c
35514 +++ b/drivers/ata/libata-core.c
35515 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
35516 static void ata_dev_xfermask(struct ata_device *dev);
35517 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
35518
35519 -atomic_t ata_print_id = ATOMIC_INIT(0);
35520 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
35521
35522 struct ata_force_param {
35523 const char *name;
35524 @@ -4823,7 +4823,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
35525 struct ata_port *ap;
35526 unsigned int tag;
35527
35528 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35529 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35530 ap = qc->ap;
35531
35532 qc->flags = 0;
35533 @@ -4839,7 +4839,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
35534 struct ata_port *ap;
35535 struct ata_link *link;
35536
35537 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35538 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35539 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
35540 ap = qc->ap;
35541 link = qc->dev->link;
35542 @@ -5958,6 +5958,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35543 return;
35544
35545 spin_lock(&lock);
35546 + pax_open_kernel();
35547
35548 for (cur = ops->inherits; cur; cur = cur->inherits) {
35549 void **inherit = (void **)cur;
35550 @@ -5971,8 +5972,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35551 if (IS_ERR(*pp))
35552 *pp = NULL;
35553
35554 - ops->inherits = NULL;
35555 + *(struct ata_port_operations **)&ops->inherits = NULL;
35556
35557 + pax_close_kernel();
35558 spin_unlock(&lock);
35559 }
35560
35561 @@ -6165,7 +6167,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
35562
35563 /* give ports names and add SCSI hosts */
35564 for (i = 0; i < host->n_ports; i++) {
35565 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
35566 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
35567 host->ports[i]->local_port_no = i + 1;
35568 }
35569
35570 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
35571 index 377eb88..8591b44 100644
35572 --- a/drivers/ata/libata-scsi.c
35573 +++ b/drivers/ata/libata-scsi.c
35574 @@ -4135,7 +4135,7 @@ int ata_sas_port_init(struct ata_port *ap)
35575
35576 if (rc)
35577 return rc;
35578 - ap->print_id = atomic_inc_return(&ata_print_id);
35579 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
35580 return 0;
35581 }
35582 EXPORT_SYMBOL_GPL(ata_sas_port_init);
35583 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
35584 index 45b5ab3..98446b8 100644
35585 --- a/drivers/ata/libata.h
35586 +++ b/drivers/ata/libata.h
35587 @@ -53,7 +53,7 @@ enum {
35588 ATA_DNXFER_QUIET = (1 << 31),
35589 };
35590
35591 -extern atomic_t ata_print_id;
35592 +extern atomic_unchecked_t ata_print_id;
35593 extern int atapi_passthru16;
35594 extern int libata_fua;
35595 extern int libata_noacpi;
35596 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
35597 index 73492dd..ca2bff5 100644
35598 --- a/drivers/ata/pata_arasan_cf.c
35599 +++ b/drivers/ata/pata_arasan_cf.c
35600 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
35601 /* Handle platform specific quirks */
35602 if (quirk) {
35603 if (quirk & CF_BROKEN_PIO) {
35604 - ap->ops->set_piomode = NULL;
35605 + pax_open_kernel();
35606 + *(void **)&ap->ops->set_piomode = NULL;
35607 + pax_close_kernel();
35608 ap->pio_mask = 0;
35609 }
35610 if (quirk & CF_BROKEN_MWDMA)
35611 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
35612 index f9b983a..887b9d8 100644
35613 --- a/drivers/atm/adummy.c
35614 +++ b/drivers/atm/adummy.c
35615 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
35616 vcc->pop(vcc, skb);
35617 else
35618 dev_kfree_skb_any(skb);
35619 - atomic_inc(&vcc->stats->tx);
35620 + atomic_inc_unchecked(&vcc->stats->tx);
35621
35622 return 0;
35623 }
35624 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
35625 index 62a7607..cc4be104 100644
35626 --- a/drivers/atm/ambassador.c
35627 +++ b/drivers/atm/ambassador.c
35628 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
35629 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
35630
35631 // VC layer stats
35632 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35633 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35634
35635 // free the descriptor
35636 kfree (tx_descr);
35637 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35638 dump_skb ("<<<", vc, skb);
35639
35640 // VC layer stats
35641 - atomic_inc(&atm_vcc->stats->rx);
35642 + atomic_inc_unchecked(&atm_vcc->stats->rx);
35643 __net_timestamp(skb);
35644 // end of our responsibility
35645 atm_vcc->push (atm_vcc, skb);
35646 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35647 } else {
35648 PRINTK (KERN_INFO, "dropped over-size frame");
35649 // should we count this?
35650 - atomic_inc(&atm_vcc->stats->rx_drop);
35651 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35652 }
35653
35654 } else {
35655 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
35656 }
35657
35658 if (check_area (skb->data, skb->len)) {
35659 - atomic_inc(&atm_vcc->stats->tx_err);
35660 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
35661 return -ENOMEM; // ?
35662 }
35663
35664 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
35665 index 0e3f8f9..765a7a5 100644
35666 --- a/drivers/atm/atmtcp.c
35667 +++ b/drivers/atm/atmtcp.c
35668 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35669 if (vcc->pop) vcc->pop(vcc,skb);
35670 else dev_kfree_skb(skb);
35671 if (dev_data) return 0;
35672 - atomic_inc(&vcc->stats->tx_err);
35673 + atomic_inc_unchecked(&vcc->stats->tx_err);
35674 return -ENOLINK;
35675 }
35676 size = skb->len+sizeof(struct atmtcp_hdr);
35677 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35678 if (!new_skb) {
35679 if (vcc->pop) vcc->pop(vcc,skb);
35680 else dev_kfree_skb(skb);
35681 - atomic_inc(&vcc->stats->tx_err);
35682 + atomic_inc_unchecked(&vcc->stats->tx_err);
35683 return -ENOBUFS;
35684 }
35685 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
35686 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35687 if (vcc->pop) vcc->pop(vcc,skb);
35688 else dev_kfree_skb(skb);
35689 out_vcc->push(out_vcc,new_skb);
35690 - atomic_inc(&vcc->stats->tx);
35691 - atomic_inc(&out_vcc->stats->rx);
35692 + atomic_inc_unchecked(&vcc->stats->tx);
35693 + atomic_inc_unchecked(&out_vcc->stats->rx);
35694 return 0;
35695 }
35696
35697 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35698 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
35699 read_unlock(&vcc_sklist_lock);
35700 if (!out_vcc) {
35701 - atomic_inc(&vcc->stats->tx_err);
35702 + atomic_inc_unchecked(&vcc->stats->tx_err);
35703 goto done;
35704 }
35705 skb_pull(skb,sizeof(struct atmtcp_hdr));
35706 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35707 __net_timestamp(new_skb);
35708 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
35709 out_vcc->push(out_vcc,new_skb);
35710 - atomic_inc(&vcc->stats->tx);
35711 - atomic_inc(&out_vcc->stats->rx);
35712 + atomic_inc_unchecked(&vcc->stats->tx);
35713 + atomic_inc_unchecked(&out_vcc->stats->rx);
35714 done:
35715 if (vcc->pop) vcc->pop(vcc,skb);
35716 else dev_kfree_skb(skb);
35717 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
35718 index b1955ba..b179940 100644
35719 --- a/drivers/atm/eni.c
35720 +++ b/drivers/atm/eni.c
35721 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
35722 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
35723 vcc->dev->number);
35724 length = 0;
35725 - atomic_inc(&vcc->stats->rx_err);
35726 + atomic_inc_unchecked(&vcc->stats->rx_err);
35727 }
35728 else {
35729 length = ATM_CELL_SIZE-1; /* no HEC */
35730 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35731 size);
35732 }
35733 eff = length = 0;
35734 - atomic_inc(&vcc->stats->rx_err);
35735 + atomic_inc_unchecked(&vcc->stats->rx_err);
35736 }
35737 else {
35738 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
35739 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35740 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
35741 vcc->dev->number,vcc->vci,length,size << 2,descr);
35742 length = eff = 0;
35743 - atomic_inc(&vcc->stats->rx_err);
35744 + atomic_inc_unchecked(&vcc->stats->rx_err);
35745 }
35746 }
35747 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
35748 @@ -767,7 +767,7 @@ rx_dequeued++;
35749 vcc->push(vcc,skb);
35750 pushed++;
35751 }
35752 - atomic_inc(&vcc->stats->rx);
35753 + atomic_inc_unchecked(&vcc->stats->rx);
35754 }
35755 wake_up(&eni_dev->rx_wait);
35756 }
35757 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
35758 PCI_DMA_TODEVICE);
35759 if (vcc->pop) vcc->pop(vcc,skb);
35760 else dev_kfree_skb_irq(skb);
35761 - atomic_inc(&vcc->stats->tx);
35762 + atomic_inc_unchecked(&vcc->stats->tx);
35763 wake_up(&eni_dev->tx_wait);
35764 dma_complete++;
35765 }
35766 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35767 index b41c948..a002b17 100644
35768 --- a/drivers/atm/firestream.c
35769 +++ b/drivers/atm/firestream.c
35770 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35771 }
35772 }
35773
35774 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35775 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35776
35777 fs_dprintk (FS_DEBUG_TXMEM, "i");
35778 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35779 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35780 #endif
35781 skb_put (skb, qe->p1 & 0xffff);
35782 ATM_SKB(skb)->vcc = atm_vcc;
35783 - atomic_inc(&atm_vcc->stats->rx);
35784 + atomic_inc_unchecked(&atm_vcc->stats->rx);
35785 __net_timestamp(skb);
35786 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35787 atm_vcc->push (atm_vcc, skb);
35788 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35789 kfree (pe);
35790 }
35791 if (atm_vcc)
35792 - atomic_inc(&atm_vcc->stats->rx_drop);
35793 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35794 break;
35795 case 0x1f: /* Reassembly abort: no buffers. */
35796 /* Silently increment error counter. */
35797 if (atm_vcc)
35798 - atomic_inc(&atm_vcc->stats->rx_drop);
35799 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35800 break;
35801 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35802 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35803 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35804 index 204814e..cede831 100644
35805 --- a/drivers/atm/fore200e.c
35806 +++ b/drivers/atm/fore200e.c
35807 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35808 #endif
35809 /* check error condition */
35810 if (*entry->status & STATUS_ERROR)
35811 - atomic_inc(&vcc->stats->tx_err);
35812 + atomic_inc_unchecked(&vcc->stats->tx_err);
35813 else
35814 - atomic_inc(&vcc->stats->tx);
35815 + atomic_inc_unchecked(&vcc->stats->tx);
35816 }
35817 }
35818
35819 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35820 if (skb == NULL) {
35821 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35822
35823 - atomic_inc(&vcc->stats->rx_drop);
35824 + atomic_inc_unchecked(&vcc->stats->rx_drop);
35825 return -ENOMEM;
35826 }
35827
35828 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35829
35830 dev_kfree_skb_any(skb);
35831
35832 - atomic_inc(&vcc->stats->rx_drop);
35833 + atomic_inc_unchecked(&vcc->stats->rx_drop);
35834 return -ENOMEM;
35835 }
35836
35837 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35838
35839 vcc->push(vcc, skb);
35840 - atomic_inc(&vcc->stats->rx);
35841 + atomic_inc_unchecked(&vcc->stats->rx);
35842
35843 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35844
35845 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35846 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35847 fore200e->atm_dev->number,
35848 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35849 - atomic_inc(&vcc->stats->rx_err);
35850 + atomic_inc_unchecked(&vcc->stats->rx_err);
35851 }
35852 }
35853
35854 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35855 goto retry_here;
35856 }
35857
35858 - atomic_inc(&vcc->stats->tx_err);
35859 + atomic_inc_unchecked(&vcc->stats->tx_err);
35860
35861 fore200e->tx_sat++;
35862 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35863 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35864 index 8557adc..3fb5d55 100644
35865 --- a/drivers/atm/he.c
35866 +++ b/drivers/atm/he.c
35867 @@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35868
35869 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35870 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35871 - atomic_inc(&vcc->stats->rx_drop);
35872 + atomic_inc_unchecked(&vcc->stats->rx_drop);
35873 goto return_host_buffers;
35874 }
35875
35876 @@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35877 RBRQ_LEN_ERR(he_dev->rbrq_head)
35878 ? "LEN_ERR" : "",
35879 vcc->vpi, vcc->vci);
35880 - atomic_inc(&vcc->stats->rx_err);
35881 + atomic_inc_unchecked(&vcc->stats->rx_err);
35882 goto return_host_buffers;
35883 }
35884
35885 @@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35886 vcc->push(vcc, skb);
35887 spin_lock(&he_dev->global_lock);
35888
35889 - atomic_inc(&vcc->stats->rx);
35890 + atomic_inc_unchecked(&vcc->stats->rx);
35891
35892 return_host_buffers:
35893 ++pdus_assembled;
35894 @@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35895 tpd->vcc->pop(tpd->vcc, tpd->skb);
35896 else
35897 dev_kfree_skb_any(tpd->skb);
35898 - atomic_inc(&tpd->vcc->stats->tx_err);
35899 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35900 }
35901 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35902 return;
35903 @@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35904 vcc->pop(vcc, skb);
35905 else
35906 dev_kfree_skb_any(skb);
35907 - atomic_inc(&vcc->stats->tx_err);
35908 + atomic_inc_unchecked(&vcc->stats->tx_err);
35909 return -EINVAL;
35910 }
35911
35912 @@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35913 vcc->pop(vcc, skb);
35914 else
35915 dev_kfree_skb_any(skb);
35916 - atomic_inc(&vcc->stats->tx_err);
35917 + atomic_inc_unchecked(&vcc->stats->tx_err);
35918 return -EINVAL;
35919 }
35920 #endif
35921 @@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35922 vcc->pop(vcc, skb);
35923 else
35924 dev_kfree_skb_any(skb);
35925 - atomic_inc(&vcc->stats->tx_err);
35926 + atomic_inc_unchecked(&vcc->stats->tx_err);
35927 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35928 return -ENOMEM;
35929 }
35930 @@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35931 vcc->pop(vcc, skb);
35932 else
35933 dev_kfree_skb_any(skb);
35934 - atomic_inc(&vcc->stats->tx_err);
35935 + atomic_inc_unchecked(&vcc->stats->tx_err);
35936 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35937 return -ENOMEM;
35938 }
35939 @@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35940 __enqueue_tpd(he_dev, tpd, cid);
35941 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35942
35943 - atomic_inc(&vcc->stats->tx);
35944 + atomic_inc_unchecked(&vcc->stats->tx);
35945
35946 return 0;
35947 }
35948 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35949 index 1dc0519..1aadaf7 100644
35950 --- a/drivers/atm/horizon.c
35951 +++ b/drivers/atm/horizon.c
35952 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35953 {
35954 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35955 // VC layer stats
35956 - atomic_inc(&vcc->stats->rx);
35957 + atomic_inc_unchecked(&vcc->stats->rx);
35958 __net_timestamp(skb);
35959 // end of our responsibility
35960 vcc->push (vcc, skb);
35961 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35962 dev->tx_iovec = NULL;
35963
35964 // VC layer stats
35965 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35966 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35967
35968 // free the skb
35969 hrz_kfree_skb (skb);
35970 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35971 index 1bdf104..9dc44b1 100644
35972 --- a/drivers/atm/idt77252.c
35973 +++ b/drivers/atm/idt77252.c
35974 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35975 else
35976 dev_kfree_skb(skb);
35977
35978 - atomic_inc(&vcc->stats->tx);
35979 + atomic_inc_unchecked(&vcc->stats->tx);
35980 }
35981
35982 atomic_dec(&scq->used);
35983 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35984 if ((sb = dev_alloc_skb(64)) == NULL) {
35985 printk("%s: Can't allocate buffers for aal0.\n",
35986 card->name);
35987 - atomic_add(i, &vcc->stats->rx_drop);
35988 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
35989 break;
35990 }
35991 if (!atm_charge(vcc, sb->truesize)) {
35992 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35993 card->name);
35994 - atomic_add(i - 1, &vcc->stats->rx_drop);
35995 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35996 dev_kfree_skb(sb);
35997 break;
35998 }
35999 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36000 ATM_SKB(sb)->vcc = vcc;
36001 __net_timestamp(sb);
36002 vcc->push(vcc, sb);
36003 - atomic_inc(&vcc->stats->rx);
36004 + atomic_inc_unchecked(&vcc->stats->rx);
36005
36006 cell += ATM_CELL_PAYLOAD;
36007 }
36008 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36009 "(CDC: %08x)\n",
36010 card->name, len, rpp->len, readl(SAR_REG_CDC));
36011 recycle_rx_pool_skb(card, rpp);
36012 - atomic_inc(&vcc->stats->rx_err);
36013 + atomic_inc_unchecked(&vcc->stats->rx_err);
36014 return;
36015 }
36016 if (stat & SAR_RSQE_CRC) {
36017 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36018 recycle_rx_pool_skb(card, rpp);
36019 - atomic_inc(&vcc->stats->rx_err);
36020 + atomic_inc_unchecked(&vcc->stats->rx_err);
36021 return;
36022 }
36023 if (skb_queue_len(&rpp->queue) > 1) {
36024 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36025 RXPRINTK("%s: Can't alloc RX skb.\n",
36026 card->name);
36027 recycle_rx_pool_skb(card, rpp);
36028 - atomic_inc(&vcc->stats->rx_err);
36029 + atomic_inc_unchecked(&vcc->stats->rx_err);
36030 return;
36031 }
36032 if (!atm_charge(vcc, skb->truesize)) {
36033 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36034 __net_timestamp(skb);
36035
36036 vcc->push(vcc, skb);
36037 - atomic_inc(&vcc->stats->rx);
36038 + atomic_inc_unchecked(&vcc->stats->rx);
36039
36040 return;
36041 }
36042 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36043 __net_timestamp(skb);
36044
36045 vcc->push(vcc, skb);
36046 - atomic_inc(&vcc->stats->rx);
36047 + atomic_inc_unchecked(&vcc->stats->rx);
36048
36049 if (skb->truesize > SAR_FB_SIZE_3)
36050 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36051 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36052 if (vcc->qos.aal != ATM_AAL0) {
36053 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36054 card->name, vpi, vci);
36055 - atomic_inc(&vcc->stats->rx_drop);
36056 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36057 goto drop;
36058 }
36059
36060 if ((sb = dev_alloc_skb(64)) == NULL) {
36061 printk("%s: Can't allocate buffers for AAL0.\n",
36062 card->name);
36063 - atomic_inc(&vcc->stats->rx_err);
36064 + atomic_inc_unchecked(&vcc->stats->rx_err);
36065 goto drop;
36066 }
36067
36068 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36069 ATM_SKB(sb)->vcc = vcc;
36070 __net_timestamp(sb);
36071 vcc->push(vcc, sb);
36072 - atomic_inc(&vcc->stats->rx);
36073 + atomic_inc_unchecked(&vcc->stats->rx);
36074
36075 drop:
36076 skb_pull(queue, 64);
36077 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36078
36079 if (vc == NULL) {
36080 printk("%s: NULL connection in send().\n", card->name);
36081 - atomic_inc(&vcc->stats->tx_err);
36082 + atomic_inc_unchecked(&vcc->stats->tx_err);
36083 dev_kfree_skb(skb);
36084 return -EINVAL;
36085 }
36086 if (!test_bit(VCF_TX, &vc->flags)) {
36087 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36088 - atomic_inc(&vcc->stats->tx_err);
36089 + atomic_inc_unchecked(&vcc->stats->tx_err);
36090 dev_kfree_skb(skb);
36091 return -EINVAL;
36092 }
36093 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36094 break;
36095 default:
36096 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36097 - atomic_inc(&vcc->stats->tx_err);
36098 + atomic_inc_unchecked(&vcc->stats->tx_err);
36099 dev_kfree_skb(skb);
36100 return -EINVAL;
36101 }
36102
36103 if (skb_shinfo(skb)->nr_frags != 0) {
36104 printk("%s: No scatter-gather yet.\n", card->name);
36105 - atomic_inc(&vcc->stats->tx_err);
36106 + atomic_inc_unchecked(&vcc->stats->tx_err);
36107 dev_kfree_skb(skb);
36108 return -EINVAL;
36109 }
36110 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36111
36112 err = queue_skb(card, vc, skb, oam);
36113 if (err) {
36114 - atomic_inc(&vcc->stats->tx_err);
36115 + atomic_inc_unchecked(&vcc->stats->tx_err);
36116 dev_kfree_skb(skb);
36117 return err;
36118 }
36119 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36120 skb = dev_alloc_skb(64);
36121 if (!skb) {
36122 printk("%s: Out of memory in send_oam().\n", card->name);
36123 - atomic_inc(&vcc->stats->tx_err);
36124 + atomic_inc_unchecked(&vcc->stats->tx_err);
36125 return -ENOMEM;
36126 }
36127 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36128 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36129 index 4217f29..88f547a 100644
36130 --- a/drivers/atm/iphase.c
36131 +++ b/drivers/atm/iphase.c
36132 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36133 status = (u_short) (buf_desc_ptr->desc_mode);
36134 if (status & (RX_CER | RX_PTE | RX_OFL))
36135 {
36136 - atomic_inc(&vcc->stats->rx_err);
36137 + atomic_inc_unchecked(&vcc->stats->rx_err);
36138 IF_ERR(printk("IA: bad packet, dropping it");)
36139 if (status & RX_CER) {
36140 IF_ERR(printk(" cause: packet CRC error\n");)
36141 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36142 len = dma_addr - buf_addr;
36143 if (len > iadev->rx_buf_sz) {
36144 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36145 - atomic_inc(&vcc->stats->rx_err);
36146 + atomic_inc_unchecked(&vcc->stats->rx_err);
36147 goto out_free_desc;
36148 }
36149
36150 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36151 ia_vcc = INPH_IA_VCC(vcc);
36152 if (ia_vcc == NULL)
36153 {
36154 - atomic_inc(&vcc->stats->rx_err);
36155 + atomic_inc_unchecked(&vcc->stats->rx_err);
36156 atm_return(vcc, skb->truesize);
36157 dev_kfree_skb_any(skb);
36158 goto INCR_DLE;
36159 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36160 if ((length > iadev->rx_buf_sz) || (length >
36161 (skb->len - sizeof(struct cpcs_trailer))))
36162 {
36163 - atomic_inc(&vcc->stats->rx_err);
36164 + atomic_inc_unchecked(&vcc->stats->rx_err);
36165 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36166 length, skb->len);)
36167 atm_return(vcc, skb->truesize);
36168 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36169
36170 IF_RX(printk("rx_dle_intr: skb push");)
36171 vcc->push(vcc,skb);
36172 - atomic_inc(&vcc->stats->rx);
36173 + atomic_inc_unchecked(&vcc->stats->rx);
36174 iadev->rx_pkt_cnt++;
36175 }
36176 INCR_DLE:
36177 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36178 {
36179 struct k_sonet_stats *stats;
36180 stats = &PRIV(_ia_dev[board])->sonet_stats;
36181 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36182 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36183 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36184 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36185 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36186 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36187 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36188 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36189 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36190 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36191 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36192 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36193 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36194 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36195 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36196 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36197 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36198 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36199 }
36200 ia_cmds.status = 0;
36201 break;
36202 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36203 if ((desc == 0) || (desc > iadev->num_tx_desc))
36204 {
36205 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36206 - atomic_inc(&vcc->stats->tx);
36207 + atomic_inc_unchecked(&vcc->stats->tx);
36208 if (vcc->pop)
36209 vcc->pop(vcc, skb);
36210 else
36211 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36212 ATM_DESC(skb) = vcc->vci;
36213 skb_queue_tail(&iadev->tx_dma_q, skb);
36214
36215 - atomic_inc(&vcc->stats->tx);
36216 + atomic_inc_unchecked(&vcc->stats->tx);
36217 iadev->tx_pkt_cnt++;
36218 /* Increment transaction counter */
36219 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36220
36221 #if 0
36222 /* add flow control logic */
36223 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36224 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36225 if (iavcc->vc_desc_cnt > 10) {
36226 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36227 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36228 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36229 index fa7d701..1e404c7 100644
36230 --- a/drivers/atm/lanai.c
36231 +++ b/drivers/atm/lanai.c
36232 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36233 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36234 lanai_endtx(lanai, lvcc);
36235 lanai_free_skb(lvcc->tx.atmvcc, skb);
36236 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36237 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36238 }
36239
36240 /* Try to fill the buffer - don't call unless there is backlog */
36241 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36242 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36243 __net_timestamp(skb);
36244 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36245 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36246 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36247 out:
36248 lvcc->rx.buf.ptr = end;
36249 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36250 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36251 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36252 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36253 lanai->stats.service_rxnotaal5++;
36254 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36255 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36256 return 0;
36257 }
36258 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36259 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36260 int bytes;
36261 read_unlock(&vcc_sklist_lock);
36262 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36263 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36264 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36265 lvcc->stats.x.aal5.service_trash++;
36266 bytes = (SERVICE_GET_END(s) * 16) -
36267 (((unsigned long) lvcc->rx.buf.ptr) -
36268 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36269 }
36270 if (s & SERVICE_STREAM) {
36271 read_unlock(&vcc_sklist_lock);
36272 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36273 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36274 lvcc->stats.x.aal5.service_stream++;
36275 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36276 "PDU on VCI %d!\n", lanai->number, vci);
36277 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36278 return 0;
36279 }
36280 DPRINTK("got rx crc error on vci %d\n", vci);
36281 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36282 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36283 lvcc->stats.x.aal5.service_rxcrc++;
36284 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36285 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36286 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36287 index 5aca5f4..ce3a6b0 100644
36288 --- a/drivers/atm/nicstar.c
36289 +++ b/drivers/atm/nicstar.c
36290 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36291 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36292 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36293 card->index);
36294 - atomic_inc(&vcc->stats->tx_err);
36295 + atomic_inc_unchecked(&vcc->stats->tx_err);
36296 dev_kfree_skb_any(skb);
36297 return -EINVAL;
36298 }
36299 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36300 if (!vc->tx) {
36301 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36302 card->index);
36303 - atomic_inc(&vcc->stats->tx_err);
36304 + atomic_inc_unchecked(&vcc->stats->tx_err);
36305 dev_kfree_skb_any(skb);
36306 return -EINVAL;
36307 }
36308 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36309 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36310 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36311 card->index);
36312 - atomic_inc(&vcc->stats->tx_err);
36313 + atomic_inc_unchecked(&vcc->stats->tx_err);
36314 dev_kfree_skb_any(skb);
36315 return -EINVAL;
36316 }
36317
36318 if (skb_shinfo(skb)->nr_frags != 0) {
36319 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36320 - atomic_inc(&vcc->stats->tx_err);
36321 + atomic_inc_unchecked(&vcc->stats->tx_err);
36322 dev_kfree_skb_any(skb);
36323 return -EINVAL;
36324 }
36325 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36326 }
36327
36328 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36329 - atomic_inc(&vcc->stats->tx_err);
36330 + atomic_inc_unchecked(&vcc->stats->tx_err);
36331 dev_kfree_skb_any(skb);
36332 return -EIO;
36333 }
36334 - atomic_inc(&vcc->stats->tx);
36335 + atomic_inc_unchecked(&vcc->stats->tx);
36336
36337 return 0;
36338 }
36339 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36340 printk
36341 ("nicstar%d: Can't allocate buffers for aal0.\n",
36342 card->index);
36343 - atomic_add(i, &vcc->stats->rx_drop);
36344 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36345 break;
36346 }
36347 if (!atm_charge(vcc, sb->truesize)) {
36348 RXPRINTK
36349 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36350 card->index);
36351 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36352 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36353 dev_kfree_skb_any(sb);
36354 break;
36355 }
36356 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36357 ATM_SKB(sb)->vcc = vcc;
36358 __net_timestamp(sb);
36359 vcc->push(vcc, sb);
36360 - atomic_inc(&vcc->stats->rx);
36361 + atomic_inc_unchecked(&vcc->stats->rx);
36362 cell += ATM_CELL_PAYLOAD;
36363 }
36364
36365 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36366 if (iovb == NULL) {
36367 printk("nicstar%d: Out of iovec buffers.\n",
36368 card->index);
36369 - atomic_inc(&vcc->stats->rx_drop);
36370 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36371 recycle_rx_buf(card, skb);
36372 return;
36373 }
36374 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36375 small or large buffer itself. */
36376 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36377 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36378 - atomic_inc(&vcc->stats->rx_err);
36379 + atomic_inc_unchecked(&vcc->stats->rx_err);
36380 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36381 NS_MAX_IOVECS);
36382 NS_PRV_IOVCNT(iovb) = 0;
36383 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36384 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36385 card->index);
36386 which_list(card, skb);
36387 - atomic_inc(&vcc->stats->rx_err);
36388 + atomic_inc_unchecked(&vcc->stats->rx_err);
36389 recycle_rx_buf(card, skb);
36390 vc->rx_iov = NULL;
36391 recycle_iov_buf(card, iovb);
36392 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36393 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36394 card->index);
36395 which_list(card, skb);
36396 - atomic_inc(&vcc->stats->rx_err);
36397 + atomic_inc_unchecked(&vcc->stats->rx_err);
36398 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36399 NS_PRV_IOVCNT(iovb));
36400 vc->rx_iov = NULL;
36401 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36402 printk(" - PDU size mismatch.\n");
36403 else
36404 printk(".\n");
36405 - atomic_inc(&vcc->stats->rx_err);
36406 + atomic_inc_unchecked(&vcc->stats->rx_err);
36407 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36408 NS_PRV_IOVCNT(iovb));
36409 vc->rx_iov = NULL;
36410 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36411 /* skb points to a small buffer */
36412 if (!atm_charge(vcc, skb->truesize)) {
36413 push_rxbufs(card, skb);
36414 - atomic_inc(&vcc->stats->rx_drop);
36415 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36416 } else {
36417 skb_put(skb, len);
36418 dequeue_sm_buf(card, skb);
36419 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36420 ATM_SKB(skb)->vcc = vcc;
36421 __net_timestamp(skb);
36422 vcc->push(vcc, skb);
36423 - atomic_inc(&vcc->stats->rx);
36424 + atomic_inc_unchecked(&vcc->stats->rx);
36425 }
36426 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36427 struct sk_buff *sb;
36428 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36429 if (len <= NS_SMBUFSIZE) {
36430 if (!atm_charge(vcc, sb->truesize)) {
36431 push_rxbufs(card, sb);
36432 - atomic_inc(&vcc->stats->rx_drop);
36433 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36434 } else {
36435 skb_put(sb, len);
36436 dequeue_sm_buf(card, sb);
36437 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36438 ATM_SKB(sb)->vcc = vcc;
36439 __net_timestamp(sb);
36440 vcc->push(vcc, sb);
36441 - atomic_inc(&vcc->stats->rx);
36442 + atomic_inc_unchecked(&vcc->stats->rx);
36443 }
36444
36445 push_rxbufs(card, skb);
36446 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36447
36448 if (!atm_charge(vcc, skb->truesize)) {
36449 push_rxbufs(card, skb);
36450 - atomic_inc(&vcc->stats->rx_drop);
36451 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36452 } else {
36453 dequeue_lg_buf(card, skb);
36454 #ifdef NS_USE_DESTRUCTORS
36455 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36456 ATM_SKB(skb)->vcc = vcc;
36457 __net_timestamp(skb);
36458 vcc->push(vcc, skb);
36459 - atomic_inc(&vcc->stats->rx);
36460 + atomic_inc_unchecked(&vcc->stats->rx);
36461 }
36462
36463 push_rxbufs(card, sb);
36464 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36465 printk
36466 ("nicstar%d: Out of huge buffers.\n",
36467 card->index);
36468 - atomic_inc(&vcc->stats->rx_drop);
36469 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36470 recycle_iovec_rx_bufs(card,
36471 (struct iovec *)
36472 iovb->data,
36473 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36474 card->hbpool.count++;
36475 } else
36476 dev_kfree_skb_any(hb);
36477 - atomic_inc(&vcc->stats->rx_drop);
36478 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36479 } else {
36480 /* Copy the small buffer to the huge buffer */
36481 sb = (struct sk_buff *)iov->iov_base;
36482 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36483 #endif /* NS_USE_DESTRUCTORS */
36484 __net_timestamp(hb);
36485 vcc->push(vcc, hb);
36486 - atomic_inc(&vcc->stats->rx);
36487 + atomic_inc_unchecked(&vcc->stats->rx);
36488 }
36489 }
36490
36491 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
36492 index 32784d1..4a8434a 100644
36493 --- a/drivers/atm/solos-pci.c
36494 +++ b/drivers/atm/solos-pci.c
36495 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
36496 }
36497 atm_charge(vcc, skb->truesize);
36498 vcc->push(vcc, skb);
36499 - atomic_inc(&vcc->stats->rx);
36500 + atomic_inc_unchecked(&vcc->stats->rx);
36501 break;
36502
36503 case PKT_STATUS:
36504 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
36505 vcc = SKB_CB(oldskb)->vcc;
36506
36507 if (vcc) {
36508 - atomic_inc(&vcc->stats->tx);
36509 + atomic_inc_unchecked(&vcc->stats->tx);
36510 solos_pop(vcc, oldskb);
36511 } else {
36512 dev_kfree_skb_irq(oldskb);
36513 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
36514 index 0215934..ce9f5b1 100644
36515 --- a/drivers/atm/suni.c
36516 +++ b/drivers/atm/suni.c
36517 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
36518
36519
36520 #define ADD_LIMITED(s,v) \
36521 - atomic_add((v),&stats->s); \
36522 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
36523 + atomic_add_unchecked((v),&stats->s); \
36524 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
36525
36526
36527 static void suni_hz(unsigned long from_timer)
36528 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
36529 index 5120a96..e2572bd 100644
36530 --- a/drivers/atm/uPD98402.c
36531 +++ b/drivers/atm/uPD98402.c
36532 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
36533 struct sonet_stats tmp;
36534 int error = 0;
36535
36536 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36537 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36538 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
36539 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
36540 if (zero && !error) {
36541 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
36542
36543
36544 #define ADD_LIMITED(s,v) \
36545 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
36546 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
36547 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36548 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
36549 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
36550 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36551
36552
36553 static void stat_event(struct atm_dev *dev)
36554 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
36555 if (reason & uPD98402_INT_PFM) stat_event(dev);
36556 if (reason & uPD98402_INT_PCO) {
36557 (void) GET(PCOCR); /* clear interrupt cause */
36558 - atomic_add(GET(HECCT),
36559 + atomic_add_unchecked(GET(HECCT),
36560 &PRIV(dev)->sonet_stats.uncorr_hcs);
36561 }
36562 if ((reason & uPD98402_INT_RFO) &&
36563 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
36564 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
36565 uPD98402_INT_LOS),PIMR); /* enable them */
36566 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
36567 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36568 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
36569 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
36570 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36571 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
36572 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
36573 return 0;
36574 }
36575
36576 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
36577 index 969c3c2..9b72956 100644
36578 --- a/drivers/atm/zatm.c
36579 +++ b/drivers/atm/zatm.c
36580 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36581 }
36582 if (!size) {
36583 dev_kfree_skb_irq(skb);
36584 - if (vcc) atomic_inc(&vcc->stats->rx_err);
36585 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
36586 continue;
36587 }
36588 if (!atm_charge(vcc,skb->truesize)) {
36589 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36590 skb->len = size;
36591 ATM_SKB(skb)->vcc = vcc;
36592 vcc->push(vcc,skb);
36593 - atomic_inc(&vcc->stats->rx);
36594 + atomic_inc_unchecked(&vcc->stats->rx);
36595 }
36596 zout(pos & 0xffff,MTA(mbx));
36597 #if 0 /* probably a stupid idea */
36598 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
36599 skb_queue_head(&zatm_vcc->backlog,skb);
36600 break;
36601 }
36602 - atomic_inc(&vcc->stats->tx);
36603 + atomic_inc_unchecked(&vcc->stats->tx);
36604 wake_up(&zatm_vcc->tx_wait);
36605 }
36606
36607 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
36608 index 73f6c29..b0c0e13 100644
36609 --- a/drivers/base/bus.c
36610 +++ b/drivers/base/bus.c
36611 @@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
36612 return -EINVAL;
36613
36614 mutex_lock(&subsys->p->mutex);
36615 - list_add_tail(&sif->node, &subsys->p->interfaces);
36616 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
36617 if (sif->add_dev) {
36618 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36619 while ((dev = subsys_dev_iter_next(&iter)))
36620 @@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
36621 subsys = sif->subsys;
36622
36623 mutex_lock(&subsys->p->mutex);
36624 - list_del_init(&sif->node);
36625 + pax_list_del_init((struct list_head *)&sif->node);
36626 if (sif->remove_dev) {
36627 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36628 while ((dev = subsys_dev_iter_next(&iter)))
36629 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
36630 index 0f38201..6c2b444 100644
36631 --- a/drivers/base/devtmpfs.c
36632 +++ b/drivers/base/devtmpfs.c
36633 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
36634 if (!thread)
36635 return 0;
36636
36637 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
36638 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
36639 if (err)
36640 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
36641 else
36642 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
36643 *err = sys_unshare(CLONE_NEWNS);
36644 if (*err)
36645 goto out;
36646 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
36647 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
36648 if (*err)
36649 goto out;
36650 - sys_chdir("/.."); /* will traverse into overmounted root */
36651 - sys_chroot(".");
36652 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
36653 + sys_chroot((char __force_user *)".");
36654 complete(&setup_done);
36655 while (1) {
36656 spin_lock(&req_lock);
36657 diff --git a/drivers/base/node.c b/drivers/base/node.c
36658 index bc9f43b..29703b8 100644
36659 --- a/drivers/base/node.c
36660 +++ b/drivers/base/node.c
36661 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
36662 struct node_attr {
36663 struct device_attribute attr;
36664 enum node_states state;
36665 -};
36666 +} __do_const;
36667
36668 static ssize_t show_node_state(struct device *dev,
36669 struct device_attribute *attr, char *buf)
36670 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
36671 index bfb8955..42c9b9a 100644
36672 --- a/drivers/base/power/domain.c
36673 +++ b/drivers/base/power/domain.c
36674 @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
36675 {
36676 struct cpuidle_driver *cpuidle_drv;
36677 struct gpd_cpu_data *cpu_data;
36678 - struct cpuidle_state *idle_state;
36679 + cpuidle_state_no_const *idle_state;
36680 int ret = 0;
36681
36682 if (IS_ERR_OR_NULL(genpd) || state < 0)
36683 @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
36684 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
36685 {
36686 struct gpd_cpu_data *cpu_data;
36687 - struct cpuidle_state *idle_state;
36688 + cpuidle_state_no_const *idle_state;
36689 int ret = 0;
36690
36691 if (IS_ERR_OR_NULL(genpd))
36692 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
36693 index 03e089a..0e9560c 100644
36694 --- a/drivers/base/power/sysfs.c
36695 +++ b/drivers/base/power/sysfs.c
36696 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
36697 return -EIO;
36698 }
36699 }
36700 - return sprintf(buf, p);
36701 + return sprintf(buf, "%s", p);
36702 }
36703
36704 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
36705 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
36706 index 2d56f41..8830f19 100644
36707 --- a/drivers/base/power/wakeup.c
36708 +++ b/drivers/base/power/wakeup.c
36709 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
36710 * They need to be modified together atomically, so it's better to use one
36711 * atomic variable to hold them both.
36712 */
36713 -static atomic_t combined_event_count = ATOMIC_INIT(0);
36714 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
36715
36716 #define IN_PROGRESS_BITS (sizeof(int) * 4)
36717 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
36718
36719 static void split_counters(unsigned int *cnt, unsigned int *inpr)
36720 {
36721 - unsigned int comb = atomic_read(&combined_event_count);
36722 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
36723
36724 *cnt = (comb >> IN_PROGRESS_BITS);
36725 *inpr = comb & MAX_IN_PROGRESS;
36726 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
36727 ws->start_prevent_time = ws->last_time;
36728
36729 /* Increment the counter of events in progress. */
36730 - cec = atomic_inc_return(&combined_event_count);
36731 + cec = atomic_inc_return_unchecked(&combined_event_count);
36732
36733 trace_wakeup_source_activate(ws->name, cec);
36734 }
36735 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
36736 * Increment the counter of registered wakeup events and decrement the
36737 * couter of wakeup events in progress simultaneously.
36738 */
36739 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
36740 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
36741 trace_wakeup_source_deactivate(ws->name, cec);
36742
36743 split_counters(&cnt, &inpr);
36744 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
36745 index e8d11b6..7b1b36f 100644
36746 --- a/drivers/base/syscore.c
36747 +++ b/drivers/base/syscore.c
36748 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
36749 void register_syscore_ops(struct syscore_ops *ops)
36750 {
36751 mutex_lock(&syscore_ops_lock);
36752 - list_add_tail(&ops->node, &syscore_ops_list);
36753 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
36754 mutex_unlock(&syscore_ops_lock);
36755 }
36756 EXPORT_SYMBOL_GPL(register_syscore_ops);
36757 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
36758 void unregister_syscore_ops(struct syscore_ops *ops)
36759 {
36760 mutex_lock(&syscore_ops_lock);
36761 - list_del(&ops->node);
36762 + pax_list_del((struct list_head *)&ops->node);
36763 mutex_unlock(&syscore_ops_lock);
36764 }
36765 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36766 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36767 index b35fc4f..c902870 100644
36768 --- a/drivers/block/cciss.c
36769 +++ b/drivers/block/cciss.c
36770 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
36771 while (!list_empty(&h->reqQ)) {
36772 c = list_entry(h->reqQ.next, CommandList_struct, list);
36773 /* can't do anything if fifo is full */
36774 - if ((h->access.fifo_full(h))) {
36775 + if ((h->access->fifo_full(h))) {
36776 dev_warn(&h->pdev->dev, "fifo full\n");
36777 break;
36778 }
36779 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
36780 h->Qdepth--;
36781
36782 /* Tell the controller execute command */
36783 - h->access.submit_command(h, c);
36784 + h->access->submit_command(h, c);
36785
36786 /* Put job onto the completed Q */
36787 addQ(&h->cmpQ, c);
36788 @@ -3447,17 +3447,17 @@ startio:
36789
36790 static inline unsigned long get_next_completion(ctlr_info_t *h)
36791 {
36792 - return h->access.command_completed(h);
36793 + return h->access->command_completed(h);
36794 }
36795
36796 static inline int interrupt_pending(ctlr_info_t *h)
36797 {
36798 - return h->access.intr_pending(h);
36799 + return h->access->intr_pending(h);
36800 }
36801
36802 static inline long interrupt_not_for_us(ctlr_info_t *h)
36803 {
36804 - return ((h->access.intr_pending(h) == 0) ||
36805 + return ((h->access->intr_pending(h) == 0) ||
36806 (h->interrupts_enabled == 0));
36807 }
36808
36809 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36810 u32 a;
36811
36812 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36813 - return h->access.command_completed(h);
36814 + return h->access->command_completed(h);
36815
36816 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36817 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36818 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36819 trans_support & CFGTBL_Trans_use_short_tags);
36820
36821 /* Change the access methods to the performant access methods */
36822 - h->access = SA5_performant_access;
36823 + h->access = &SA5_performant_access;
36824 h->transMethod = CFGTBL_Trans_Performant;
36825
36826 return;
36827 @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36828 if (prod_index < 0)
36829 return -ENODEV;
36830 h->product_name = products[prod_index].product_name;
36831 - h->access = *(products[prod_index].access);
36832 + h->access = products[prod_index].access;
36833
36834 if (cciss_board_disabled(h)) {
36835 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36836 @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
36837 }
36838
36839 /* make sure the board interrupts are off */
36840 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36841 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36842 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36843 if (rc)
36844 goto clean2;
36845 @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
36846 * fake ones to scoop up any residual completions.
36847 */
36848 spin_lock_irqsave(&h->lock, flags);
36849 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36850 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36851 spin_unlock_irqrestore(&h->lock, flags);
36852 free_irq(h->intr[h->intr_mode], h);
36853 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36854 @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
36855 dev_info(&h->pdev->dev, "Board READY.\n");
36856 dev_info(&h->pdev->dev,
36857 "Waiting for stale completions to drain.\n");
36858 - h->access.set_intr_mask(h, CCISS_INTR_ON);
36859 + h->access->set_intr_mask(h, CCISS_INTR_ON);
36860 msleep(10000);
36861 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36862 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36863
36864 rc = controller_reset_failed(h->cfgtable);
36865 if (rc)
36866 @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
36867 cciss_scsi_setup(h);
36868
36869 /* Turn the interrupts on so we can service requests */
36870 - h->access.set_intr_mask(h, CCISS_INTR_ON);
36871 + h->access->set_intr_mask(h, CCISS_INTR_ON);
36872
36873 /* Get the firmware version */
36874 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36875 @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36876 kfree(flush_buf);
36877 if (return_code != IO_OK)
36878 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36879 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36880 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36881 free_irq(h->intr[h->intr_mode], h);
36882 }
36883
36884 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36885 index 7fda30e..2f27946 100644
36886 --- a/drivers/block/cciss.h
36887 +++ b/drivers/block/cciss.h
36888 @@ -101,7 +101,7 @@ struct ctlr_info
36889 /* information about each logical volume */
36890 drive_info_struct *drv[CISS_MAX_LUN];
36891
36892 - struct access_method access;
36893 + struct access_method *access;
36894
36895 /* queue and queue Info */
36896 struct list_head reqQ;
36897 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
36898 }
36899
36900 static struct access_method SA5_access = {
36901 - SA5_submit_command,
36902 - SA5_intr_mask,
36903 - SA5_fifo_full,
36904 - SA5_intr_pending,
36905 - SA5_completed,
36906 + .submit_command = SA5_submit_command,
36907 + .set_intr_mask = SA5_intr_mask,
36908 + .fifo_full = SA5_fifo_full,
36909 + .intr_pending = SA5_intr_pending,
36910 + .command_completed = SA5_completed,
36911 };
36912
36913 static struct access_method SA5B_access = {
36914 - SA5_submit_command,
36915 - SA5B_intr_mask,
36916 - SA5_fifo_full,
36917 - SA5B_intr_pending,
36918 - SA5_completed,
36919 + .submit_command = SA5_submit_command,
36920 + .set_intr_mask = SA5B_intr_mask,
36921 + .fifo_full = SA5_fifo_full,
36922 + .intr_pending = SA5B_intr_pending,
36923 + .command_completed = SA5_completed,
36924 };
36925
36926 static struct access_method SA5_performant_access = {
36927 - SA5_submit_command,
36928 - SA5_performant_intr_mask,
36929 - SA5_fifo_full,
36930 - SA5_performant_intr_pending,
36931 - SA5_performant_completed,
36932 + .submit_command = SA5_submit_command,
36933 + .set_intr_mask = SA5_performant_intr_mask,
36934 + .fifo_full = SA5_fifo_full,
36935 + .intr_pending = SA5_performant_intr_pending,
36936 + .command_completed = SA5_performant_completed,
36937 };
36938
36939 struct board_type {
36940 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36941 index 2b94403..fd6ad1f 100644
36942 --- a/drivers/block/cpqarray.c
36943 +++ b/drivers/block/cpqarray.c
36944 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36945 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36946 goto Enomem4;
36947 }
36948 - hba[i]->access.set_intr_mask(hba[i], 0);
36949 + hba[i]->access->set_intr_mask(hba[i], 0);
36950 if (request_irq(hba[i]->intr, do_ida_intr,
36951 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36952 {
36953 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36954 add_timer(&hba[i]->timer);
36955
36956 /* Enable IRQ now that spinlock and rate limit timer are set up */
36957 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36958 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36959
36960 for(j=0; j<NWD; j++) {
36961 struct gendisk *disk = ida_gendisk[i][j];
36962 @@ -694,7 +694,7 @@ DBGINFO(
36963 for(i=0; i<NR_PRODUCTS; i++) {
36964 if (board_id == products[i].board_id) {
36965 c->product_name = products[i].product_name;
36966 - c->access = *(products[i].access);
36967 + c->access = products[i].access;
36968 break;
36969 }
36970 }
36971 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36972 hba[ctlr]->intr = intr;
36973 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36974 hba[ctlr]->product_name = products[j].product_name;
36975 - hba[ctlr]->access = *(products[j].access);
36976 + hba[ctlr]->access = products[j].access;
36977 hba[ctlr]->ctlr = ctlr;
36978 hba[ctlr]->board_id = board_id;
36979 hba[ctlr]->pci_dev = NULL; /* not PCI */
36980 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36981
36982 while((c = h->reqQ) != NULL) {
36983 /* Can't do anything if we're busy */
36984 - if (h->access.fifo_full(h) == 0)
36985 + if (h->access->fifo_full(h) == 0)
36986 return;
36987
36988 /* Get the first entry from the request Q */
36989 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36990 h->Qdepth--;
36991
36992 /* Tell the controller to do our bidding */
36993 - h->access.submit_command(h, c);
36994 + h->access->submit_command(h, c);
36995
36996 /* Get onto the completion Q */
36997 addQ(&h->cmpQ, c);
36998 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36999 unsigned long flags;
37000 __u32 a,a1;
37001
37002 - istat = h->access.intr_pending(h);
37003 + istat = h->access->intr_pending(h);
37004 /* Is this interrupt for us? */
37005 if (istat == 0)
37006 return IRQ_NONE;
37007 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37008 */
37009 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37010 if (istat & FIFO_NOT_EMPTY) {
37011 - while((a = h->access.command_completed(h))) {
37012 + while((a = h->access->command_completed(h))) {
37013 a1 = a; a &= ~3;
37014 if ((c = h->cmpQ) == NULL)
37015 {
37016 @@ -1448,11 +1448,11 @@ static int sendcmd(
37017 /*
37018 * Disable interrupt
37019 */
37020 - info_p->access.set_intr_mask(info_p, 0);
37021 + info_p->access->set_intr_mask(info_p, 0);
37022 /* Make sure there is room in the command FIFO */
37023 /* Actually it should be completely empty at this time. */
37024 for (i = 200000; i > 0; i--) {
37025 - temp = info_p->access.fifo_full(info_p);
37026 + temp = info_p->access->fifo_full(info_p);
37027 if (temp != 0) {
37028 break;
37029 }
37030 @@ -1465,7 +1465,7 @@ DBG(
37031 /*
37032 * Send the cmd
37033 */
37034 - info_p->access.submit_command(info_p, c);
37035 + info_p->access->submit_command(info_p, c);
37036 complete = pollcomplete(ctlr);
37037
37038 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37039 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37040 * we check the new geometry. Then turn interrupts back on when
37041 * we're done.
37042 */
37043 - host->access.set_intr_mask(host, 0);
37044 + host->access->set_intr_mask(host, 0);
37045 getgeometry(ctlr);
37046 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37047 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37048
37049 for(i=0; i<NWD; i++) {
37050 struct gendisk *disk = ida_gendisk[ctlr][i];
37051 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37052 /* Wait (up to 2 seconds) for a command to complete */
37053
37054 for (i = 200000; i > 0; i--) {
37055 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37056 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37057 if (done == 0) {
37058 udelay(10); /* a short fixed delay */
37059 } else
37060 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37061 index be73e9d..7fbf140 100644
37062 --- a/drivers/block/cpqarray.h
37063 +++ b/drivers/block/cpqarray.h
37064 @@ -99,7 +99,7 @@ struct ctlr_info {
37065 drv_info_t drv[NWD];
37066 struct proc_dir_entry *proc;
37067
37068 - struct access_method access;
37069 + struct access_method *access;
37070
37071 cmdlist_t *reqQ;
37072 cmdlist_t *cmpQ;
37073 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37074 index 0e06f0c..c47b81d 100644
37075 --- a/drivers/block/drbd/drbd_int.h
37076 +++ b/drivers/block/drbd/drbd_int.h
37077 @@ -582,7 +582,7 @@ struct drbd_epoch {
37078 struct drbd_tconn *tconn;
37079 struct list_head list;
37080 unsigned int barrier_nr;
37081 - atomic_t epoch_size; /* increased on every request added. */
37082 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37083 atomic_t active; /* increased on every req. added, and dec on every finished. */
37084 unsigned long flags;
37085 };
37086 @@ -1022,7 +1022,7 @@ struct drbd_conf {
37087 unsigned int al_tr_number;
37088 int al_tr_cycle;
37089 wait_queue_head_t seq_wait;
37090 - atomic_t packet_seq;
37091 + atomic_unchecked_t packet_seq;
37092 unsigned int peer_seq;
37093 spinlock_t peer_seq_lock;
37094 unsigned int minor;
37095 @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37096 char __user *uoptval;
37097 int err;
37098
37099 - uoptval = (char __user __force *)optval;
37100 + uoptval = (char __force_user *)optval;
37101
37102 set_fs(KERNEL_DS);
37103 if (level == SOL_SOCKET)
37104 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37105 index 89c497c..9c736ae 100644
37106 --- a/drivers/block/drbd/drbd_interval.c
37107 +++ b/drivers/block/drbd/drbd_interval.c
37108 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37109 }
37110
37111 static const struct rb_augment_callbacks augment_callbacks = {
37112 - augment_propagate,
37113 - augment_copy,
37114 - augment_rotate,
37115 + .propagate = augment_propagate,
37116 + .copy = augment_copy,
37117 + .rotate = augment_rotate,
37118 };
37119
37120 /**
37121 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37122 index 9e3818b..7b64c92 100644
37123 --- a/drivers/block/drbd/drbd_main.c
37124 +++ b/drivers/block/drbd/drbd_main.c
37125 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37126 p->sector = sector;
37127 p->block_id = block_id;
37128 p->blksize = blksize;
37129 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37130 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37131 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37132 }
37133
37134 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37135 return -EIO;
37136 p->sector = cpu_to_be64(req->i.sector);
37137 p->block_id = (unsigned long)req;
37138 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37139 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37140 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37141 if (mdev->state.conn >= C_SYNC_SOURCE &&
37142 mdev->state.conn <= C_PAUSED_SYNC_T)
37143 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37144 {
37145 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37146
37147 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37148 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37149 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37150 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37151 kfree(tconn->current_epoch);
37152
37153 idr_destroy(&tconn->volumes);
37154 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37155 index c706d50..5e1b472 100644
37156 --- a/drivers/block/drbd/drbd_nl.c
37157 +++ b/drivers/block/drbd/drbd_nl.c
37158 @@ -3440,7 +3440,7 @@ out:
37159
37160 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37161 {
37162 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37163 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37164 struct sk_buff *msg;
37165 struct drbd_genlmsghdr *d_out;
37166 unsigned seq;
37167 @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37168 return;
37169 }
37170
37171 - seq = atomic_inc_return(&drbd_genl_seq);
37172 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37173 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37174 if (!msg)
37175 goto failed;
37176 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37177 index 6fa6673..b7f97e9 100644
37178 --- a/drivers/block/drbd/drbd_receiver.c
37179 +++ b/drivers/block/drbd/drbd_receiver.c
37180 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37181 {
37182 int err;
37183
37184 - atomic_set(&mdev->packet_seq, 0);
37185 + atomic_set_unchecked(&mdev->packet_seq, 0);
37186 mdev->peer_seq = 0;
37187
37188 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37189 @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37190 do {
37191 next_epoch = NULL;
37192
37193 - epoch_size = atomic_read(&epoch->epoch_size);
37194 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37195
37196 switch (ev & ~EV_CLEANUP) {
37197 case EV_PUT:
37198 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37199 rv = FE_DESTROYED;
37200 } else {
37201 epoch->flags = 0;
37202 - atomic_set(&epoch->epoch_size, 0);
37203 + atomic_set_unchecked(&epoch->epoch_size, 0);
37204 /* atomic_set(&epoch->active, 0); is already zero */
37205 if (rv == FE_STILL_LIVE)
37206 rv = FE_RECYCLED;
37207 @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37208 conn_wait_active_ee_empty(tconn);
37209 drbd_flush(tconn);
37210
37211 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37212 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37213 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37214 if (epoch)
37215 break;
37216 @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37217 }
37218
37219 epoch->flags = 0;
37220 - atomic_set(&epoch->epoch_size, 0);
37221 + atomic_set_unchecked(&epoch->epoch_size, 0);
37222 atomic_set(&epoch->active, 0);
37223
37224 spin_lock(&tconn->epoch_lock);
37225 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37226 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37227 list_add(&epoch->list, &tconn->current_epoch->list);
37228 tconn->current_epoch = epoch;
37229 tconn->epochs++;
37230 @@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37231
37232 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37233 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37234 - atomic_inc(&tconn->current_epoch->epoch_size);
37235 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37236 err2 = drbd_drain_block(mdev, pi->size);
37237 if (!err)
37238 err = err2;
37239 @@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37240
37241 spin_lock(&tconn->epoch_lock);
37242 peer_req->epoch = tconn->current_epoch;
37243 - atomic_inc(&peer_req->epoch->epoch_size);
37244 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37245 atomic_inc(&peer_req->epoch->active);
37246 spin_unlock(&tconn->epoch_lock);
37247
37248 @@ -4344,7 +4344,7 @@ struct data_cmd {
37249 int expect_payload;
37250 size_t pkt_size;
37251 int (*fn)(struct drbd_tconn *, struct packet_info *);
37252 -};
37253 +} __do_const;
37254
37255 static struct data_cmd drbd_cmd_handler[] = {
37256 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37257 @@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37258 if (!list_empty(&tconn->current_epoch->list))
37259 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37260 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37261 - atomic_set(&tconn->current_epoch->epoch_size, 0);
37262 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37263 tconn->send.seen_any_write_yet = false;
37264
37265 conn_info(tconn, "Connection closed\n");
37266 @@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37267 struct asender_cmd {
37268 size_t pkt_size;
37269 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37270 -};
37271 +} __do_const;
37272
37273 static struct asender_cmd asender_tbl[] = {
37274 [P_PING] = { 0, got_Ping },
37275 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37276 index c8dac73..1800093 100644
37277 --- a/drivers/block/loop.c
37278 +++ b/drivers/block/loop.c
37279 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37280
37281 file_start_write(file);
37282 set_fs(get_ds());
37283 - bw = file->f_op->write(file, buf, len, &pos);
37284 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37285 set_fs(old_fs);
37286 file_end_write(file);
37287 if (likely(bw == len))
37288 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37289 index 83a598e..2de5ce3 100644
37290 --- a/drivers/block/null_blk.c
37291 +++ b/drivers/block/null_blk.c
37292 @@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37293 return 0;
37294 }
37295
37296 -static struct blk_mq_ops null_mq_ops = {
37297 - .queue_rq = null_queue_rq,
37298 - .map_queue = blk_mq_map_queue,
37299 +static struct blk_mq_ops null_mq_single_ops = {
37300 + .queue_rq = null_queue_rq,
37301 + .map_queue = blk_mq_map_queue,
37302 .init_hctx = null_init_hctx,
37303 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
37304 + .free_hctx = blk_mq_free_single_hw_queue,
37305 +};
37306 +
37307 +static struct blk_mq_ops null_mq_per_node_ops = {
37308 + .queue_rq = null_queue_rq,
37309 + .map_queue = blk_mq_map_queue,
37310 + .init_hctx = null_init_hctx,
37311 + .alloc_hctx = null_alloc_hctx,
37312 + .free_hctx = null_free_hctx,
37313 };
37314
37315 static struct blk_mq_reg null_mq_reg = {
37316 - .ops = &null_mq_ops,
37317 + .ops = &null_mq_single_ops,
37318 .queue_depth = 64,
37319 .cmd_size = sizeof(struct nullb_cmd),
37320 .flags = BLK_MQ_F_SHOULD_MERGE,
37321 @@ -545,13 +555,8 @@ static int null_add_dev(void)
37322 null_mq_reg.queue_depth = hw_queue_depth;
37323 null_mq_reg.nr_hw_queues = submit_queues;
37324
37325 - if (use_per_node_hctx) {
37326 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37327 - null_mq_reg.ops->free_hctx = null_free_hctx;
37328 - } else {
37329 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37330 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37331 - }
37332 + if (use_per_node_hctx)
37333 + null_mq_reg.ops = &null_mq_per_node_ops;
37334
37335 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37336 } else if (queue_mode == NULL_Q_BIO) {
37337 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37338 index ff8668c..f62167a 100644
37339 --- a/drivers/block/pktcdvd.c
37340 +++ b/drivers/block/pktcdvd.c
37341 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37342
37343 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37344 {
37345 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37346 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37347 }
37348
37349 /*
37350 @@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37351 return -EROFS;
37352 }
37353 pd->settings.fp = ti.fp;
37354 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37355 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37356
37357 if (ti.nwa_v) {
37358 pd->nwa = be32_to_cpu(ti.next_writable);
37359 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37360 index e5565fb..71be10b4 100644
37361 --- a/drivers/block/smart1,2.h
37362 +++ b/drivers/block/smart1,2.h
37363 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37364 }
37365
37366 static struct access_method smart4_access = {
37367 - smart4_submit_command,
37368 - smart4_intr_mask,
37369 - smart4_fifo_full,
37370 - smart4_intr_pending,
37371 - smart4_completed,
37372 + .submit_command = smart4_submit_command,
37373 + .set_intr_mask = smart4_intr_mask,
37374 + .fifo_full = smart4_fifo_full,
37375 + .intr_pending = smart4_intr_pending,
37376 + .command_completed = smart4_completed,
37377 };
37378
37379 /*
37380 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37381 }
37382
37383 static struct access_method smart2_access = {
37384 - smart2_submit_command,
37385 - smart2_intr_mask,
37386 - smart2_fifo_full,
37387 - smart2_intr_pending,
37388 - smart2_completed,
37389 + .submit_command = smart2_submit_command,
37390 + .set_intr_mask = smart2_intr_mask,
37391 + .fifo_full = smart2_fifo_full,
37392 + .intr_pending = smart2_intr_pending,
37393 + .command_completed = smart2_completed,
37394 };
37395
37396 /*
37397 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37398 }
37399
37400 static struct access_method smart2e_access = {
37401 - smart2e_submit_command,
37402 - smart2e_intr_mask,
37403 - smart2e_fifo_full,
37404 - smart2e_intr_pending,
37405 - smart2e_completed,
37406 + .submit_command = smart2e_submit_command,
37407 + .set_intr_mask = smart2e_intr_mask,
37408 + .fifo_full = smart2e_fifo_full,
37409 + .intr_pending = smart2e_intr_pending,
37410 + .command_completed = smart2e_completed,
37411 };
37412
37413 /*
37414 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
37415 }
37416
37417 static struct access_method smart1_access = {
37418 - smart1_submit_command,
37419 - smart1_intr_mask,
37420 - smart1_fifo_full,
37421 - smart1_intr_pending,
37422 - smart1_completed,
37423 + .submit_command = smart1_submit_command,
37424 + .set_intr_mask = smart1_intr_mask,
37425 + .fifo_full = smart1_fifo_full,
37426 + .intr_pending = smart1_intr_pending,
37427 + .command_completed = smart1_completed,
37428 };
37429 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
37430 index f038dba..bb74c08 100644
37431 --- a/drivers/bluetooth/btwilink.c
37432 +++ b/drivers/bluetooth/btwilink.c
37433 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
37434
37435 static int bt_ti_probe(struct platform_device *pdev)
37436 {
37437 - static struct ti_st *hst;
37438 + struct ti_st *hst;
37439 struct hci_dev *hdev;
37440 int err;
37441
37442 diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
37443 index b6739cb..962fd35 100644
37444 --- a/drivers/bus/arm-cci.c
37445 +++ b/drivers/bus/arm-cci.c
37446 @@ -979,7 +979,7 @@ static int cci_probe(void)
37447
37448 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
37449
37450 - ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
37451 + ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
37452 if (!ports)
37453 return -ENOMEM;
37454
37455 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
37456 index 8a3aff7..d7538c2 100644
37457 --- a/drivers/cdrom/cdrom.c
37458 +++ b/drivers/cdrom/cdrom.c
37459 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
37460 ENSURE(reset, CDC_RESET);
37461 ENSURE(generic_packet, CDC_GENERIC_PACKET);
37462 cdi->mc_flags = 0;
37463 - cdo->n_minors = 0;
37464 cdi->options = CDO_USE_FFLAGS;
37465
37466 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
37467 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
37468 else
37469 cdi->cdda_method = CDDA_OLD;
37470
37471 - if (!cdo->generic_packet)
37472 - cdo->generic_packet = cdrom_dummy_generic_packet;
37473 + if (!cdo->generic_packet) {
37474 + pax_open_kernel();
37475 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
37476 + pax_close_kernel();
37477 + }
37478
37479 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
37480 mutex_lock(&cdrom_mutex);
37481 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
37482 if (cdi->exit)
37483 cdi->exit(cdi);
37484
37485 - cdi->ops->n_minors--;
37486 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
37487 }
37488
37489 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
37490 */
37491 nr = nframes;
37492 do {
37493 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37494 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37495 if (cgc.buffer)
37496 break;
37497
37498 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
37499 struct cdrom_device_info *cdi;
37500 int ret;
37501
37502 - ret = scnprintf(info + *pos, max_size - *pos, header);
37503 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
37504 if (!ret)
37505 return 1;
37506
37507 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
37508 index 5980cb9..6d7bd7e 100644
37509 --- a/drivers/cdrom/gdrom.c
37510 +++ b/drivers/cdrom/gdrom.c
37511 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
37512 .audio_ioctl = gdrom_audio_ioctl,
37513 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
37514 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
37515 - .n_minors = 1,
37516 };
37517
37518 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
37519 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
37520 index fa3243d..8c98297 100644
37521 --- a/drivers/char/Kconfig
37522 +++ b/drivers/char/Kconfig
37523 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
37524
37525 config DEVKMEM
37526 bool "/dev/kmem virtual device support"
37527 - default y
37528 + default n
37529 + depends on !GRKERNSEC_KMEM
37530 help
37531 Say Y here if you want to support the /dev/kmem device. The
37532 /dev/kmem device is rarely used, but can be used for certain
37533 @@ -576,6 +577,7 @@ config DEVPORT
37534 bool
37535 depends on !M68K
37536 depends on ISA || PCI
37537 + depends on !GRKERNSEC_KMEM
37538 default y
37539
37540 source "drivers/s390/char/Kconfig"
37541 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
37542 index a48e05b..6bac831 100644
37543 --- a/drivers/char/agp/compat_ioctl.c
37544 +++ b/drivers/char/agp/compat_ioctl.c
37545 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
37546 return -ENOMEM;
37547 }
37548
37549 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
37550 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
37551 sizeof(*usegment) * ureserve.seg_count)) {
37552 kfree(usegment);
37553 kfree(ksegment);
37554 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
37555 index 1b19239..b87b143 100644
37556 --- a/drivers/char/agp/frontend.c
37557 +++ b/drivers/char/agp/frontend.c
37558 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37559 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
37560 return -EFAULT;
37561
37562 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
37563 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
37564 return -EFAULT;
37565
37566 client = agp_find_client_by_pid(reserve.pid);
37567 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37568 if (segment == NULL)
37569 return -ENOMEM;
37570
37571 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
37572 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
37573 sizeof(struct agp_segment) * reserve.seg_count)) {
37574 kfree(segment);
37575 return -EFAULT;
37576 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
37577 index 4f94375..413694e 100644
37578 --- a/drivers/char/genrtc.c
37579 +++ b/drivers/char/genrtc.c
37580 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
37581 switch (cmd) {
37582
37583 case RTC_PLL_GET:
37584 + memset(&pll, 0, sizeof(pll));
37585 if (get_rtc_pll(&pll))
37586 return -EINVAL;
37587 else
37588 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
37589 index 5d9c31d..c94ccb5 100644
37590 --- a/drivers/char/hpet.c
37591 +++ b/drivers/char/hpet.c
37592 @@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
37593 }
37594
37595 static int
37596 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
37597 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
37598 struct hpet_info *info)
37599 {
37600 struct hpet_timer __iomem *timer;
37601 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
37602 index 86fe45c..c0ea948 100644
37603 --- a/drivers/char/hw_random/intel-rng.c
37604 +++ b/drivers/char/hw_random/intel-rng.c
37605 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
37606
37607 if (no_fwh_detect)
37608 return -ENODEV;
37609 - printk(warning);
37610 + printk("%s", warning);
37611 return -EBUSY;
37612 }
37613
37614 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
37615 index ec4e10f..f2a763b 100644
37616 --- a/drivers/char/ipmi/ipmi_msghandler.c
37617 +++ b/drivers/char/ipmi/ipmi_msghandler.c
37618 @@ -420,7 +420,7 @@ struct ipmi_smi {
37619 struct proc_dir_entry *proc_dir;
37620 char proc_dir_name[10];
37621
37622 - atomic_t stats[IPMI_NUM_STATS];
37623 + atomic_unchecked_t stats[IPMI_NUM_STATS];
37624
37625 /*
37626 * run_to_completion duplicate of smb_info, smi_info
37627 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
37628
37629
37630 #define ipmi_inc_stat(intf, stat) \
37631 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
37632 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
37633 #define ipmi_get_stat(intf, stat) \
37634 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
37635 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
37636
37637 static int is_lan_addr(struct ipmi_addr *addr)
37638 {
37639 @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
37640 INIT_LIST_HEAD(&intf->cmd_rcvrs);
37641 init_waitqueue_head(&intf->waitq);
37642 for (i = 0; i < IPMI_NUM_STATS; i++)
37643 - atomic_set(&intf->stats[i], 0);
37644 + atomic_set_unchecked(&intf->stats[i], 0);
37645
37646 intf->proc_dir = NULL;
37647
37648 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
37649 index 15e4a60..b046093 100644
37650 --- a/drivers/char/ipmi/ipmi_si_intf.c
37651 +++ b/drivers/char/ipmi/ipmi_si_intf.c
37652 @@ -280,7 +280,7 @@ struct smi_info {
37653 unsigned char slave_addr;
37654
37655 /* Counters and things for the proc filesystem. */
37656 - atomic_t stats[SI_NUM_STATS];
37657 + atomic_unchecked_t stats[SI_NUM_STATS];
37658
37659 struct task_struct *thread;
37660
37661 @@ -289,9 +289,9 @@ struct smi_info {
37662 };
37663
37664 #define smi_inc_stat(smi, stat) \
37665 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
37666 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
37667 #define smi_get_stat(smi, stat) \
37668 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
37669 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
37670
37671 #define SI_MAX_PARMS 4
37672
37673 @@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
37674 atomic_set(&new_smi->req_events, 0);
37675 new_smi->run_to_completion = 0;
37676 for (i = 0; i < SI_NUM_STATS; i++)
37677 - atomic_set(&new_smi->stats[i], 0);
37678 + atomic_set_unchecked(&new_smi->stats[i], 0);
37679
37680 new_smi->interrupt_disabled = 1;
37681 atomic_set(&new_smi->stop_operation, 0);
37682 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
37683 index f895a8c..2bc9147 100644
37684 --- a/drivers/char/mem.c
37685 +++ b/drivers/char/mem.c
37686 @@ -18,6 +18,7 @@
37687 #include <linux/raw.h>
37688 #include <linux/tty.h>
37689 #include <linux/capability.h>
37690 +#include <linux/security.h>
37691 #include <linux/ptrace.h>
37692 #include <linux/device.h>
37693 #include <linux/highmem.h>
37694 @@ -37,6 +38,10 @@
37695
37696 #define DEVPORT_MINOR 4
37697
37698 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37699 +extern const struct file_operations grsec_fops;
37700 +#endif
37701 +
37702 static inline unsigned long size_inside_page(unsigned long start,
37703 unsigned long size)
37704 {
37705 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37706
37707 while (cursor < to) {
37708 if (!devmem_is_allowed(pfn)) {
37709 +#ifdef CONFIG_GRKERNSEC_KMEM
37710 + gr_handle_mem_readwrite(from, to);
37711 +#else
37712 printk(KERN_INFO
37713 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
37714 current->comm, from, to);
37715 +#endif
37716 return 0;
37717 }
37718 cursor += PAGE_SIZE;
37719 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37720 }
37721 return 1;
37722 }
37723 +#elif defined(CONFIG_GRKERNSEC_KMEM)
37724 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37725 +{
37726 + return 0;
37727 +}
37728 #else
37729 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37730 {
37731 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37732
37733 while (count > 0) {
37734 unsigned long remaining;
37735 + char *temp;
37736
37737 sz = size_inside_page(p, count);
37738
37739 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37740 if (!ptr)
37741 return -EFAULT;
37742
37743 - remaining = copy_to_user(buf, ptr, sz);
37744 +#ifdef CONFIG_PAX_USERCOPY
37745 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37746 + if (!temp) {
37747 + unxlate_dev_mem_ptr(p, ptr);
37748 + return -ENOMEM;
37749 + }
37750 + memcpy(temp, ptr, sz);
37751 +#else
37752 + temp = ptr;
37753 +#endif
37754 +
37755 + remaining = copy_to_user(buf, temp, sz);
37756 +
37757 +#ifdef CONFIG_PAX_USERCOPY
37758 + kfree(temp);
37759 +#endif
37760 +
37761 unxlate_dev_mem_ptr(p, ptr);
37762 if (remaining)
37763 return -EFAULT;
37764 @@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37765 size_t count, loff_t *ppos)
37766 {
37767 unsigned long p = *ppos;
37768 - ssize_t low_count, read, sz;
37769 + ssize_t low_count, read, sz, err = 0;
37770 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
37771 - int err = 0;
37772
37773 read = 0;
37774 if (p < (unsigned long) high_memory) {
37775 @@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37776 }
37777 #endif
37778 while (low_count > 0) {
37779 + char *temp;
37780 +
37781 sz = size_inside_page(p, low_count);
37782
37783 /*
37784 @@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37785 */
37786 kbuf = xlate_dev_kmem_ptr((char *)p);
37787
37788 - if (copy_to_user(buf, kbuf, sz))
37789 +#ifdef CONFIG_PAX_USERCOPY
37790 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37791 + if (!temp)
37792 + return -ENOMEM;
37793 + memcpy(temp, kbuf, sz);
37794 +#else
37795 + temp = kbuf;
37796 +#endif
37797 +
37798 + err = copy_to_user(buf, temp, sz);
37799 +
37800 +#ifdef CONFIG_PAX_USERCOPY
37801 + kfree(temp);
37802 +#endif
37803 +
37804 + if (err)
37805 return -EFAULT;
37806 buf += sz;
37807 p += sz;
37808 @@ -822,6 +869,9 @@ static const struct memdev {
37809 #ifdef CONFIG_PRINTK
37810 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
37811 #endif
37812 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37813 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
37814 +#endif
37815 };
37816
37817 static int memory_open(struct inode *inode, struct file *filp)
37818 @@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
37819 continue;
37820
37821 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
37822 - NULL, devlist[minor].name);
37823 + NULL, "%s", devlist[minor].name);
37824 }
37825
37826 return tty_init();
37827 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
37828 index 9df78e2..01ba9ae 100644
37829 --- a/drivers/char/nvram.c
37830 +++ b/drivers/char/nvram.c
37831 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
37832
37833 spin_unlock_irq(&rtc_lock);
37834
37835 - if (copy_to_user(buf, contents, tmp - contents))
37836 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
37837 return -EFAULT;
37838
37839 *ppos = i;
37840 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
37841 index d39cca6..8c1e269 100644
37842 --- a/drivers/char/pcmcia/synclink_cs.c
37843 +++ b/drivers/char/pcmcia/synclink_cs.c
37844 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37845
37846 if (debug_level >= DEBUG_LEVEL_INFO)
37847 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
37848 - __FILE__, __LINE__, info->device_name, port->count);
37849 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
37850
37851 - WARN_ON(!port->count);
37852 + WARN_ON(!atomic_read(&port->count));
37853
37854 if (tty_port_close_start(port, tty, filp) == 0)
37855 goto cleanup;
37856 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37857 cleanup:
37858 if (debug_level >= DEBUG_LEVEL_INFO)
37859 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
37860 - tty->driver->name, port->count);
37861 + tty->driver->name, atomic_read(&port->count));
37862 }
37863
37864 /* Wait until the transmitter is empty.
37865 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37866
37867 if (debug_level >= DEBUG_LEVEL_INFO)
37868 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
37869 - __FILE__, __LINE__, tty->driver->name, port->count);
37870 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
37871
37872 /* If port is closing, signal caller to try again */
37873 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
37874 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37875 goto cleanup;
37876 }
37877 spin_lock(&port->lock);
37878 - port->count++;
37879 + atomic_inc(&port->count);
37880 spin_unlock(&port->lock);
37881 spin_unlock_irqrestore(&info->netlock, flags);
37882
37883 - if (port->count == 1) {
37884 + if (atomic_read(&port->count) == 1) {
37885 /* 1st open on this device, init hardware */
37886 retval = startup(info, tty);
37887 if (retval < 0)
37888 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
37889 unsigned short new_crctype;
37890
37891 /* return error if TTY interface open */
37892 - if (info->port.count)
37893 + if (atomic_read(&info->port.count))
37894 return -EBUSY;
37895
37896 switch (encoding)
37897 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
37898
37899 /* arbitrate between network and tty opens */
37900 spin_lock_irqsave(&info->netlock, flags);
37901 - if (info->port.count != 0 || info->netcount != 0) {
37902 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
37903 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
37904 spin_unlock_irqrestore(&info->netlock, flags);
37905 return -EBUSY;
37906 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37907 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
37908
37909 /* return error if TTY interface open */
37910 - if (info->port.count)
37911 + if (atomic_read(&info->port.count))
37912 return -EBUSY;
37913
37914 if (cmd != SIOCWANDEV)
37915 diff --git a/drivers/char/random.c b/drivers/char/random.c
37916 index 429b75b..03d60db 100644
37917 --- a/drivers/char/random.c
37918 +++ b/drivers/char/random.c
37919 @@ -270,10 +270,17 @@
37920 /*
37921 * Configuration information
37922 */
37923 +#ifdef CONFIG_GRKERNSEC_RANDNET
37924 +#define INPUT_POOL_SHIFT 14
37925 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
37926 +#define OUTPUT_POOL_SHIFT 12
37927 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
37928 +#else
37929 #define INPUT_POOL_SHIFT 12
37930 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
37931 #define OUTPUT_POOL_SHIFT 10
37932 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
37933 +#endif
37934 #define SEC_XFER_SIZE 512
37935 #define EXTRACT_SIZE 10
37936
37937 @@ -361,12 +368,19 @@ static struct poolinfo {
37938 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
37939 int tap1, tap2, tap3, tap4, tap5;
37940 } poolinfo_table[] = {
37941 +#ifdef CONFIG_GRKERNSEC_RANDNET
37942 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
37943 + { S(512), 411, 308, 208, 104, 1 },
37944 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
37945 + { S(128), 104, 76, 51, 25, 1 },
37946 +#else
37947 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
37948 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
37949 { S(128), 104, 76, 51, 25, 1 },
37950 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
37951 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
37952 { S(32), 26, 19, 14, 7, 1 },
37953 +#endif
37954 #if 0
37955 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
37956 { S(2048), 1638, 1231, 819, 411, 1 },
37957 @@ -524,8 +538,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
37958 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
37959 }
37960
37961 - ACCESS_ONCE(r->input_rotate) = input_rotate;
37962 - ACCESS_ONCE(r->add_ptr) = i;
37963 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
37964 + ACCESS_ONCE_RW(r->add_ptr) = i;
37965 smp_wmb();
37966
37967 if (out)
37968 @@ -1151,7 +1165,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
37969
37970 extract_buf(r, tmp);
37971 i = min_t(int, nbytes, EXTRACT_SIZE);
37972 - if (copy_to_user(buf, tmp, i)) {
37973 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
37974 ret = -EFAULT;
37975 break;
37976 }
37977 @@ -1507,7 +1521,7 @@ EXPORT_SYMBOL(generate_random_uuid);
37978 #include <linux/sysctl.h>
37979
37980 static int min_read_thresh = 8, min_write_thresh;
37981 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
37982 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
37983 static int max_write_thresh = INPUT_POOL_WORDS * 32;
37984 static char sysctl_bootid[16];
37985
37986 @@ -1523,7 +1537,7 @@ static char sysctl_bootid[16];
37987 static int proc_do_uuid(struct ctl_table *table, int write,
37988 void __user *buffer, size_t *lenp, loff_t *ppos)
37989 {
37990 - struct ctl_table fake_table;
37991 + ctl_table_no_const fake_table;
37992 unsigned char buf[64], tmp_uuid[16], *uuid;
37993
37994 uuid = table->data;
37995 @@ -1553,7 +1567,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
37996 static int proc_do_entropy(ctl_table *table, int write,
37997 void __user *buffer, size_t *lenp, loff_t *ppos)
37998 {
37999 - ctl_table fake_table;
38000 + ctl_table_no_const fake_table;
38001 int entropy_count;
38002
38003 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38004 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38005 index 7cc1fe22..b602d6b 100644
38006 --- a/drivers/char/sonypi.c
38007 +++ b/drivers/char/sonypi.c
38008 @@ -54,6 +54,7 @@
38009
38010 #include <asm/uaccess.h>
38011 #include <asm/io.h>
38012 +#include <asm/local.h>
38013
38014 #include <linux/sonypi.h>
38015
38016 @@ -490,7 +491,7 @@ static struct sonypi_device {
38017 spinlock_t fifo_lock;
38018 wait_queue_head_t fifo_proc_list;
38019 struct fasync_struct *fifo_async;
38020 - int open_count;
38021 + local_t open_count;
38022 int model;
38023 struct input_dev *input_jog_dev;
38024 struct input_dev *input_key_dev;
38025 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38026 static int sonypi_misc_release(struct inode *inode, struct file *file)
38027 {
38028 mutex_lock(&sonypi_device.lock);
38029 - sonypi_device.open_count--;
38030 + local_dec(&sonypi_device.open_count);
38031 mutex_unlock(&sonypi_device.lock);
38032 return 0;
38033 }
38034 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38035 {
38036 mutex_lock(&sonypi_device.lock);
38037 /* Flush input queue on first open */
38038 - if (!sonypi_device.open_count)
38039 + if (!local_read(&sonypi_device.open_count))
38040 kfifo_reset(&sonypi_device.fifo);
38041 - sonypi_device.open_count++;
38042 + local_inc(&sonypi_device.open_count);
38043 mutex_unlock(&sonypi_device.lock);
38044
38045 return 0;
38046 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38047 index 64420b3..5c40b56 100644
38048 --- a/drivers/char/tpm/tpm_acpi.c
38049 +++ b/drivers/char/tpm/tpm_acpi.c
38050 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38051 virt = acpi_os_map_memory(start, len);
38052 if (!virt) {
38053 kfree(log->bios_event_log);
38054 + log->bios_event_log = NULL;
38055 printk("%s: ERROR - Unable to map memory\n", __func__);
38056 return -EIO;
38057 }
38058
38059 - memcpy_fromio(log->bios_event_log, virt, len);
38060 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38061
38062 acpi_os_unmap_memory(virt, len);
38063 return 0;
38064 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38065 index 59f7cb2..bac8b6d 100644
38066 --- a/drivers/char/tpm/tpm_eventlog.c
38067 +++ b/drivers/char/tpm/tpm_eventlog.c
38068 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38069 event = addr;
38070
38071 if ((event->event_type == 0 && event->event_size == 0) ||
38072 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38073 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38074 return NULL;
38075
38076 return addr;
38077 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38078 return NULL;
38079
38080 if ((event->event_type == 0 && event->event_size == 0) ||
38081 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38082 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38083 return NULL;
38084
38085 (*pos)++;
38086 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38087 int i;
38088
38089 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38090 - seq_putc(m, data[i]);
38091 + if (!seq_putc(m, data[i]))
38092 + return -EFAULT;
38093
38094 return 0;
38095 }
38096 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38097 index feea87c..18aefff 100644
38098 --- a/drivers/char/virtio_console.c
38099 +++ b/drivers/char/virtio_console.c
38100 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38101 if (to_user) {
38102 ssize_t ret;
38103
38104 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38105 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38106 if (ret)
38107 return -EFAULT;
38108 } else {
38109 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38110 if (!port_has_data(port) && !port->host_connected)
38111 return 0;
38112
38113 - return fill_readbuf(port, ubuf, count, true);
38114 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38115 }
38116
38117 static int wait_port_writable(struct port *port, bool nonblock)
38118 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38119 index a33f46f..a720eed 100644
38120 --- a/drivers/clk/clk-composite.c
38121 +++ b/drivers/clk/clk-composite.c
38122 @@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38123 struct clk *clk;
38124 struct clk_init_data init;
38125 struct clk_composite *composite;
38126 - struct clk_ops *clk_composite_ops;
38127 + clk_ops_no_const *clk_composite_ops;
38128
38129 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38130 if (!composite) {
38131 diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38132 index 81dd31a..ef5c542 100644
38133 --- a/drivers/clk/socfpga/clk.c
38134 +++ b/drivers/clk/socfpga/clk.c
38135 @@ -22,6 +22,7 @@
38136 #include <linux/clk-provider.h>
38137 #include <linux/io.h>
38138 #include <linux/of.h>
38139 +#include <asm/pgtable.h>
38140
38141 /* Clock Manager offsets */
38142 #define CLKMGR_CTRL 0x0
38143 @@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38144 streq(clk_name, "periph_pll") ||
38145 streq(clk_name, "sdram_pll")) {
38146 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38147 - clk_pll_ops.enable = clk_gate_ops.enable;
38148 - clk_pll_ops.disable = clk_gate_ops.disable;
38149 + pax_open_kernel();
38150 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38151 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38152 + pax_close_kernel();
38153 }
38154
38155 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38156 @@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38157 return parent_rate / div;
38158 }
38159
38160 -static struct clk_ops gateclk_ops = {
38161 +static clk_ops_no_const gateclk_ops __read_only = {
38162 .recalc_rate = socfpga_clk_recalc_rate,
38163 .get_parent = socfpga_clk_get_parent,
38164 .set_parent = socfpga_clk_set_parent,
38165 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38166 index caf41eb..223d27a 100644
38167 --- a/drivers/cpufreq/acpi-cpufreq.c
38168 +++ b/drivers/cpufreq/acpi-cpufreq.c
38169 @@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38170 return sprintf(buf, "%u\n", boost_enabled);
38171 }
38172
38173 -static struct global_attr global_boost = __ATTR(boost, 0644,
38174 +static global_attr_no_const global_boost = __ATTR(boost, 0644,
38175 show_global_boost,
38176 store_global_boost);
38177
38178 @@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38179 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38180 per_cpu(acfreq_data, cpu) = data;
38181
38182 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38183 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38184 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38185 + pax_open_kernel();
38186 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38187 + pax_close_kernel();
38188 + }
38189
38190 result = acpi_processor_register_performance(data->acpi_data, cpu);
38191 if (result)
38192 @@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38193 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38194 break;
38195 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38196 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38197 + pax_open_kernel();
38198 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38199 + pax_close_kernel();
38200 break;
38201 default:
38202 break;
38203 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38204 index 8d19f7c..6bc2daa 100644
38205 --- a/drivers/cpufreq/cpufreq.c
38206 +++ b/drivers/cpufreq/cpufreq.c
38207 @@ -1885,7 +1885,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38208 #endif
38209
38210 mutex_lock(&cpufreq_governor_mutex);
38211 - list_del(&governor->governor_list);
38212 + pax_list_del(&governor->governor_list);
38213 mutex_unlock(&cpufreq_governor_mutex);
38214 return;
38215 }
38216 @@ -2115,7 +2115,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38217 return NOTIFY_OK;
38218 }
38219
38220 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
38221 +static struct notifier_block cpufreq_cpu_notifier = {
38222 .notifier_call = cpufreq_cpu_callback,
38223 };
38224
38225 @@ -2148,8 +2148,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38226
38227 pr_debug("trying to register driver %s\n", driver_data->name);
38228
38229 - if (driver_data->setpolicy)
38230 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
38231 + if (driver_data->setpolicy) {
38232 + pax_open_kernel();
38233 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38234 + pax_close_kernel();
38235 + }
38236
38237 write_lock_irqsave(&cpufreq_driver_lock, flags);
38238 if (cpufreq_driver) {
38239 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38240 index e6be635..f8a90dc 100644
38241 --- a/drivers/cpufreq/cpufreq_governor.c
38242 +++ b/drivers/cpufreq/cpufreq_governor.c
38243 @@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38244 struct dbs_data *dbs_data;
38245 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38246 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38247 - struct od_ops *od_ops = NULL;
38248 + const struct od_ops *od_ops = NULL;
38249 struct od_dbs_tuners *od_tuners = NULL;
38250 struct cs_dbs_tuners *cs_tuners = NULL;
38251 struct cpu_dbs_common_info *cpu_cdbs;
38252 @@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38253
38254 if ((cdata->governor == GOV_CONSERVATIVE) &&
38255 (!policy->governor->initialized)) {
38256 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38257 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38258
38259 cpufreq_register_notifier(cs_ops->notifier_block,
38260 CPUFREQ_TRANSITION_NOTIFIER);
38261 @@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38262
38263 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38264 (policy->governor->initialized == 1)) {
38265 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38266 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38267
38268 cpufreq_unregister_notifier(cs_ops->notifier_block,
38269 CPUFREQ_TRANSITION_NOTIFIER);
38270 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38271 index b5f2b86..daa801b 100644
38272 --- a/drivers/cpufreq/cpufreq_governor.h
38273 +++ b/drivers/cpufreq/cpufreq_governor.h
38274 @@ -205,7 +205,7 @@ struct common_dbs_data {
38275 void (*exit)(struct dbs_data *dbs_data);
38276
38277 /* Governor specific ops, see below */
38278 - void *gov_ops;
38279 + const void *gov_ops;
38280 };
38281
38282 /* Governor Per policy data */
38283 @@ -225,7 +225,7 @@ struct od_ops {
38284 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38285 unsigned int freq_next, unsigned int relation);
38286 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38287 -};
38288 +} __no_const;
38289
38290 struct cs_ops {
38291 struct notifier_block *notifier_block;
38292 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38293 index 18d4091..434be15 100644
38294 --- a/drivers/cpufreq/cpufreq_ondemand.c
38295 +++ b/drivers/cpufreq/cpufreq_ondemand.c
38296 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38297
38298 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38299
38300 -static struct od_ops od_ops = {
38301 +static struct od_ops od_ops __read_only = {
38302 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38303 .powersave_bias_target = generic_powersave_bias_target,
38304 .freq_increase = dbs_freq_increase,
38305 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38306 (struct cpufreq_policy *, unsigned int, unsigned int),
38307 unsigned int powersave_bias)
38308 {
38309 - od_ops.powersave_bias_target = f;
38310 + pax_open_kernel();
38311 + *(void **)&od_ops.powersave_bias_target = f;
38312 + pax_close_kernel();
38313 od_set_powersave_bias(powersave_bias);
38314 }
38315 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38316
38317 void od_unregister_powersave_bias_handler(void)
38318 {
38319 - od_ops.powersave_bias_target = generic_powersave_bias_target;
38320 + pax_open_kernel();
38321 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38322 + pax_close_kernel();
38323 od_set_powersave_bias(0);
38324 }
38325 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38326 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38327 index 4cf0d28..5830372 100644
38328 --- a/drivers/cpufreq/cpufreq_stats.c
38329 +++ b/drivers/cpufreq/cpufreq_stats.c
38330 @@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38331 }
38332
38333 /* priority=1 so this will get called before cpufreq_remove_dev */
38334 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38335 +static struct notifier_block cpufreq_stat_cpu_notifier = {
38336 .notifier_call = cpufreq_stat_cpu_callback,
38337 .priority = 1,
38338 };
38339 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38340 index d51f17ed..9f43b15 100644
38341 --- a/drivers/cpufreq/intel_pstate.c
38342 +++ b/drivers/cpufreq/intel_pstate.c
38343 @@ -112,10 +112,10 @@ struct pstate_funcs {
38344 struct cpu_defaults {
38345 struct pstate_adjust_policy pid_policy;
38346 struct pstate_funcs funcs;
38347 -};
38348 +} __do_const;
38349
38350 static struct pstate_adjust_policy pid_params;
38351 -static struct pstate_funcs pstate_funcs;
38352 +static struct pstate_funcs *pstate_funcs;
38353
38354 struct perf_limits {
38355 int no_turbo;
38356 @@ -462,7 +462,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38357
38358 cpu->pstate.current_pstate = pstate;
38359
38360 - pstate_funcs.set(pstate);
38361 + pstate_funcs->set(pstate);
38362 }
38363
38364 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
38365 @@ -484,9 +484,9 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
38366 {
38367 sprintf(cpu->name, "Intel 2nd generation core");
38368
38369 - cpu->pstate.min_pstate = pstate_funcs.get_min();
38370 - cpu->pstate.max_pstate = pstate_funcs.get_max();
38371 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
38372 + cpu->pstate.min_pstate = pstate_funcs->get_min();
38373 + cpu->pstate.max_pstate = pstate_funcs->get_max();
38374 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
38375
38376 /*
38377 * goto max pstate so we don't slow up boot if we are built-in if we are
38378 @@ -750,9 +750,9 @@ static int intel_pstate_msrs_not_valid(void)
38379 rdmsrl(MSR_IA32_APERF, aperf);
38380 rdmsrl(MSR_IA32_MPERF, mperf);
38381
38382 - if (!pstate_funcs.get_max() ||
38383 - !pstate_funcs.get_min() ||
38384 - !pstate_funcs.get_turbo())
38385 + if (!pstate_funcs->get_max() ||
38386 + !pstate_funcs->get_min() ||
38387 + !pstate_funcs->get_turbo())
38388 return -ENODEV;
38389
38390 rdmsrl(MSR_IA32_APERF, tmp);
38391 @@ -766,7 +766,7 @@ static int intel_pstate_msrs_not_valid(void)
38392 return 0;
38393 }
38394
38395 -static void copy_pid_params(struct pstate_adjust_policy *policy)
38396 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
38397 {
38398 pid_params.sample_rate_ms = policy->sample_rate_ms;
38399 pid_params.p_gain_pct = policy->p_gain_pct;
38400 @@ -778,10 +778,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
38401
38402 static void copy_cpu_funcs(struct pstate_funcs *funcs)
38403 {
38404 - pstate_funcs.get_max = funcs->get_max;
38405 - pstate_funcs.get_min = funcs->get_min;
38406 - pstate_funcs.get_turbo = funcs->get_turbo;
38407 - pstate_funcs.set = funcs->set;
38408 + pstate_funcs = funcs;
38409 }
38410
38411 #if IS_ENABLED(CONFIG_ACPI)
38412 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
38413 index 3d1cba9..0ab21d2 100644
38414 --- a/drivers/cpufreq/p4-clockmod.c
38415 +++ b/drivers/cpufreq/p4-clockmod.c
38416 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38417 case 0x0F: /* Core Duo */
38418 case 0x16: /* Celeron Core */
38419 case 0x1C: /* Atom */
38420 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38421 + pax_open_kernel();
38422 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38423 + pax_close_kernel();
38424 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
38425 case 0x0D: /* Pentium M (Dothan) */
38426 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38427 + pax_open_kernel();
38428 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38429 + pax_close_kernel();
38430 /* fall through */
38431 case 0x09: /* Pentium M (Banias) */
38432 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
38433 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38434
38435 /* on P-4s, the TSC runs with constant frequency independent whether
38436 * throttling is active or not. */
38437 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38438 + pax_open_kernel();
38439 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38440 + pax_close_kernel();
38441
38442 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
38443 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
38444 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
38445 index 724ffbd..ad83692 100644
38446 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
38447 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
38448 @@ -18,14 +18,12 @@
38449 #include <asm/head.h>
38450 #include <asm/timer.h>
38451
38452 -static struct cpufreq_driver *cpufreq_us3_driver;
38453 -
38454 struct us3_freq_percpu_info {
38455 struct cpufreq_frequency_table table[4];
38456 };
38457
38458 /* Indexed by cpu number. */
38459 -static struct us3_freq_percpu_info *us3_freq_table;
38460 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
38461
38462 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
38463 * in the Safari config register.
38464 @@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
38465
38466 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
38467 {
38468 - if (cpufreq_us3_driver) {
38469 - cpufreq_frequency_table_put_attr(policy->cpu);
38470 - us3_freq_target(policy, 0);
38471 - }
38472 + cpufreq_frequency_table_put_attr(policy->cpu);
38473 + us3_freq_target(policy, 0);
38474
38475 return 0;
38476 }
38477
38478 +static int __init us3_freq_init(void);
38479 +static void __exit us3_freq_exit(void);
38480 +
38481 +static struct cpufreq_driver cpufreq_us3_driver = {
38482 + .init = us3_freq_cpu_init,
38483 + .verify = cpufreq_generic_frequency_table_verify,
38484 + .target_index = us3_freq_target,
38485 + .get = us3_freq_get,
38486 + .exit = us3_freq_cpu_exit,
38487 + .owner = THIS_MODULE,
38488 + .name = "UltraSPARC-III",
38489 +
38490 +};
38491 +
38492 static int __init us3_freq_init(void)
38493 {
38494 unsigned long manuf, impl, ver;
38495 @@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
38496 (impl == CHEETAH_IMPL ||
38497 impl == CHEETAH_PLUS_IMPL ||
38498 impl == JAGUAR_IMPL ||
38499 - impl == PANTHER_IMPL)) {
38500 - struct cpufreq_driver *driver;
38501 -
38502 - ret = -ENOMEM;
38503 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
38504 - if (!driver)
38505 - goto err_out;
38506 -
38507 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
38508 - GFP_KERNEL);
38509 - if (!us3_freq_table)
38510 - goto err_out;
38511 -
38512 - driver->init = us3_freq_cpu_init;
38513 - driver->verify = cpufreq_generic_frequency_table_verify;
38514 - driver->target_index = us3_freq_target;
38515 - driver->get = us3_freq_get;
38516 - driver->exit = us3_freq_cpu_exit;
38517 - strcpy(driver->name, "UltraSPARC-III");
38518 -
38519 - cpufreq_us3_driver = driver;
38520 - ret = cpufreq_register_driver(driver);
38521 - if (ret)
38522 - goto err_out;
38523 -
38524 - return 0;
38525 -
38526 -err_out:
38527 - if (driver) {
38528 - kfree(driver);
38529 - cpufreq_us3_driver = NULL;
38530 - }
38531 - kfree(us3_freq_table);
38532 - us3_freq_table = NULL;
38533 - return ret;
38534 - }
38535 + impl == PANTHER_IMPL))
38536 + return cpufreq_register_driver(&cpufreq_us3_driver);
38537
38538 return -ENODEV;
38539 }
38540
38541 static void __exit us3_freq_exit(void)
38542 {
38543 - if (cpufreq_us3_driver) {
38544 - cpufreq_unregister_driver(cpufreq_us3_driver);
38545 - kfree(cpufreq_us3_driver);
38546 - cpufreq_us3_driver = NULL;
38547 - kfree(us3_freq_table);
38548 - us3_freq_table = NULL;
38549 - }
38550 + cpufreq_unregister_driver(&cpufreq_us3_driver);
38551 }
38552
38553 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
38554 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
38555 index 4e1daca..e707b61 100644
38556 --- a/drivers/cpufreq/speedstep-centrino.c
38557 +++ b/drivers/cpufreq/speedstep-centrino.c
38558 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
38559 !cpu_has(cpu, X86_FEATURE_EST))
38560 return -ENODEV;
38561
38562 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
38563 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38564 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
38565 + pax_open_kernel();
38566 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38567 + pax_close_kernel();
38568 + }
38569
38570 if (policy->cpu != 0)
38571 return -ENODEV;
38572 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
38573 index 06dbe7c..c2c8671 100644
38574 --- a/drivers/cpuidle/driver.c
38575 +++ b/drivers/cpuidle/driver.c
38576 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
38577
38578 static void poll_idle_init(struct cpuidle_driver *drv)
38579 {
38580 - struct cpuidle_state *state = &drv->states[0];
38581 + cpuidle_state_no_const *state = &drv->states[0];
38582
38583 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
38584 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
38585 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
38586 index ca89412..a7b9c49 100644
38587 --- a/drivers/cpuidle/governor.c
38588 +++ b/drivers/cpuidle/governor.c
38589 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
38590 mutex_lock(&cpuidle_lock);
38591 if (__cpuidle_find_governor(gov->name) == NULL) {
38592 ret = 0;
38593 - list_add_tail(&gov->governor_list, &cpuidle_governors);
38594 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
38595 if (!cpuidle_curr_governor ||
38596 cpuidle_curr_governor->rating < gov->rating)
38597 cpuidle_switch_governor(gov);
38598 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
38599 index e918b6d..f87ea80 100644
38600 --- a/drivers/cpuidle/sysfs.c
38601 +++ b/drivers/cpuidle/sysfs.c
38602 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
38603 NULL
38604 };
38605
38606 -static struct attribute_group cpuidle_attr_group = {
38607 +static attribute_group_no_const cpuidle_attr_group = {
38608 .attrs = cpuidle_default_attrs,
38609 .name = "cpuidle",
38610 };
38611 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
38612 index 12fea3e..1e28f47 100644
38613 --- a/drivers/crypto/hifn_795x.c
38614 +++ b/drivers/crypto/hifn_795x.c
38615 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
38616 MODULE_PARM_DESC(hifn_pll_ref,
38617 "PLL reference clock (pci[freq] or ext[freq], default ext)");
38618
38619 -static atomic_t hifn_dev_number;
38620 +static atomic_unchecked_t hifn_dev_number;
38621
38622 #define ACRYPTO_OP_DECRYPT 0
38623 #define ACRYPTO_OP_ENCRYPT 1
38624 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
38625 goto err_out_disable_pci_device;
38626
38627 snprintf(name, sizeof(name), "hifn%d",
38628 - atomic_inc_return(&hifn_dev_number)-1);
38629 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
38630
38631 err = pci_request_regions(pdev, name);
38632 if (err)
38633 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
38634 index a0b2f7e..1b6f028 100644
38635 --- a/drivers/devfreq/devfreq.c
38636 +++ b/drivers/devfreq/devfreq.c
38637 @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
38638 goto err_out;
38639 }
38640
38641 - list_add(&governor->node, &devfreq_governor_list);
38642 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
38643
38644 list_for_each_entry(devfreq, &devfreq_list, node) {
38645 int ret = 0;
38646 @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
38647 }
38648 }
38649
38650 - list_del(&governor->node);
38651 + pax_list_del((struct list_head *)&governor->node);
38652 err_out:
38653 mutex_unlock(&devfreq_list_lock);
38654
38655 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
38656 index 0d765c0..60b7480 100644
38657 --- a/drivers/dma/sh/shdmac.c
38658 +++ b/drivers/dma/sh/shdmac.c
38659 @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
38660 return ret;
38661 }
38662
38663 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
38664 +static struct notifier_block sh_dmae_nmi_notifier = {
38665 .notifier_call = sh_dmae_nmi_handler,
38666
38667 /* Run before NMI debug handler and KGDB */
38668 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
38669 index 1026743..80b081c 100644
38670 --- a/drivers/edac/edac_device.c
38671 +++ b/drivers/edac/edac_device.c
38672 @@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
38673 */
38674 int edac_device_alloc_index(void)
38675 {
38676 - static atomic_t device_indexes = ATOMIC_INIT(0);
38677 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
38678
38679 - return atomic_inc_return(&device_indexes) - 1;
38680 + return atomic_inc_return_unchecked(&device_indexes) - 1;
38681 }
38682 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
38683
38684 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
38685 index 9f7e0e60..348c875 100644
38686 --- a/drivers/edac/edac_mc_sysfs.c
38687 +++ b/drivers/edac/edac_mc_sysfs.c
38688 @@ -150,7 +150,7 @@ static const char * const edac_caps[] = {
38689 struct dev_ch_attribute {
38690 struct device_attribute attr;
38691 int channel;
38692 -};
38693 +} __do_const;
38694
38695 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
38696 struct dev_ch_attribute dev_attr_legacy_##_name = \
38697 @@ -1007,14 +1007,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
38698 }
38699
38700 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
38701 + pax_open_kernel();
38702 if (mci->get_sdram_scrub_rate) {
38703 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38704 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38705 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38706 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38707 }
38708 if (mci->set_sdram_scrub_rate) {
38709 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38710 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38711 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38712 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38713 }
38714 + pax_close_kernel();
38715 err = device_create_file(&mci->dev,
38716 &dev_attr_sdram_scrub_rate);
38717 if (err) {
38718 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
38719 index 2cf44b4d..6dd2dc7 100644
38720 --- a/drivers/edac/edac_pci.c
38721 +++ b/drivers/edac/edac_pci.c
38722 @@ -29,7 +29,7 @@
38723
38724 static DEFINE_MUTEX(edac_pci_ctls_mutex);
38725 static LIST_HEAD(edac_pci_list);
38726 -static atomic_t pci_indexes = ATOMIC_INIT(0);
38727 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
38728
38729 /*
38730 * edac_pci_alloc_ctl_info
38731 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
38732 */
38733 int edac_pci_alloc_index(void)
38734 {
38735 - return atomic_inc_return(&pci_indexes) - 1;
38736 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
38737 }
38738 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
38739
38740 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
38741 index e8658e4..22746d6 100644
38742 --- a/drivers/edac/edac_pci_sysfs.c
38743 +++ b/drivers/edac/edac_pci_sysfs.c
38744 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
38745 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
38746 static int edac_pci_poll_msec = 1000; /* one second workq period */
38747
38748 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
38749 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
38750 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
38751 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
38752
38753 static struct kobject *edac_pci_top_main_kobj;
38754 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
38755 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
38756 void *value;
38757 ssize_t(*show) (void *, char *);
38758 ssize_t(*store) (void *, const char *, size_t);
38759 -};
38760 +} __do_const;
38761
38762 /* Set of show/store abstract level functions for PCI Parity object */
38763 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
38764 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38765 edac_printk(KERN_CRIT, EDAC_PCI,
38766 "Signaled System Error on %s\n",
38767 pci_name(dev));
38768 - atomic_inc(&pci_nonparity_count);
38769 + atomic_inc_unchecked(&pci_nonparity_count);
38770 }
38771
38772 if (status & (PCI_STATUS_PARITY)) {
38773 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38774 "Master Data Parity Error on %s\n",
38775 pci_name(dev));
38776
38777 - atomic_inc(&pci_parity_count);
38778 + atomic_inc_unchecked(&pci_parity_count);
38779 }
38780
38781 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38782 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38783 "Detected Parity Error on %s\n",
38784 pci_name(dev));
38785
38786 - atomic_inc(&pci_parity_count);
38787 + atomic_inc_unchecked(&pci_parity_count);
38788 }
38789 }
38790
38791 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38792 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
38793 "Signaled System Error on %s\n",
38794 pci_name(dev));
38795 - atomic_inc(&pci_nonparity_count);
38796 + atomic_inc_unchecked(&pci_nonparity_count);
38797 }
38798
38799 if (status & (PCI_STATUS_PARITY)) {
38800 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38801 "Master Data Parity Error on "
38802 "%s\n", pci_name(dev));
38803
38804 - atomic_inc(&pci_parity_count);
38805 + atomic_inc_unchecked(&pci_parity_count);
38806 }
38807
38808 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38809 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38810 "Detected Parity Error on %s\n",
38811 pci_name(dev));
38812
38813 - atomic_inc(&pci_parity_count);
38814 + atomic_inc_unchecked(&pci_parity_count);
38815 }
38816 }
38817 }
38818 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
38819 if (!check_pci_errors)
38820 return;
38821
38822 - before_count = atomic_read(&pci_parity_count);
38823 + before_count = atomic_read_unchecked(&pci_parity_count);
38824
38825 /* scan all PCI devices looking for a Parity Error on devices and
38826 * bridges.
38827 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
38828 /* Only if operator has selected panic on PCI Error */
38829 if (edac_pci_get_panic_on_pe()) {
38830 /* If the count is different 'after' from 'before' */
38831 - if (before_count != atomic_read(&pci_parity_count))
38832 + if (before_count != atomic_read_unchecked(&pci_parity_count))
38833 panic("EDAC: PCI Parity Error");
38834 }
38835 }
38836 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
38837 index 51b7e3a..aa8a3e8 100644
38838 --- a/drivers/edac/mce_amd.h
38839 +++ b/drivers/edac/mce_amd.h
38840 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
38841 bool (*mc0_mce)(u16, u8);
38842 bool (*mc1_mce)(u16, u8);
38843 bool (*mc2_mce)(u16, u8);
38844 -};
38845 +} __no_const;
38846
38847 void amd_report_gart_errors(bool);
38848 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
38849 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
38850 index 57ea7f4..af06b76 100644
38851 --- a/drivers/firewire/core-card.c
38852 +++ b/drivers/firewire/core-card.c
38853 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
38854 const struct fw_card_driver *driver,
38855 struct device *device)
38856 {
38857 - static atomic_t index = ATOMIC_INIT(-1);
38858 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
38859
38860 - card->index = atomic_inc_return(&index);
38861 + card->index = atomic_inc_return_unchecked(&index);
38862 card->driver = driver;
38863 card->device = device;
38864 card->current_tlabel = 0;
38865 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
38866
38867 void fw_core_remove_card(struct fw_card *card)
38868 {
38869 - struct fw_card_driver dummy_driver = dummy_driver_template;
38870 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
38871
38872 card->driver->update_phy_reg(card, 4,
38873 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
38874 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
38875 index de4aa40..49ab1f2 100644
38876 --- a/drivers/firewire/core-device.c
38877 +++ b/drivers/firewire/core-device.c
38878 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
38879 struct config_rom_attribute {
38880 struct device_attribute attr;
38881 u32 key;
38882 -};
38883 +} __do_const;
38884
38885 static ssize_t show_immediate(struct device *dev,
38886 struct device_attribute *dattr, char *buf)
38887 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
38888 index 0e79951..b180217 100644
38889 --- a/drivers/firewire/core-transaction.c
38890 +++ b/drivers/firewire/core-transaction.c
38891 @@ -38,6 +38,7 @@
38892 #include <linux/timer.h>
38893 #include <linux/types.h>
38894 #include <linux/workqueue.h>
38895 +#include <linux/sched.h>
38896
38897 #include <asm/byteorder.h>
38898
38899 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
38900 index 515a42c..5ecf3ba 100644
38901 --- a/drivers/firewire/core.h
38902 +++ b/drivers/firewire/core.h
38903 @@ -111,6 +111,7 @@ struct fw_card_driver {
38904
38905 int (*stop_iso)(struct fw_iso_context *ctx);
38906 };
38907 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
38908
38909 void fw_card_initialize(struct fw_card *card,
38910 const struct fw_card_driver *driver, struct device *device);
38911 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
38912 index 94a58a0..f5eba42 100644
38913 --- a/drivers/firmware/dmi-id.c
38914 +++ b/drivers/firmware/dmi-id.c
38915 @@ -16,7 +16,7 @@
38916 struct dmi_device_attribute{
38917 struct device_attribute dev_attr;
38918 int field;
38919 -};
38920 +} __do_const;
38921 #define to_dmi_dev_attr(_dev_attr) \
38922 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
38923
38924 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
38925 index c7e81ff..94a7401 100644
38926 --- a/drivers/firmware/dmi_scan.c
38927 +++ b/drivers/firmware/dmi_scan.c
38928 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
38929 if (buf == NULL)
38930 return -1;
38931
38932 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
38933 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
38934
38935 iounmap(buf);
38936 return 0;
38937 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
38938 index 1491dd4..aa910db 100644
38939 --- a/drivers/firmware/efi/cper.c
38940 +++ b/drivers/firmware/efi/cper.c
38941 @@ -41,12 +41,12 @@
38942 */
38943 u64 cper_next_record_id(void)
38944 {
38945 - static atomic64_t seq;
38946 + static atomic64_unchecked_t seq;
38947
38948 - if (!atomic64_read(&seq))
38949 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
38950 + if (!atomic64_read_unchecked(&seq))
38951 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
38952
38953 - return atomic64_inc_return(&seq);
38954 + return atomic64_inc_return_unchecked(&seq);
38955 }
38956 EXPORT_SYMBOL_GPL(cper_next_record_id);
38957
38958 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
38959 index 2e2fbde..7676c8b 100644
38960 --- a/drivers/firmware/efi/efi.c
38961 +++ b/drivers/firmware/efi/efi.c
38962 @@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
38963 };
38964
38965 static struct efivars generic_efivars;
38966 -static struct efivar_operations generic_ops;
38967 +static efivar_operations_no_const generic_ops __read_only;
38968
38969 static int generic_ops_register(void)
38970 {
38971 - generic_ops.get_variable = efi.get_variable;
38972 - generic_ops.set_variable = efi.set_variable;
38973 - generic_ops.get_next_variable = efi.get_next_variable;
38974 - generic_ops.query_variable_store = efi_query_variable_store;
38975 + pax_open_kernel();
38976 + *(void **)&generic_ops.get_variable = efi.get_variable;
38977 + *(void **)&generic_ops.set_variable = efi.set_variable;
38978 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
38979 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
38980 + pax_close_kernel();
38981
38982 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
38983 }
38984 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
38985 index 3dc2482..7bd2f61 100644
38986 --- a/drivers/firmware/efi/efivars.c
38987 +++ b/drivers/firmware/efi/efivars.c
38988 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
38989 static int
38990 create_efivars_bin_attributes(void)
38991 {
38992 - struct bin_attribute *attr;
38993 + bin_attribute_no_const *attr;
38994 int error;
38995
38996 /* new_var */
38997 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
38998 index 2a90ba6..07f3733 100644
38999 --- a/drivers/firmware/google/memconsole.c
39000 +++ b/drivers/firmware/google/memconsole.c
39001 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39002 if (!found_memconsole())
39003 return -ENODEV;
39004
39005 - memconsole_bin_attr.size = memconsole_length;
39006 + pax_open_kernel();
39007 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39008 + pax_close_kernel();
39009
39010 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39011
39012 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39013 index 814addb..0937d7f 100644
39014 --- a/drivers/gpio/gpio-ich.c
39015 +++ b/drivers/gpio/gpio-ich.c
39016 @@ -71,7 +71,7 @@ struct ichx_desc {
39017 /* Some chipsets have quirks, let these use their own request/get */
39018 int (*request)(struct gpio_chip *chip, unsigned offset);
39019 int (*get)(struct gpio_chip *chip, unsigned offset);
39020 -};
39021 +} __do_const;
39022
39023 static struct {
39024 spinlock_t lock;
39025 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39026 index 9902732..64b62dd 100644
39027 --- a/drivers/gpio/gpio-vr41xx.c
39028 +++ b/drivers/gpio/gpio-vr41xx.c
39029 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39030 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39031 maskl, pendl, maskh, pendh);
39032
39033 - atomic_inc(&irq_err_count);
39034 + atomic_inc_unchecked(&irq_err_count);
39035
39036 return -EINVAL;
39037 }
39038 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39039 index d6cf77c..2842146 100644
39040 --- a/drivers/gpu/drm/drm_crtc.c
39041 +++ b/drivers/gpu/drm/drm_crtc.c
39042 @@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39043 goto done;
39044 }
39045
39046 - if (copy_to_user(&enum_ptr[copied].name,
39047 + if (copy_to_user(enum_ptr[copied].name,
39048 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39049 ret = -EFAULT;
39050 goto done;
39051 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39052 index 01361ab..891e821 100644
39053 --- a/drivers/gpu/drm/drm_crtc_helper.c
39054 +++ b/drivers/gpu/drm/drm_crtc_helper.c
39055 @@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39056 struct drm_crtc *tmp;
39057 int crtc_mask = 1;
39058
39059 - WARN(!crtc, "checking null crtc?\n");
39060 + BUG_ON(!crtc);
39061
39062 dev = crtc->dev;
39063
39064 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39065 index d9137e4..69b73a0 100644
39066 --- a/drivers/gpu/drm/drm_drv.c
39067 +++ b/drivers/gpu/drm/drm_drv.c
39068 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39069 /**
39070 * Copy and IOCTL return string to user space
39071 */
39072 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39073 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39074 {
39075 int len;
39076
39077 @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39078 struct drm_file *file_priv = filp->private_data;
39079 struct drm_device *dev;
39080 const struct drm_ioctl_desc *ioctl = NULL;
39081 - drm_ioctl_t *func;
39082 + drm_ioctl_no_const_t func;
39083 unsigned int nr = DRM_IOCTL_NR(cmd);
39084 int retcode = -EINVAL;
39085 char stack_kdata[128];
39086 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39087 index c5b929c..8a3b8be 100644
39088 --- a/drivers/gpu/drm/drm_fops.c
39089 +++ b/drivers/gpu/drm/drm_fops.c
39090 @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39091 if (drm_device_is_unplugged(dev))
39092 return -ENODEV;
39093
39094 - if (!dev->open_count++)
39095 + if (local_inc_return(&dev->open_count) == 1)
39096 need_setup = 1;
39097 mutex_lock(&dev->struct_mutex);
39098 old_imapping = inode->i_mapping;
39099 @@ -127,7 +127,7 @@ err_undo:
39100 iput(container_of(dev->dev_mapping, struct inode, i_data));
39101 dev->dev_mapping = old_mapping;
39102 mutex_unlock(&dev->struct_mutex);
39103 - dev->open_count--;
39104 + local_dec(&dev->open_count);
39105 return retcode;
39106 }
39107 EXPORT_SYMBOL(drm_open);
39108 @@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39109
39110 mutex_lock(&drm_global_mutex);
39111
39112 - DRM_DEBUG("open_count = %d\n", dev->open_count);
39113 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39114
39115 if (dev->driver->preclose)
39116 dev->driver->preclose(dev, file_priv);
39117 @@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39118 * Begin inline drm_release
39119 */
39120
39121 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39122 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39123 task_pid_nr(current),
39124 (long)old_encode_dev(file_priv->minor->device),
39125 - dev->open_count);
39126 + local_read(&dev->open_count));
39127
39128 /* Release any auth tokens that might point to this file_priv,
39129 (do that under the drm_global_mutex) */
39130 @@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39131 * End inline drm_release
39132 */
39133
39134 - if (!--dev->open_count) {
39135 + if (local_dec_and_test(&dev->open_count)) {
39136 if (atomic_read(&dev->ioctl_count)) {
39137 DRM_ERROR("Device busy: %d\n",
39138 atomic_read(&dev->ioctl_count));
39139 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39140 index 3d2e91c..d31c4c9 100644
39141 --- a/drivers/gpu/drm/drm_global.c
39142 +++ b/drivers/gpu/drm/drm_global.c
39143 @@ -36,7 +36,7 @@
39144 struct drm_global_item {
39145 struct mutex mutex;
39146 void *object;
39147 - int refcount;
39148 + atomic_t refcount;
39149 };
39150
39151 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39152 @@ -49,7 +49,7 @@ void drm_global_init(void)
39153 struct drm_global_item *item = &glob[i];
39154 mutex_init(&item->mutex);
39155 item->object = NULL;
39156 - item->refcount = 0;
39157 + atomic_set(&item->refcount, 0);
39158 }
39159 }
39160
39161 @@ -59,7 +59,7 @@ void drm_global_release(void)
39162 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39163 struct drm_global_item *item = &glob[i];
39164 BUG_ON(item->object != NULL);
39165 - BUG_ON(item->refcount != 0);
39166 + BUG_ON(atomic_read(&item->refcount) != 0);
39167 }
39168 }
39169
39170 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39171 struct drm_global_item *item = &glob[ref->global_type];
39172
39173 mutex_lock(&item->mutex);
39174 - if (item->refcount == 0) {
39175 + if (atomic_read(&item->refcount) == 0) {
39176 item->object = kzalloc(ref->size, GFP_KERNEL);
39177 if (unlikely(item->object == NULL)) {
39178 ret = -ENOMEM;
39179 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39180 goto out_err;
39181
39182 }
39183 - ++item->refcount;
39184 + atomic_inc(&item->refcount);
39185 ref->object = item->object;
39186 mutex_unlock(&item->mutex);
39187 return 0;
39188 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39189 struct drm_global_item *item = &glob[ref->global_type];
39190
39191 mutex_lock(&item->mutex);
39192 - BUG_ON(item->refcount == 0);
39193 + BUG_ON(atomic_read(&item->refcount) == 0);
39194 BUG_ON(ref->object != item->object);
39195 - if (--item->refcount == 0) {
39196 + if (atomic_dec_and_test(&item->refcount)) {
39197 ref->release(ref);
39198 item->object = NULL;
39199 }
39200 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39201 index 7d5a152..d7186da 100644
39202 --- a/drivers/gpu/drm/drm_info.c
39203 +++ b/drivers/gpu/drm/drm_info.c
39204 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39205 struct drm_local_map *map;
39206 struct drm_map_list *r_list;
39207
39208 - /* Hardcoded from _DRM_FRAME_BUFFER,
39209 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39210 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39211 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39212 + static const char * const types[] = {
39213 + [_DRM_FRAME_BUFFER] = "FB",
39214 + [_DRM_REGISTERS] = "REG",
39215 + [_DRM_SHM] = "SHM",
39216 + [_DRM_AGP] = "AGP",
39217 + [_DRM_SCATTER_GATHER] = "SG",
39218 + [_DRM_CONSISTENT] = "PCI",
39219 + [_DRM_GEM] = "GEM" };
39220 const char *type;
39221 int i;
39222
39223 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39224 map = r_list->map;
39225 if (!map)
39226 continue;
39227 - if (map->type < 0 || map->type > 5)
39228 + if (map->type >= ARRAY_SIZE(types))
39229 type = "??";
39230 else
39231 type = types[map->type];
39232 @@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39233 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39234 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39235 vma->vm_flags & VM_IO ? 'i' : '-',
39236 +#ifdef CONFIG_GRKERNSEC_HIDESYM
39237 + 0);
39238 +#else
39239 vma->vm_pgoff);
39240 +#endif
39241
39242 #if defined(__i386__)
39243 pgprot = pgprot_val(vma->vm_page_prot);
39244 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39245 index 2f4c434..dd12cd2 100644
39246 --- a/drivers/gpu/drm/drm_ioc32.c
39247 +++ b/drivers/gpu/drm/drm_ioc32.c
39248 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39249 request = compat_alloc_user_space(nbytes);
39250 if (!access_ok(VERIFY_WRITE, request, nbytes))
39251 return -EFAULT;
39252 - list = (struct drm_buf_desc *) (request + 1);
39253 + list = (struct drm_buf_desc __user *) (request + 1);
39254
39255 if (__put_user(count, &request->count)
39256 || __put_user(list, &request->list))
39257 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39258 request = compat_alloc_user_space(nbytes);
39259 if (!access_ok(VERIFY_WRITE, request, nbytes))
39260 return -EFAULT;
39261 - list = (struct drm_buf_pub *) (request + 1);
39262 + list = (struct drm_buf_pub __user *) (request + 1);
39263
39264 if (__put_user(count, &request->count)
39265 || __put_user(list, &request->list))
39266 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39267 return 0;
39268 }
39269
39270 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
39271 +drm_ioctl_compat_t drm_compat_ioctls[] = {
39272 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39273 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39274 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39275 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39276 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39277 {
39278 unsigned int nr = DRM_IOCTL_NR(cmd);
39279 - drm_ioctl_compat_t *fn;
39280 int ret;
39281
39282 /* Assume that ioctls without an explicit compat routine will just
39283 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39284 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39285 return drm_ioctl(filp, cmd, arg);
39286
39287 - fn = drm_compat_ioctls[nr];
39288 -
39289 - if (fn != NULL)
39290 - ret = (*fn) (filp, cmd, arg);
39291 + if (drm_compat_ioctls[nr] != NULL)
39292 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39293 else
39294 ret = drm_ioctl(filp, cmd, arg);
39295
39296 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39297 index 66dd3a0..3bed6c4 100644
39298 --- a/drivers/gpu/drm/drm_stub.c
39299 +++ b/drivers/gpu/drm/drm_stub.c
39300 @@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39301
39302 drm_device_set_unplugged(dev);
39303
39304 - if (dev->open_count == 0) {
39305 + if (local_read(&dev->open_count) == 0) {
39306 drm_put_dev(dev);
39307 }
39308 mutex_unlock(&drm_global_mutex);
39309 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39310 index c22c309..ae758c3 100644
39311 --- a/drivers/gpu/drm/drm_sysfs.c
39312 +++ b/drivers/gpu/drm/drm_sysfs.c
39313 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39314 */
39315 int drm_sysfs_device_add(struct drm_minor *minor)
39316 {
39317 - char *minor_str;
39318 + const char *minor_str;
39319 int r;
39320
39321 if (minor->type == DRM_MINOR_CONTROL)
39322 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39323 index d4d16ed..8fb0b51 100644
39324 --- a/drivers/gpu/drm/i810/i810_drv.h
39325 +++ b/drivers/gpu/drm/i810/i810_drv.h
39326 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
39327 int page_flipping;
39328
39329 wait_queue_head_t irq_queue;
39330 - atomic_t irq_received;
39331 - atomic_t irq_emitted;
39332 + atomic_unchecked_t irq_received;
39333 + atomic_unchecked_t irq_emitted;
39334
39335 int front_offset;
39336 } drm_i810_private_t;
39337 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
39338 index 6ed45a9..eb6dc41 100644
39339 --- a/drivers/gpu/drm/i915/i915_debugfs.c
39340 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
39341 @@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
39342 I915_READ(GTIMR));
39343 }
39344 seq_printf(m, "Interrupts received: %d\n",
39345 - atomic_read(&dev_priv->irq_received));
39346 + atomic_read_unchecked(&dev_priv->irq_received));
39347 for_each_ring(ring, dev_priv, i) {
39348 if (INTEL_INFO(dev)->gen >= 6) {
39349 seq_printf(m,
39350 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
39351 index 5c64842..f14bdf8 100644
39352 --- a/drivers/gpu/drm/i915/i915_dma.c
39353 +++ b/drivers/gpu/drm/i915/i915_dma.c
39354 @@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
39355 bool can_switch;
39356
39357 spin_lock(&dev->count_lock);
39358 - can_switch = (dev->open_count == 0);
39359 + can_switch = (local_read(&dev->open_count) == 0);
39360 spin_unlock(&dev->count_lock);
39361 return can_switch;
39362 }
39363 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
39364 index 90fcccb..b8aabc9 100644
39365 --- a/drivers/gpu/drm/i915/i915_drv.h
39366 +++ b/drivers/gpu/drm/i915/i915_drv.h
39367 @@ -1325,7 +1325,7 @@ typedef struct drm_i915_private {
39368 drm_dma_handle_t *status_page_dmah;
39369 struct resource mch_res;
39370
39371 - atomic_t irq_received;
39372 + atomic_unchecked_t irq_received;
39373
39374 /* protects the irq masks */
39375 spinlock_t irq_lock;
39376 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39377 index a3ba9a8..ee52ddd 100644
39378 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39379 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39380 @@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
39381
39382 static int
39383 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
39384 - int count)
39385 + unsigned int count)
39386 {
39387 - int i;
39388 + unsigned int i;
39389 unsigned relocs_total = 0;
39390 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
39391
39392 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
39393 index 3c59584..500f2e9 100644
39394 --- a/drivers/gpu/drm/i915/i915_ioc32.c
39395 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
39396 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
39397 (unsigned long)request);
39398 }
39399
39400 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39401 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
39402 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
39403 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
39404 [DRM_I915_GETPARAM] = compat_i915_getparam,
39405 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39406 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39407 {
39408 unsigned int nr = DRM_IOCTL_NR(cmd);
39409 - drm_ioctl_compat_t *fn = NULL;
39410 int ret;
39411
39412 if (nr < DRM_COMMAND_BASE)
39413 return drm_compat_ioctl(filp, cmd, arg);
39414
39415 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
39416 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39417 -
39418 - if (fn != NULL)
39419 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
39420 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39421 ret = (*fn) (filp, cmd, arg);
39422 - else
39423 + } else
39424 ret = drm_ioctl(filp, cmd, arg);
39425
39426 return ret;
39427 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
39428 index f13d5ed..8e6f36d 100644
39429 --- a/drivers/gpu/drm/i915/i915_irq.c
39430 +++ b/drivers/gpu/drm/i915/i915_irq.c
39431 @@ -1420,7 +1420,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
39432 int pipe;
39433 u32 pipe_stats[I915_MAX_PIPES];
39434
39435 - atomic_inc(&dev_priv->irq_received);
39436 + atomic_inc_unchecked(&dev_priv->irq_received);
39437
39438 while (true) {
39439 iir = I915_READ(VLV_IIR);
39440 @@ -1730,7 +1730,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
39441 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
39442 irqreturn_t ret = IRQ_NONE;
39443
39444 - atomic_inc(&dev_priv->irq_received);
39445 + atomic_inc_unchecked(&dev_priv->irq_received);
39446
39447 /* We get interrupts on unclaimed registers, so check for this before we
39448 * do any I915_{READ,WRITE}. */
39449 @@ -1800,7 +1800,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
39450 uint32_t tmp = 0;
39451 enum pipe pipe;
39452
39453 - atomic_inc(&dev_priv->irq_received);
39454 + atomic_inc_unchecked(&dev_priv->irq_received);
39455
39456 master_ctl = I915_READ(GEN8_MASTER_IRQ);
39457 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
39458 @@ -2624,7 +2624,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
39459 {
39460 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39461
39462 - atomic_set(&dev_priv->irq_received, 0);
39463 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39464
39465 I915_WRITE(HWSTAM, 0xeffe);
39466
39467 @@ -2642,7 +2642,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
39468 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39469 int pipe;
39470
39471 - atomic_set(&dev_priv->irq_received, 0);
39472 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39473
39474 /* VLV magic */
39475 I915_WRITE(VLV_IMR, 0);
39476 @@ -2673,7 +2673,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
39477 struct drm_i915_private *dev_priv = dev->dev_private;
39478 int pipe;
39479
39480 - atomic_set(&dev_priv->irq_received, 0);
39481 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39482
39483 I915_WRITE(GEN8_MASTER_IRQ, 0);
39484 POSTING_READ(GEN8_MASTER_IRQ);
39485 @@ -2999,7 +2999,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
39486 if (!dev_priv)
39487 return;
39488
39489 - atomic_set(&dev_priv->irq_received, 0);
39490 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39491
39492 I915_WRITE(GEN8_MASTER_IRQ, 0);
39493
39494 @@ -3093,7 +3093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
39495 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39496 int pipe;
39497
39498 - atomic_set(&dev_priv->irq_received, 0);
39499 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39500
39501 for_each_pipe(pipe)
39502 I915_WRITE(PIPESTAT(pipe), 0);
39503 @@ -3179,7 +3179,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
39504 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39505 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39506
39507 - atomic_inc(&dev_priv->irq_received);
39508 + atomic_inc_unchecked(&dev_priv->irq_received);
39509
39510 iir = I915_READ16(IIR);
39511 if (iir == 0)
39512 @@ -3254,7 +3254,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
39513 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39514 int pipe;
39515
39516 - atomic_set(&dev_priv->irq_received, 0);
39517 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39518
39519 if (I915_HAS_HOTPLUG(dev)) {
39520 I915_WRITE(PORT_HOTPLUG_EN, 0);
39521 @@ -3361,7 +3361,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
39522 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39523 int pipe, ret = IRQ_NONE;
39524
39525 - atomic_inc(&dev_priv->irq_received);
39526 + atomic_inc_unchecked(&dev_priv->irq_received);
39527
39528 iir = I915_READ(IIR);
39529 do {
39530 @@ -3488,7 +3488,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
39531 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39532 int pipe;
39533
39534 - atomic_set(&dev_priv->irq_received, 0);
39535 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39536
39537 I915_WRITE(PORT_HOTPLUG_EN, 0);
39538 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
39539 @@ -3604,7 +3604,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
39540 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39541 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39542
39543 - atomic_inc(&dev_priv->irq_received);
39544 + atomic_inc_unchecked(&dev_priv->irq_received);
39545
39546 iir = I915_READ(IIR);
39547
39548 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
39549 index 2bde35d..529646c 100644
39550 --- a/drivers/gpu/drm/i915/intel_display.c
39551 +++ b/drivers/gpu/drm/i915/intel_display.c
39552 @@ -10492,13 +10492,13 @@ struct intel_quirk {
39553 int subsystem_vendor;
39554 int subsystem_device;
39555 void (*hook)(struct drm_device *dev);
39556 -};
39557 +} __do_const;
39558
39559 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
39560 struct intel_dmi_quirk {
39561 void (*hook)(struct drm_device *dev);
39562 const struct dmi_system_id (*dmi_id_list)[];
39563 -};
39564 +} __do_const;
39565
39566 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39567 {
39568 @@ -10506,18 +10506,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39569 return 1;
39570 }
39571
39572 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39573 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
39574 {
39575 - .dmi_id_list = &(const struct dmi_system_id[]) {
39576 - {
39577 - .callback = intel_dmi_reverse_brightness,
39578 - .ident = "NCR Corporation",
39579 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39580 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
39581 - },
39582 - },
39583 - { } /* terminating entry */
39584 + .callback = intel_dmi_reverse_brightness,
39585 + .ident = "NCR Corporation",
39586 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39587 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
39588 },
39589 + },
39590 + { } /* terminating entry */
39591 +};
39592 +
39593 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39594 + {
39595 + .dmi_id_list = &intel_dmi_quirks_table,
39596 .hook = quirk_invert_brightness,
39597 },
39598 };
39599 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
39600 index ca4bc54..ee598a2 100644
39601 --- a/drivers/gpu/drm/mga/mga_drv.h
39602 +++ b/drivers/gpu/drm/mga/mga_drv.h
39603 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
39604 u32 clear_cmd;
39605 u32 maccess;
39606
39607 - atomic_t vbl_received; /**< Number of vblanks received. */
39608 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
39609 wait_queue_head_t fence_queue;
39610 - atomic_t last_fence_retired;
39611 + atomic_unchecked_t last_fence_retired;
39612 u32 next_fence_to_post;
39613
39614 unsigned int fb_cpp;
39615 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
39616 index 709e90d..89a1c0d 100644
39617 --- a/drivers/gpu/drm/mga/mga_ioc32.c
39618 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
39619 @@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
39620 return 0;
39621 }
39622
39623 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
39624 +drm_ioctl_compat_t mga_compat_ioctls[] = {
39625 [DRM_MGA_INIT] = compat_mga_init,
39626 [DRM_MGA_GETPARAM] = compat_mga_getparam,
39627 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
39628 @@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
39629 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39630 {
39631 unsigned int nr = DRM_IOCTL_NR(cmd);
39632 - drm_ioctl_compat_t *fn = NULL;
39633 int ret;
39634
39635 if (nr < DRM_COMMAND_BASE)
39636 return drm_compat_ioctl(filp, cmd, arg);
39637
39638 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
39639 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39640 -
39641 - if (fn != NULL)
39642 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
39643 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39644 ret = (*fn) (filp, cmd, arg);
39645 - else
39646 + } else
39647 ret = drm_ioctl(filp, cmd, arg);
39648
39649 return ret;
39650 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
39651 index 2b0ceb8..517e99e 100644
39652 --- a/drivers/gpu/drm/mga/mga_irq.c
39653 +++ b/drivers/gpu/drm/mga/mga_irq.c
39654 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
39655 if (crtc != 0)
39656 return 0;
39657
39658 - return atomic_read(&dev_priv->vbl_received);
39659 + return atomic_read_unchecked(&dev_priv->vbl_received);
39660 }
39661
39662
39663 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39664 /* VBLANK interrupt */
39665 if (status & MGA_VLINEPEN) {
39666 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
39667 - atomic_inc(&dev_priv->vbl_received);
39668 + atomic_inc_unchecked(&dev_priv->vbl_received);
39669 drm_handle_vblank(dev, 0);
39670 handled = 1;
39671 }
39672 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39673 if ((prim_start & ~0x03) != (prim_end & ~0x03))
39674 MGA_WRITE(MGA_PRIMEND, prim_end);
39675
39676 - atomic_inc(&dev_priv->last_fence_retired);
39677 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
39678 DRM_WAKEUP(&dev_priv->fence_queue);
39679 handled = 1;
39680 }
39681 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
39682 * using fences.
39683 */
39684 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
39685 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
39686 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
39687 - *sequence) <= (1 << 23)));
39688
39689 *sequence = cur_fence;
39690 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
39691 index 4c3feaa..26391ce 100644
39692 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
39693 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
39694 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
39695 struct bit_table {
39696 const char id;
39697 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
39698 -};
39699 +} __no_const;
39700
39701 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
39702
39703 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
39704 index 4b0fb6c..67667a9 100644
39705 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
39706 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
39707 @@ -96,7 +96,6 @@ struct nouveau_drm {
39708 struct drm_global_reference mem_global_ref;
39709 struct ttm_bo_global_ref bo_global_ref;
39710 struct ttm_bo_device bdev;
39711 - atomic_t validate_sequence;
39712 int (*move)(struct nouveau_channel *,
39713 struct ttm_buffer_object *,
39714 struct ttm_mem_reg *, struct ttm_mem_reg *);
39715 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39716 index c1a7e5a..38b8539 100644
39717 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39718 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39719 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
39720 unsigned long arg)
39721 {
39722 unsigned int nr = DRM_IOCTL_NR(cmd);
39723 - drm_ioctl_compat_t *fn = NULL;
39724 + drm_ioctl_compat_t fn = NULL;
39725 int ret;
39726
39727 if (nr < DRM_COMMAND_BASE)
39728 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39729 index 19e3757..ad16478 100644
39730 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
39731 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39732 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39733 }
39734
39735 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
39736 - nouveau_vram_manager_init,
39737 - nouveau_vram_manager_fini,
39738 - nouveau_vram_manager_new,
39739 - nouveau_vram_manager_del,
39740 - nouveau_vram_manager_debug
39741 + .init = nouveau_vram_manager_init,
39742 + .takedown = nouveau_vram_manager_fini,
39743 + .get_node = nouveau_vram_manager_new,
39744 + .put_node = nouveau_vram_manager_del,
39745 + .debug = nouveau_vram_manager_debug
39746 };
39747
39748 static int
39749 @@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39750 }
39751
39752 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
39753 - nouveau_gart_manager_init,
39754 - nouveau_gart_manager_fini,
39755 - nouveau_gart_manager_new,
39756 - nouveau_gart_manager_del,
39757 - nouveau_gart_manager_debug
39758 + .init = nouveau_gart_manager_init,
39759 + .takedown = nouveau_gart_manager_fini,
39760 + .get_node = nouveau_gart_manager_new,
39761 + .put_node = nouveau_gart_manager_del,
39762 + .debug = nouveau_gart_manager_debug
39763 };
39764
39765 #include <core/subdev/vm/nv04.h>
39766 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39767 }
39768
39769 const struct ttm_mem_type_manager_func nv04_gart_manager = {
39770 - nv04_gart_manager_init,
39771 - nv04_gart_manager_fini,
39772 - nv04_gart_manager_new,
39773 - nv04_gart_manager_del,
39774 - nv04_gart_manager_debug
39775 + .init = nv04_gart_manager_init,
39776 + .takedown = nv04_gart_manager_fini,
39777 + .get_node = nv04_gart_manager_new,
39778 + .put_node = nv04_gart_manager_del,
39779 + .debug = nv04_gart_manager_debug
39780 };
39781
39782 int
39783 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
39784 index 81638d7..2e45854 100644
39785 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
39786 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
39787 @@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
39788 bool can_switch;
39789
39790 spin_lock(&dev->count_lock);
39791 - can_switch = (dev->open_count == 0);
39792 + can_switch = (local_read(&dev->open_count) == 0);
39793 spin_unlock(&dev->count_lock);
39794 return can_switch;
39795 }
39796 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
39797 index eb89653..613cf71 100644
39798 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
39799 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
39800 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
39801 int ret;
39802
39803 mutex_lock(&qdev->async_io_mutex);
39804 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
39805 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39806 if (qdev->last_sent_io_cmd > irq_num) {
39807 if (intr)
39808 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39809 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39810 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39811 else
39812 ret = wait_event_timeout(qdev->io_cmd_event,
39813 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39814 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39815 /* 0 is timeout, just bail the "hw" has gone away */
39816 if (ret <= 0)
39817 goto out;
39818 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
39819 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39820 }
39821 outb(val, addr);
39822 qdev->last_sent_io_cmd = irq_num + 1;
39823 if (intr)
39824 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39825 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39826 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39827 else
39828 ret = wait_event_timeout(qdev->io_cmd_event,
39829 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39830 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39831 out:
39832 if (ret > 0)
39833 ret = 0;
39834 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
39835 index c3c2bbd..bc3c0fb 100644
39836 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
39837 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
39838 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
39839 struct drm_info_node *node = (struct drm_info_node *) m->private;
39840 struct qxl_device *qdev = node->minor->dev->dev_private;
39841
39842 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
39843 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
39844 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
39845 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
39846 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
39847 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
39848 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
39849 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
39850 seq_printf(m, "%d\n", qdev->irq_received_error);
39851 return 0;
39852 }
39853 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
39854 index 7bda32f..dd98fc5 100644
39855 --- a/drivers/gpu/drm/qxl/qxl_drv.h
39856 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
39857 @@ -290,10 +290,10 @@ struct qxl_device {
39858 unsigned int last_sent_io_cmd;
39859
39860 /* interrupt handling */
39861 - atomic_t irq_received;
39862 - atomic_t irq_received_display;
39863 - atomic_t irq_received_cursor;
39864 - atomic_t irq_received_io_cmd;
39865 + atomic_unchecked_t irq_received;
39866 + atomic_unchecked_t irq_received_display;
39867 + atomic_unchecked_t irq_received_cursor;
39868 + atomic_unchecked_t irq_received_io_cmd;
39869 unsigned irq_received_error;
39870 wait_queue_head_t display_event;
39871 wait_queue_head_t cursor_event;
39872 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
39873 index 7b95c75..9cffb4f 100644
39874 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
39875 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
39876 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
39877
39878 /* TODO copy slow path code from i915 */
39879 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
39880 - 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);
39881 + 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);
39882
39883 {
39884 struct qxl_drawable *draw = fb_cmd;
39885 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
39886 struct drm_qxl_reloc reloc;
39887
39888 if (DRM_COPY_FROM_USER(&reloc,
39889 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
39890 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
39891 sizeof(reloc))) {
39892 ret = -EFAULT;
39893 goto out_free_bos;
39894 @@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
39895 struct drm_qxl_command *commands =
39896 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
39897
39898 - if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
39899 + if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
39900 sizeof(user_cmd)))
39901 return -EFAULT;
39902
39903 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
39904 index 21393dc..329f3a9 100644
39905 --- a/drivers/gpu/drm/qxl/qxl_irq.c
39906 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
39907 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
39908
39909 pending = xchg(&qdev->ram_header->int_pending, 0);
39910
39911 - atomic_inc(&qdev->irq_received);
39912 + atomic_inc_unchecked(&qdev->irq_received);
39913
39914 if (pending & QXL_INTERRUPT_DISPLAY) {
39915 - atomic_inc(&qdev->irq_received_display);
39916 + atomic_inc_unchecked(&qdev->irq_received_display);
39917 wake_up_all(&qdev->display_event);
39918 qxl_queue_garbage_collect(qdev, false);
39919 }
39920 if (pending & QXL_INTERRUPT_CURSOR) {
39921 - atomic_inc(&qdev->irq_received_cursor);
39922 + atomic_inc_unchecked(&qdev->irq_received_cursor);
39923 wake_up_all(&qdev->cursor_event);
39924 }
39925 if (pending & QXL_INTERRUPT_IO_CMD) {
39926 - atomic_inc(&qdev->irq_received_io_cmd);
39927 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
39928 wake_up_all(&qdev->io_cmd_event);
39929 }
39930 if (pending & QXL_INTERRUPT_ERROR) {
39931 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
39932 init_waitqueue_head(&qdev->io_cmd_event);
39933 INIT_WORK(&qdev->client_monitors_config_work,
39934 qxl_client_monitors_config_work_func);
39935 - atomic_set(&qdev->irq_received, 0);
39936 - atomic_set(&qdev->irq_received_display, 0);
39937 - atomic_set(&qdev->irq_received_cursor, 0);
39938 - atomic_set(&qdev->irq_received_io_cmd, 0);
39939 + atomic_set_unchecked(&qdev->irq_received, 0);
39940 + atomic_set_unchecked(&qdev->irq_received_display, 0);
39941 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
39942 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
39943 qdev->irq_received_error = 0;
39944 ret = drm_irq_install(qdev->ddev);
39945 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
39946 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
39947 index c7e7e65..7dddd4d 100644
39948 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
39949 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
39950 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
39951 }
39952 }
39953
39954 -static struct vm_operations_struct qxl_ttm_vm_ops;
39955 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
39956 static const struct vm_operations_struct *ttm_vm_ops;
39957
39958 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39959 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
39960 return r;
39961 if (unlikely(ttm_vm_ops == NULL)) {
39962 ttm_vm_ops = vma->vm_ops;
39963 + pax_open_kernel();
39964 qxl_ttm_vm_ops = *ttm_vm_ops;
39965 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
39966 + pax_close_kernel();
39967 }
39968 vma->vm_ops = &qxl_ttm_vm_ops;
39969 return 0;
39970 @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
39971 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
39972 {
39973 #if defined(CONFIG_DEBUG_FS)
39974 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
39975 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
39976 - unsigned i;
39977 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
39978 + {
39979 + .name = "qxl_mem_mm",
39980 + .show = &qxl_mm_dump_table,
39981 + },
39982 + {
39983 + .name = "qxl_surf_mm",
39984 + .show = &qxl_mm_dump_table,
39985 + }
39986 + };
39987
39988 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
39989 - if (i == 0)
39990 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
39991 - else
39992 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
39993 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
39994 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
39995 - qxl_mem_types_list[i].driver_features = 0;
39996 - if (i == 0)
39997 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
39998 - else
39999 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40000 + pax_open_kernel();
40001 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40002 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40003 + pax_close_kernel();
40004
40005 - }
40006 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40007 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40008 #else
40009 return 0;
40010 #endif
40011 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40012 index c451257..0ad2134 100644
40013 --- a/drivers/gpu/drm/r128/r128_cce.c
40014 +++ b/drivers/gpu/drm/r128/r128_cce.c
40015 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40016
40017 /* GH: Simple idle check.
40018 */
40019 - atomic_set(&dev_priv->idle_count, 0);
40020 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40021
40022 /* We don't support anything other than bus-mastering ring mode,
40023 * but the ring can be in either AGP or PCI space for the ring
40024 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40025 index 56eb5e3..c4ec43d 100644
40026 --- a/drivers/gpu/drm/r128/r128_drv.h
40027 +++ b/drivers/gpu/drm/r128/r128_drv.h
40028 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40029 int is_pci;
40030 unsigned long cce_buffers_offset;
40031
40032 - atomic_t idle_count;
40033 + atomic_unchecked_t idle_count;
40034
40035 int page_flipping;
40036 int current_page;
40037 u32 crtc_offset;
40038 u32 crtc_offset_cntl;
40039
40040 - atomic_t vbl_received;
40041 + atomic_unchecked_t vbl_received;
40042
40043 u32 color_fmt;
40044 unsigned int front_offset;
40045 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40046 index a954c54..9cc595c 100644
40047 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40048 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40049 @@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40050 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40051 }
40052
40053 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40054 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40055 [DRM_R128_INIT] = compat_r128_init,
40056 [DRM_R128_DEPTH] = compat_r128_depth,
40057 [DRM_R128_STIPPLE] = compat_r128_stipple,
40058 @@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40059 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40060 {
40061 unsigned int nr = DRM_IOCTL_NR(cmd);
40062 - drm_ioctl_compat_t *fn = NULL;
40063 int ret;
40064
40065 if (nr < DRM_COMMAND_BASE)
40066 return drm_compat_ioctl(filp, cmd, arg);
40067
40068 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40069 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40070 -
40071 - if (fn != NULL)
40072 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40073 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40074 ret = (*fn) (filp, cmd, arg);
40075 - else
40076 + } else
40077 ret = drm_ioctl(filp, cmd, arg);
40078
40079 return ret;
40080 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40081 index 2ea4f09..d391371 100644
40082 --- a/drivers/gpu/drm/r128/r128_irq.c
40083 +++ b/drivers/gpu/drm/r128/r128_irq.c
40084 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40085 if (crtc != 0)
40086 return 0;
40087
40088 - return atomic_read(&dev_priv->vbl_received);
40089 + return atomic_read_unchecked(&dev_priv->vbl_received);
40090 }
40091
40092 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40093 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40094 /* VBLANK interrupt */
40095 if (status & R128_CRTC_VBLANK_INT) {
40096 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40097 - atomic_inc(&dev_priv->vbl_received);
40098 + atomic_inc_unchecked(&dev_priv->vbl_received);
40099 drm_handle_vblank(dev, 0);
40100 return IRQ_HANDLED;
40101 }
40102 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40103 index 01dd9ae..6352f04 100644
40104 --- a/drivers/gpu/drm/r128/r128_state.c
40105 +++ b/drivers/gpu/drm/r128/r128_state.c
40106 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40107
40108 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40109 {
40110 - if (atomic_read(&dev_priv->idle_count) == 0)
40111 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40112 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40113 else
40114 - atomic_set(&dev_priv->idle_count, 0);
40115 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40116 }
40117
40118 #endif
40119 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40120 index af85299..ed9ac8d 100644
40121 --- a/drivers/gpu/drm/radeon/mkregtable.c
40122 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40123 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40124 regex_t mask_rex;
40125 regmatch_t match[4];
40126 char buf[1024];
40127 - size_t end;
40128 + long end;
40129 int len;
40130 int done = 0;
40131 int r;
40132 unsigned o;
40133 struct offset *offset;
40134 char last_reg_s[10];
40135 - int last_reg;
40136 + unsigned long last_reg;
40137
40138 if (regcomp
40139 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40140 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40141 index 39b033b..6efc056 100644
40142 --- a/drivers/gpu/drm/radeon/radeon_device.c
40143 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40144 @@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40145 bool can_switch;
40146
40147 spin_lock(&dev->count_lock);
40148 - can_switch = (dev->open_count == 0);
40149 + can_switch = (local_read(&dev->open_count) == 0);
40150 spin_unlock(&dev->count_lock);
40151 return can_switch;
40152 }
40153 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40154 index 00e0d44..08381a4 100644
40155 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40156 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40157 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40158
40159 /* SW interrupt */
40160 wait_queue_head_t swi_queue;
40161 - atomic_t swi_emitted;
40162 + atomic_unchecked_t swi_emitted;
40163 int vblank_crtc;
40164 uint32_t irq_enable_reg;
40165 uint32_t r500_disp_irq_reg;
40166 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40167 index bdb0f93..5ff558f 100644
40168 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40169 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40170 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40171 request = compat_alloc_user_space(sizeof(*request));
40172 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40173 || __put_user(req32.param, &request->param)
40174 - || __put_user((void __user *)(unsigned long)req32.value,
40175 + || __put_user((unsigned long)req32.value,
40176 &request->value))
40177 return -EFAULT;
40178
40179 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40180 #define compat_radeon_cp_setparam NULL
40181 #endif /* X86_64 || IA64 */
40182
40183 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40184 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40185 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40186 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40187 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40188 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40189 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40190 {
40191 unsigned int nr = DRM_IOCTL_NR(cmd);
40192 - drm_ioctl_compat_t *fn = NULL;
40193 int ret;
40194
40195 if (nr < DRM_COMMAND_BASE)
40196 return drm_compat_ioctl(filp, cmd, arg);
40197
40198 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40199 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40200 -
40201 - if (fn != NULL)
40202 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40203 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40204 ret = (*fn) (filp, cmd, arg);
40205 - else
40206 + } else
40207 ret = drm_ioctl(filp, cmd, arg);
40208
40209 return ret;
40210 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40211 index 8d68e97..9dcfed8 100644
40212 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40213 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40214 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40215 unsigned int ret;
40216 RING_LOCALS;
40217
40218 - atomic_inc(&dev_priv->swi_emitted);
40219 - ret = atomic_read(&dev_priv->swi_emitted);
40220 + atomic_inc_unchecked(&dev_priv->swi_emitted);
40221 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40222
40223 BEGIN_RING(4);
40224 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40225 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40226 drm_radeon_private_t *dev_priv =
40227 (drm_radeon_private_t *) dev->dev_private;
40228
40229 - atomic_set(&dev_priv->swi_emitted, 0);
40230 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40231 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40232
40233 dev->max_vblank_count = 0x001fffff;
40234 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40235 index 4d20910..6726b6d 100644
40236 --- a/drivers/gpu/drm/radeon/radeon_state.c
40237 +++ b/drivers/gpu/drm/radeon/radeon_state.c
40238 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40239 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40240 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40241
40242 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40243 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40244 sarea_priv->nbox * sizeof(depth_boxes[0])))
40245 return -EFAULT;
40246
40247 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40248 {
40249 drm_radeon_private_t *dev_priv = dev->dev_private;
40250 drm_radeon_getparam_t *param = data;
40251 - int value;
40252 + int value = 0;
40253
40254 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40255
40256 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40257 index 71245d6..94c556d 100644
40258 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
40259 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40260 @@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40261 man->size = size >> PAGE_SHIFT;
40262 }
40263
40264 -static struct vm_operations_struct radeon_ttm_vm_ops;
40265 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40266 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40267
40268 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40269 @@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40270 }
40271 if (unlikely(ttm_vm_ops == NULL)) {
40272 ttm_vm_ops = vma->vm_ops;
40273 + pax_open_kernel();
40274 radeon_ttm_vm_ops = *ttm_vm_ops;
40275 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40276 + pax_close_kernel();
40277 }
40278 vma->vm_ops = &radeon_ttm_vm_ops;
40279 return 0;
40280 @@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40281 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40282 {
40283 #if defined(CONFIG_DEBUG_FS)
40284 - static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40285 - static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40286 - unsigned i;
40287 + static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40288 + {
40289 + .name = "radeon_vram_mm",
40290 + .show = &radeon_mm_dump_table,
40291 + },
40292 + {
40293 + .name = "radeon_gtt_mm",
40294 + .show = &radeon_mm_dump_table,
40295 + },
40296 + {
40297 + .name = "ttm_page_pool",
40298 + .show = &ttm_page_alloc_debugfs,
40299 + },
40300 + {
40301 + .name = "ttm_dma_page_pool",
40302 + .show = &ttm_dma_page_alloc_debugfs,
40303 + },
40304 + };
40305 + unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40306
40307 - for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40308 - if (i == 0)
40309 - sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40310 - else
40311 - sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40312 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40313 - radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40314 - radeon_mem_types_list[i].driver_features = 0;
40315 - if (i == 0)
40316 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40317 - else
40318 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40319 -
40320 - }
40321 - /* Add ttm page pool to debugfs */
40322 - sprintf(radeon_mem_types_names[i], "ttm_page_pool");
40323 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40324 - radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
40325 - radeon_mem_types_list[i].driver_features = 0;
40326 - radeon_mem_types_list[i++].data = NULL;
40327 + pax_open_kernel();
40328 + *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40329 + *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40330 + pax_close_kernel();
40331 #ifdef CONFIG_SWIOTLB
40332 - if (swiotlb_nr_tbl()) {
40333 - sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
40334 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40335 - radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
40336 - radeon_mem_types_list[i].driver_features = 0;
40337 - radeon_mem_types_list[i++].data = NULL;
40338 - }
40339 + if (swiotlb_nr_tbl())
40340 + i++;
40341 #endif
40342 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
40343
40344 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
40345 index ae1cb31..5b5b6b7c 100644
40346 --- a/drivers/gpu/drm/tegra/dc.c
40347 +++ b/drivers/gpu/drm/tegra/dc.c
40348 @@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40349 }
40350
40351 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40352 - dc->debugfs_files[i].data = dc;
40353 + *(void **)&dc->debugfs_files[i].data = dc;
40354
40355 err = drm_debugfs_create_files(dc->debugfs_files,
40356 ARRAY_SIZE(debugfs_files),
40357 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40358 index c58eba33..83c2728 100644
40359 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
40360 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40361 @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
40362 }
40363
40364 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
40365 - ttm_bo_man_init,
40366 - ttm_bo_man_takedown,
40367 - ttm_bo_man_get_node,
40368 - ttm_bo_man_put_node,
40369 - ttm_bo_man_debug
40370 + .init = ttm_bo_man_init,
40371 + .takedown = ttm_bo_man_takedown,
40372 + .get_node = ttm_bo_man_get_node,
40373 + .put_node = ttm_bo_man_put_node,
40374 + .debug = ttm_bo_man_debug
40375 };
40376 EXPORT_SYMBOL(ttm_bo_manager_func);
40377 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
40378 index dbc2def..0a9f710 100644
40379 --- a/drivers/gpu/drm/ttm/ttm_memory.c
40380 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
40381 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
40382 zone->glob = glob;
40383 glob->zone_kernel = zone;
40384 ret = kobject_init_and_add(
40385 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40386 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40387 if (unlikely(ret != 0)) {
40388 kobject_put(&zone->kobj);
40389 return ret;
40390 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
40391 zone->glob = glob;
40392 glob->zone_dma32 = zone;
40393 ret = kobject_init_and_add(
40394 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40395 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40396 if (unlikely(ret != 0)) {
40397 kobject_put(&zone->kobj);
40398 return ret;
40399 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40400 index 863bef9..cba15cf 100644
40401 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
40402 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40403 @@ -391,9 +391,9 @@ out:
40404 static unsigned long
40405 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
40406 {
40407 - static atomic_t start_pool = ATOMIC_INIT(0);
40408 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
40409 unsigned i;
40410 - unsigned pool_offset = atomic_add_return(1, &start_pool);
40411 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
40412 struct ttm_page_pool *pool;
40413 int shrink_pages = sc->nr_to_scan;
40414 unsigned long freed = 0;
40415 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
40416 index 97e9d61..bf23c461 100644
40417 --- a/drivers/gpu/drm/udl/udl_fb.c
40418 +++ b/drivers/gpu/drm/udl/udl_fb.c
40419 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
40420 fb_deferred_io_cleanup(info);
40421 kfree(info->fbdefio);
40422 info->fbdefio = NULL;
40423 - info->fbops->fb_mmap = udl_fb_mmap;
40424 }
40425
40426 pr_warn("released /dev/fb%d user=%d count=%d\n",
40427 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
40428 index a811ef2..ff99b05 100644
40429 --- a/drivers/gpu/drm/via/via_drv.h
40430 +++ b/drivers/gpu/drm/via/via_drv.h
40431 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
40432 typedef uint32_t maskarray_t[5];
40433
40434 typedef struct drm_via_irq {
40435 - atomic_t irq_received;
40436 + atomic_unchecked_t irq_received;
40437 uint32_t pending_mask;
40438 uint32_t enable_mask;
40439 wait_queue_head_t irq_queue;
40440 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
40441 struct timeval last_vblank;
40442 int last_vblank_valid;
40443 unsigned usec_per_vblank;
40444 - atomic_t vbl_received;
40445 + atomic_unchecked_t vbl_received;
40446 drm_via_state_t hc_state;
40447 char pci_buf[VIA_PCI_BUF_SIZE];
40448 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
40449 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
40450 index ac98964..5dbf512 100644
40451 --- a/drivers/gpu/drm/via/via_irq.c
40452 +++ b/drivers/gpu/drm/via/via_irq.c
40453 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
40454 if (crtc != 0)
40455 return 0;
40456
40457 - return atomic_read(&dev_priv->vbl_received);
40458 + return atomic_read_unchecked(&dev_priv->vbl_received);
40459 }
40460
40461 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40462 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40463
40464 status = VIA_READ(VIA_REG_INTERRUPT);
40465 if (status & VIA_IRQ_VBLANK_PENDING) {
40466 - atomic_inc(&dev_priv->vbl_received);
40467 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
40468 + atomic_inc_unchecked(&dev_priv->vbl_received);
40469 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
40470 do_gettimeofday(&cur_vblank);
40471 if (dev_priv->last_vblank_valid) {
40472 dev_priv->usec_per_vblank =
40473 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40474 dev_priv->last_vblank = cur_vblank;
40475 dev_priv->last_vblank_valid = 1;
40476 }
40477 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
40478 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
40479 DRM_DEBUG("US per vblank is: %u\n",
40480 dev_priv->usec_per_vblank);
40481 }
40482 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40483
40484 for (i = 0; i < dev_priv->num_irqs; ++i) {
40485 if (status & cur_irq->pending_mask) {
40486 - atomic_inc(&cur_irq->irq_received);
40487 + atomic_inc_unchecked(&cur_irq->irq_received);
40488 DRM_WAKEUP(&cur_irq->irq_queue);
40489 handled = 1;
40490 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
40491 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
40492 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40493 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
40494 masks[irq][4]));
40495 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
40496 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
40497 } else {
40498 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40499 (((cur_irq_sequence =
40500 - atomic_read(&cur_irq->irq_received)) -
40501 + atomic_read_unchecked(&cur_irq->irq_received)) -
40502 *sequence) <= (1 << 23)));
40503 }
40504 *sequence = cur_irq_sequence;
40505 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
40506 }
40507
40508 for (i = 0; i < dev_priv->num_irqs; ++i) {
40509 - atomic_set(&cur_irq->irq_received, 0);
40510 + atomic_set_unchecked(&cur_irq->irq_received, 0);
40511 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
40512 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
40513 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
40514 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
40515 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
40516 case VIA_IRQ_RELATIVE:
40517 irqwait->request.sequence +=
40518 - atomic_read(&cur_irq->irq_received);
40519 + atomic_read_unchecked(&cur_irq->irq_received);
40520 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
40521 case VIA_IRQ_ABSOLUTE:
40522 break;
40523 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40524 index 20890ad..699e4f2 100644
40525 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40526 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40527 @@ -342,7 +342,7 @@ struct vmw_private {
40528 * Fencing and IRQs.
40529 */
40530
40531 - atomic_t marker_seq;
40532 + atomic_unchecked_t marker_seq;
40533 wait_queue_head_t fence_queue;
40534 wait_queue_head_t fifo_queue;
40535 int fence_queue_waiters; /* Protected by hw_mutex */
40536 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40537 index 3eb1486..0a47ee9 100644
40538 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40539 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40540 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
40541 (unsigned int) min,
40542 (unsigned int) fifo->capabilities);
40543
40544 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40545 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40546 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
40547 vmw_marker_queue_init(&fifo->marker_queue);
40548 return vmw_fifo_send_fence(dev_priv, &dummy);
40549 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
40550 if (reserveable)
40551 iowrite32(bytes, fifo_mem +
40552 SVGA_FIFO_RESERVED);
40553 - return fifo_mem + (next_cmd >> 2);
40554 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
40555 } else {
40556 need_bounce = true;
40557 }
40558 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40559
40560 fm = vmw_fifo_reserve(dev_priv, bytes);
40561 if (unlikely(fm == NULL)) {
40562 - *seqno = atomic_read(&dev_priv->marker_seq);
40563 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40564 ret = -ENOMEM;
40565 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
40566 false, 3*HZ);
40567 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40568 }
40569
40570 do {
40571 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
40572 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
40573 } while (*seqno == 0);
40574
40575 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
40576 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40577 index c5c054a..46f0548 100644
40578 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40579 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40580 @@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
40581 }
40582
40583 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
40584 - vmw_gmrid_man_init,
40585 - vmw_gmrid_man_takedown,
40586 - vmw_gmrid_man_get_node,
40587 - vmw_gmrid_man_put_node,
40588 - vmw_gmrid_man_debug
40589 + .init = vmw_gmrid_man_init,
40590 + .takedown = vmw_gmrid_man_takedown,
40591 + .get_node = vmw_gmrid_man_get_node,
40592 + .put_node = vmw_gmrid_man_put_node,
40593 + .debug = vmw_gmrid_man_debug
40594 };
40595 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40596 index 45d5b5a..f3f5e4e 100644
40597 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40598 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40599 @@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
40600 int ret;
40601
40602 num_clips = arg->num_clips;
40603 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40604 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40605
40606 if (unlikely(num_clips == 0))
40607 return 0;
40608 @@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
40609 int ret;
40610
40611 num_clips = arg->num_clips;
40612 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40613 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40614
40615 if (unlikely(num_clips == 0))
40616 return 0;
40617 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40618 index 4640adb..e1384ed 100644
40619 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40620 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40621 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
40622 * emitted. Then the fence is stale and signaled.
40623 */
40624
40625 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
40626 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
40627 > VMW_FENCE_WRAP);
40628
40629 return ret;
40630 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
40631
40632 if (fifo_idle)
40633 down_read(&fifo_state->rwsem);
40634 - signal_seq = atomic_read(&dev_priv->marker_seq);
40635 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
40636 ret = 0;
40637
40638 for (;;) {
40639 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40640 index 8a8725c2..afed796 100644
40641 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40642 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40643 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
40644 while (!vmw_lag_lt(queue, us)) {
40645 spin_lock(&queue->lock);
40646 if (list_empty(&queue->head))
40647 - seqno = atomic_read(&dev_priv->marker_seq);
40648 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40649 else {
40650 marker = list_first_entry(&queue->head,
40651 struct vmw_marker, head);
40652 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
40653 index ec0ae2d..dc0780b 100644
40654 --- a/drivers/gpu/vga/vga_switcheroo.c
40655 +++ b/drivers/gpu/vga/vga_switcheroo.c
40656 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
40657
40658 /* this version is for the case where the power switch is separate
40659 to the device being powered down. */
40660 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
40661 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
40662 {
40663 /* copy over all the bus versions */
40664 if (dev->bus && dev->bus->pm) {
40665 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
40666 return ret;
40667 }
40668
40669 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
40670 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
40671 {
40672 /* copy over all the bus versions */
40673 if (dev->bus && dev->bus->pm) {
40674 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
40675 index 253fe23..0dfec5f 100644
40676 --- a/drivers/hid/hid-core.c
40677 +++ b/drivers/hid/hid-core.c
40678 @@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
40679
40680 int hid_add_device(struct hid_device *hdev)
40681 {
40682 - static atomic_t id = ATOMIC_INIT(0);
40683 + static atomic_unchecked_t id = ATOMIC_INIT(0);
40684 int ret;
40685
40686 if (WARN_ON(hdev->status & HID_STAT_ADDED))
40687 @@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
40688 /* XXX hack, any other cleaner solution after the driver core
40689 * is converted to allow more than 20 bytes as the device name? */
40690 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
40691 - hdev->vendor, hdev->product, atomic_inc_return(&id));
40692 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
40693
40694 hid_debug_register(hdev, dev_name(&hdev->dev));
40695 ret = device_add(&hdev->dev);
40696 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
40697 index c13fb5b..55a3802 100644
40698 --- a/drivers/hid/hid-wiimote-debug.c
40699 +++ b/drivers/hid/hid-wiimote-debug.c
40700 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
40701 else if (size == 0)
40702 return -EIO;
40703
40704 - if (copy_to_user(u, buf, size))
40705 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
40706 return -EFAULT;
40707
40708 *off += size;
40709 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
40710 index cedc6da..2c3da2a 100644
40711 --- a/drivers/hid/uhid.c
40712 +++ b/drivers/hid/uhid.c
40713 @@ -47,7 +47,7 @@ struct uhid_device {
40714 struct mutex report_lock;
40715 wait_queue_head_t report_wait;
40716 atomic_t report_done;
40717 - atomic_t report_id;
40718 + atomic_unchecked_t report_id;
40719 struct uhid_event report_buf;
40720 };
40721
40722 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
40723
40724 spin_lock_irqsave(&uhid->qlock, flags);
40725 ev->type = UHID_FEATURE;
40726 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
40727 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
40728 ev->u.feature.rnum = rnum;
40729 ev->u.feature.rtype = report_type;
40730
40731 @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
40732 spin_lock_irqsave(&uhid->qlock, flags);
40733
40734 /* id for old report; drop it silently */
40735 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
40736 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
40737 goto unlock;
40738 if (atomic_read(&uhid->report_done))
40739 goto unlock;
40740 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
40741 index cea623c..73011b0 100644
40742 --- a/drivers/hv/channel.c
40743 +++ b/drivers/hv/channel.c
40744 @@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
40745 int ret = 0;
40746 int t;
40747
40748 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
40749 - atomic_inc(&vmbus_connection.next_gpadl_handle);
40750 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
40751 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
40752
40753 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
40754 if (ret)
40755 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
40756 index f0c5e07..399256e 100644
40757 --- a/drivers/hv/hv.c
40758 +++ b/drivers/hv/hv.c
40759 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
40760 u64 output_address = (output) ? virt_to_phys(output) : 0;
40761 u32 output_address_hi = output_address >> 32;
40762 u32 output_address_lo = output_address & 0xFFFFFFFF;
40763 - void *hypercall_page = hv_context.hypercall_page;
40764 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
40765
40766 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
40767 "=a"(hv_status_lo) : "d" (control_hi),
40768 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
40769 index 7e17a54..a50a33d 100644
40770 --- a/drivers/hv/hv_balloon.c
40771 +++ b/drivers/hv/hv_balloon.c
40772 @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40773
40774 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40775 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40776 -static atomic_t trans_id = ATOMIC_INIT(0);
40777 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40778
40779 static int dm_ring_size = (5 * PAGE_SIZE);
40780
40781 @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
40782 pr_info("Memory hot add failed\n");
40783
40784 dm->state = DM_INITIALIZED;
40785 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
40786 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40787 vmbus_sendpacket(dm->dev->channel, &resp,
40788 sizeof(struct dm_hot_add_response),
40789 (unsigned long)NULL,
40790 @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40791 memset(&status, 0, sizeof(struct dm_status));
40792 status.hdr.type = DM_STATUS_REPORT;
40793 status.hdr.size = sizeof(struct dm_status);
40794 - status.hdr.trans_id = atomic_inc_return(&trans_id);
40795 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40796
40797 /*
40798 * The host expects the guest to report free memory.
40799 @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40800 * send the status. This can happen if we were interrupted
40801 * after we picked our transaction ID.
40802 */
40803 - if (status.hdr.trans_id != atomic_read(&trans_id))
40804 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40805 return;
40806
40807 vmbus_sendpacket(dm->dev->channel, &status,
40808 @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
40809 */
40810
40811 do {
40812 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40813 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40814 ret = vmbus_sendpacket(dm_device.dev->channel,
40815 bl_resp,
40816 bl_resp->hdr.size,
40817 @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40818
40819 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40820 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40821 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
40822 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40823 resp.hdr.size = sizeof(struct dm_unballoon_response);
40824
40825 vmbus_sendpacket(dm_device.dev->channel, &resp,
40826 @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40827 memset(&version_req, 0, sizeof(struct dm_version_request));
40828 version_req.hdr.type = DM_VERSION_REQUEST;
40829 version_req.hdr.size = sizeof(struct dm_version_request);
40830 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40831 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40832 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40833 version_req.is_last_attempt = 1;
40834
40835 @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40836 memset(&version_req, 0, sizeof(struct dm_version_request));
40837 version_req.hdr.type = DM_VERSION_REQUEST;
40838 version_req.hdr.size = sizeof(struct dm_version_request);
40839 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40840 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40841 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40842 version_req.is_last_attempt = 0;
40843
40844 @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40845 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40846 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40847 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40848 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40849 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40850
40851 cap_msg.caps.cap_bits.balloon = 1;
40852 cap_msg.caps.cap_bits.hot_add = 1;
40853 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40854 index e055176..c22ff1f 100644
40855 --- a/drivers/hv/hyperv_vmbus.h
40856 +++ b/drivers/hv/hyperv_vmbus.h
40857 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
40858 struct vmbus_connection {
40859 enum vmbus_connect_state conn_state;
40860
40861 - atomic_t next_gpadl_handle;
40862 + atomic_unchecked_t next_gpadl_handle;
40863
40864 /*
40865 * Represents channel interrupts. Each bit position represents a
40866 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40867 index 48aad4f..c768fb2 100644
40868 --- a/drivers/hv/vmbus_drv.c
40869 +++ b/drivers/hv/vmbus_drv.c
40870 @@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40871 {
40872 int ret = 0;
40873
40874 - static atomic_t device_num = ATOMIC_INIT(0);
40875 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40876
40877 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40878 - atomic_inc_return(&device_num));
40879 + atomic_inc_return_unchecked(&device_num));
40880
40881 child_device_obj->device.bus = &hv_bus;
40882 child_device_obj->device.parent = &hv_acpi_dev->dev;
40883 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40884 index 6a34f7f..aa4c3a6 100644
40885 --- a/drivers/hwmon/acpi_power_meter.c
40886 +++ b/drivers/hwmon/acpi_power_meter.c
40887 @@ -117,7 +117,7 @@ struct sensor_template {
40888 struct device_attribute *devattr,
40889 const char *buf, size_t count);
40890 int index;
40891 -};
40892 +} __do_const;
40893
40894 /* Averaging interval */
40895 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40896 @@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40897 struct sensor_template *attrs)
40898 {
40899 struct device *dev = &resource->acpi_dev->dev;
40900 - struct sensor_device_attribute *sensors =
40901 + sensor_device_attribute_no_const *sensors =
40902 &resource->sensors[resource->num_sensors];
40903 int res = 0;
40904
40905 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40906 index 3288f13..71cfb4e 100644
40907 --- a/drivers/hwmon/applesmc.c
40908 +++ b/drivers/hwmon/applesmc.c
40909 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40910 {
40911 struct applesmc_node_group *grp;
40912 struct applesmc_dev_attr *node;
40913 - struct attribute *attr;
40914 + attribute_no_const *attr;
40915 int ret, i;
40916
40917 for (grp = groups; grp->format; grp++) {
40918 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40919 index dafc63c..4abb96c 100644
40920 --- a/drivers/hwmon/asus_atk0110.c
40921 +++ b/drivers/hwmon/asus_atk0110.c
40922 @@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40923 struct atk_sensor_data {
40924 struct list_head list;
40925 struct atk_data *data;
40926 - struct device_attribute label_attr;
40927 - struct device_attribute input_attr;
40928 - struct device_attribute limit1_attr;
40929 - struct device_attribute limit2_attr;
40930 + device_attribute_no_const label_attr;
40931 + device_attribute_no_const input_attr;
40932 + device_attribute_no_const limit1_attr;
40933 + device_attribute_no_const limit2_attr;
40934 char label_attr_name[ATTR_NAME_SIZE];
40935 char input_attr_name[ATTR_NAME_SIZE];
40936 char limit1_attr_name[ATTR_NAME_SIZE];
40937 @@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
40938 static struct device_attribute atk_name_attr =
40939 __ATTR(name, 0444, atk_name_show, NULL);
40940
40941 -static void atk_init_attribute(struct device_attribute *attr, char *name,
40942 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40943 sysfs_show_func show)
40944 {
40945 sysfs_attr_init(&attr->attr);
40946 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40947 index 9425098..7646cc5 100644
40948 --- a/drivers/hwmon/coretemp.c
40949 +++ b/drivers/hwmon/coretemp.c
40950 @@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
40951 return NOTIFY_OK;
40952 }
40953
40954 -static struct notifier_block coretemp_cpu_notifier __refdata = {
40955 +static struct notifier_block coretemp_cpu_notifier = {
40956 .notifier_call = coretemp_cpu_callback,
40957 };
40958
40959 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40960 index 632f1dc..57e6a58 100644
40961 --- a/drivers/hwmon/ibmaem.c
40962 +++ b/drivers/hwmon/ibmaem.c
40963 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40964 struct aem_rw_sensor_template *rw)
40965 {
40966 struct device *dev = &data->pdev->dev;
40967 - struct sensor_device_attribute *sensors = data->sensors;
40968 + sensor_device_attribute_no_const *sensors = data->sensors;
40969 int err;
40970
40971 /* Set up read-only sensors */
40972 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40973 index 708081b..fe2d4ab 100644
40974 --- a/drivers/hwmon/iio_hwmon.c
40975 +++ b/drivers/hwmon/iio_hwmon.c
40976 @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40977 {
40978 struct device *dev = &pdev->dev;
40979 struct iio_hwmon_state *st;
40980 - struct sensor_device_attribute *a;
40981 + sensor_device_attribute_no_const *a;
40982 int ret, i;
40983 int in_i = 1, temp_i = 1, curr_i = 1;
40984 enum iio_chan_type type;
40985 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
40986 index cf811c1..4c17110 100644
40987 --- a/drivers/hwmon/nct6775.c
40988 +++ b/drivers/hwmon/nct6775.c
40989 @@ -944,10 +944,10 @@ static struct attribute_group *
40990 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
40991 int repeat)
40992 {
40993 - struct attribute_group *group;
40994 + attribute_group_no_const *group;
40995 struct sensor_device_attr_u *su;
40996 - struct sensor_device_attribute *a;
40997 - struct sensor_device_attribute_2 *a2;
40998 + sensor_device_attribute_no_const *a;
40999 + sensor_device_attribute_2_no_const *a2;
41000 struct attribute **attrs;
41001 struct sensor_device_template **t;
41002 int i, count;
41003 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41004 index 3cbf66e..8c5cc2a 100644
41005 --- a/drivers/hwmon/pmbus/pmbus_core.c
41006 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41007 @@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41008 return 0;
41009 }
41010
41011 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41012 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41013 const char *name,
41014 umode_t mode,
41015 ssize_t (*show)(struct device *dev,
41016 @@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41017 dev_attr->store = store;
41018 }
41019
41020 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41021 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41022 const char *name,
41023 umode_t mode,
41024 ssize_t (*show)(struct device *dev,
41025 @@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41026 u16 reg, u8 mask)
41027 {
41028 struct pmbus_boolean *boolean;
41029 - struct sensor_device_attribute *a;
41030 + sensor_device_attribute_no_const *a;
41031
41032 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41033 if (!boolean)
41034 @@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41035 bool update, bool readonly)
41036 {
41037 struct pmbus_sensor *sensor;
41038 - struct device_attribute *a;
41039 + device_attribute_no_const *a;
41040
41041 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41042 if (!sensor)
41043 @@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41044 const char *lstring, int index)
41045 {
41046 struct pmbus_label *label;
41047 - struct device_attribute *a;
41048 + device_attribute_no_const *a;
41049
41050 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41051 if (!label)
41052 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41053 index 97cd45a..ac54d8b 100644
41054 --- a/drivers/hwmon/sht15.c
41055 +++ b/drivers/hwmon/sht15.c
41056 @@ -169,7 +169,7 @@ struct sht15_data {
41057 int supply_uv;
41058 bool supply_uv_valid;
41059 struct work_struct update_supply_work;
41060 - atomic_t interrupt_handled;
41061 + atomic_unchecked_t interrupt_handled;
41062 };
41063
41064 /**
41065 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41066 ret = gpio_direction_input(data->pdata->gpio_data);
41067 if (ret)
41068 return ret;
41069 - atomic_set(&data->interrupt_handled, 0);
41070 + atomic_set_unchecked(&data->interrupt_handled, 0);
41071
41072 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41073 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41074 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41075 /* Only relevant if the interrupt hasn't occurred. */
41076 - if (!atomic_read(&data->interrupt_handled))
41077 + if (!atomic_read_unchecked(&data->interrupt_handled))
41078 schedule_work(&data->read_work);
41079 }
41080 ret = wait_event_timeout(data->wait_queue,
41081 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41082
41083 /* First disable the interrupt */
41084 disable_irq_nosync(irq);
41085 - atomic_inc(&data->interrupt_handled);
41086 + atomic_inc_unchecked(&data->interrupt_handled);
41087 /* Then schedule a reading work struct */
41088 if (data->state != SHT15_READING_NOTHING)
41089 schedule_work(&data->read_work);
41090 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41091 * If not, then start the interrupt again - care here as could
41092 * have gone low in meantime so verify it hasn't!
41093 */
41094 - atomic_set(&data->interrupt_handled, 0);
41095 + atomic_set_unchecked(&data->interrupt_handled, 0);
41096 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41097 /* If still not occurred or another handler was scheduled */
41098 if (gpio_get_value(data->pdata->gpio_data)
41099 - || atomic_read(&data->interrupt_handled))
41100 + || atomic_read_unchecked(&data->interrupt_handled))
41101 return;
41102 }
41103
41104 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41105 index 38944e9..ae9e5ed 100644
41106 --- a/drivers/hwmon/via-cputemp.c
41107 +++ b/drivers/hwmon/via-cputemp.c
41108 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41109 return NOTIFY_OK;
41110 }
41111
41112 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41113 +static struct notifier_block via_cputemp_cpu_notifier = {
41114 .notifier_call = via_cputemp_cpu_callback,
41115 };
41116
41117 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41118 index 07f01ac..d79ad3d 100644
41119 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41120 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41121 @@ -43,7 +43,7 @@
41122 extern struct i2c_adapter amd756_smbus;
41123
41124 static struct i2c_adapter *s4882_adapter;
41125 -static struct i2c_algorithm *s4882_algo;
41126 +static i2c_algorithm_no_const *s4882_algo;
41127
41128 /* Wrapper access functions for multiplexed SMBus */
41129 static DEFINE_MUTEX(amd756_lock);
41130 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41131 index 721f7eb..0fd2a09 100644
41132 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41133 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41134 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41135 /* usb layer */
41136
41137 /* Send command to device, and get response. */
41138 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41139 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41140 {
41141 int ret = 0;
41142 int actual;
41143 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41144 index 2ca268d..c6acbdf 100644
41145 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41146 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41147 @@ -41,7 +41,7 @@
41148 extern struct i2c_adapter *nforce2_smbus;
41149
41150 static struct i2c_adapter *s4985_adapter;
41151 -static struct i2c_algorithm *s4985_algo;
41152 +static i2c_algorithm_no_const *s4985_algo;
41153
41154 /* Wrapper access functions for multiplexed SMBus */
41155 static DEFINE_MUTEX(nforce2_lock);
41156 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41157 index 80b47e8..1a6040d9 100644
41158 --- a/drivers/i2c/i2c-dev.c
41159 +++ b/drivers/i2c/i2c-dev.c
41160 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41161 break;
41162 }
41163
41164 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41165 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41166 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41167 if (IS_ERR(rdwr_pa[i].buf)) {
41168 res = PTR_ERR(rdwr_pa[i].buf);
41169 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41170 index 0b510ba..4fbb5085 100644
41171 --- a/drivers/ide/ide-cd.c
41172 +++ b/drivers/ide/ide-cd.c
41173 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41174 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41175 if ((unsigned long)buf & alignment
41176 || blk_rq_bytes(rq) & q->dma_pad_mask
41177 - || object_is_on_stack(buf))
41178 + || object_starts_on_stack(buf))
41179 drive->dma = 0;
41180 }
41181 }
41182 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41183 index 18f72e3..3722327 100644
41184 --- a/drivers/iio/industrialio-core.c
41185 +++ b/drivers/iio/industrialio-core.c
41186 @@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41187 }
41188
41189 static
41190 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41191 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41192 const char *postfix,
41193 struct iio_chan_spec const *chan,
41194 ssize_t (*readfunc)(struct device *dev,
41195 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41196 index f2ef7ef..743d02f 100644
41197 --- a/drivers/infiniband/core/cm.c
41198 +++ b/drivers/infiniband/core/cm.c
41199 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41200
41201 struct cm_counter_group {
41202 struct kobject obj;
41203 - atomic_long_t counter[CM_ATTR_COUNT];
41204 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41205 };
41206
41207 struct cm_counter_attribute {
41208 @@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41209 struct ib_mad_send_buf *msg = NULL;
41210 int ret;
41211
41212 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41213 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41214 counter[CM_REQ_COUNTER]);
41215
41216 /* Quick state check to discard duplicate REQs. */
41217 @@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41218 if (!cm_id_priv)
41219 return;
41220
41221 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41222 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41223 counter[CM_REP_COUNTER]);
41224 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41225 if (ret)
41226 @@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41227 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41228 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41229 spin_unlock_irq(&cm_id_priv->lock);
41230 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41231 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41232 counter[CM_RTU_COUNTER]);
41233 goto out;
41234 }
41235 @@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41236 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41237 dreq_msg->local_comm_id);
41238 if (!cm_id_priv) {
41239 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41240 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41241 counter[CM_DREQ_COUNTER]);
41242 cm_issue_drep(work->port, work->mad_recv_wc);
41243 return -EINVAL;
41244 @@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41245 case IB_CM_MRA_REP_RCVD:
41246 break;
41247 case IB_CM_TIMEWAIT:
41248 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41249 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41250 counter[CM_DREQ_COUNTER]);
41251 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41252 goto unlock;
41253 @@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41254 cm_free_msg(msg);
41255 goto deref;
41256 case IB_CM_DREQ_RCVD:
41257 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41258 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41259 counter[CM_DREQ_COUNTER]);
41260 goto unlock;
41261 default:
41262 @@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41263 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41264 cm_id_priv->msg, timeout)) {
41265 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41266 - atomic_long_inc(&work->port->
41267 + atomic_long_inc_unchecked(&work->port->
41268 counter_group[CM_RECV_DUPLICATES].
41269 counter[CM_MRA_COUNTER]);
41270 goto out;
41271 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41272 break;
41273 case IB_CM_MRA_REQ_RCVD:
41274 case IB_CM_MRA_REP_RCVD:
41275 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41276 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41277 counter[CM_MRA_COUNTER]);
41278 /* fall through */
41279 default:
41280 @@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41281 case IB_CM_LAP_IDLE:
41282 break;
41283 case IB_CM_MRA_LAP_SENT:
41284 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41285 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41286 counter[CM_LAP_COUNTER]);
41287 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41288 goto unlock;
41289 @@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
41290 cm_free_msg(msg);
41291 goto deref;
41292 case IB_CM_LAP_RCVD:
41293 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41294 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41295 counter[CM_LAP_COUNTER]);
41296 goto unlock;
41297 default:
41298 @@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41299 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41300 if (cur_cm_id_priv) {
41301 spin_unlock_irq(&cm.lock);
41302 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41303 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41304 counter[CM_SIDR_REQ_COUNTER]);
41305 goto out; /* Duplicate message. */
41306 }
41307 @@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41308 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41309 msg->retries = 1;
41310
41311 - atomic_long_add(1 + msg->retries,
41312 + atomic_long_add_unchecked(1 + msg->retries,
41313 &port->counter_group[CM_XMIT].counter[attr_index]);
41314 if (msg->retries)
41315 - atomic_long_add(msg->retries,
41316 + atomic_long_add_unchecked(msg->retries,
41317 &port->counter_group[CM_XMIT_RETRIES].
41318 counter[attr_index]);
41319
41320 @@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41321 }
41322
41323 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41324 - atomic_long_inc(&port->counter_group[CM_RECV].
41325 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41326 counter[attr_id - CM_ATTR_ID_OFFSET]);
41327
41328 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41329 @@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41330 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
41331
41332 return sprintf(buf, "%ld\n",
41333 - atomic_long_read(&group->counter[cm_attr->index]));
41334 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
41335 }
41336
41337 static const struct sysfs_ops cm_counter_ops = {
41338 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
41339 index 9f5ad7c..588cd84 100644
41340 --- a/drivers/infiniband/core/fmr_pool.c
41341 +++ b/drivers/infiniband/core/fmr_pool.c
41342 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
41343
41344 struct task_struct *thread;
41345
41346 - atomic_t req_ser;
41347 - atomic_t flush_ser;
41348 + atomic_unchecked_t req_ser;
41349 + atomic_unchecked_t flush_ser;
41350
41351 wait_queue_head_t force_wait;
41352 };
41353 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41354 struct ib_fmr_pool *pool = pool_ptr;
41355
41356 do {
41357 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
41358 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
41359 ib_fmr_batch_release(pool);
41360
41361 - atomic_inc(&pool->flush_ser);
41362 + atomic_inc_unchecked(&pool->flush_ser);
41363 wake_up_interruptible(&pool->force_wait);
41364
41365 if (pool->flush_function)
41366 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41367 }
41368
41369 set_current_state(TASK_INTERRUPTIBLE);
41370 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
41371 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
41372 !kthread_should_stop())
41373 schedule();
41374 __set_current_state(TASK_RUNNING);
41375 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
41376 pool->dirty_watermark = params->dirty_watermark;
41377 pool->dirty_len = 0;
41378 spin_lock_init(&pool->pool_lock);
41379 - atomic_set(&pool->req_ser, 0);
41380 - atomic_set(&pool->flush_ser, 0);
41381 + atomic_set_unchecked(&pool->req_ser, 0);
41382 + atomic_set_unchecked(&pool->flush_ser, 0);
41383 init_waitqueue_head(&pool->force_wait);
41384
41385 pool->thread = kthread_run(ib_fmr_cleanup_thread,
41386 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
41387 }
41388 spin_unlock_irq(&pool->pool_lock);
41389
41390 - serial = atomic_inc_return(&pool->req_ser);
41391 + serial = atomic_inc_return_unchecked(&pool->req_ser);
41392 wake_up_process(pool->thread);
41393
41394 if (wait_event_interruptible(pool->force_wait,
41395 - atomic_read(&pool->flush_ser) - serial >= 0))
41396 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
41397 return -EINTR;
41398
41399 return 0;
41400 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
41401 } else {
41402 list_add_tail(&fmr->list, &pool->dirty_list);
41403 if (++pool->dirty_len >= pool->dirty_watermark) {
41404 - atomic_inc(&pool->req_ser);
41405 + atomic_inc_unchecked(&pool->req_ser);
41406 wake_up_process(pool->thread);
41407 }
41408 }
41409 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
41410 index 84e4500..2c9beeb 100644
41411 --- a/drivers/infiniband/hw/cxgb4/mem.c
41412 +++ b/drivers/infiniband/hw/cxgb4/mem.c
41413 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41414 int err;
41415 struct fw_ri_tpte tpt;
41416 u32 stag_idx;
41417 - static atomic_t key;
41418 + static atomic_unchecked_t key;
41419
41420 if (c4iw_fatal_error(rdev))
41421 return -EIO;
41422 @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41423 if (rdev->stats.stag.cur > rdev->stats.stag.max)
41424 rdev->stats.stag.max = rdev->stats.stag.cur;
41425 mutex_unlock(&rdev->stats.lock);
41426 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
41427 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
41428 }
41429 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
41430 __func__, stag_state, type, pdid, stag_idx);
41431 diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
41432 index 644c2c7..ecf0879 100644
41433 --- a/drivers/infiniband/hw/ipath/ipath_dma.c
41434 +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
41435 @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
41436 }
41437
41438 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
41439 - ipath_mapping_error,
41440 - ipath_dma_map_single,
41441 - ipath_dma_unmap_single,
41442 - ipath_dma_map_page,
41443 - ipath_dma_unmap_page,
41444 - ipath_map_sg,
41445 - ipath_unmap_sg,
41446 - ipath_sg_dma_address,
41447 - ipath_sg_dma_len,
41448 - ipath_sync_single_for_cpu,
41449 - ipath_sync_single_for_device,
41450 - ipath_dma_alloc_coherent,
41451 - ipath_dma_free_coherent
41452 + .mapping_error = ipath_mapping_error,
41453 + .map_single = ipath_dma_map_single,
41454 + .unmap_single = ipath_dma_unmap_single,
41455 + .map_page = ipath_dma_map_page,
41456 + .unmap_page = ipath_dma_unmap_page,
41457 + .map_sg = ipath_map_sg,
41458 + .unmap_sg = ipath_unmap_sg,
41459 + .dma_address = ipath_sg_dma_address,
41460 + .dma_len = ipath_sg_dma_len,
41461 + .sync_single_for_cpu = ipath_sync_single_for_cpu,
41462 + .sync_single_for_device = ipath_sync_single_for_device,
41463 + .alloc_coherent = ipath_dma_alloc_coherent,
41464 + .free_coherent = ipath_dma_free_coherent
41465 };
41466 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
41467 index 79b3dbc..96e5fcc 100644
41468 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
41469 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
41470 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41471 struct ib_atomic_eth *ateth;
41472 struct ipath_ack_entry *e;
41473 u64 vaddr;
41474 - atomic64_t *maddr;
41475 + atomic64_unchecked_t *maddr;
41476 u64 sdata;
41477 u32 rkey;
41478 u8 next;
41479 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41480 IB_ACCESS_REMOTE_ATOMIC)))
41481 goto nack_acc_unlck;
41482 /* Perform atomic OP and save result. */
41483 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41484 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41485 sdata = be64_to_cpu(ateth->swap_data);
41486 e = &qp->s_ack_queue[qp->r_head_ack_queue];
41487 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
41488 - (u64) atomic64_add_return(sdata, maddr) - sdata :
41489 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41490 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41491 be64_to_cpu(ateth->compare_data),
41492 sdata);
41493 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
41494 index 1f95bba..9530f87 100644
41495 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
41496 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
41497 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
41498 unsigned long flags;
41499 struct ib_wc wc;
41500 u64 sdata;
41501 - atomic64_t *maddr;
41502 + atomic64_unchecked_t *maddr;
41503 enum ib_wc_status send_status;
41504
41505 /*
41506 @@ -382,11 +382,11 @@ again:
41507 IB_ACCESS_REMOTE_ATOMIC)))
41508 goto acc_err;
41509 /* Perform atomic OP and save result. */
41510 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41511 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41512 sdata = wqe->wr.wr.atomic.compare_add;
41513 *(u64 *) sqp->s_sge.sge.vaddr =
41514 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
41515 - (u64) atomic64_add_return(sdata, maddr) - sdata :
41516 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41517 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41518 sdata, wqe->wr.wr.atomic.swap);
41519 goto send_comp;
41520 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
41521 index f2a3f48..673ec79 100644
41522 --- a/drivers/infiniband/hw/mlx4/mad.c
41523 +++ b/drivers/infiniband/hw/mlx4/mad.c
41524 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
41525
41526 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
41527 {
41528 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
41529 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
41530 cpu_to_be64(0xff00000000000000LL);
41531 }
41532
41533 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
41534 index 25b2cdf..099ff97 100644
41535 --- a/drivers/infiniband/hw/mlx4/mcg.c
41536 +++ b/drivers/infiniband/hw/mlx4/mcg.c
41537 @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
41538 {
41539 char name[20];
41540
41541 - atomic_set(&ctx->tid, 0);
41542 + atomic_set_unchecked(&ctx->tid, 0);
41543 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
41544 ctx->mcg_wq = create_singlethread_workqueue(name);
41545 if (!ctx->mcg_wq)
41546 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41547 index 036b663..c9a8c73 100644
41548 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
41549 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41550 @@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
41551 struct list_head mcg_mgid0_list;
41552 struct workqueue_struct *mcg_wq;
41553 struct mlx4_ib_demux_pv_ctx **tun;
41554 - atomic_t tid;
41555 + atomic_unchecked_t tid;
41556 int flushing; /* flushing the work queue */
41557 };
41558
41559 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
41560 index 9d3e5c1..6f166df 100644
41561 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
41562 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
41563 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
41564 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
41565 }
41566
41567 -int mthca_QUERY_FW(struct mthca_dev *dev)
41568 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
41569 {
41570 struct mthca_mailbox *mailbox;
41571 u32 *outbox;
41572 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41573 CMD_TIME_CLASS_B);
41574 }
41575
41576 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41577 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41578 int num_mtt)
41579 {
41580 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
41581 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
41582 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
41583 }
41584
41585 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41586 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41587 int eq_num)
41588 {
41589 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
41590 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
41591 CMD_TIME_CLASS_B);
41592 }
41593
41594 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41595 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41596 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
41597 void *in_mad, void *response_mad)
41598 {
41599 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
41600 index 87897b9..7e79542 100644
41601 --- a/drivers/infiniband/hw/mthca/mthca_main.c
41602 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
41603 @@ -692,7 +692,7 @@ err_close:
41604 return err;
41605 }
41606
41607 -static int mthca_setup_hca(struct mthca_dev *dev)
41608 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
41609 {
41610 int err;
41611
41612 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
41613 index ed9a989..6aa5dc2 100644
41614 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
41615 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
41616 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
41617 * through the bitmaps)
41618 */
41619
41620 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41621 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41622 {
41623 int o;
41624 int m;
41625 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
41626 return key;
41627 }
41628
41629 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41630 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41631 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
41632 {
41633 struct mthca_mailbox *mailbox;
41634 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
41635 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
41636 }
41637
41638 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41639 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41640 u64 *buffer_list, int buffer_size_shift,
41641 int list_len, u64 iova, u64 total_size,
41642 u32 access, struct mthca_mr *mr)
41643 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
41644 index 5b71d43..35a9e14 100644
41645 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
41646 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
41647 @@ -763,7 +763,7 @@ unlock:
41648 return 0;
41649 }
41650
41651 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41652 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41653 {
41654 struct mthca_dev *dev = to_mdev(ibcq->device);
41655 struct mthca_cq *cq = to_mcq(ibcq);
41656 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
41657 index 4291410..d2ab1fb 100644
41658 --- a/drivers/infiniband/hw/nes/nes.c
41659 +++ b/drivers/infiniband/hw/nes/nes.c
41660 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
41661 LIST_HEAD(nes_adapter_list);
41662 static LIST_HEAD(nes_dev_list);
41663
41664 -atomic_t qps_destroyed;
41665 +atomic_unchecked_t qps_destroyed;
41666
41667 static unsigned int ee_flsh_adapter;
41668 static unsigned int sysfs_nonidx_addr;
41669 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
41670 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
41671 struct nes_adapter *nesadapter = nesdev->nesadapter;
41672
41673 - atomic_inc(&qps_destroyed);
41674 + atomic_inc_unchecked(&qps_destroyed);
41675
41676 /* Free the control structures */
41677
41678 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
41679 index 33cc589..3bd6538 100644
41680 --- a/drivers/infiniband/hw/nes/nes.h
41681 +++ b/drivers/infiniband/hw/nes/nes.h
41682 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
41683 extern unsigned int wqm_quanta;
41684 extern struct list_head nes_adapter_list;
41685
41686 -extern atomic_t cm_connects;
41687 -extern atomic_t cm_accepts;
41688 -extern atomic_t cm_disconnects;
41689 -extern atomic_t cm_closes;
41690 -extern atomic_t cm_connecteds;
41691 -extern atomic_t cm_connect_reqs;
41692 -extern atomic_t cm_rejects;
41693 -extern atomic_t mod_qp_timouts;
41694 -extern atomic_t qps_created;
41695 -extern atomic_t qps_destroyed;
41696 -extern atomic_t sw_qps_destroyed;
41697 +extern atomic_unchecked_t cm_connects;
41698 +extern atomic_unchecked_t cm_accepts;
41699 +extern atomic_unchecked_t cm_disconnects;
41700 +extern atomic_unchecked_t cm_closes;
41701 +extern atomic_unchecked_t cm_connecteds;
41702 +extern atomic_unchecked_t cm_connect_reqs;
41703 +extern atomic_unchecked_t cm_rejects;
41704 +extern atomic_unchecked_t mod_qp_timouts;
41705 +extern atomic_unchecked_t qps_created;
41706 +extern atomic_unchecked_t qps_destroyed;
41707 +extern atomic_unchecked_t sw_qps_destroyed;
41708 extern u32 mh_detected;
41709 extern u32 mh_pauses_sent;
41710 extern u32 cm_packets_sent;
41711 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
41712 extern u32 cm_packets_received;
41713 extern u32 cm_packets_dropped;
41714 extern u32 cm_packets_retrans;
41715 -extern atomic_t cm_listens_created;
41716 -extern atomic_t cm_listens_destroyed;
41717 +extern atomic_unchecked_t cm_listens_created;
41718 +extern atomic_unchecked_t cm_listens_destroyed;
41719 extern u32 cm_backlog_drops;
41720 -extern atomic_t cm_loopbacks;
41721 -extern atomic_t cm_nodes_created;
41722 -extern atomic_t cm_nodes_destroyed;
41723 -extern atomic_t cm_accel_dropped_pkts;
41724 -extern atomic_t cm_resets_recvd;
41725 -extern atomic_t pau_qps_created;
41726 -extern atomic_t pau_qps_destroyed;
41727 +extern atomic_unchecked_t cm_loopbacks;
41728 +extern atomic_unchecked_t cm_nodes_created;
41729 +extern atomic_unchecked_t cm_nodes_destroyed;
41730 +extern atomic_unchecked_t cm_accel_dropped_pkts;
41731 +extern atomic_unchecked_t cm_resets_recvd;
41732 +extern atomic_unchecked_t pau_qps_created;
41733 +extern atomic_unchecked_t pau_qps_destroyed;
41734
41735 extern u32 int_mod_timer_init;
41736 extern u32 int_mod_cq_depth_256;
41737 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
41738 index 6b29249..461d143 100644
41739 --- a/drivers/infiniband/hw/nes/nes_cm.c
41740 +++ b/drivers/infiniband/hw/nes/nes_cm.c
41741 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
41742 u32 cm_packets_retrans;
41743 u32 cm_packets_created;
41744 u32 cm_packets_received;
41745 -atomic_t cm_listens_created;
41746 -atomic_t cm_listens_destroyed;
41747 +atomic_unchecked_t cm_listens_created;
41748 +atomic_unchecked_t cm_listens_destroyed;
41749 u32 cm_backlog_drops;
41750 -atomic_t cm_loopbacks;
41751 -atomic_t cm_nodes_created;
41752 -atomic_t cm_nodes_destroyed;
41753 -atomic_t cm_accel_dropped_pkts;
41754 -atomic_t cm_resets_recvd;
41755 +atomic_unchecked_t cm_loopbacks;
41756 +atomic_unchecked_t cm_nodes_created;
41757 +atomic_unchecked_t cm_nodes_destroyed;
41758 +atomic_unchecked_t cm_accel_dropped_pkts;
41759 +atomic_unchecked_t cm_resets_recvd;
41760
41761 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
41762 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
41763 @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
41764 /* instance of function pointers for client API */
41765 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
41766 static struct nes_cm_ops nes_cm_api = {
41767 - mini_cm_accelerated,
41768 - mini_cm_listen,
41769 - mini_cm_del_listen,
41770 - mini_cm_connect,
41771 - mini_cm_close,
41772 - mini_cm_accept,
41773 - mini_cm_reject,
41774 - mini_cm_recv_pkt,
41775 - mini_cm_dealloc_core,
41776 - mini_cm_get,
41777 - mini_cm_set
41778 + .accelerated = mini_cm_accelerated,
41779 + .listen = mini_cm_listen,
41780 + .stop_listener = mini_cm_del_listen,
41781 + .connect = mini_cm_connect,
41782 + .close = mini_cm_close,
41783 + .accept = mini_cm_accept,
41784 + .reject = mini_cm_reject,
41785 + .recv_pkt = mini_cm_recv_pkt,
41786 + .destroy_cm_core = mini_cm_dealloc_core,
41787 + .get = mini_cm_get,
41788 + .set = mini_cm_set
41789 };
41790
41791 static struct nes_cm_core *g_cm_core;
41792
41793 -atomic_t cm_connects;
41794 -atomic_t cm_accepts;
41795 -atomic_t cm_disconnects;
41796 -atomic_t cm_closes;
41797 -atomic_t cm_connecteds;
41798 -atomic_t cm_connect_reqs;
41799 -atomic_t cm_rejects;
41800 +atomic_unchecked_t cm_connects;
41801 +atomic_unchecked_t cm_accepts;
41802 +atomic_unchecked_t cm_disconnects;
41803 +atomic_unchecked_t cm_closes;
41804 +atomic_unchecked_t cm_connecteds;
41805 +atomic_unchecked_t cm_connect_reqs;
41806 +atomic_unchecked_t cm_rejects;
41807
41808 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
41809 {
41810 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
41811 kfree(listener);
41812 listener = NULL;
41813 ret = 0;
41814 - atomic_inc(&cm_listens_destroyed);
41815 + atomic_inc_unchecked(&cm_listens_destroyed);
41816 } else {
41817 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
41818 }
41819 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
41820 cm_node->rem_mac);
41821
41822 add_hte_node(cm_core, cm_node);
41823 - atomic_inc(&cm_nodes_created);
41824 + atomic_inc_unchecked(&cm_nodes_created);
41825
41826 return cm_node;
41827 }
41828 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
41829 }
41830
41831 atomic_dec(&cm_core->node_cnt);
41832 - atomic_inc(&cm_nodes_destroyed);
41833 + atomic_inc_unchecked(&cm_nodes_destroyed);
41834 nesqp = cm_node->nesqp;
41835 if (nesqp) {
41836 nesqp->cm_node = NULL;
41837 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
41838
41839 static void drop_packet(struct sk_buff *skb)
41840 {
41841 - atomic_inc(&cm_accel_dropped_pkts);
41842 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
41843 dev_kfree_skb_any(skb);
41844 }
41845
41846 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
41847 {
41848
41849 int reset = 0; /* whether to send reset in case of err.. */
41850 - atomic_inc(&cm_resets_recvd);
41851 + atomic_inc_unchecked(&cm_resets_recvd);
41852 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
41853 " refcnt=%d\n", cm_node, cm_node->state,
41854 atomic_read(&cm_node->ref_count));
41855 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
41856 rem_ref_cm_node(cm_node->cm_core, cm_node);
41857 return NULL;
41858 }
41859 - atomic_inc(&cm_loopbacks);
41860 + atomic_inc_unchecked(&cm_loopbacks);
41861 loopbackremotenode->loopbackpartner = cm_node;
41862 loopbackremotenode->tcp_cntxt.rcv_wscale =
41863 NES_CM_DEFAULT_RCV_WND_SCALE;
41864 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
41865 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
41866 else {
41867 rem_ref_cm_node(cm_core, cm_node);
41868 - atomic_inc(&cm_accel_dropped_pkts);
41869 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
41870 dev_kfree_skb_any(skb);
41871 }
41872 break;
41873 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41874
41875 if ((cm_id) && (cm_id->event_handler)) {
41876 if (issue_disconn) {
41877 - atomic_inc(&cm_disconnects);
41878 + atomic_inc_unchecked(&cm_disconnects);
41879 cm_event.event = IW_CM_EVENT_DISCONNECT;
41880 cm_event.status = disconn_status;
41881 cm_event.local_addr = cm_id->local_addr;
41882 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
41883 }
41884
41885 if (issue_close) {
41886 - atomic_inc(&cm_closes);
41887 + atomic_inc_unchecked(&cm_closes);
41888 nes_disconnect(nesqp, 1);
41889
41890 cm_id->provider_data = nesqp;
41891 @@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41892
41893 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
41894 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
41895 - atomic_inc(&cm_accepts);
41896 + atomic_inc_unchecked(&cm_accepts);
41897
41898 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
41899 netdev_refcnt_read(nesvnic->netdev));
41900 @@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
41901 struct nes_cm_core *cm_core;
41902 u8 *start_buff;
41903
41904 - atomic_inc(&cm_rejects);
41905 + atomic_inc_unchecked(&cm_rejects);
41906 cm_node = (struct nes_cm_node *)cm_id->provider_data;
41907 loopback = cm_node->loopbackpartner;
41908 cm_core = cm_node->cm_core;
41909 @@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
41910 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
41911 ntohs(laddr->sin_port));
41912
41913 - atomic_inc(&cm_connects);
41914 + atomic_inc_unchecked(&cm_connects);
41915 nesqp->active_conn = 1;
41916
41917 /* cache the cm_id in the qp */
41918 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
41919 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
41920 return err;
41921 }
41922 - atomic_inc(&cm_listens_created);
41923 + atomic_inc_unchecked(&cm_listens_created);
41924 }
41925
41926 cm_id->add_ref(cm_id);
41927 @@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
41928
41929 if (nesqp->destroyed)
41930 return;
41931 - atomic_inc(&cm_connecteds);
41932 + atomic_inc_unchecked(&cm_connecteds);
41933 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
41934 " local port 0x%04X. jiffies = %lu.\n",
41935 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
41936 @@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
41937
41938 cm_id->add_ref(cm_id);
41939 ret = cm_id->event_handler(cm_id, &cm_event);
41940 - atomic_inc(&cm_closes);
41941 + atomic_inc_unchecked(&cm_closes);
41942 cm_event.event = IW_CM_EVENT_CLOSE;
41943 cm_event.status = 0;
41944 cm_event.provider_data = cm_id->provider_data;
41945 @@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
41946 return;
41947 cm_id = cm_node->cm_id;
41948
41949 - atomic_inc(&cm_connect_reqs);
41950 + atomic_inc_unchecked(&cm_connect_reqs);
41951 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41952 cm_node, cm_id, jiffies);
41953
41954 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
41955 return;
41956 cm_id = cm_node->cm_id;
41957
41958 - atomic_inc(&cm_connect_reqs);
41959 + atomic_inc_unchecked(&cm_connect_reqs);
41960 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41961 cm_node, cm_id, jiffies);
41962
41963 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
41964 index 4166452..fc952c3 100644
41965 --- a/drivers/infiniband/hw/nes/nes_mgt.c
41966 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
41967 @@ -40,8 +40,8 @@
41968 #include "nes.h"
41969 #include "nes_mgt.h"
41970
41971 -atomic_t pau_qps_created;
41972 -atomic_t pau_qps_destroyed;
41973 +atomic_unchecked_t pau_qps_created;
41974 +atomic_unchecked_t pau_qps_destroyed;
41975
41976 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
41977 {
41978 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
41979 {
41980 struct sk_buff *skb;
41981 unsigned long flags;
41982 - atomic_inc(&pau_qps_destroyed);
41983 + atomic_inc_unchecked(&pau_qps_destroyed);
41984
41985 /* Free packets that have not yet been forwarded */
41986 /* Lock is acquired by skb_dequeue when removing the skb */
41987 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
41988 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
41989 skb_queue_head_init(&nesqp->pau_list);
41990 spin_lock_init(&nesqp->pau_lock);
41991 - atomic_inc(&pau_qps_created);
41992 + atomic_inc_unchecked(&pau_qps_created);
41993 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
41994 }
41995
41996 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
41997 index 49eb511..a774366 100644
41998 --- a/drivers/infiniband/hw/nes/nes_nic.c
41999 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42000 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42001 target_stat_values[++index] = mh_detected;
42002 target_stat_values[++index] = mh_pauses_sent;
42003 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42004 - target_stat_values[++index] = atomic_read(&cm_connects);
42005 - target_stat_values[++index] = atomic_read(&cm_accepts);
42006 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42007 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42008 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42009 - target_stat_values[++index] = atomic_read(&cm_rejects);
42010 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42011 - target_stat_values[++index] = atomic_read(&qps_created);
42012 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42013 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42014 - target_stat_values[++index] = atomic_read(&cm_closes);
42015 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42016 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42017 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42018 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42019 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42020 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42021 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42022 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42023 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42024 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42025 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42026 target_stat_values[++index] = cm_packets_sent;
42027 target_stat_values[++index] = cm_packets_bounced;
42028 target_stat_values[++index] = cm_packets_created;
42029 target_stat_values[++index] = cm_packets_received;
42030 target_stat_values[++index] = cm_packets_dropped;
42031 target_stat_values[++index] = cm_packets_retrans;
42032 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42033 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42034 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42035 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42036 target_stat_values[++index] = cm_backlog_drops;
42037 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42038 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42039 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42040 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42041 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42042 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42043 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42044 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42045 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42046 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42047 target_stat_values[++index] = nesadapter->free_4kpbl;
42048 target_stat_values[++index] = nesadapter->free_256pbl;
42049 target_stat_values[++index] = int_mod_timer_init;
42050 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42051 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42052 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42053 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42054 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42055 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42056 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42057 }
42058
42059 /**
42060 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42061 index 8308e36..ae0d3b5 100644
42062 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42063 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42064 @@ -46,9 +46,9 @@
42065
42066 #include <rdma/ib_umem.h>
42067
42068 -atomic_t mod_qp_timouts;
42069 -atomic_t qps_created;
42070 -atomic_t sw_qps_destroyed;
42071 +atomic_unchecked_t mod_qp_timouts;
42072 +atomic_unchecked_t qps_created;
42073 +atomic_unchecked_t sw_qps_destroyed;
42074
42075 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42076
42077 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42078 if (init_attr->create_flags)
42079 return ERR_PTR(-EINVAL);
42080
42081 - atomic_inc(&qps_created);
42082 + atomic_inc_unchecked(&qps_created);
42083 switch (init_attr->qp_type) {
42084 case IB_QPT_RC:
42085 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42086 @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42087 struct iw_cm_event cm_event;
42088 int ret = 0;
42089
42090 - atomic_inc(&sw_qps_destroyed);
42091 + atomic_inc_unchecked(&sw_qps_destroyed);
42092 nesqp->destroyed = 1;
42093
42094 /* Blow away the connection if it exists. */
42095 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42096 index 1946101..09766d2 100644
42097 --- a/drivers/infiniband/hw/qib/qib.h
42098 +++ b/drivers/infiniband/hw/qib/qib.h
42099 @@ -52,6 +52,7 @@
42100 #include <linux/kref.h>
42101 #include <linux/sched.h>
42102 #include <linux/kthread.h>
42103 +#include <linux/slab.h>
42104
42105 #include "qib_common.h"
42106 #include "qib_verbs.h"
42107 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42108 index 24c41ba..102d71f 100644
42109 --- a/drivers/input/gameport/gameport.c
42110 +++ b/drivers/input/gameport/gameport.c
42111 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42112 */
42113 static void gameport_init_port(struct gameport *gameport)
42114 {
42115 - static atomic_t gameport_no = ATOMIC_INIT(0);
42116 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42117
42118 __module_get(THIS_MODULE);
42119
42120 mutex_init(&gameport->drv_mutex);
42121 device_initialize(&gameport->dev);
42122 dev_set_name(&gameport->dev, "gameport%lu",
42123 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42124 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42125 gameport->dev.bus = &gameport_bus;
42126 gameport->dev.release = gameport_release_port;
42127 if (gameport->parent)
42128 diff --git a/drivers/input/input.c b/drivers/input/input.c
42129 index d2965e4..f52b7d7 100644
42130 --- a/drivers/input/input.c
42131 +++ b/drivers/input/input.c
42132 @@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42133 */
42134 struct input_dev *input_allocate_device(void)
42135 {
42136 - static atomic_t input_no = ATOMIC_INIT(0);
42137 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42138 struct input_dev *dev;
42139
42140 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42141 @@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42142 INIT_LIST_HEAD(&dev->node);
42143
42144 dev_set_name(&dev->dev, "input%ld",
42145 - (unsigned long) atomic_inc_return(&input_no) - 1);
42146 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42147
42148 __module_get(THIS_MODULE);
42149 }
42150 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42151 index 04c69af..5f92d00 100644
42152 --- a/drivers/input/joystick/sidewinder.c
42153 +++ b/drivers/input/joystick/sidewinder.c
42154 @@ -30,6 +30,7 @@
42155 #include <linux/kernel.h>
42156 #include <linux/module.h>
42157 #include <linux/slab.h>
42158 +#include <linux/sched.h>
42159 #include <linux/init.h>
42160 #include <linux/input.h>
42161 #include <linux/gameport.h>
42162 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42163 index 75e3b10..fb390fd 100644
42164 --- a/drivers/input/joystick/xpad.c
42165 +++ b/drivers/input/joystick/xpad.c
42166 @@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42167
42168 static int xpad_led_probe(struct usb_xpad *xpad)
42169 {
42170 - static atomic_t led_seq = ATOMIC_INIT(0);
42171 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42172 long led_no;
42173 struct xpad_led *led;
42174 struct led_classdev *led_cdev;
42175 @@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42176 if (!led)
42177 return -ENOMEM;
42178
42179 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42180 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42181
42182 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42183 led->xpad = xpad;
42184 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42185 index e204f26..8459f15 100644
42186 --- a/drivers/input/misc/ims-pcu.c
42187 +++ b/drivers/input/misc/ims-pcu.c
42188 @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42189
42190 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42191 {
42192 - static atomic_t device_no = ATOMIC_INIT(0);
42193 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42194
42195 const struct ims_pcu_device_info *info;
42196 u8 device_id;
42197 @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42198 }
42199
42200 /* Device appears to be operable, complete initialization */
42201 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42202 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42203
42204 error = ims_pcu_setup_backlight(pcu);
42205 if (error)
42206 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42207 index 2f0b39d..7370f13 100644
42208 --- a/drivers/input/mouse/psmouse.h
42209 +++ b/drivers/input/mouse/psmouse.h
42210 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42211 ssize_t (*set)(struct psmouse *psmouse, void *data,
42212 const char *buf, size_t count);
42213 bool protect;
42214 -};
42215 +} __do_const;
42216 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42217
42218 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42219 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42220 index 4c842c3..590b0bf 100644
42221 --- a/drivers/input/mousedev.c
42222 +++ b/drivers/input/mousedev.c
42223 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42224
42225 spin_unlock_irq(&client->packet_lock);
42226
42227 - if (copy_to_user(buffer, data, count))
42228 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42229 return -EFAULT;
42230
42231 return count;
42232 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42233 index 8f4c4ab..5fc8a45 100644
42234 --- a/drivers/input/serio/serio.c
42235 +++ b/drivers/input/serio/serio.c
42236 @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42237 */
42238 static void serio_init_port(struct serio *serio)
42239 {
42240 - static atomic_t serio_no = ATOMIC_INIT(0);
42241 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42242
42243 __module_get(THIS_MODULE);
42244
42245 @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42246 mutex_init(&serio->drv_mutex);
42247 device_initialize(&serio->dev);
42248 dev_set_name(&serio->dev, "serio%ld",
42249 - (long)atomic_inc_return(&serio_no) - 1);
42250 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42251 serio->dev.bus = &serio_bus;
42252 serio->dev.release = serio_release_port;
42253 serio->dev.groups = serio_device_attr_groups;
42254 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42255 index 59df2e7..8f1cafb 100644
42256 --- a/drivers/input/serio/serio_raw.c
42257 +++ b/drivers/input/serio/serio_raw.c
42258 @@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42259
42260 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42261 {
42262 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
42263 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42264 struct serio_raw *serio_raw;
42265 int err;
42266
42267 @@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42268 }
42269
42270 snprintf(serio_raw->name, sizeof(serio_raw->name),
42271 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42272 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42273 kref_init(&serio_raw->kref);
42274 INIT_LIST_HEAD(&serio_raw->client_list);
42275 init_waitqueue_head(&serio_raw->wait);
42276 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42277 index e5555fc..937986d 100644
42278 --- a/drivers/iommu/iommu.c
42279 +++ b/drivers/iommu/iommu.c
42280 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42281 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42282 {
42283 bus_register_notifier(bus, &iommu_bus_nb);
42284 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42285 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42286 }
42287
42288 /**
42289 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42290 index 39f81ae..2660096 100644
42291 --- a/drivers/iommu/irq_remapping.c
42292 +++ b/drivers/iommu/irq_remapping.c
42293 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42294 void panic_if_irq_remap(const char *msg)
42295 {
42296 if (irq_remapping_enabled)
42297 - panic(msg);
42298 + panic("%s", msg);
42299 }
42300
42301 static void ir_ack_apic_edge(struct irq_data *data)
42302 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42303
42304 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42305 {
42306 - chip->irq_print_chip = ir_print_prefix;
42307 - chip->irq_ack = ir_ack_apic_edge;
42308 - chip->irq_eoi = ir_ack_apic_level;
42309 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42310 + pax_open_kernel();
42311 + *(void **)&chip->irq_print_chip = ir_print_prefix;
42312 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
42313 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
42314 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42315 + pax_close_kernel();
42316 }
42317
42318 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42319 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42320 index 341c601..e5f407e 100644
42321 --- a/drivers/irqchip/irq-gic.c
42322 +++ b/drivers/irqchip/irq-gic.c
42323 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42324 * Supported arch specific GIC irq extension.
42325 * Default make them NULL.
42326 */
42327 -struct irq_chip gic_arch_extn = {
42328 +irq_chip_no_const gic_arch_extn = {
42329 .irq_eoi = NULL,
42330 .irq_mask = NULL,
42331 .irq_unmask = NULL,
42332 @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
42333 chained_irq_exit(chip, desc);
42334 }
42335
42336 -static struct irq_chip gic_chip = {
42337 +static irq_chip_no_const gic_chip __read_only = {
42338 .name = "GIC",
42339 .irq_mask = gic_mask_irq,
42340 .irq_unmask = gic_unmask_irq,
42341 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
42342 index ac6f72b..81150f2 100644
42343 --- a/drivers/isdn/capi/capi.c
42344 +++ b/drivers/isdn/capi/capi.c
42345 @@ -81,8 +81,8 @@ struct capiminor {
42346
42347 struct capi20_appl *ap;
42348 u32 ncci;
42349 - atomic_t datahandle;
42350 - atomic_t msgid;
42351 + atomic_unchecked_t datahandle;
42352 + atomic_unchecked_t msgid;
42353
42354 struct tty_port port;
42355 int ttyinstop;
42356 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
42357 capimsg_setu16(s, 2, mp->ap->applid);
42358 capimsg_setu8 (s, 4, CAPI_DATA_B3);
42359 capimsg_setu8 (s, 5, CAPI_RESP);
42360 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
42361 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
42362 capimsg_setu32(s, 8, mp->ncci);
42363 capimsg_setu16(s, 12, datahandle);
42364 }
42365 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
42366 mp->outbytes -= len;
42367 spin_unlock_bh(&mp->outlock);
42368
42369 - datahandle = atomic_inc_return(&mp->datahandle);
42370 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
42371 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
42372 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42373 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42374 capimsg_setu16(skb->data, 2, mp->ap->applid);
42375 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
42376 capimsg_setu8 (skb->data, 5, CAPI_REQ);
42377 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
42378 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
42379 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
42380 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
42381 capimsg_setu16(skb->data, 16, len); /* Data length */
42382 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
42383 index c44950d..10ac276 100644
42384 --- a/drivers/isdn/gigaset/bas-gigaset.c
42385 +++ b/drivers/isdn/gigaset/bas-gigaset.c
42386 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
42387
42388
42389 static const struct gigaset_ops gigops = {
42390 - gigaset_write_cmd,
42391 - gigaset_write_room,
42392 - gigaset_chars_in_buffer,
42393 - gigaset_brkchars,
42394 - gigaset_init_bchannel,
42395 - gigaset_close_bchannel,
42396 - gigaset_initbcshw,
42397 - gigaset_freebcshw,
42398 - gigaset_reinitbcshw,
42399 - gigaset_initcshw,
42400 - gigaset_freecshw,
42401 - gigaset_set_modem_ctrl,
42402 - gigaset_baud_rate,
42403 - gigaset_set_line_ctrl,
42404 - gigaset_isoc_send_skb,
42405 - gigaset_isoc_input,
42406 + .write_cmd = gigaset_write_cmd,
42407 + .write_room = gigaset_write_room,
42408 + .chars_in_buffer = gigaset_chars_in_buffer,
42409 + .brkchars = gigaset_brkchars,
42410 + .init_bchannel = gigaset_init_bchannel,
42411 + .close_bchannel = gigaset_close_bchannel,
42412 + .initbcshw = gigaset_initbcshw,
42413 + .freebcshw = gigaset_freebcshw,
42414 + .reinitbcshw = gigaset_reinitbcshw,
42415 + .initcshw = gigaset_initcshw,
42416 + .freecshw = gigaset_freecshw,
42417 + .set_modem_ctrl = gigaset_set_modem_ctrl,
42418 + .baud_rate = gigaset_baud_rate,
42419 + .set_line_ctrl = gigaset_set_line_ctrl,
42420 + .send_skb = gigaset_isoc_send_skb,
42421 + .handle_input = gigaset_isoc_input,
42422 };
42423
42424 /* bas_gigaset_init
42425 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
42426 index 600c79b..3752bab 100644
42427 --- a/drivers/isdn/gigaset/interface.c
42428 +++ b/drivers/isdn/gigaset/interface.c
42429 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
42430 }
42431 tty->driver_data = cs;
42432
42433 - ++cs->port.count;
42434 + atomic_inc(&cs->port.count);
42435
42436 - if (cs->port.count == 1) {
42437 + if (atomic_read(&cs->port.count) == 1) {
42438 tty_port_tty_set(&cs->port, tty);
42439 cs->port.low_latency = 1;
42440 }
42441 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
42442
42443 if (!cs->connected)
42444 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
42445 - else if (!cs->port.count)
42446 + else if (!atomic_read(&cs->port.count))
42447 dev_warn(cs->dev, "%s: device not opened\n", __func__);
42448 - else if (!--cs->port.count)
42449 + else if (!atomic_dec_return(&cs->port.count))
42450 tty_port_tty_set(&cs->port, NULL);
42451
42452 mutex_unlock(&cs->mutex);
42453 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
42454 index 8c91fd5..14f13ce 100644
42455 --- a/drivers/isdn/gigaset/ser-gigaset.c
42456 +++ b/drivers/isdn/gigaset/ser-gigaset.c
42457 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
42458 }
42459
42460 static const struct gigaset_ops ops = {
42461 - gigaset_write_cmd,
42462 - gigaset_write_room,
42463 - gigaset_chars_in_buffer,
42464 - gigaset_brkchars,
42465 - gigaset_init_bchannel,
42466 - gigaset_close_bchannel,
42467 - gigaset_initbcshw,
42468 - gigaset_freebcshw,
42469 - gigaset_reinitbcshw,
42470 - gigaset_initcshw,
42471 - gigaset_freecshw,
42472 - gigaset_set_modem_ctrl,
42473 - gigaset_baud_rate,
42474 - gigaset_set_line_ctrl,
42475 - gigaset_m10x_send_skb, /* asyncdata.c */
42476 - gigaset_m10x_input, /* asyncdata.c */
42477 + .write_cmd = gigaset_write_cmd,
42478 + .write_room = gigaset_write_room,
42479 + .chars_in_buffer = gigaset_chars_in_buffer,
42480 + .brkchars = gigaset_brkchars,
42481 + .init_bchannel = gigaset_init_bchannel,
42482 + .close_bchannel = gigaset_close_bchannel,
42483 + .initbcshw = gigaset_initbcshw,
42484 + .freebcshw = gigaset_freebcshw,
42485 + .reinitbcshw = gigaset_reinitbcshw,
42486 + .initcshw = gigaset_initcshw,
42487 + .freecshw = gigaset_freecshw,
42488 + .set_modem_ctrl = gigaset_set_modem_ctrl,
42489 + .baud_rate = gigaset_baud_rate,
42490 + .set_line_ctrl = gigaset_set_line_ctrl,
42491 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
42492 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
42493 };
42494
42495
42496 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
42497 index d0a41cb..b953e50 100644
42498 --- a/drivers/isdn/gigaset/usb-gigaset.c
42499 +++ b/drivers/isdn/gigaset/usb-gigaset.c
42500 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
42501 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
42502 memcpy(cs->hw.usb->bchars, buf, 6);
42503 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
42504 - 0, 0, &buf, 6, 2000);
42505 + 0, 0, buf, 6, 2000);
42506 }
42507
42508 static void gigaset_freebcshw(struct bc_state *bcs)
42509 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
42510 }
42511
42512 static const struct gigaset_ops ops = {
42513 - gigaset_write_cmd,
42514 - gigaset_write_room,
42515 - gigaset_chars_in_buffer,
42516 - gigaset_brkchars,
42517 - gigaset_init_bchannel,
42518 - gigaset_close_bchannel,
42519 - gigaset_initbcshw,
42520 - gigaset_freebcshw,
42521 - gigaset_reinitbcshw,
42522 - gigaset_initcshw,
42523 - gigaset_freecshw,
42524 - gigaset_set_modem_ctrl,
42525 - gigaset_baud_rate,
42526 - gigaset_set_line_ctrl,
42527 - gigaset_m10x_send_skb,
42528 - gigaset_m10x_input,
42529 + .write_cmd = gigaset_write_cmd,
42530 + .write_room = gigaset_write_room,
42531 + .chars_in_buffer = gigaset_chars_in_buffer,
42532 + .brkchars = gigaset_brkchars,
42533 + .init_bchannel = gigaset_init_bchannel,
42534 + .close_bchannel = gigaset_close_bchannel,
42535 + .initbcshw = gigaset_initbcshw,
42536 + .freebcshw = gigaset_freebcshw,
42537 + .reinitbcshw = gigaset_reinitbcshw,
42538 + .initcshw = gigaset_initcshw,
42539 + .freecshw = gigaset_freecshw,
42540 + .set_modem_ctrl = gigaset_set_modem_ctrl,
42541 + .baud_rate = gigaset_baud_rate,
42542 + .set_line_ctrl = gigaset_set_line_ctrl,
42543 + .send_skb = gigaset_m10x_send_skb,
42544 + .handle_input = gigaset_m10x_input,
42545 };
42546
42547 /*
42548 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
42549 index 4d9b195..455075c 100644
42550 --- a/drivers/isdn/hardware/avm/b1.c
42551 +++ b/drivers/isdn/hardware/avm/b1.c
42552 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
42553 }
42554 if (left) {
42555 if (t4file->user) {
42556 - if (copy_from_user(buf, dp, left))
42557 + if (left > sizeof buf || copy_from_user(buf, dp, left))
42558 return -EFAULT;
42559 } else {
42560 memcpy(buf, dp, left);
42561 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
42562 }
42563 if (left) {
42564 if (config->user) {
42565 - if (copy_from_user(buf, dp, left))
42566 + if (left > sizeof buf || copy_from_user(buf, dp, left))
42567 return -EFAULT;
42568 } else {
42569 memcpy(buf, dp, left);
42570 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42571 index 9bb12ba..d4262f7 100644
42572 --- a/drivers/isdn/i4l/isdn_common.c
42573 +++ b/drivers/isdn/i4l/isdn_common.c
42574 @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42575 } else
42576 return -EINVAL;
42577 case IIOCDBGVAR:
42578 + if (!capable(CAP_SYS_RAWIO))
42579 + return -EPERM;
42580 if (arg) {
42581 if (copy_to_user(argp, &dev, sizeof(ulong)))
42582 return -EFAULT;
42583 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
42584 index 91d5730..336523e 100644
42585 --- a/drivers/isdn/i4l/isdn_concap.c
42586 +++ b/drivers/isdn/i4l/isdn_concap.c
42587 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
42588 }
42589
42590 struct concap_device_ops isdn_concap_reliable_dl_dops = {
42591 - &isdn_concap_dl_data_req,
42592 - &isdn_concap_dl_connect_req,
42593 - &isdn_concap_dl_disconn_req
42594 + .data_req = &isdn_concap_dl_data_req,
42595 + .connect_req = &isdn_concap_dl_connect_req,
42596 + .disconn_req = &isdn_concap_dl_disconn_req
42597 };
42598
42599 /* The following should better go into a dedicated source file such that
42600 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42601 index 3c5f249..5fac4d0 100644
42602 --- a/drivers/isdn/i4l/isdn_tty.c
42603 +++ b/drivers/isdn/i4l/isdn_tty.c
42604 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42605
42606 #ifdef ISDN_DEBUG_MODEM_OPEN
42607 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42608 - port->count);
42609 + atomic_read(&port->count));
42610 #endif
42611 - port->count++;
42612 + atomic_inc(&port->count);
42613 port->tty = tty;
42614 /*
42615 * Start up serial port
42616 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42617 #endif
42618 return;
42619 }
42620 - if ((tty->count == 1) && (port->count != 1)) {
42621 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42622 /*
42623 * Uh, oh. tty->count is 1, which means that the tty
42624 * structure will be freed. Info->count should always
42625 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42626 * serial port won't be shutdown.
42627 */
42628 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42629 - "info->count is %d\n", port->count);
42630 - port->count = 1;
42631 + "info->count is %d\n", atomic_read(&port->count));
42632 + atomic_set(&port->count, 1);
42633 }
42634 - if (--port->count < 0) {
42635 + if (atomic_dec_return(&port->count) < 0) {
42636 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42637 - info->line, port->count);
42638 - port->count = 0;
42639 + info->line, atomic_read(&port->count));
42640 + atomic_set(&port->count, 0);
42641 }
42642 - if (port->count) {
42643 + if (atomic_read(&port->count)) {
42644 #ifdef ISDN_DEBUG_MODEM_OPEN
42645 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42646 #endif
42647 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42648 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42649 return;
42650 isdn_tty_shutdown(info);
42651 - port->count = 0;
42652 + atomic_set(&port->count, 0);
42653 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42654 port->tty = NULL;
42655 wake_up_interruptible(&port->open_wait);
42656 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42657 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42658 modem_info *info = &dev->mdm.info[i];
42659
42660 - if (info->port.count == 0)
42661 + if (atomic_read(&info->port.count) == 0)
42662 continue;
42663 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42664 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42665 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
42666 index e2d4e58..40cd045 100644
42667 --- a/drivers/isdn/i4l/isdn_x25iface.c
42668 +++ b/drivers/isdn/i4l/isdn_x25iface.c
42669 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
42670
42671
42672 static struct concap_proto_ops ix25_pops = {
42673 - &isdn_x25iface_proto_new,
42674 - &isdn_x25iface_proto_del,
42675 - &isdn_x25iface_proto_restart,
42676 - &isdn_x25iface_proto_close,
42677 - &isdn_x25iface_xmit,
42678 - &isdn_x25iface_receive,
42679 - &isdn_x25iface_connect_ind,
42680 - &isdn_x25iface_disconn_ind
42681 + .proto_new = &isdn_x25iface_proto_new,
42682 + .proto_del = &isdn_x25iface_proto_del,
42683 + .restart = &isdn_x25iface_proto_restart,
42684 + .close = &isdn_x25iface_proto_close,
42685 + .encap_and_xmit = &isdn_x25iface_xmit,
42686 + .data_ind = &isdn_x25iface_receive,
42687 + .connect_ind = &isdn_x25iface_connect_ind,
42688 + .disconn_ind = &isdn_x25iface_disconn_ind
42689 };
42690
42691 /* error message helper function */
42692 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42693 index 53d487f..f020f41 100644
42694 --- a/drivers/isdn/icn/icn.c
42695 +++ b/drivers/isdn/icn/icn.c
42696 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42697 if (count > len)
42698 count = len;
42699 if (user) {
42700 - if (copy_from_user(msg, buf, count))
42701 + if (count > sizeof msg || copy_from_user(msg, buf, count))
42702 return -EFAULT;
42703 } else
42704 memcpy(msg, buf, count);
42705 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
42706 index a4f05c5..1433bc5 100644
42707 --- a/drivers/isdn/mISDN/dsp_cmx.c
42708 +++ b/drivers/isdn/mISDN/dsp_cmx.c
42709 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
42710 static u16 dsp_count; /* last sample count */
42711 static int dsp_count_valid; /* if we have last sample count */
42712
42713 -void
42714 +void __intentional_overflow(-1)
42715 dsp_cmx_send(void *arg)
42716 {
42717 struct dsp_conf *conf;
42718 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42719 index d93e245..e7ece6b 100644
42720 --- a/drivers/leds/leds-clevo-mail.c
42721 +++ b/drivers/leds/leds-clevo-mail.c
42722 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42723 * detected as working, but in reality it is not) as low as
42724 * possible.
42725 */
42726 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
42727 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
42728 {
42729 .callback = clevo_mail_led_dmi_callback,
42730 .ident = "Clevo D410J",
42731 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42732 index 5b8f938..b73d657 100644
42733 --- a/drivers/leds/leds-ss4200.c
42734 +++ b/drivers/leds/leds-ss4200.c
42735 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42736 * detected as working, but in reality it is not) as low as
42737 * possible.
42738 */
42739 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
42740 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
42741 {
42742 .callback = ss4200_led_dmi_callback,
42743 .ident = "Intel SS4200-E",
42744 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42745 index 0bf1e4e..b4bf44e 100644
42746 --- a/drivers/lguest/core.c
42747 +++ b/drivers/lguest/core.c
42748 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
42749 * The end address needs +1 because __get_vm_area allocates an
42750 * extra guard page, so we need space for that.
42751 */
42752 +
42753 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42754 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42755 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42756 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42757 +#else
42758 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42759 VM_ALLOC, switcher_addr, switcher_addr
42760 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42761 +#endif
42762 +
42763 if (!switcher_vma) {
42764 err = -ENOMEM;
42765 printk("lguest: could not map switcher pages high\n");
42766 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
42767 * Now the Switcher is mapped at the right address, we can't fail!
42768 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42769 */
42770 - memcpy(switcher_vma->addr, start_switcher_text,
42771 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42772 end_switcher_text - start_switcher_text);
42773
42774 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42775 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42776 index bfb39bb..08a603b 100644
42777 --- a/drivers/lguest/page_tables.c
42778 +++ b/drivers/lguest/page_tables.c
42779 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42780 /*:*/
42781
42782 #ifdef CONFIG_X86_PAE
42783 -static void release_pmd(pmd_t *spmd)
42784 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42785 {
42786 /* If the entry's not present, there's nothing to release. */
42787 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42788 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42789 index 922a1ac..9dd0c2a 100644
42790 --- a/drivers/lguest/x86/core.c
42791 +++ b/drivers/lguest/x86/core.c
42792 @@ -59,7 +59,7 @@ static struct {
42793 /* Offset from where switcher.S was compiled to where we've copied it */
42794 static unsigned long switcher_offset(void)
42795 {
42796 - return switcher_addr - (unsigned long)start_switcher_text;
42797 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42798 }
42799
42800 /* This cpu's struct lguest_pages (after the Switcher text page) */
42801 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42802 * These copies are pretty cheap, so we do them unconditionally: */
42803 /* Save the current Host top-level page directory.
42804 */
42805 +
42806 +#ifdef CONFIG_PAX_PER_CPU_PGD
42807 + pages->state.host_cr3 = read_cr3();
42808 +#else
42809 pages->state.host_cr3 = __pa(current->mm->pgd);
42810 +#endif
42811 +
42812 /*
42813 * Set up the Guest's page tables to see this CPU's pages (and no
42814 * other CPU's pages).
42815 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
42816 * compiled-in switcher code and the high-mapped copy we just made.
42817 */
42818 for (i = 0; i < IDT_ENTRIES; i++)
42819 - default_idt_entries[i] += switcher_offset();
42820 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42821
42822 /*
42823 * Set up the Switcher's per-cpu areas.
42824 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
42825 * it will be undisturbed when we switch. To change %cs and jump we
42826 * need this structure to feed to Intel's "lcall" instruction.
42827 */
42828 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42829 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42830 lguest_entry.segment = LGUEST_CS;
42831
42832 /*
42833 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42834 index 40634b0..4f5855e 100644
42835 --- a/drivers/lguest/x86/switcher_32.S
42836 +++ b/drivers/lguest/x86/switcher_32.S
42837 @@ -87,6 +87,7 @@
42838 #include <asm/page.h>
42839 #include <asm/segment.h>
42840 #include <asm/lguest.h>
42841 +#include <asm/processor-flags.h>
42842
42843 // We mark the start of the code to copy
42844 // It's placed in .text tho it's never run here
42845 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42846 // Changes type when we load it: damn Intel!
42847 // For after we switch over our page tables
42848 // That entry will be read-only: we'd crash.
42849 +
42850 +#ifdef CONFIG_PAX_KERNEXEC
42851 + mov %cr0, %edx
42852 + xor $X86_CR0_WP, %edx
42853 + mov %edx, %cr0
42854 +#endif
42855 +
42856 movl $(GDT_ENTRY_TSS*8), %edx
42857 ltr %dx
42858
42859 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42860 // Let's clear it again for our return.
42861 // The GDT descriptor of the Host
42862 // Points to the table after two "size" bytes
42863 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42864 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42865 // Clear "used" from type field (byte 5, bit 2)
42866 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42867 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42868 +
42869 +#ifdef CONFIG_PAX_KERNEXEC
42870 + mov %cr0, %eax
42871 + xor $X86_CR0_WP, %eax
42872 + mov %eax, %cr0
42873 +#endif
42874
42875 // Once our page table's switched, the Guest is live!
42876 // The Host fades as we run this final step.
42877 @@ -295,13 +309,12 @@ deliver_to_host:
42878 // I consulted gcc, and it gave
42879 // These instructions, which I gladly credit:
42880 leal (%edx,%ebx,8), %eax
42881 - movzwl (%eax),%edx
42882 - movl 4(%eax), %eax
42883 - xorw %ax, %ax
42884 - orl %eax, %edx
42885 + movl 4(%eax), %edx
42886 + movw (%eax), %dx
42887 // Now the address of the handler's in %edx
42888 // We call it now: its "iret" drops us home.
42889 - jmp *%edx
42890 + ljmp $__KERNEL_CS, $1f
42891 +1: jmp *%edx
42892
42893 // Every interrupt can come to us here
42894 // But we must truly tell each apart.
42895 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42896 index 9762f1b..3e79734 100644
42897 --- a/drivers/md/bcache/closure.h
42898 +++ b/drivers/md/bcache/closure.h
42899 @@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
42900 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42901 struct workqueue_struct *wq)
42902 {
42903 - BUG_ON(object_is_on_stack(cl));
42904 + BUG_ON(object_starts_on_stack(cl));
42905 closure_set_ip(cl);
42906 cl->fn = fn;
42907 cl->wq = wq;
42908 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42909 index 12dc29b..1596277 100644
42910 --- a/drivers/md/bitmap.c
42911 +++ b/drivers/md/bitmap.c
42912 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42913 chunk_kb ? "KB" : "B");
42914 if (bitmap->storage.file) {
42915 seq_printf(seq, ", file: ");
42916 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42917 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42918 }
42919
42920 seq_printf(seq, "\n");
42921 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42922 index 5152142..623d141 100644
42923 --- a/drivers/md/dm-ioctl.c
42924 +++ b/drivers/md/dm-ioctl.c
42925 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42926 cmd == DM_LIST_VERSIONS_CMD)
42927 return 0;
42928
42929 - if ((cmd == DM_DEV_CREATE_CMD)) {
42930 + if (cmd == DM_DEV_CREATE_CMD) {
42931 if (!*param->name) {
42932 DMWARN("name not supplied when creating device");
42933 return -EINVAL;
42934 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42935 index 9584443..9fc9ac9 100644
42936 --- a/drivers/md/dm-raid1.c
42937 +++ b/drivers/md/dm-raid1.c
42938 @@ -40,7 +40,7 @@ enum dm_raid1_error {
42939
42940 struct mirror {
42941 struct mirror_set *ms;
42942 - atomic_t error_count;
42943 + atomic_unchecked_t error_count;
42944 unsigned long error_type;
42945 struct dm_dev *dev;
42946 sector_t offset;
42947 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42948 struct mirror *m;
42949
42950 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42951 - if (!atomic_read(&m->error_count))
42952 + if (!atomic_read_unchecked(&m->error_count))
42953 return m;
42954
42955 return NULL;
42956 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42957 * simple way to tell if a device has encountered
42958 * errors.
42959 */
42960 - atomic_inc(&m->error_count);
42961 + atomic_inc_unchecked(&m->error_count);
42962
42963 if (test_and_set_bit(error_type, &m->error_type))
42964 return;
42965 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42966 struct mirror *m = get_default_mirror(ms);
42967
42968 do {
42969 - if (likely(!atomic_read(&m->error_count)))
42970 + if (likely(!atomic_read_unchecked(&m->error_count)))
42971 return m;
42972
42973 if (m-- == ms->mirror)
42974 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42975 {
42976 struct mirror *default_mirror = get_default_mirror(m->ms);
42977
42978 - return !atomic_read(&default_mirror->error_count);
42979 + return !atomic_read_unchecked(&default_mirror->error_count);
42980 }
42981
42982 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42983 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42984 */
42985 if (likely(region_in_sync(ms, region, 1)))
42986 m = choose_mirror(ms, bio->bi_sector);
42987 - else if (m && atomic_read(&m->error_count))
42988 + else if (m && atomic_read_unchecked(&m->error_count))
42989 m = NULL;
42990
42991 if (likely(m))
42992 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42993 }
42994
42995 ms->mirror[mirror].ms = ms;
42996 - atomic_set(&(ms->mirror[mirror].error_count), 0);
42997 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42998 ms->mirror[mirror].error_type = 0;
42999 ms->mirror[mirror].offset = offset;
43000
43001 @@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
43002 */
43003 static char device_status_char(struct mirror *m)
43004 {
43005 - if (!atomic_read(&(m->error_count)))
43006 + if (!atomic_read_unchecked(&(m->error_count)))
43007 return 'A';
43008
43009 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43010 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43011 index 28a9012..9c0f6a5 100644
43012 --- a/drivers/md/dm-stats.c
43013 +++ b/drivers/md/dm-stats.c
43014 @@ -382,7 +382,7 @@ do_sync_free:
43015 synchronize_rcu_expedited();
43016 dm_stat_free(&s->rcu_head);
43017 } else {
43018 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43019 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43020 call_rcu(&s->rcu_head, dm_stat_free);
43021 }
43022 return 0;
43023 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43024 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43025 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43026 ));
43027 - ACCESS_ONCE(last->last_sector) = end_sector;
43028 - ACCESS_ONCE(last->last_rw) = bi_rw;
43029 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43030 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43031 }
43032
43033 rcu_read_lock();
43034 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43035 index 73c1712..7347292 100644
43036 --- a/drivers/md/dm-stripe.c
43037 +++ b/drivers/md/dm-stripe.c
43038 @@ -21,7 +21,7 @@ struct stripe {
43039 struct dm_dev *dev;
43040 sector_t physical_start;
43041
43042 - atomic_t error_count;
43043 + atomic_unchecked_t error_count;
43044 };
43045
43046 struct stripe_c {
43047 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43048 kfree(sc);
43049 return r;
43050 }
43051 - atomic_set(&(sc->stripe[i].error_count), 0);
43052 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43053 }
43054
43055 ti->private = sc;
43056 @@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43057 DMEMIT("%d ", sc->stripes);
43058 for (i = 0; i < sc->stripes; i++) {
43059 DMEMIT("%s ", sc->stripe[i].dev->name);
43060 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43061 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43062 'D' : 'A';
43063 }
43064 buffer[i] = '\0';
43065 @@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43066 */
43067 for (i = 0; i < sc->stripes; i++)
43068 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43069 - atomic_inc(&(sc->stripe[i].error_count));
43070 - if (atomic_read(&(sc->stripe[i].error_count)) <
43071 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43072 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43073 DM_IO_ERROR_THRESHOLD)
43074 schedule_work(&sc->trigger_event);
43075 }
43076 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43077 index 3ba6a38..b0fa9b0 100644
43078 --- a/drivers/md/dm-table.c
43079 +++ b/drivers/md/dm-table.c
43080 @@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43081 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43082 struct mapped_device *md)
43083 {
43084 - static char *_claim_ptr = "I belong to device-mapper";
43085 + static char _claim_ptr[] = "I belong to device-mapper";
43086 struct block_device *bdev;
43087
43088 int r;
43089 @@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43090 if (!dev_size)
43091 return 0;
43092
43093 - if ((start >= dev_size) || (start + len > dev_size)) {
43094 + if ((start >= dev_size) || (len > dev_size - start)) {
43095 DMWARN("%s: %s too small for target: "
43096 "start=%llu, len=%llu, dev_size=%llu",
43097 dm_device_name(ti->table->md), bdevname(bdev, b),
43098 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43099 index 8a30ad5..72792d3 100644
43100 --- a/drivers/md/dm-thin-metadata.c
43101 +++ b/drivers/md/dm-thin-metadata.c
43102 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43103 {
43104 pmd->info.tm = pmd->tm;
43105 pmd->info.levels = 2;
43106 - pmd->info.value_type.context = pmd->data_sm;
43107 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43108 pmd->info.value_type.size = sizeof(__le64);
43109 pmd->info.value_type.inc = data_block_inc;
43110 pmd->info.value_type.dec = data_block_dec;
43111 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43112
43113 pmd->bl_info.tm = pmd->tm;
43114 pmd->bl_info.levels = 1;
43115 - pmd->bl_info.value_type.context = pmd->data_sm;
43116 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43117 pmd->bl_info.value_type.size = sizeof(__le64);
43118 pmd->bl_info.value_type.inc = data_block_inc;
43119 pmd->bl_info.value_type.dec = data_block_dec;
43120 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43121 index 0704c52..0a33d61 100644
43122 --- a/drivers/md/dm.c
43123 +++ b/drivers/md/dm.c
43124 @@ -185,9 +185,9 @@ struct mapped_device {
43125 /*
43126 * Event handling.
43127 */
43128 - atomic_t event_nr;
43129 + atomic_unchecked_t event_nr;
43130 wait_queue_head_t eventq;
43131 - atomic_t uevent_seq;
43132 + atomic_unchecked_t uevent_seq;
43133 struct list_head uevent_list;
43134 spinlock_t uevent_lock; /* Protect access to uevent_list */
43135
43136 @@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43137 spin_lock_init(&md->deferred_lock);
43138 atomic_set(&md->holders, 1);
43139 atomic_set(&md->open_count, 0);
43140 - atomic_set(&md->event_nr, 0);
43141 - atomic_set(&md->uevent_seq, 0);
43142 + atomic_set_unchecked(&md->event_nr, 0);
43143 + atomic_set_unchecked(&md->uevent_seq, 0);
43144 INIT_LIST_HEAD(&md->uevent_list);
43145 spin_lock_init(&md->uevent_lock);
43146
43147 @@ -2175,7 +2175,7 @@ static void event_callback(void *context)
43148
43149 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43150
43151 - atomic_inc(&md->event_nr);
43152 + atomic_inc_unchecked(&md->event_nr);
43153 wake_up(&md->eventq);
43154 }
43155
43156 @@ -2868,18 +2868,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43157
43158 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43159 {
43160 - return atomic_add_return(1, &md->uevent_seq);
43161 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43162 }
43163
43164 uint32_t dm_get_event_nr(struct mapped_device *md)
43165 {
43166 - return atomic_read(&md->event_nr);
43167 + return atomic_read_unchecked(&md->event_nr);
43168 }
43169
43170 int dm_wait_event(struct mapped_device *md, int event_nr)
43171 {
43172 return wait_event_interruptible(md->eventq,
43173 - (event_nr != atomic_read(&md->event_nr)));
43174 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43175 }
43176
43177 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43178 diff --git a/drivers/md/md.c b/drivers/md/md.c
43179 index 369d919..ba7049c 100644
43180 --- a/drivers/md/md.c
43181 +++ b/drivers/md/md.c
43182 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43183 * start build, activate spare
43184 */
43185 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43186 -static atomic_t md_event_count;
43187 +static atomic_unchecked_t md_event_count;
43188 void md_new_event(struct mddev *mddev)
43189 {
43190 - atomic_inc(&md_event_count);
43191 + atomic_inc_unchecked(&md_event_count);
43192 wake_up(&md_event_waiters);
43193 }
43194 EXPORT_SYMBOL_GPL(md_new_event);
43195 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43196 */
43197 static void md_new_event_inintr(struct mddev *mddev)
43198 {
43199 - atomic_inc(&md_event_count);
43200 + atomic_inc_unchecked(&md_event_count);
43201 wake_up(&md_event_waiters);
43202 }
43203
43204 @@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43205 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43206 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43207 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43208 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43209 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43210
43211 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43212 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43213 @@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43214 else
43215 sb->resync_offset = cpu_to_le64(0);
43216
43217 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43218 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43219
43220 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43221 sb->size = cpu_to_le64(mddev->dev_sectors);
43222 @@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43223 static ssize_t
43224 errors_show(struct md_rdev *rdev, char *page)
43225 {
43226 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43227 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43228 }
43229
43230 static ssize_t
43231 @@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43232 char *e;
43233 unsigned long n = simple_strtoul(buf, &e, 10);
43234 if (*buf && (*e == 0 || *e == '\n')) {
43235 - atomic_set(&rdev->corrected_errors, n);
43236 + atomic_set_unchecked(&rdev->corrected_errors, n);
43237 return len;
43238 }
43239 return -EINVAL;
43240 @@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
43241 rdev->sb_loaded = 0;
43242 rdev->bb_page = NULL;
43243 atomic_set(&rdev->nr_pending, 0);
43244 - atomic_set(&rdev->read_errors, 0);
43245 - atomic_set(&rdev->corrected_errors, 0);
43246 + atomic_set_unchecked(&rdev->read_errors, 0);
43247 + atomic_set_unchecked(&rdev->corrected_errors, 0);
43248
43249 INIT_LIST_HEAD(&rdev->same_set);
43250 init_waitqueue_head(&rdev->blocked_wait);
43251 @@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43252
43253 spin_unlock(&pers_lock);
43254 seq_printf(seq, "\n");
43255 - seq->poll_event = atomic_read(&md_event_count);
43256 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43257 return 0;
43258 }
43259 if (v == (void*)2) {
43260 @@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43261 return error;
43262
43263 seq = file->private_data;
43264 - seq->poll_event = atomic_read(&md_event_count);
43265 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43266 return error;
43267 }
43268
43269 @@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43270 /* always allow read */
43271 mask = POLLIN | POLLRDNORM;
43272
43273 - if (seq->poll_event != atomic_read(&md_event_count))
43274 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43275 mask |= POLLERR | POLLPRI;
43276 return mask;
43277 }
43278 @@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43279 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43280 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43281 (int)part_stat_read(&disk->part0, sectors[1]) -
43282 - atomic_read(&disk->sync_io);
43283 + atomic_read_unchecked(&disk->sync_io);
43284 /* sync IO will cause sync_io to increase before the disk_stats
43285 * as sync_io is counted when a request starts, and
43286 * disk_stats is counted when it completes.
43287 diff --git a/drivers/md/md.h b/drivers/md/md.h
43288 index 0095ec8..c89277a 100644
43289 --- a/drivers/md/md.h
43290 +++ b/drivers/md/md.h
43291 @@ -94,13 +94,13 @@ struct md_rdev {
43292 * only maintained for arrays that
43293 * support hot removal
43294 */
43295 - atomic_t read_errors; /* number of consecutive read errors that
43296 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
43297 * we have tried to ignore.
43298 */
43299 struct timespec last_read_error; /* monotonic time since our
43300 * last read error
43301 */
43302 - atomic_t corrected_errors; /* number of corrected read errors,
43303 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43304 * for reporting to userspace and storing
43305 * in superblock.
43306 */
43307 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
43308
43309 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
43310 {
43311 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43312 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43313 }
43314
43315 struct md_personality
43316 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
43317 index 3e6d115..ffecdeb 100644
43318 --- a/drivers/md/persistent-data/dm-space-map.h
43319 +++ b/drivers/md/persistent-data/dm-space-map.h
43320 @@ -71,6 +71,7 @@ struct dm_space_map {
43321 dm_sm_threshold_fn fn,
43322 void *context);
43323 };
43324 +typedef struct dm_space_map __no_const dm_space_map_no_const;
43325
43326 /*----------------------------------------------------------------*/
43327
43328 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
43329 index a49cfcc..20b9a65 100644
43330 --- a/drivers/md/raid1.c
43331 +++ b/drivers/md/raid1.c
43332 @@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
43333 if (r1_sync_page_io(rdev, sect, s,
43334 bio->bi_io_vec[idx].bv_page,
43335 READ) != 0)
43336 - atomic_add(s, &rdev->corrected_errors);
43337 + atomic_add_unchecked(s, &rdev->corrected_errors);
43338 }
43339 sectors -= s;
43340 sect += s;
43341 @@ -2148,7 +2148,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
43342 test_bit(In_sync, &rdev->flags)) {
43343 if (r1_sync_page_io(rdev, sect, s,
43344 conf->tmppage, READ)) {
43345 - atomic_add(s, &rdev->corrected_errors);
43346 + atomic_add_unchecked(s, &rdev->corrected_errors);
43347 printk(KERN_INFO
43348 "md/raid1:%s: read error corrected "
43349 "(%d sectors at %llu on %s)\n",
43350 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
43351 index 06eeb99..770613e 100644
43352 --- a/drivers/md/raid10.c
43353 +++ b/drivers/md/raid10.c
43354 @@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
43355 /* The write handler will notice the lack of
43356 * R10BIO_Uptodate and record any errors etc
43357 */
43358 - atomic_add(r10_bio->sectors,
43359 + atomic_add_unchecked(r10_bio->sectors,
43360 &conf->mirrors[d].rdev->corrected_errors);
43361
43362 /* for reconstruct, we always reschedule after a read.
43363 @@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43364 {
43365 struct timespec cur_time_mon;
43366 unsigned long hours_since_last;
43367 - unsigned int read_errors = atomic_read(&rdev->read_errors);
43368 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
43369
43370 ktime_get_ts(&cur_time_mon);
43371
43372 @@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43373 * overflowing the shift of read_errors by hours_since_last.
43374 */
43375 if (hours_since_last >= 8 * sizeof(read_errors))
43376 - atomic_set(&rdev->read_errors, 0);
43377 + atomic_set_unchecked(&rdev->read_errors, 0);
43378 else
43379 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
43380 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
43381 }
43382
43383 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
43384 @@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43385 return;
43386
43387 check_decay_read_errors(mddev, rdev);
43388 - atomic_inc(&rdev->read_errors);
43389 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
43390 + atomic_inc_unchecked(&rdev->read_errors);
43391 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
43392 char b[BDEVNAME_SIZE];
43393 bdevname(rdev->bdev, b);
43394
43395 @@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43396 "md/raid10:%s: %s: Raid device exceeded "
43397 "read_error threshold [cur %d:max %d]\n",
43398 mdname(mddev), b,
43399 - atomic_read(&rdev->read_errors), max_read_errors);
43400 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
43401 printk(KERN_NOTICE
43402 "md/raid10:%s: %s: Failing raid device\n",
43403 mdname(mddev), b);
43404 @@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43405 sect +
43406 choose_data_offset(r10_bio, rdev)),
43407 bdevname(rdev->bdev, b));
43408 - atomic_add(s, &rdev->corrected_errors);
43409 + atomic_add_unchecked(s, &rdev->corrected_errors);
43410 }
43411
43412 rdev_dec_pending(rdev, mddev);
43413 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
43414 index 03f82ab..374bb38 100644
43415 --- a/drivers/md/raid5.c
43416 +++ b/drivers/md/raid5.c
43417 @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
43418 mdname(conf->mddev), STRIPE_SECTORS,
43419 (unsigned long long)s,
43420 bdevname(rdev->bdev, b));
43421 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
43422 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
43423 clear_bit(R5_ReadError, &sh->dev[i].flags);
43424 clear_bit(R5_ReWrite, &sh->dev[i].flags);
43425 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
43426 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
43427
43428 - if (atomic_read(&rdev->read_errors))
43429 - atomic_set(&rdev->read_errors, 0);
43430 + if (atomic_read_unchecked(&rdev->read_errors))
43431 + atomic_set_unchecked(&rdev->read_errors, 0);
43432 } else {
43433 const char *bdn = bdevname(rdev->bdev, b);
43434 int retry = 0;
43435 int set_bad = 0;
43436
43437 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
43438 - atomic_inc(&rdev->read_errors);
43439 + atomic_inc_unchecked(&rdev->read_errors);
43440 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
43441 printk_ratelimited(
43442 KERN_WARNING
43443 @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
43444 mdname(conf->mddev),
43445 (unsigned long long)s,
43446 bdn);
43447 - } else if (atomic_read(&rdev->read_errors)
43448 + } else if (atomic_read_unchecked(&rdev->read_errors)
43449 > conf->max_nr_stripes)
43450 printk(KERN_WARNING
43451 "md/raid:%s: Too many read errors, failing device %s.\n",
43452 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
43453 index 983db75..ef9248c 100644
43454 --- a/drivers/media/dvb-core/dvbdev.c
43455 +++ b/drivers/media/dvb-core/dvbdev.c
43456 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
43457 const struct dvb_device *template, void *priv, int type)
43458 {
43459 struct dvb_device *dvbdev;
43460 - struct file_operations *dvbdevfops;
43461 + file_operations_no_const *dvbdevfops;
43462 struct device *clsdev;
43463 int minor;
43464 int id;
43465 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
43466 index 9b6c3bb..baeb5c7 100644
43467 --- a/drivers/media/dvb-frontends/dib3000.h
43468 +++ b/drivers/media/dvb-frontends/dib3000.h
43469 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
43470 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
43471 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
43472 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
43473 -};
43474 +} __no_const;
43475
43476 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
43477 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
43478 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
43479 index ed8cb90..5ef7f79 100644
43480 --- a/drivers/media/pci/cx88/cx88-video.c
43481 +++ b/drivers/media/pci/cx88/cx88-video.c
43482 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
43483
43484 /* ------------------------------------------------------------------ */
43485
43486 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43487 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43488 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43489 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43490 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43491 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43492
43493 module_param_array(video_nr, int, NULL, 0444);
43494 module_param_array(vbi_nr, int, NULL, 0444);
43495 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
43496 index 802642d..5534900 100644
43497 --- a/drivers/media/pci/ivtv/ivtv-driver.c
43498 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
43499 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
43500 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
43501
43502 /* ivtv instance counter */
43503 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
43504 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
43505
43506 /* Parameter declarations */
43507 static int cardtype[IVTV_MAX_CARDS];
43508 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
43509 index dfd0a21..6bbb465 100644
43510 --- a/drivers/media/platform/omap/omap_vout.c
43511 +++ b/drivers/media/platform/omap/omap_vout.c
43512 @@ -63,7 +63,6 @@ enum omap_vout_channels {
43513 OMAP_VIDEO2,
43514 };
43515
43516 -static struct videobuf_queue_ops video_vbq_ops;
43517 /* Variables configurable through module params*/
43518 static u32 video1_numbuffers = 3;
43519 static u32 video2_numbuffers = 3;
43520 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
43521 {
43522 struct videobuf_queue *q;
43523 struct omap_vout_device *vout = NULL;
43524 + static struct videobuf_queue_ops video_vbq_ops = {
43525 + .buf_setup = omap_vout_buffer_setup,
43526 + .buf_prepare = omap_vout_buffer_prepare,
43527 + .buf_release = omap_vout_buffer_release,
43528 + .buf_queue = omap_vout_buffer_queue,
43529 + };
43530
43531 vout = video_drvdata(file);
43532 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
43533 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
43534 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
43535
43536 q = &vout->vbq;
43537 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
43538 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
43539 - video_vbq_ops.buf_release = omap_vout_buffer_release;
43540 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
43541 spin_lock_init(&vout->vbq_lock);
43542
43543 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
43544 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
43545 index fb2acc5..a2fcbdc4 100644
43546 --- a/drivers/media/platform/s5p-tv/mixer.h
43547 +++ b/drivers/media/platform/s5p-tv/mixer.h
43548 @@ -156,7 +156,7 @@ struct mxr_layer {
43549 /** layer index (unique identifier) */
43550 int idx;
43551 /** callbacks for layer methods */
43552 - struct mxr_layer_ops ops;
43553 + struct mxr_layer_ops *ops;
43554 /** format array */
43555 const struct mxr_format **fmt_array;
43556 /** size of format array */
43557 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43558 index 74344c7..a39e70e 100644
43559 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43560 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43561 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
43562 {
43563 struct mxr_layer *layer;
43564 int ret;
43565 - struct mxr_layer_ops ops = {
43566 + static struct mxr_layer_ops ops = {
43567 .release = mxr_graph_layer_release,
43568 .buffer_set = mxr_graph_buffer_set,
43569 .stream_set = mxr_graph_stream_set,
43570 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
43571 index b713403..53cb5ad 100644
43572 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
43573 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
43574 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
43575 layer->update_buf = next;
43576 }
43577
43578 - layer->ops.buffer_set(layer, layer->update_buf);
43579 + layer->ops->buffer_set(layer, layer->update_buf);
43580
43581 if (done && done != layer->shadow_buf)
43582 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
43583 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
43584 index 81b97db..b089ccd 100644
43585 --- a/drivers/media/platform/s5p-tv/mixer_video.c
43586 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
43587 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
43588 layer->geo.src.height = layer->geo.src.full_height;
43589
43590 mxr_geometry_dump(mdev, &layer->geo);
43591 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43592 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43593 mxr_geometry_dump(mdev, &layer->geo);
43594 }
43595
43596 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
43597 layer->geo.dst.full_width = mbus_fmt.width;
43598 layer->geo.dst.full_height = mbus_fmt.height;
43599 layer->geo.dst.field = mbus_fmt.field;
43600 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43601 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43602
43603 mxr_geometry_dump(mdev, &layer->geo);
43604 }
43605 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43606 /* set source size to highest accepted value */
43607 geo->src.full_width = max(geo->dst.full_width, pix->width);
43608 geo->src.full_height = max(geo->dst.full_height, pix->height);
43609 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43610 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43611 mxr_geometry_dump(mdev, &layer->geo);
43612 /* set cropping to total visible screen */
43613 geo->src.width = pix->width;
43614 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43615 geo->src.x_offset = 0;
43616 geo->src.y_offset = 0;
43617 /* assure consistency of geometry */
43618 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43619 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43620 mxr_geometry_dump(mdev, &layer->geo);
43621 /* set full size to lowest possible value */
43622 geo->src.full_width = 0;
43623 geo->src.full_height = 0;
43624 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43625 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43626 mxr_geometry_dump(mdev, &layer->geo);
43627
43628 /* returning results */
43629 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43630 target->width = s->r.width;
43631 target->height = s->r.height;
43632
43633 - layer->ops.fix_geometry(layer, stage, s->flags);
43634 + layer->ops->fix_geometry(layer, stage, s->flags);
43635
43636 /* retrieve update selection rectangle */
43637 res.left = target->x_offset;
43638 @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43639 mxr_output_get(mdev);
43640
43641 mxr_layer_update_output(layer);
43642 - layer->ops.format_set(layer);
43643 + layer->ops->format_set(layer);
43644 /* enabling layer in hardware */
43645 spin_lock_irqsave(&layer->enq_slock, flags);
43646 layer->state = MXR_LAYER_STREAMING;
43647 spin_unlock_irqrestore(&layer->enq_slock, flags);
43648
43649 - layer->ops.stream_set(layer, MXR_ENABLE);
43650 + layer->ops->stream_set(layer, MXR_ENABLE);
43651 mxr_streamer_get(mdev);
43652
43653 return 0;
43654 @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43655 spin_unlock_irqrestore(&layer->enq_slock, flags);
43656
43657 /* disabling layer in hardware */
43658 - layer->ops.stream_set(layer, MXR_DISABLE);
43659 + layer->ops->stream_set(layer, MXR_DISABLE);
43660 /* remove one streamer */
43661 mxr_streamer_put(mdev);
43662 /* allow changes in output configuration */
43663 @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43664
43665 void mxr_layer_release(struct mxr_layer *layer)
43666 {
43667 - if (layer->ops.release)
43668 - layer->ops.release(layer);
43669 + if (layer->ops->release)
43670 + layer->ops->release(layer);
43671 }
43672
43673 void mxr_base_layer_release(struct mxr_layer *layer)
43674 @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43675
43676 layer->mdev = mdev;
43677 layer->idx = idx;
43678 - layer->ops = *ops;
43679 + layer->ops = ops;
43680
43681 spin_lock_init(&layer->enq_slock);
43682 INIT_LIST_HEAD(&layer->enq_list);
43683 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43684 index c9388c4..ce71ece 100644
43685 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43686 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43687 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43688 {
43689 struct mxr_layer *layer;
43690 int ret;
43691 - struct mxr_layer_ops ops = {
43692 + static struct mxr_layer_ops ops = {
43693 .release = mxr_vp_layer_release,
43694 .buffer_set = mxr_vp_buffer_set,
43695 .stream_set = mxr_vp_stream_set,
43696 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
43697 index 2d4e73b..8b4d5b6 100644
43698 --- a/drivers/media/platform/vivi.c
43699 +++ b/drivers/media/platform/vivi.c
43700 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
43701 MODULE_LICENSE("Dual BSD/GPL");
43702 MODULE_VERSION(VIVI_VERSION);
43703
43704 -static unsigned video_nr = -1;
43705 -module_param(video_nr, uint, 0644);
43706 +static int video_nr = -1;
43707 +module_param(video_nr, int, 0644);
43708 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
43709
43710 static unsigned n_devs = 1;
43711 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43712 index 545c04c..a14bded 100644
43713 --- a/drivers/media/radio/radio-cadet.c
43714 +++ b/drivers/media/radio/radio-cadet.c
43715 @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43716 unsigned char readbuf[RDS_BUFFER];
43717 int i = 0;
43718
43719 + if (count > RDS_BUFFER)
43720 + return -EFAULT;
43721 mutex_lock(&dev->lock);
43722 if (dev->rdsstat == 0)
43723 cadet_start_rds(dev);
43724 @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43725 while (i < count && dev->rdsin != dev->rdsout)
43726 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43727
43728 - if (i && copy_to_user(data, readbuf, i))
43729 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43730 i = -EFAULT;
43731 unlock:
43732 mutex_unlock(&dev->lock);
43733 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43734 index 5236035..c622c74 100644
43735 --- a/drivers/media/radio/radio-maxiradio.c
43736 +++ b/drivers/media/radio/radio-maxiradio.c
43737 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43738 /* TEA5757 pin mappings */
43739 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43740
43741 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43742 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43743
43744 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43745 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43746 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43747 index 050b3bb..79f62b9 100644
43748 --- a/drivers/media/radio/radio-shark.c
43749 +++ b/drivers/media/radio/radio-shark.c
43750 @@ -79,7 +79,7 @@ struct shark_device {
43751 u32 last_val;
43752 };
43753
43754 -static atomic_t shark_instance = ATOMIC_INIT(0);
43755 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43756
43757 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43758 {
43759 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43760 index 8654e0d..0608a64 100644
43761 --- a/drivers/media/radio/radio-shark2.c
43762 +++ b/drivers/media/radio/radio-shark2.c
43763 @@ -74,7 +74,7 @@ struct shark_device {
43764 u8 *transfer_buffer;
43765 };
43766
43767 -static atomic_t shark_instance = ATOMIC_INIT(0);
43768 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43769
43770 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43771 {
43772 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43773 index 2fd9009..278cc1e 100644
43774 --- a/drivers/media/radio/radio-si476x.c
43775 +++ b/drivers/media/radio/radio-si476x.c
43776 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43777 struct si476x_radio *radio;
43778 struct v4l2_ctrl *ctrl;
43779
43780 - static atomic_t instance = ATOMIC_INIT(0);
43781 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
43782
43783 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43784 if (!radio)
43785 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43786 index 46da365..3ba4206 100644
43787 --- a/drivers/media/rc/rc-main.c
43788 +++ b/drivers/media/rc/rc-main.c
43789 @@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43790 int rc_register_device(struct rc_dev *dev)
43791 {
43792 static bool raw_init = false; /* raw decoders loaded? */
43793 - static atomic_t devno = ATOMIC_INIT(0);
43794 + static atomic_unchecked_t devno = ATOMIC_INIT(0);
43795 struct rc_map *rc_map;
43796 const char *path;
43797 int rc;
43798 @@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
43799 */
43800 mutex_lock(&dev->lock);
43801
43802 - dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43803 + dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43804 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43805 dev_set_drvdata(&dev->dev, dev);
43806 rc = device_add(&dev->dev);
43807 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43808 index 20e345d..da56fe4 100644
43809 --- a/drivers/media/usb/dvb-usb/cxusb.c
43810 +++ b/drivers/media/usb/dvb-usb/cxusb.c
43811 @@ -1101,7 +1101,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43812
43813 struct dib0700_adapter_state {
43814 int (*set_param_save) (struct dvb_frontend *);
43815 -};
43816 +} __no_const;
43817
43818 static int dib7070_set_param_override(struct dvb_frontend *fe)
43819 {
43820 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43821 index c1a63b2..dbcbfb6 100644
43822 --- a/drivers/media/usb/dvb-usb/dw2102.c
43823 +++ b/drivers/media/usb/dvb-usb/dw2102.c
43824 @@ -121,7 +121,7 @@ struct su3000_state {
43825
43826 struct s6x0_state {
43827 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43828 -};
43829 +} __no_const;
43830
43831 /* debug */
43832 static int dvb_usb_dw2102_debug;
43833 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43834 index 8f7a6a4..eb0e1d4 100644
43835 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43836 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43837 @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43838 __u32 reserved;
43839 };
43840
43841 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43842 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43843 enum v4l2_memory memory)
43844 {
43845 void __user *up_pln;
43846 @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43847 return 0;
43848 }
43849
43850 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43851 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43852 enum v4l2_memory memory)
43853 {
43854 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43855 @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
43856 * by passing a very big num_planes value */
43857 uplane = compat_alloc_user_space(num_planes *
43858 sizeof(struct v4l2_plane));
43859 - kp->m.planes = uplane;
43860 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
43861
43862 while (--num_planes >= 0) {
43863 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
43864 @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
43865 if (num_planes == 0)
43866 return 0;
43867
43868 - uplane = kp->m.planes;
43869 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
43870 if (get_user(p, &up->m.planes))
43871 return -EFAULT;
43872 uplane32 = compat_ptr(p);
43873 @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
43874 get_user(kp->capability, &up->capability) ||
43875 get_user(kp->flags, &up->flags))
43876 return -EFAULT;
43877 - kp->base = compat_ptr(tmp);
43878 + kp->base = (void __force_kernel *)compat_ptr(tmp);
43879 get_v4l2_pix_format(&kp->fmt, &up->fmt);
43880 return 0;
43881 }
43882 @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
43883 n * sizeof(struct v4l2_ext_control32)))
43884 return -EFAULT;
43885 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
43886 - kp->controls = kcontrols;
43887 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
43888 while (--n >= 0) {
43889 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
43890 return -EFAULT;
43891 @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
43892 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
43893 {
43894 struct v4l2_ext_control32 __user *ucontrols;
43895 - struct v4l2_ext_control __user *kcontrols = kp->controls;
43896 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
43897 int n = kp->count;
43898 compat_caddr_t p;
43899
43900 @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43901 put_user(kp->start_block, &up->start_block) ||
43902 put_user(kp->blocks, &up->blocks) ||
43903 put_user(tmp, &up->edid) ||
43904 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43905 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43906 return -EFAULT;
43907 return 0;
43908 }
43909 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
43910 index fb46790..ae1f8fa 100644
43911 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
43912 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
43913 @@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
43914 return 0;
43915
43916 case V4L2_CTRL_TYPE_STRING:
43917 - len = strlen(c->string);
43918 - if (len < ctrl->minimum)
43919 + len = strlen_user(c->string);
43920 + if (!len || len < ctrl->minimum)
43921 return -ERANGE;
43922 if ((len - ctrl->minimum) % ctrl->step)
43923 return -ERANGE;
43924 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43925 index 02d1b63..5fd6b16 100644
43926 --- a/drivers/media/v4l2-core/v4l2-device.c
43927 +++ b/drivers/media/v4l2-core/v4l2-device.c
43928 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43929 EXPORT_SYMBOL_GPL(v4l2_device_put);
43930
43931 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43932 - atomic_t *instance)
43933 + atomic_unchecked_t *instance)
43934 {
43935 - int num = atomic_inc_return(instance) - 1;
43936 + int num = atomic_inc_return_unchecked(instance) - 1;
43937 int len = strlen(basename);
43938
43939 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43940 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43941 index 68e6b5e..8eb2aec 100644
43942 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
43943 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43944 @@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43945 struct file *file, void *fh, void *p);
43946 } u;
43947 void (*debug)(const void *arg, bool write_only);
43948 -};
43949 +} __do_const;
43950 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43951
43952 /* This control needs a priority check */
43953 #define INFO_FL_PRIO (1 << 0)
43954 @@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43955 struct video_device *vfd = video_devdata(file);
43956 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43957 bool write_only = false;
43958 - struct v4l2_ioctl_info default_info;
43959 + v4l2_ioctl_info_no_const default_info;
43960 const struct v4l2_ioctl_info *info;
43961 void *fh = file->private_data;
43962 struct v4l2_fh *vfh = NULL;
43963 @@ -2194,7 +2195,7 @@ done:
43964 }
43965
43966 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43967 - void * __user *user_ptr, void ***kernel_ptr)
43968 + void __user **user_ptr, void ***kernel_ptr)
43969 {
43970 int ret = 0;
43971
43972 @@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43973 ret = -EINVAL;
43974 break;
43975 }
43976 - *user_ptr = (void __user *)buf->m.planes;
43977 + *user_ptr = (void __force_user *)buf->m.planes;
43978 *kernel_ptr = (void *)&buf->m.planes;
43979 *array_size = sizeof(struct v4l2_plane) * buf->length;
43980 ret = 1;
43981 @@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43982 ret = -EINVAL;
43983 break;
43984 }
43985 - *user_ptr = (void __user *)ctrls->controls;
43986 + *user_ptr = (void __force_user *)ctrls->controls;
43987 *kernel_ptr = (void *)&ctrls->controls;
43988 *array_size = sizeof(struct v4l2_ext_control)
43989 * ctrls->count;
43990 @@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
43991 err = -ENOTTY;
43992
43993 if (has_array_args) {
43994 - *kernel_ptr = user_ptr;
43995 + *kernel_ptr = (void __force_kernel *)user_ptr;
43996 if (copy_to_user(user_ptr, mbuf, array_size))
43997 err = -EFAULT;
43998 goto out_array_args;
43999 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44000 index 767ff4d..c69d259 100644
44001 --- a/drivers/message/fusion/mptbase.c
44002 +++ b/drivers/message/fusion/mptbase.c
44003 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44004 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44005 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44006
44007 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44008 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44009 +#else
44010 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44011 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44012 +#endif
44013 +
44014 /*
44015 * Rounding UP to nearest 4-kB boundary here...
44016 */
44017 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44018 ioc->facts.GlobalCredits);
44019
44020 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44021 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44022 + NULL, NULL);
44023 +#else
44024 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44025 +#endif
44026 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44027 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44028 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44029 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44030 index dd239bd..689c4f7 100644
44031 --- a/drivers/message/fusion/mptsas.c
44032 +++ b/drivers/message/fusion/mptsas.c
44033 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44034 return 0;
44035 }
44036
44037 +static inline void
44038 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44039 +{
44040 + if (phy_info->port_details) {
44041 + phy_info->port_details->rphy = rphy;
44042 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44043 + ioc->name, rphy));
44044 + }
44045 +
44046 + if (rphy) {
44047 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44048 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44049 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44050 + ioc->name, rphy, rphy->dev.release));
44051 + }
44052 +}
44053 +
44054 /* no mutex */
44055 static void
44056 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44057 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44058 return NULL;
44059 }
44060
44061 -static inline void
44062 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44063 -{
44064 - if (phy_info->port_details) {
44065 - phy_info->port_details->rphy = rphy;
44066 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44067 - ioc->name, rphy));
44068 - }
44069 -
44070 - if (rphy) {
44071 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44072 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44073 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44074 - ioc->name, rphy, rphy->dev.release));
44075 - }
44076 -}
44077 -
44078 static inline struct sas_port *
44079 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44080 {
44081 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44082 index 727819c..ad74694 100644
44083 --- a/drivers/message/fusion/mptscsih.c
44084 +++ b/drivers/message/fusion/mptscsih.c
44085 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44086
44087 h = shost_priv(SChost);
44088
44089 - if (h) {
44090 - if (h->info_kbuf == NULL)
44091 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44092 - return h->info_kbuf;
44093 - h->info_kbuf[0] = '\0';
44094 + if (!h)
44095 + return NULL;
44096
44097 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44098 - h->info_kbuf[size-1] = '\0';
44099 - }
44100 + if (h->info_kbuf == NULL)
44101 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44102 + return h->info_kbuf;
44103 + h->info_kbuf[0] = '\0';
44104 +
44105 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44106 + h->info_kbuf[size-1] = '\0';
44107
44108 return h->info_kbuf;
44109 }
44110 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44111 index b7d87cd..3fb36da 100644
44112 --- a/drivers/message/i2o/i2o_proc.c
44113 +++ b/drivers/message/i2o/i2o_proc.c
44114 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44115 "Array Controller Device"
44116 };
44117
44118 -static char *chtostr(char *tmp, u8 *chars, int n)
44119 -{
44120 - tmp[0] = 0;
44121 - return strncat(tmp, (char *)chars, n);
44122 -}
44123 -
44124 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44125 char *group)
44126 {
44127 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44128 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44129 {
44130 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44131 - static u32 work32[5];
44132 - static u8 *work8 = (u8 *) work32;
44133 - static u16 *work16 = (u16 *) work32;
44134 + u32 work32[5];
44135 + u8 *work8 = (u8 *) work32;
44136 + u16 *work16 = (u16 *) work32;
44137 int token;
44138 u32 hwcap;
44139
44140 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44141 } *result;
44142
44143 i2o_exec_execute_ddm_table ddm_table;
44144 - char tmp[28 + 1];
44145
44146 result = kmalloc(sizeof(*result), GFP_KERNEL);
44147 if (!result)
44148 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44149
44150 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44151 seq_printf(seq, "%-#8x", ddm_table.module_id);
44152 - seq_printf(seq, "%-29s",
44153 - chtostr(tmp, ddm_table.module_name_version, 28));
44154 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44155 seq_printf(seq, "%9d ", ddm_table.data_size);
44156 seq_printf(seq, "%8d", ddm_table.code_size);
44157
44158 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44159
44160 i2o_driver_result_table *result;
44161 i2o_driver_store_table *dst;
44162 - char tmp[28 + 1];
44163
44164 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44165 if (result == NULL)
44166 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44167
44168 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44169 seq_printf(seq, "%-#8x", dst->module_id);
44170 - seq_printf(seq, "%-29s",
44171 - chtostr(tmp, dst->module_name_version, 28));
44172 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44173 + seq_printf(seq, "%-.28s", dst->module_name_version);
44174 + seq_printf(seq, "%-.8s", dst->date);
44175 seq_printf(seq, "%8d ", dst->module_size);
44176 seq_printf(seq, "%8d ", dst->mpb_size);
44177 seq_printf(seq, "0x%04x", dst->module_flags);
44178 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44179 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44180 {
44181 struct i2o_device *d = (struct i2o_device *)seq->private;
44182 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44183 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44184 // == (allow) 512d bytes (max)
44185 - static u16 *work16 = (u16 *) work32;
44186 + u16 *work16 = (u16 *) work32;
44187 int token;
44188 - char tmp[16 + 1];
44189
44190 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44191
44192 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44193 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44194 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44195 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44196 - seq_printf(seq, "Vendor info : %s\n",
44197 - chtostr(tmp, (u8 *) (work32 + 2), 16));
44198 - seq_printf(seq, "Product info : %s\n",
44199 - chtostr(tmp, (u8 *) (work32 + 6), 16));
44200 - seq_printf(seq, "Description : %s\n",
44201 - chtostr(tmp, (u8 *) (work32 + 10), 16));
44202 - seq_printf(seq, "Product rev. : %s\n",
44203 - chtostr(tmp, (u8 *) (work32 + 14), 8));
44204 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44205 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44206 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44207 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44208
44209 seq_printf(seq, "Serial number : ");
44210 print_serial_number(seq, (u8 *) (work32 + 16),
44211 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44212 u8 pad[256]; // allow up to 256 byte (max) serial number
44213 } result;
44214
44215 - char tmp[24 + 1];
44216 -
44217 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44218
44219 if (token < 0) {
44220 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44221 }
44222
44223 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44224 - seq_printf(seq, "Module name : %s\n",
44225 - chtostr(tmp, result.module_name, 24));
44226 - seq_printf(seq, "Module revision : %s\n",
44227 - chtostr(tmp, result.module_rev, 8));
44228 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
44229 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44230
44231 seq_printf(seq, "Serial number : ");
44232 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44233 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44234 u8 instance_number[4];
44235 } result;
44236
44237 - char tmp[64 + 1];
44238 -
44239 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44240
44241 if (token < 0) {
44242 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44243 return 0;
44244 }
44245
44246 - seq_printf(seq, "Device name : %s\n",
44247 - chtostr(tmp, result.device_name, 64));
44248 - seq_printf(seq, "Service name : %s\n",
44249 - chtostr(tmp, result.service_name, 64));
44250 - seq_printf(seq, "Physical name : %s\n",
44251 - chtostr(tmp, result.physical_location, 64));
44252 - seq_printf(seq, "Instance number : %s\n",
44253 - chtostr(tmp, result.instance_number, 4));
44254 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
44255 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
44256 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44257 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44258
44259 return 0;
44260 }
44261 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44262 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44263 {
44264 struct i2o_device *d = (struct i2o_device *)seq->private;
44265 - static u32 work32[12];
44266 - static u16 *work16 = (u16 *) work32;
44267 - static u8 *work8 = (u8 *) work32;
44268 + u32 work32[12];
44269 + u16 *work16 = (u16 *) work32;
44270 + u8 *work8 = (u8 *) work32;
44271 int token;
44272
44273 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44274 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44275 index a8c08f3..155fe3d 100644
44276 --- a/drivers/message/i2o/iop.c
44277 +++ b/drivers/message/i2o/iop.c
44278 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44279
44280 spin_lock_irqsave(&c->context_list_lock, flags);
44281
44282 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44283 - atomic_inc(&c->context_list_counter);
44284 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44285 + atomic_inc_unchecked(&c->context_list_counter);
44286
44287 - entry->context = atomic_read(&c->context_list_counter);
44288 + entry->context = atomic_read_unchecked(&c->context_list_counter);
44289
44290 list_add(&entry->list, &c->context_list);
44291
44292 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
44293
44294 #if BITS_PER_LONG == 64
44295 spin_lock_init(&c->context_list_lock);
44296 - atomic_set(&c->context_list_counter, 0);
44297 + atomic_set_unchecked(&c->context_list_counter, 0);
44298 INIT_LIST_HEAD(&c->context_list);
44299 #endif
44300
44301 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
44302 index fcbb2e9..2635e11 100644
44303 --- a/drivers/mfd/janz-cmodio.c
44304 +++ b/drivers/mfd/janz-cmodio.c
44305 @@ -13,6 +13,7 @@
44306
44307 #include <linux/kernel.h>
44308 #include <linux/module.h>
44309 +#include <linux/slab.h>
44310 #include <linux/init.h>
44311 #include <linux/pci.h>
44312 #include <linux/interrupt.h>
44313 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
44314 index 176aa26..27811b2 100644
44315 --- a/drivers/mfd/max8925-i2c.c
44316 +++ b/drivers/mfd/max8925-i2c.c
44317 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
44318 const struct i2c_device_id *id)
44319 {
44320 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
44321 - static struct max8925_chip *chip;
44322 + struct max8925_chip *chip;
44323 struct device_node *node = client->dev.of_node;
44324
44325 if (node && !pdata) {
44326 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
44327 index c0f608e..286f8ec 100644
44328 --- a/drivers/mfd/tps65910.c
44329 +++ b/drivers/mfd/tps65910.c
44330 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
44331 struct tps65910_platform_data *pdata)
44332 {
44333 int ret = 0;
44334 - static struct regmap_irq_chip *tps6591x_irqs_chip;
44335 + struct regmap_irq_chip *tps6591x_irqs_chip;
44336
44337 if (!irq) {
44338 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
44339 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
44340 index 9aa6d1e..1631bfc 100644
44341 --- a/drivers/mfd/twl4030-irq.c
44342 +++ b/drivers/mfd/twl4030-irq.c
44343 @@ -35,6 +35,7 @@
44344 #include <linux/of.h>
44345 #include <linux/irqdomain.h>
44346 #include <linux/i2c/twl.h>
44347 +#include <asm/pgtable.h>
44348
44349 #include "twl-core.h"
44350
44351 @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
44352 * Install an irq handler for each of the SIH modules;
44353 * clone dummy irq_chip since PIH can't *do* anything
44354 */
44355 - twl4030_irq_chip = dummy_irq_chip;
44356 - twl4030_irq_chip.name = "twl4030";
44357 + pax_open_kernel();
44358 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
44359 + *(const char **)&twl4030_irq_chip.name = "twl4030";
44360
44361 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44362 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44363 + pax_close_kernel();
44364
44365 for (i = irq_base; i < irq_end; i++) {
44366 irq_set_chip_and_handler(i, &twl4030_irq_chip,
44367 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
44368 index 464419b..64bae8d 100644
44369 --- a/drivers/misc/c2port/core.c
44370 +++ b/drivers/misc/c2port/core.c
44371 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
44372 goto error_idr_alloc;
44373 c2dev->id = ret;
44374
44375 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44376 + pax_open_kernel();
44377 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44378 + pax_close_kernel();
44379
44380 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
44381 "c2port%d", c2dev->id);
44382 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
44383 index 36f5d52..32311c3 100644
44384 --- a/drivers/misc/kgdbts.c
44385 +++ b/drivers/misc/kgdbts.c
44386 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
44387 char before[BREAK_INSTR_SIZE];
44388 char after[BREAK_INSTR_SIZE];
44389
44390 - probe_kernel_read(before, (char *)kgdbts_break_test,
44391 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
44392 BREAK_INSTR_SIZE);
44393 init_simple_test();
44394 ts.tst = plant_and_detach_test;
44395 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
44396 /* Activate test with initial breakpoint */
44397 if (!is_early)
44398 kgdb_breakpoint();
44399 - probe_kernel_read(after, (char *)kgdbts_break_test,
44400 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
44401 BREAK_INSTR_SIZE);
44402 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
44403 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
44404 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
44405 index 036effe..b3a6336 100644
44406 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
44407 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
44408 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
44409 * the lid is closed. This leads to interrupts as soon as a little move
44410 * is done.
44411 */
44412 - atomic_inc(&lis3->count);
44413 + atomic_inc_unchecked(&lis3->count);
44414
44415 wake_up_interruptible(&lis3->misc_wait);
44416 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
44417 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
44418 if (lis3->pm_dev)
44419 pm_runtime_get_sync(lis3->pm_dev);
44420
44421 - atomic_set(&lis3->count, 0);
44422 + atomic_set_unchecked(&lis3->count, 0);
44423 return 0;
44424 }
44425
44426 @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
44427 add_wait_queue(&lis3->misc_wait, &wait);
44428 while (true) {
44429 set_current_state(TASK_INTERRUPTIBLE);
44430 - data = atomic_xchg(&lis3->count, 0);
44431 + data = atomic_xchg_unchecked(&lis3->count, 0);
44432 if (data)
44433 break;
44434
44435 @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
44436 struct lis3lv02d, miscdev);
44437
44438 poll_wait(file, &lis3->misc_wait, wait);
44439 - if (atomic_read(&lis3->count))
44440 + if (atomic_read_unchecked(&lis3->count))
44441 return POLLIN | POLLRDNORM;
44442 return 0;
44443 }
44444 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
44445 index c439c82..1f20f57 100644
44446 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
44447 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
44448 @@ -297,7 +297,7 @@ struct lis3lv02d {
44449 struct input_polled_dev *idev; /* input device */
44450 struct platform_device *pdev; /* platform device */
44451 struct regulator_bulk_data regulators[2];
44452 - atomic_t count; /* interrupt count after last read */
44453 + atomic_unchecked_t count; /* interrupt count after last read */
44454 union axis_conversion ac; /* hw -> logical axis */
44455 int mapped_btns[3];
44456
44457 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
44458 index 2f30bad..c4c13d0 100644
44459 --- a/drivers/misc/sgi-gru/gruhandles.c
44460 +++ b/drivers/misc/sgi-gru/gruhandles.c
44461 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
44462 unsigned long nsec;
44463
44464 nsec = CLKS2NSEC(clks);
44465 - atomic_long_inc(&mcs_op_statistics[op].count);
44466 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
44467 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
44468 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
44469 if (mcs_op_statistics[op].max < nsec)
44470 mcs_op_statistics[op].max = nsec;
44471 }
44472 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
44473 index 4f76359..cdfcb2e 100644
44474 --- a/drivers/misc/sgi-gru/gruprocfs.c
44475 +++ b/drivers/misc/sgi-gru/gruprocfs.c
44476 @@ -32,9 +32,9 @@
44477
44478 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
44479
44480 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
44481 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
44482 {
44483 - unsigned long val = atomic_long_read(v);
44484 + unsigned long val = atomic_long_read_unchecked(v);
44485
44486 seq_printf(s, "%16lu %s\n", val, id);
44487 }
44488 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
44489
44490 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
44491 for (op = 0; op < mcsop_last; op++) {
44492 - count = atomic_long_read(&mcs_op_statistics[op].count);
44493 - total = atomic_long_read(&mcs_op_statistics[op].total);
44494 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
44495 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
44496 max = mcs_op_statistics[op].max;
44497 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
44498 count ? total / count : 0, max);
44499 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
44500 index 5c3ce24..4915ccb 100644
44501 --- a/drivers/misc/sgi-gru/grutables.h
44502 +++ b/drivers/misc/sgi-gru/grutables.h
44503 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
44504 * GRU statistics.
44505 */
44506 struct gru_stats_s {
44507 - atomic_long_t vdata_alloc;
44508 - atomic_long_t vdata_free;
44509 - atomic_long_t gts_alloc;
44510 - atomic_long_t gts_free;
44511 - atomic_long_t gms_alloc;
44512 - atomic_long_t gms_free;
44513 - atomic_long_t gts_double_allocate;
44514 - atomic_long_t assign_context;
44515 - atomic_long_t assign_context_failed;
44516 - atomic_long_t free_context;
44517 - atomic_long_t load_user_context;
44518 - atomic_long_t load_kernel_context;
44519 - atomic_long_t lock_kernel_context;
44520 - atomic_long_t unlock_kernel_context;
44521 - atomic_long_t steal_user_context;
44522 - atomic_long_t steal_kernel_context;
44523 - atomic_long_t steal_context_failed;
44524 - atomic_long_t nopfn;
44525 - atomic_long_t asid_new;
44526 - atomic_long_t asid_next;
44527 - atomic_long_t asid_wrap;
44528 - atomic_long_t asid_reuse;
44529 - atomic_long_t intr;
44530 - atomic_long_t intr_cbr;
44531 - atomic_long_t intr_tfh;
44532 - atomic_long_t intr_spurious;
44533 - atomic_long_t intr_mm_lock_failed;
44534 - atomic_long_t call_os;
44535 - atomic_long_t call_os_wait_queue;
44536 - atomic_long_t user_flush_tlb;
44537 - atomic_long_t user_unload_context;
44538 - atomic_long_t user_exception;
44539 - atomic_long_t set_context_option;
44540 - atomic_long_t check_context_retarget_intr;
44541 - atomic_long_t check_context_unload;
44542 - atomic_long_t tlb_dropin;
44543 - atomic_long_t tlb_preload_page;
44544 - atomic_long_t tlb_dropin_fail_no_asid;
44545 - atomic_long_t tlb_dropin_fail_upm;
44546 - atomic_long_t tlb_dropin_fail_invalid;
44547 - atomic_long_t tlb_dropin_fail_range_active;
44548 - atomic_long_t tlb_dropin_fail_idle;
44549 - atomic_long_t tlb_dropin_fail_fmm;
44550 - atomic_long_t tlb_dropin_fail_no_exception;
44551 - atomic_long_t tfh_stale_on_fault;
44552 - atomic_long_t mmu_invalidate_range;
44553 - atomic_long_t mmu_invalidate_page;
44554 - atomic_long_t flush_tlb;
44555 - atomic_long_t flush_tlb_gru;
44556 - atomic_long_t flush_tlb_gru_tgh;
44557 - atomic_long_t flush_tlb_gru_zero_asid;
44558 + atomic_long_unchecked_t vdata_alloc;
44559 + atomic_long_unchecked_t vdata_free;
44560 + atomic_long_unchecked_t gts_alloc;
44561 + atomic_long_unchecked_t gts_free;
44562 + atomic_long_unchecked_t gms_alloc;
44563 + atomic_long_unchecked_t gms_free;
44564 + atomic_long_unchecked_t gts_double_allocate;
44565 + atomic_long_unchecked_t assign_context;
44566 + atomic_long_unchecked_t assign_context_failed;
44567 + atomic_long_unchecked_t free_context;
44568 + atomic_long_unchecked_t load_user_context;
44569 + atomic_long_unchecked_t load_kernel_context;
44570 + atomic_long_unchecked_t lock_kernel_context;
44571 + atomic_long_unchecked_t unlock_kernel_context;
44572 + atomic_long_unchecked_t steal_user_context;
44573 + atomic_long_unchecked_t steal_kernel_context;
44574 + atomic_long_unchecked_t steal_context_failed;
44575 + atomic_long_unchecked_t nopfn;
44576 + atomic_long_unchecked_t asid_new;
44577 + atomic_long_unchecked_t asid_next;
44578 + atomic_long_unchecked_t asid_wrap;
44579 + atomic_long_unchecked_t asid_reuse;
44580 + atomic_long_unchecked_t intr;
44581 + atomic_long_unchecked_t intr_cbr;
44582 + atomic_long_unchecked_t intr_tfh;
44583 + atomic_long_unchecked_t intr_spurious;
44584 + atomic_long_unchecked_t intr_mm_lock_failed;
44585 + atomic_long_unchecked_t call_os;
44586 + atomic_long_unchecked_t call_os_wait_queue;
44587 + atomic_long_unchecked_t user_flush_tlb;
44588 + atomic_long_unchecked_t user_unload_context;
44589 + atomic_long_unchecked_t user_exception;
44590 + atomic_long_unchecked_t set_context_option;
44591 + atomic_long_unchecked_t check_context_retarget_intr;
44592 + atomic_long_unchecked_t check_context_unload;
44593 + atomic_long_unchecked_t tlb_dropin;
44594 + atomic_long_unchecked_t tlb_preload_page;
44595 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
44596 + atomic_long_unchecked_t tlb_dropin_fail_upm;
44597 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
44598 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
44599 + atomic_long_unchecked_t tlb_dropin_fail_idle;
44600 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
44601 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
44602 + atomic_long_unchecked_t tfh_stale_on_fault;
44603 + atomic_long_unchecked_t mmu_invalidate_range;
44604 + atomic_long_unchecked_t mmu_invalidate_page;
44605 + atomic_long_unchecked_t flush_tlb;
44606 + atomic_long_unchecked_t flush_tlb_gru;
44607 + atomic_long_unchecked_t flush_tlb_gru_tgh;
44608 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
44609
44610 - atomic_long_t copy_gpa;
44611 - atomic_long_t read_gpa;
44612 + atomic_long_unchecked_t copy_gpa;
44613 + atomic_long_unchecked_t read_gpa;
44614
44615 - atomic_long_t mesq_receive;
44616 - atomic_long_t mesq_receive_none;
44617 - atomic_long_t mesq_send;
44618 - atomic_long_t mesq_send_failed;
44619 - atomic_long_t mesq_noop;
44620 - atomic_long_t mesq_send_unexpected_error;
44621 - atomic_long_t mesq_send_lb_overflow;
44622 - atomic_long_t mesq_send_qlimit_reached;
44623 - atomic_long_t mesq_send_amo_nacked;
44624 - atomic_long_t mesq_send_put_nacked;
44625 - atomic_long_t mesq_page_overflow;
44626 - atomic_long_t mesq_qf_locked;
44627 - atomic_long_t mesq_qf_noop_not_full;
44628 - atomic_long_t mesq_qf_switch_head_failed;
44629 - atomic_long_t mesq_qf_unexpected_error;
44630 - atomic_long_t mesq_noop_unexpected_error;
44631 - atomic_long_t mesq_noop_lb_overflow;
44632 - atomic_long_t mesq_noop_qlimit_reached;
44633 - atomic_long_t mesq_noop_amo_nacked;
44634 - atomic_long_t mesq_noop_put_nacked;
44635 - atomic_long_t mesq_noop_page_overflow;
44636 + atomic_long_unchecked_t mesq_receive;
44637 + atomic_long_unchecked_t mesq_receive_none;
44638 + atomic_long_unchecked_t mesq_send;
44639 + atomic_long_unchecked_t mesq_send_failed;
44640 + atomic_long_unchecked_t mesq_noop;
44641 + atomic_long_unchecked_t mesq_send_unexpected_error;
44642 + atomic_long_unchecked_t mesq_send_lb_overflow;
44643 + atomic_long_unchecked_t mesq_send_qlimit_reached;
44644 + atomic_long_unchecked_t mesq_send_amo_nacked;
44645 + atomic_long_unchecked_t mesq_send_put_nacked;
44646 + atomic_long_unchecked_t mesq_page_overflow;
44647 + atomic_long_unchecked_t mesq_qf_locked;
44648 + atomic_long_unchecked_t mesq_qf_noop_not_full;
44649 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
44650 + atomic_long_unchecked_t mesq_qf_unexpected_error;
44651 + atomic_long_unchecked_t mesq_noop_unexpected_error;
44652 + atomic_long_unchecked_t mesq_noop_lb_overflow;
44653 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
44654 + atomic_long_unchecked_t mesq_noop_amo_nacked;
44655 + atomic_long_unchecked_t mesq_noop_put_nacked;
44656 + atomic_long_unchecked_t mesq_noop_page_overflow;
44657
44658 };
44659
44660 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
44661 tghop_invalidate, mcsop_last};
44662
44663 struct mcs_op_statistic {
44664 - atomic_long_t count;
44665 - atomic_long_t total;
44666 + atomic_long_unchecked_t count;
44667 + atomic_long_unchecked_t total;
44668 unsigned long max;
44669 };
44670
44671 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
44672
44673 #define STAT(id) do { \
44674 if (gru_options & OPT_STATS) \
44675 - atomic_long_inc(&gru_stats.id); \
44676 + atomic_long_inc_unchecked(&gru_stats.id); \
44677 } while (0)
44678
44679 #ifdef CONFIG_SGI_GRU_DEBUG
44680 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
44681 index c862cd4..0d176fe 100644
44682 --- a/drivers/misc/sgi-xp/xp.h
44683 +++ b/drivers/misc/sgi-xp/xp.h
44684 @@ -288,7 +288,7 @@ struct xpc_interface {
44685 xpc_notify_func, void *);
44686 void (*received) (short, int, void *);
44687 enum xp_retval (*partid_to_nasids) (short, void *);
44688 -};
44689 +} __no_const;
44690
44691 extern struct xpc_interface xpc_interface;
44692
44693 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
44694 index 01be66d..e3a0c7e 100644
44695 --- a/drivers/misc/sgi-xp/xp_main.c
44696 +++ b/drivers/misc/sgi-xp/xp_main.c
44697 @@ -78,13 +78,13 @@ xpc_notloaded(void)
44698 }
44699
44700 struct xpc_interface xpc_interface = {
44701 - (void (*)(int))xpc_notloaded,
44702 - (void (*)(int))xpc_notloaded,
44703 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44704 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44705 + .connect = (void (*)(int))xpc_notloaded,
44706 + .disconnect = (void (*)(int))xpc_notloaded,
44707 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44708 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44709 void *))xpc_notloaded,
44710 - (void (*)(short, int, void *))xpc_notloaded,
44711 - (enum xp_retval(*)(short, void *))xpc_notloaded
44712 + .received = (void (*)(short, int, void *))xpc_notloaded,
44713 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
44714 };
44715 EXPORT_SYMBOL_GPL(xpc_interface);
44716
44717 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
44718 index b94d5f7..7f494c5 100644
44719 --- a/drivers/misc/sgi-xp/xpc.h
44720 +++ b/drivers/misc/sgi-xp/xpc.h
44721 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
44722 void (*received_payload) (struct xpc_channel *, void *);
44723 void (*notify_senders_of_disconnect) (struct xpc_channel *);
44724 };
44725 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
44726
44727 /* struct xpc_partition act_state values (for XPC HB) */
44728
44729 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
44730 /* found in xpc_main.c */
44731 extern struct device *xpc_part;
44732 extern struct device *xpc_chan;
44733 -extern struct xpc_arch_operations xpc_arch_ops;
44734 +extern xpc_arch_operations_no_const xpc_arch_ops;
44735 extern int xpc_disengage_timelimit;
44736 extern int xpc_disengage_timedout;
44737 extern int xpc_activate_IRQ_rcvd;
44738 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
44739 index 82dc574..8539ab2 100644
44740 --- a/drivers/misc/sgi-xp/xpc_main.c
44741 +++ b/drivers/misc/sgi-xp/xpc_main.c
44742 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
44743 .notifier_call = xpc_system_die,
44744 };
44745
44746 -struct xpc_arch_operations xpc_arch_ops;
44747 +xpc_arch_operations_no_const xpc_arch_ops;
44748
44749 /*
44750 * Timer function to enforce the timelimit on the partition disengage.
44751 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44752
44753 if (((die_args->trapnr == X86_TRAP_MF) ||
44754 (die_args->trapnr == X86_TRAP_XF)) &&
44755 - !user_mode_vm(die_args->regs))
44756 + !user_mode(die_args->regs))
44757 xpc_die_deactivate();
44758
44759 break;
44760 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
44761 index 29d5d98..fea356f 100644
44762 --- a/drivers/mmc/card/block.c
44763 +++ b/drivers/mmc/card/block.c
44764 @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
44765 if (idata->ic.postsleep_min_us)
44766 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
44767
44768 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
44769 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
44770 err = -EFAULT;
44771 goto cmd_rel_host;
44772 }
44773 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44774 index e5b5eeb..7bf2212 100644
44775 --- a/drivers/mmc/core/mmc_ops.c
44776 +++ b/drivers/mmc/core/mmc_ops.c
44777 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44778 void *data_buf;
44779 int is_on_stack;
44780
44781 - is_on_stack = object_is_on_stack(buf);
44782 + is_on_stack = object_starts_on_stack(buf);
44783 if (is_on_stack) {
44784 /*
44785 * dma onto stack is unsafe/nonportable, but callers to this
44786 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44787 index 6bf24ab..13d0293b 100644
44788 --- a/drivers/mmc/host/dw_mmc.h
44789 +++ b/drivers/mmc/host/dw_mmc.h
44790 @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
44791 int (*parse_dt)(struct dw_mci *host);
44792 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
44793 struct dw_mci_tuning_data *tuning_data);
44794 -};
44795 +} __do_const;
44796 #endif /* _DW_MMC_H_ */
44797 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
44798 index f320579..7b7ebac 100644
44799 --- a/drivers/mmc/host/mmci.c
44800 +++ b/drivers/mmc/host/mmci.c
44801 @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
44802 }
44803
44804 if (variant->busy_detect) {
44805 - mmci_ops.card_busy = mmci_card_busy;
44806 + pax_open_kernel();
44807 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
44808 + pax_close_kernel();
44809 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
44810 }
44811
44812 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44813 index 6debda9..2ba7427 100644
44814 --- a/drivers/mmc/host/sdhci-s3c.c
44815 +++ b/drivers/mmc/host/sdhci-s3c.c
44816 @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44817 * we can use overriding functions instead of default.
44818 */
44819 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44820 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44821 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44822 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44823 + pax_open_kernel();
44824 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44825 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44826 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44827 + pax_close_kernel();
44828 }
44829
44830 /* It supports additional host capabilities if needed */
44831 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
44832 index 096993f..f02c23b 100644
44833 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
44834 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
44835 @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
44836 size_t totlen = 0, thislen;
44837 int ret = 0;
44838 size_t buflen = 0;
44839 - static char *buffer;
44840 + char *buffer;
44841
44842 if (!ECCBUF_SIZE) {
44843 /* We should fall back to a general writev implementation.
44844 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44845 index 370b9dd..1a1176b 100644
44846 --- a/drivers/mtd/nand/denali.c
44847 +++ b/drivers/mtd/nand/denali.c
44848 @@ -24,6 +24,7 @@
44849 #include <linux/slab.h>
44850 #include <linux/mtd/mtd.h>
44851 #include <linux/module.h>
44852 +#include <linux/slab.h>
44853
44854 #include "denali.h"
44855
44856 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44857 index 51b9d6a..52af9a7 100644
44858 --- a/drivers/mtd/nftlmount.c
44859 +++ b/drivers/mtd/nftlmount.c
44860 @@ -24,6 +24,7 @@
44861 #include <asm/errno.h>
44862 #include <linux/delay.h>
44863 #include <linux/slab.h>
44864 +#include <linux/sched.h>
44865 #include <linux/mtd/mtd.h>
44866 #include <linux/mtd/nand.h>
44867 #include <linux/mtd/nftl.h>
44868 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44869 index 4b8e895..6b3c498 100644
44870 --- a/drivers/mtd/sm_ftl.c
44871 +++ b/drivers/mtd/sm_ftl.c
44872 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44873 #define SM_CIS_VENDOR_OFFSET 0x59
44874 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44875 {
44876 - struct attribute_group *attr_group;
44877 + attribute_group_no_const *attr_group;
44878 struct attribute **attributes;
44879 struct sm_sysfs_attribute *vendor_attribute;
44880
44881 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44882 index 4b8c58b..a200546 100644
44883 --- a/drivers/net/bonding/bond_main.c
44884 +++ b/drivers/net/bonding/bond_main.c
44885 @@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
44886
44887 bond_netlink_fini();
44888 unregister_pernet_subsys(&bond_net_ops);
44889 + rtnl_link_unregister(&bond_link_ops);
44890
44891 #ifdef CONFIG_NET_POLL_CONTROLLER
44892 /*
44893 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
44894 index 40e7b1c..6a70fff 100644
44895 --- a/drivers/net/bonding/bond_netlink.c
44896 +++ b/drivers/net/bonding/bond_netlink.c
44897 @@ -102,7 +102,7 @@ nla_put_failure:
44898 return -EMSGSIZE;
44899 }
44900
44901 -struct rtnl_link_ops bond_link_ops __read_mostly = {
44902 +struct rtnl_link_ops bond_link_ops = {
44903 .kind = "bond",
44904 .priv_size = sizeof(struct bonding),
44905 .setup = bond_setup,
44906 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44907 index 36fa577..a158806 100644
44908 --- a/drivers/net/ethernet/8390/ax88796.c
44909 +++ b/drivers/net/ethernet/8390/ax88796.c
44910 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44911 if (ax->plat->reg_offsets)
44912 ei_local->reg_offset = ax->plat->reg_offsets;
44913 else {
44914 + resource_size_t _mem_size = mem_size;
44915 + do_div(_mem_size, 0x18);
44916 ei_local->reg_offset = ax->reg_offsets;
44917 for (ret = 0; ret < 0x18; ret++)
44918 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44919 + ax->reg_offsets[ret] = _mem_size * ret;
44920 }
44921
44922 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44923 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44924 index 41f3ca5a..1ee5364 100644
44925 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44926 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44927 @@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44928 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44929 {
44930 /* RX_MODE controlling object */
44931 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44932 + bnx2x_init_rx_mode_obj(bp);
44933
44934 /* multicast configuration controlling object */
44935 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44936 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44937 index 18438a5..c923b8e 100644
44938 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44939 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44940 @@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44941 return rc;
44942 }
44943
44944 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44945 - struct bnx2x_rx_mode_obj *o)
44946 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44947 {
44948 if (CHIP_IS_E1x(bp)) {
44949 - o->wait_comp = bnx2x_empty_rx_mode_wait;
44950 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44951 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44952 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44953 } else {
44954 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44955 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
44956 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44957 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44958 }
44959 }
44960
44961 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44962 index 6a53c15..6e7d1e7 100644
44963 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44964 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44965 @@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44966
44967 /********************* RX MODE ****************/
44968
44969 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44970 - struct bnx2x_rx_mode_obj *o);
44971 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44972
44973 /**
44974 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44975 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44976 index 5c3835a..d18b952 100644
44977 --- a/drivers/net/ethernet/broadcom/tg3.h
44978 +++ b/drivers/net/ethernet/broadcom/tg3.h
44979 @@ -150,6 +150,7 @@
44980 #define CHIPREV_ID_5750_A0 0x4000
44981 #define CHIPREV_ID_5750_A1 0x4001
44982 #define CHIPREV_ID_5750_A3 0x4003
44983 +#define CHIPREV_ID_5750_C1 0x4201
44984 #define CHIPREV_ID_5750_C2 0x4202
44985 #define CHIPREV_ID_5752_A0_HW 0x5000
44986 #define CHIPREV_ID_5752_A0 0x6000
44987 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
44988 index 3ca77fa..fcc015f 100644
44989 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
44990 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
44991 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
44992 }
44993
44994 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
44995 - bna_cb_ioceth_enable,
44996 - bna_cb_ioceth_disable,
44997 - bna_cb_ioceth_hbfail,
44998 - bna_cb_ioceth_reset
44999 + .enable_cbfn = bna_cb_ioceth_enable,
45000 + .disable_cbfn = bna_cb_ioceth_disable,
45001 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
45002 + .reset_cbfn = bna_cb_ioceth_reset
45003 };
45004
45005 static void bna_attr_init(struct bna_ioceth *ioceth)
45006 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45007 index 8cffcdf..aadf043 100644
45008 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45009 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45010 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45011 */
45012 struct l2t_skb_cb {
45013 arp_failure_handler_func arp_failure_handler;
45014 -};
45015 +} __no_const;
45016
45017 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45018
45019 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45020 index fff02ed..d421412 100644
45021 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45022 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45023 @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45024
45025 int i;
45026 struct adapter *ap = netdev2adap(dev);
45027 - static const unsigned int *reg_ranges;
45028 + const unsigned int *reg_ranges;
45029 int arr_size = 0, buf_size = 0;
45030
45031 if (is_t4(ap->params.chip)) {
45032 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45033 index c05b66d..ed69872 100644
45034 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
45035 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45036 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45037 for (i=0; i<ETH_ALEN; i++) {
45038 tmp.addr[i] = dev->dev_addr[i];
45039 }
45040 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45041 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45042 break;
45043
45044 case DE4X5_SET_HWADDR: /* Set the hardware address */
45045 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45046 spin_lock_irqsave(&lp->lock, flags);
45047 memcpy(&statbuf, &lp->pktStats, ioc->len);
45048 spin_unlock_irqrestore(&lp->lock, flags);
45049 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
45050 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45051 return -EFAULT;
45052 break;
45053 }
45054 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45055 index a37039d..a51d7e8 100644
45056 --- a/drivers/net/ethernet/emulex/benet/be_main.c
45057 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
45058 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45059
45060 if (wrapped)
45061 newacc += 65536;
45062 - ACCESS_ONCE(*acc) = newacc;
45063 + ACCESS_ONCE_RW(*acc) = newacc;
45064 }
45065
45066 static void populate_erx_stats(struct be_adapter *adapter,
45067 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45068 index 212f44b..fb69959 100644
45069 --- a/drivers/net/ethernet/faraday/ftgmac100.c
45070 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
45071 @@ -31,6 +31,8 @@
45072 #include <linux/netdevice.h>
45073 #include <linux/phy.h>
45074 #include <linux/platform_device.h>
45075 +#include <linux/interrupt.h>
45076 +#include <linux/irqreturn.h>
45077 #include <net/ip.h>
45078
45079 #include "ftgmac100.h"
45080 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45081 index 8be5b40..081bc1b 100644
45082 --- a/drivers/net/ethernet/faraday/ftmac100.c
45083 +++ b/drivers/net/ethernet/faraday/ftmac100.c
45084 @@ -31,6 +31,8 @@
45085 #include <linux/module.h>
45086 #include <linux/netdevice.h>
45087 #include <linux/platform_device.h>
45088 +#include <linux/interrupt.h>
45089 +#include <linux/irqreturn.h>
45090
45091 #include "ftmac100.h"
45092
45093 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45094 index 5184e2a..acb28c3 100644
45095 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45096 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45097 @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45098 }
45099
45100 /* update the base incval used to calculate frequency adjustment */
45101 - ACCESS_ONCE(adapter->base_incval) = incval;
45102 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
45103 smp_mb();
45104
45105 /* need lock to prevent incorrect read while modifying cyclecounter */
45106 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45107 index fbe5363..266b4e3 100644
45108 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45109 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45110 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45111 struct __vxge_hw_fifo *fifo;
45112 struct vxge_hw_fifo_config *config;
45113 u32 txdl_size, txdl_per_memblock;
45114 - struct vxge_hw_mempool_cbs fifo_mp_callback;
45115 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45116 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45117 + };
45118 +
45119 struct __vxge_hw_virtualpath *vpath;
45120
45121 if ((vp == NULL) || (attr == NULL)) {
45122 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45123 goto exit;
45124 }
45125
45126 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45127 -
45128 fifo->mempool =
45129 __vxge_hw_mempool_create(vpath->hldev,
45130 fifo->config->memblock_size,
45131 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45132 index 918e18d..4ca3650 100644
45133 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45134 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45135 @@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45136 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45137 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45138 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45139 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45140 + pax_open_kernel();
45141 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45142 + pax_close_kernel();
45143 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45144 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45145 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45146 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45147 index 734d286..b017bf5 100644
45148 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45149 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45150 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45151 case QLCNIC_NON_PRIV_FUNC:
45152 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45153 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45154 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45155 + pax_open_kernel();
45156 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45157 + pax_close_kernel();
45158 break;
45159 case QLCNIC_PRIV_FUNC:
45160 ahw->op_mode = QLCNIC_PRIV_FUNC;
45161 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45162 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45163 + pax_open_kernel();
45164 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45165 + pax_close_kernel();
45166 break;
45167 case QLCNIC_MGMT_FUNC:
45168 ahw->op_mode = QLCNIC_MGMT_FUNC;
45169 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45170 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45171 + pax_open_kernel();
45172 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45173 + pax_close_kernel();
45174 break;
45175 default:
45176 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45177 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45178 index 7763962..c3499a7 100644
45179 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45180 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45181 @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45182 struct qlcnic_dump_entry *entry;
45183 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45184 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45185 - static const struct qlcnic_dump_operations *fw_dump_ops;
45186 + const struct qlcnic_dump_operations *fw_dump_ops;
45187 struct device *dev = &adapter->pdev->dev;
45188 struct qlcnic_hardware_context *ahw;
45189 void *temp_buffer;
45190 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45191 index c737f0e..32b8682 100644
45192 --- a/drivers/net/ethernet/realtek/r8169.c
45193 +++ b/drivers/net/ethernet/realtek/r8169.c
45194 @@ -759,22 +759,22 @@ struct rtl8169_private {
45195 struct mdio_ops {
45196 void (*write)(struct rtl8169_private *, int, int);
45197 int (*read)(struct rtl8169_private *, int);
45198 - } mdio_ops;
45199 + } __no_const mdio_ops;
45200
45201 struct pll_power_ops {
45202 void (*down)(struct rtl8169_private *);
45203 void (*up)(struct rtl8169_private *);
45204 - } pll_power_ops;
45205 + } __no_const pll_power_ops;
45206
45207 struct jumbo_ops {
45208 void (*enable)(struct rtl8169_private *);
45209 void (*disable)(struct rtl8169_private *);
45210 - } jumbo_ops;
45211 + } __no_const jumbo_ops;
45212
45213 struct csi_ops {
45214 void (*write)(struct rtl8169_private *, int, int);
45215 u32 (*read)(struct rtl8169_private *, int);
45216 - } csi_ops;
45217 + } __no_const csi_ops;
45218
45219 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45220 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45221 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45222 index 3dd39dc..85efa46 100644
45223 --- a/drivers/net/ethernet/sfc/ptp.c
45224 +++ b/drivers/net/ethernet/sfc/ptp.c
45225 @@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
45226 ptp->start.dma_addr);
45227
45228 /* Clear flag that signals MC ready */
45229 - ACCESS_ONCE(*start) = 0;
45230 + ACCESS_ONCE_RW(*start) = 0;
45231 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
45232 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
45233 EFX_BUG_ON_PARANOID(rc);
45234 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45235 index 50617c5..b13724c 100644
45236 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45237 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45238 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
45239
45240 writel(value, ioaddr + MMC_CNTRL);
45241
45242 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45243 - MMC_CNTRL, value);
45244 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45245 +// MMC_CNTRL, value);
45246 }
45247
45248 /* To mask all all interrupts.*/
45249 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
45250 index e6fe0d8..2b7d752 100644
45251 --- a/drivers/net/hyperv/hyperv_net.h
45252 +++ b/drivers/net/hyperv/hyperv_net.h
45253 @@ -101,7 +101,7 @@ struct rndis_device {
45254
45255 enum rndis_device_state state;
45256 bool link_state;
45257 - atomic_t new_req_id;
45258 + atomic_unchecked_t new_req_id;
45259
45260 spinlock_t request_lock;
45261 struct list_head req_list;
45262 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
45263 index 0775f0a..d4fb316 100644
45264 --- a/drivers/net/hyperv/rndis_filter.c
45265 +++ b/drivers/net/hyperv/rndis_filter.c
45266 @@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
45267 * template
45268 */
45269 set = &rndis_msg->msg.set_req;
45270 - set->req_id = atomic_inc_return(&dev->new_req_id);
45271 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45272
45273 /* Add to the request list */
45274 spin_lock_irqsave(&dev->request_lock, flags);
45275 @@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
45276
45277 /* Setup the rndis set */
45278 halt = &request->request_msg.msg.halt_req;
45279 - halt->req_id = atomic_inc_return(&dev->new_req_id);
45280 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45281
45282 /* Ignore return since this msg is optional. */
45283 rndis_filter_send_request(dev, request);
45284 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
45285 index bf0d55e..82bcfbd1 100644
45286 --- a/drivers/net/ieee802154/fakehard.c
45287 +++ b/drivers/net/ieee802154/fakehard.c
45288 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
45289 phy->transmit_power = 0xbf;
45290
45291 dev->netdev_ops = &fake_ops;
45292 - dev->ml_priv = &fake_mlme;
45293 + dev->ml_priv = (void *)&fake_mlme;
45294
45295 priv = netdev_priv(dev);
45296 priv->phy = phy;
45297 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
45298 index bc8faae..e51e25d 100644
45299 --- a/drivers/net/macvlan.c
45300 +++ b/drivers/net/macvlan.c
45301 @@ -990,13 +990,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
45302 int macvlan_link_register(struct rtnl_link_ops *ops)
45303 {
45304 /* common fields */
45305 - ops->priv_size = sizeof(struct macvlan_dev);
45306 - ops->validate = macvlan_validate;
45307 - ops->maxtype = IFLA_MACVLAN_MAX;
45308 - ops->policy = macvlan_policy;
45309 - ops->changelink = macvlan_changelink;
45310 - ops->get_size = macvlan_get_size;
45311 - ops->fill_info = macvlan_fill_info;
45312 + pax_open_kernel();
45313 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
45314 + *(void **)&ops->validate = macvlan_validate;
45315 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
45316 + *(const void **)&ops->policy = macvlan_policy;
45317 + *(void **)&ops->changelink = macvlan_changelink;
45318 + *(void **)&ops->get_size = macvlan_get_size;
45319 + *(void **)&ops->fill_info = macvlan_fill_info;
45320 + pax_close_kernel();
45321
45322 return rtnl_link_register(ops);
45323 };
45324 @@ -1051,7 +1053,7 @@ static int macvlan_device_event(struct notifier_block *unused,
45325 return NOTIFY_DONE;
45326 }
45327
45328 -static struct notifier_block macvlan_notifier_block __read_mostly = {
45329 +static struct notifier_block macvlan_notifier_block = {
45330 .notifier_call = macvlan_device_event,
45331 };
45332
45333 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
45334 index 2a89da0..c17fe1d 100644
45335 --- a/drivers/net/macvtap.c
45336 +++ b/drivers/net/macvtap.c
45337 @@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
45338 }
45339
45340 ret = 0;
45341 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
45342 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
45343 put_user(q->flags, &ifr->ifr_flags))
45344 ret = -EFAULT;
45345 macvtap_put_vlan(vlan);
45346 @@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
45347 return NOTIFY_DONE;
45348 }
45349
45350 -static struct notifier_block macvtap_notifier_block __read_mostly = {
45351 +static struct notifier_block macvtap_notifier_block = {
45352 .notifier_call = macvtap_device_event,
45353 };
45354
45355 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
45356 index daec9b0..6428fcb 100644
45357 --- a/drivers/net/phy/mdio-bitbang.c
45358 +++ b/drivers/net/phy/mdio-bitbang.c
45359 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
45360 struct mdiobb_ctrl *ctrl = bus->priv;
45361
45362 module_put(ctrl->ops->owner);
45363 + mdiobus_unregister(bus);
45364 mdiobus_free(bus);
45365 }
45366 EXPORT_SYMBOL(free_mdio_bitbang);
45367 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
45368 index 72ff14b..11d442d 100644
45369 --- a/drivers/net/ppp/ppp_generic.c
45370 +++ b/drivers/net/ppp/ppp_generic.c
45371 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45372 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
45373 struct ppp_stats stats;
45374 struct ppp_comp_stats cstats;
45375 - char *vers;
45376
45377 switch (cmd) {
45378 case SIOCGPPPSTATS:
45379 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45380 break;
45381
45382 case SIOCGPPPVER:
45383 - vers = PPP_VERSION;
45384 - if (copy_to_user(addr, vers, strlen(vers) + 1))
45385 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
45386 break;
45387 err = 0;
45388 break;
45389 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
45390 index 1252d9c..80e660b 100644
45391 --- a/drivers/net/slip/slhc.c
45392 +++ b/drivers/net/slip/slhc.c
45393 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
45394 register struct tcphdr *thp;
45395 register struct iphdr *ip;
45396 register struct cstate *cs;
45397 - int len, hdrlen;
45398 + long len, hdrlen;
45399 unsigned char *cp = icp;
45400
45401 /* We've got a compressed packet; read the change byte */
45402 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
45403 index b75ae5b..953c157 100644
45404 --- a/drivers/net/team/team.c
45405 +++ b/drivers/net/team/team.c
45406 @@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
45407 return NOTIFY_DONE;
45408 }
45409
45410 -static struct notifier_block team_notifier_block __read_mostly = {
45411 +static struct notifier_block team_notifier_block = {
45412 .notifier_call = team_device_event,
45413 };
45414
45415 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
45416 index ecec802..614f08f 100644
45417 --- a/drivers/net/tun.c
45418 +++ b/drivers/net/tun.c
45419 @@ -1839,7 +1839,7 @@ unlock:
45420 }
45421
45422 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45423 - unsigned long arg, int ifreq_len)
45424 + unsigned long arg, size_t ifreq_len)
45425 {
45426 struct tun_file *tfile = file->private_data;
45427 struct tun_struct *tun;
45428 @@ -1852,6 +1852,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45429 unsigned int ifindex;
45430 int ret;
45431
45432 + if (ifreq_len > sizeof ifr)
45433 + return -EFAULT;
45434 +
45435 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
45436 if (copy_from_user(&ifr, argp, ifreq_len))
45437 return -EFAULT;
45438 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
45439 index 1a48234..a555339 100644
45440 --- a/drivers/net/usb/hso.c
45441 +++ b/drivers/net/usb/hso.c
45442 @@ -71,7 +71,7 @@
45443 #include <asm/byteorder.h>
45444 #include <linux/serial_core.h>
45445 #include <linux/serial.h>
45446 -
45447 +#include <asm/local.h>
45448
45449 #define MOD_AUTHOR "Option Wireless"
45450 #define MOD_DESCRIPTION "USB High Speed Option driver"
45451 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
45452 struct urb *urb;
45453
45454 urb = serial->rx_urb[0];
45455 - if (serial->port.count > 0) {
45456 + if (atomic_read(&serial->port.count) > 0) {
45457 count = put_rxbuf_data(urb, serial);
45458 if (count == -1)
45459 return;
45460 @@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
45461 DUMP1(urb->transfer_buffer, urb->actual_length);
45462
45463 /* Anyone listening? */
45464 - if (serial->port.count == 0)
45465 + if (atomic_read(&serial->port.count) == 0)
45466 return;
45467
45468 if (status == 0) {
45469 @@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45470 tty_port_tty_set(&serial->port, tty);
45471
45472 /* check for port already opened, if not set the termios */
45473 - serial->port.count++;
45474 - if (serial->port.count == 1) {
45475 + if (atomic_inc_return(&serial->port.count) == 1) {
45476 serial->rx_state = RX_IDLE;
45477 /* Force default termio settings */
45478 _hso_serial_set_termios(tty, NULL);
45479 @@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45480 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
45481 if (result) {
45482 hso_stop_serial_device(serial->parent);
45483 - serial->port.count--;
45484 + atomic_dec(&serial->port.count);
45485 kref_put(&serial->parent->ref, hso_serial_ref_free);
45486 }
45487 } else {
45488 @@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
45489
45490 /* reset the rts and dtr */
45491 /* do the actual close */
45492 - serial->port.count--;
45493 + atomic_dec(&serial->port.count);
45494
45495 - if (serial->port.count <= 0) {
45496 - serial->port.count = 0;
45497 + if (atomic_read(&serial->port.count) <= 0) {
45498 + atomic_set(&serial->port.count, 0);
45499 tty_port_tty_set(&serial->port, NULL);
45500 if (!usb_gone)
45501 hso_stop_serial_device(serial->parent);
45502 @@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
45503
45504 /* the actual setup */
45505 spin_lock_irqsave(&serial->serial_lock, flags);
45506 - if (serial->port.count)
45507 + if (atomic_read(&serial->port.count))
45508 _hso_serial_set_termios(tty, old);
45509 else
45510 tty->termios = *old;
45511 @@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
45512 D1("Pending read interrupt on port %d\n", i);
45513 spin_lock(&serial->serial_lock);
45514 if (serial->rx_state == RX_IDLE &&
45515 - serial->port.count > 0) {
45516 + atomic_read(&serial->port.count) > 0) {
45517 /* Setup and send a ctrl req read on
45518 * port i */
45519 if (!serial->rx_urb_filled[0]) {
45520 @@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
45521 /* Start all serial ports */
45522 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
45523 if (serial_table[i] && (serial_table[i]->interface == iface)) {
45524 - if (dev2ser(serial_table[i])->port.count) {
45525 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
45526 result =
45527 hso_start_serial_device(serial_table[i], GFP_NOIO);
45528 hso_kick_transmit(dev2ser(serial_table[i]));
45529 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
45530 index a79e9d3..78cd4fa 100644
45531 --- a/drivers/net/usb/sierra_net.c
45532 +++ b/drivers/net/usb/sierra_net.c
45533 @@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
45534 /* atomic counter partially included in MAC address to make sure 2 devices
45535 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
45536 */
45537 -static atomic_t iface_counter = ATOMIC_INIT(0);
45538 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
45539
45540 /*
45541 * SYNC Timer Delay definition used to set the expiry time
45542 @@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
45543 dev->net->netdev_ops = &sierra_net_device_ops;
45544
45545 /* change MAC addr to include, ifacenum, and to be unique */
45546 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
45547 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
45548 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
45549
45550 /* we will have to manufacture ethernet headers, prepare template */
45551 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
45552 index ed384fe..9e3f4f4 100644
45553 --- a/drivers/net/vxlan.c
45554 +++ b/drivers/net/vxlan.c
45555 @@ -2617,7 +2617,7 @@ nla_put_failure:
45556 return -EMSGSIZE;
45557 }
45558
45559 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
45560 +static struct rtnl_link_ops vxlan_link_ops = {
45561 .kind = "vxlan",
45562 .maxtype = IFLA_VXLAN_MAX,
45563 .policy = vxlan_policy,
45564 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
45565 index 5920c99..ff2e4a5 100644
45566 --- a/drivers/net/wan/lmc/lmc_media.c
45567 +++ b/drivers/net/wan/lmc/lmc_media.c
45568 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
45569 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
45570
45571 lmc_media_t lmc_ds3_media = {
45572 - lmc_ds3_init, /* special media init stuff */
45573 - lmc_ds3_default, /* reset to default state */
45574 - lmc_ds3_set_status, /* reset status to state provided */
45575 - lmc_dummy_set_1, /* set clock source */
45576 - lmc_dummy_set2_1, /* set line speed */
45577 - lmc_ds3_set_100ft, /* set cable length */
45578 - lmc_ds3_set_scram, /* set scrambler */
45579 - lmc_ds3_get_link_status, /* get link status */
45580 - lmc_dummy_set_1, /* set link status */
45581 - lmc_ds3_set_crc_length, /* set CRC length */
45582 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
45583 - lmc_ds3_watchdog
45584 + .init = lmc_ds3_init, /* special media init stuff */
45585 + .defaults = lmc_ds3_default, /* reset to default state */
45586 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
45587 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
45588 + .set_speed = lmc_dummy_set2_1, /* set line speed */
45589 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
45590 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
45591 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
45592 + .set_link_status = lmc_dummy_set_1, /* set link status */
45593 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
45594 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45595 + .watchdog = lmc_ds3_watchdog
45596 };
45597
45598 lmc_media_t lmc_hssi_media = {
45599 - lmc_hssi_init, /* special media init stuff */
45600 - lmc_hssi_default, /* reset to default state */
45601 - lmc_hssi_set_status, /* reset status to state provided */
45602 - lmc_hssi_set_clock, /* set clock source */
45603 - lmc_dummy_set2_1, /* set line speed */
45604 - lmc_dummy_set_1, /* set cable length */
45605 - lmc_dummy_set_1, /* set scrambler */
45606 - lmc_hssi_get_link_status, /* get link status */
45607 - lmc_hssi_set_link_status, /* set link status */
45608 - lmc_hssi_set_crc_length, /* set CRC length */
45609 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
45610 - lmc_hssi_watchdog
45611 + .init = lmc_hssi_init, /* special media init stuff */
45612 + .defaults = lmc_hssi_default, /* reset to default state */
45613 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
45614 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
45615 + .set_speed = lmc_dummy_set2_1, /* set line speed */
45616 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
45617 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45618 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
45619 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
45620 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
45621 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45622 + .watchdog = lmc_hssi_watchdog
45623 };
45624
45625 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
45626 - lmc_ssi_default, /* reset to default state */
45627 - lmc_ssi_set_status, /* reset status to state provided */
45628 - lmc_ssi_set_clock, /* set clock source */
45629 - lmc_ssi_set_speed, /* set line speed */
45630 - lmc_dummy_set_1, /* set cable length */
45631 - lmc_dummy_set_1, /* set scrambler */
45632 - lmc_ssi_get_link_status, /* get link status */
45633 - lmc_ssi_set_link_status, /* set link status */
45634 - lmc_ssi_set_crc_length, /* set CRC length */
45635 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
45636 - lmc_ssi_watchdog
45637 +lmc_media_t lmc_ssi_media = {
45638 + .init = lmc_ssi_init, /* special media init stuff */
45639 + .defaults = lmc_ssi_default, /* reset to default state */
45640 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
45641 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
45642 + .set_speed = lmc_ssi_set_speed, /* set line speed */
45643 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
45644 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45645 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
45646 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
45647 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
45648 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45649 + .watchdog = lmc_ssi_watchdog
45650 };
45651
45652 lmc_media_t lmc_t1_media = {
45653 - lmc_t1_init, /* special media init stuff */
45654 - lmc_t1_default, /* reset to default state */
45655 - lmc_t1_set_status, /* reset status to state provided */
45656 - lmc_t1_set_clock, /* set clock source */
45657 - lmc_dummy_set2_1, /* set line speed */
45658 - lmc_dummy_set_1, /* set cable length */
45659 - lmc_dummy_set_1, /* set scrambler */
45660 - lmc_t1_get_link_status, /* get link status */
45661 - lmc_dummy_set_1, /* set link status */
45662 - lmc_t1_set_crc_length, /* set CRC length */
45663 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45664 - lmc_t1_watchdog
45665 + .init = lmc_t1_init, /* special media init stuff */
45666 + .defaults = lmc_t1_default, /* reset to default state */
45667 + .set_status = lmc_t1_set_status, /* reset status to state provided */
45668 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
45669 + .set_speed = lmc_dummy_set2_1, /* set line speed */
45670 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
45671 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45672 + .get_link_status = lmc_t1_get_link_status, /* get link status */
45673 + .set_link_status = lmc_dummy_set_1, /* set link status */
45674 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
45675 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45676 + .watchdog = lmc_t1_watchdog
45677 };
45678
45679 static void
45680 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
45681 index feacc3b..5bac0de 100644
45682 --- a/drivers/net/wan/z85230.c
45683 +++ b/drivers/net/wan/z85230.c
45684 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
45685
45686 struct z8530_irqhandler z8530_sync =
45687 {
45688 - z8530_rx,
45689 - z8530_tx,
45690 - z8530_status
45691 + .rx = z8530_rx,
45692 + .tx = z8530_tx,
45693 + .status = z8530_status
45694 };
45695
45696 EXPORT_SYMBOL(z8530_sync);
45697 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
45698 }
45699
45700 static struct z8530_irqhandler z8530_dma_sync = {
45701 - z8530_dma_rx,
45702 - z8530_dma_tx,
45703 - z8530_dma_status
45704 + .rx = z8530_dma_rx,
45705 + .tx = z8530_dma_tx,
45706 + .status = z8530_dma_status
45707 };
45708
45709 static struct z8530_irqhandler z8530_txdma_sync = {
45710 - z8530_rx,
45711 - z8530_dma_tx,
45712 - z8530_dma_status
45713 + .rx = z8530_rx,
45714 + .tx = z8530_dma_tx,
45715 + .status = z8530_dma_status
45716 };
45717
45718 /**
45719 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
45720
45721 struct z8530_irqhandler z8530_nop=
45722 {
45723 - z8530_rx_clear,
45724 - z8530_tx_clear,
45725 - z8530_status_clear
45726 + .rx = z8530_rx_clear,
45727 + .tx = z8530_tx_clear,
45728 + .status = z8530_status_clear
45729 };
45730
45731
45732 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
45733 index 0b60295..b8bfa5b 100644
45734 --- a/drivers/net/wimax/i2400m/rx.c
45735 +++ b/drivers/net/wimax/i2400m/rx.c
45736 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
45737 if (i2400m->rx_roq == NULL)
45738 goto error_roq_alloc;
45739
45740 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
45741 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
45742 GFP_KERNEL);
45743 if (rd == NULL) {
45744 result = -ENOMEM;
45745 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
45746 index edf4b57..68b51c0 100644
45747 --- a/drivers/net/wireless/airo.c
45748 +++ b/drivers/net/wireless/airo.c
45749 @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
45750 struct airo_info *ai = dev->ml_priv;
45751 int ridcode;
45752 int enabled;
45753 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45754 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45755 unsigned char *iobuf;
45756
45757 /* Only super-user can write RIDs */
45758 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
45759 index 34c8a33..3261fdc 100644
45760 --- a/drivers/net/wireless/at76c50x-usb.c
45761 +++ b/drivers/net/wireless/at76c50x-usb.c
45762 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
45763 }
45764
45765 /* Convert timeout from the DFU status to jiffies */
45766 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
45767 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
45768 {
45769 return msecs_to_jiffies((s->poll_timeout[2] << 16)
45770 | (s->poll_timeout[1] << 8)
45771 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
45772 index edae50b..b24278c 100644
45773 --- a/drivers/net/wireless/ath/ath10k/htc.c
45774 +++ b/drivers/net/wireless/ath/ath10k/htc.c
45775 @@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
45776 /* registered target arrival callback from the HIF layer */
45777 int ath10k_htc_init(struct ath10k *ar)
45778 {
45779 - struct ath10k_hif_cb htc_callbacks;
45780 + static struct ath10k_hif_cb htc_callbacks = {
45781 + .rx_completion = ath10k_htc_rx_completion_handler,
45782 + .tx_completion = ath10k_htc_tx_completion_handler,
45783 + };
45784 struct ath10k_htc_ep *ep = NULL;
45785 struct ath10k_htc *htc = &ar->htc;
45786
45787 @@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
45788 ath10k_htc_reset_endpoint_states(htc);
45789
45790 /* setup HIF layer callbacks */
45791 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
45792 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
45793 htc->ar = ar;
45794
45795 /* Get HIF default pipe for HTC message exchange */
45796 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
45797 index 4716d33..a688310 100644
45798 --- a/drivers/net/wireless/ath/ath10k/htc.h
45799 +++ b/drivers/net/wireless/ath/ath10k/htc.h
45800 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
45801
45802 struct ath10k_htc_ops {
45803 void (*target_send_suspend_complete)(struct ath10k *ar);
45804 -};
45805 +} __no_const;
45806
45807 struct ath10k_htc_ep_ops {
45808 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
45809 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
45810 void (*ep_tx_credits)(struct ath10k *);
45811 -};
45812 +} __no_const;
45813
45814 /* service connection information */
45815 struct ath10k_htc_svc_conn_req {
45816 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45817 index a366d6b..b6f28f8 100644
45818 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45819 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45820 @@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45821 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
45822 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
45823
45824 - ACCESS_ONCE(ads->ds_link) = i->link;
45825 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
45826 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
45827 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
45828
45829 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
45830 ctl6 = SM(i->keytype, AR_EncrType);
45831 @@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45832
45833 if ((i->is_first || i->is_last) &&
45834 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
45835 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
45836 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
45837 | set11nTries(i->rates, 1)
45838 | set11nTries(i->rates, 2)
45839 | set11nTries(i->rates, 3)
45840 | (i->dur_update ? AR_DurUpdateEna : 0)
45841 | SM(0, AR_BurstDur);
45842
45843 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
45844 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
45845 | set11nRate(i->rates, 1)
45846 | set11nRate(i->rates, 2)
45847 | set11nRate(i->rates, 3);
45848 } else {
45849 - ACCESS_ONCE(ads->ds_ctl2) = 0;
45850 - ACCESS_ONCE(ads->ds_ctl3) = 0;
45851 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
45852 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
45853 }
45854
45855 if (!i->is_first) {
45856 - ACCESS_ONCE(ads->ds_ctl0) = 0;
45857 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
45858 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
45859 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
45860 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
45861 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
45862 return;
45863 }
45864
45865 @@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45866 break;
45867 }
45868
45869 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
45870 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
45871 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45872 | SM(i->txpower, AR_XmitPower)
45873 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45874 @@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45875 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
45876 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
45877
45878 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
45879 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
45880 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
45881 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
45882
45883 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
45884 return;
45885
45886 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
45887 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
45888 | set11nPktDurRTSCTS(i->rates, 1);
45889
45890 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
45891 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
45892 | set11nPktDurRTSCTS(i->rates, 3);
45893
45894 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
45895 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
45896 | set11nRateFlags(i->rates, 1)
45897 | set11nRateFlags(i->rates, 2)
45898 | set11nRateFlags(i->rates, 3)
45899 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45900 index f6c5c1b..6058354 100644
45901 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45902 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45903 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45904 (i->qcu << AR_TxQcuNum_S) | desc_len;
45905
45906 checksum += val;
45907 - ACCESS_ONCE(ads->info) = val;
45908 + ACCESS_ONCE_RW(ads->info) = val;
45909
45910 checksum += i->link;
45911 - ACCESS_ONCE(ads->link) = i->link;
45912 + ACCESS_ONCE_RW(ads->link) = i->link;
45913
45914 checksum += i->buf_addr[0];
45915 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
45916 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
45917 checksum += i->buf_addr[1];
45918 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
45919 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
45920 checksum += i->buf_addr[2];
45921 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
45922 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
45923 checksum += i->buf_addr[3];
45924 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
45925 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
45926
45927 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
45928 - ACCESS_ONCE(ads->ctl3) = val;
45929 + ACCESS_ONCE_RW(ads->ctl3) = val;
45930 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
45931 - ACCESS_ONCE(ads->ctl5) = val;
45932 + ACCESS_ONCE_RW(ads->ctl5) = val;
45933 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
45934 - ACCESS_ONCE(ads->ctl7) = val;
45935 + ACCESS_ONCE_RW(ads->ctl7) = val;
45936 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
45937 - ACCESS_ONCE(ads->ctl9) = val;
45938 + ACCESS_ONCE_RW(ads->ctl9) = val;
45939
45940 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
45941 - ACCESS_ONCE(ads->ctl10) = checksum;
45942 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
45943
45944 if (i->is_first || i->is_last) {
45945 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
45946 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
45947 | set11nTries(i->rates, 1)
45948 | set11nTries(i->rates, 2)
45949 | set11nTries(i->rates, 3)
45950 | (i->dur_update ? AR_DurUpdateEna : 0)
45951 | SM(0, AR_BurstDur);
45952
45953 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
45954 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
45955 | set11nRate(i->rates, 1)
45956 | set11nRate(i->rates, 2)
45957 | set11nRate(i->rates, 3);
45958 } else {
45959 - ACCESS_ONCE(ads->ctl13) = 0;
45960 - ACCESS_ONCE(ads->ctl14) = 0;
45961 + ACCESS_ONCE_RW(ads->ctl13) = 0;
45962 + ACCESS_ONCE_RW(ads->ctl14) = 0;
45963 }
45964
45965 ads->ctl20 = 0;
45966 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45967
45968 ctl17 = SM(i->keytype, AR_EncrType);
45969 if (!i->is_first) {
45970 - ACCESS_ONCE(ads->ctl11) = 0;
45971 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45972 - ACCESS_ONCE(ads->ctl15) = 0;
45973 - ACCESS_ONCE(ads->ctl16) = 0;
45974 - ACCESS_ONCE(ads->ctl17) = ctl17;
45975 - ACCESS_ONCE(ads->ctl18) = 0;
45976 - ACCESS_ONCE(ads->ctl19) = 0;
45977 + ACCESS_ONCE_RW(ads->ctl11) = 0;
45978 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45979 + ACCESS_ONCE_RW(ads->ctl15) = 0;
45980 + ACCESS_ONCE_RW(ads->ctl16) = 0;
45981 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45982 + ACCESS_ONCE_RW(ads->ctl18) = 0;
45983 + ACCESS_ONCE_RW(ads->ctl19) = 0;
45984 return;
45985 }
45986
45987 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45988 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45989 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45990 | SM(i->txpower, AR_XmitPower)
45991 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45992 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45993 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
45994 ctl12 |= SM(val, AR_PAPRDChainMask);
45995
45996 - ACCESS_ONCE(ads->ctl12) = ctl12;
45997 - ACCESS_ONCE(ads->ctl17) = ctl17;
45998 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
45999 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46000
46001 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46002 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46003 | set11nPktDurRTSCTS(i->rates, 1);
46004
46005 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46006 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46007 | set11nPktDurRTSCTS(i->rates, 3);
46008
46009 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46010 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46011 | set11nRateFlags(i->rates, 1)
46012 | set11nRateFlags(i->rates, 2)
46013 | set11nRateFlags(i->rates, 3)
46014 | SM(i->rtscts_rate, AR_RTSCTSRate);
46015
46016 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46017 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46018 }
46019
46020 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46021 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46022 index a2c9a5d..b52273e 100644
46023 --- a/drivers/net/wireless/ath/ath9k/hw.h
46024 +++ b/drivers/net/wireless/ath/ath9k/hw.h
46025 @@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46026
46027 /* ANI */
46028 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46029 -};
46030 +} __no_const;
46031
46032 /**
46033 * struct ath_spec_scan - parameters for Atheros spectral scan
46034 @@ -711,7 +711,7 @@ struct ath_hw_ops {
46035 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46036 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46037 #endif
46038 -};
46039 +} __no_const;
46040
46041 struct ath_nf_limits {
46042 s16 max;
46043 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46044 index 92190da..f3a4c4c 100644
46045 --- a/drivers/net/wireless/b43/phy_lp.c
46046 +++ b/drivers/net/wireless/b43/phy_lp.c
46047 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46048 {
46049 struct ssb_bus *bus = dev->dev->sdev->bus;
46050
46051 - static const struct b206x_channel *chandata = NULL;
46052 + const struct b206x_channel *chandata = NULL;
46053 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46054 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46055 u16 old_comm15, scale;
46056 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46057 index dea3b50..543db99 100644
46058 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
46059 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46060 @@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46061 */
46062 if (il3945_mod_params.disable_hw_scan) {
46063 D_INFO("Disabling hw_scan\n");
46064 - il3945_mac_ops.hw_scan = NULL;
46065 + pax_open_kernel();
46066 + *(void **)&il3945_mac_ops.hw_scan = NULL;
46067 + pax_close_kernel();
46068 }
46069
46070 D_INFO("*** LOAD DRIVER ***\n");
46071 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46072 index d94f8ab..5b568c8 100644
46073 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46074 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46075 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46076 {
46077 struct iwl_priv *priv = file->private_data;
46078 char buf[64];
46079 - int buf_size;
46080 + size_t buf_size;
46081 u32 offset, len;
46082
46083 memset(buf, 0, sizeof(buf));
46084 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46085 struct iwl_priv *priv = file->private_data;
46086
46087 char buf[8];
46088 - int buf_size;
46089 + size_t buf_size;
46090 u32 reset_flag;
46091
46092 memset(buf, 0, sizeof(buf));
46093 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46094 {
46095 struct iwl_priv *priv = file->private_data;
46096 char buf[8];
46097 - int buf_size;
46098 + size_t buf_size;
46099 int ht40;
46100
46101 memset(buf, 0, sizeof(buf));
46102 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46103 {
46104 struct iwl_priv *priv = file->private_data;
46105 char buf[8];
46106 - int buf_size;
46107 + size_t buf_size;
46108 int value;
46109
46110 memset(buf, 0, sizeof(buf));
46111 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46112 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46113 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46114
46115 -static const char *fmt_value = " %-30s %10u\n";
46116 -static const char *fmt_hex = " %-30s 0x%02X\n";
46117 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46118 -static const char *fmt_header =
46119 +static const char fmt_value[] = " %-30s %10u\n";
46120 +static const char fmt_hex[] = " %-30s 0x%02X\n";
46121 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46122 +static const char fmt_header[] =
46123 "%-32s current cumulative delta max\n";
46124
46125 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46126 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46127 {
46128 struct iwl_priv *priv = file->private_data;
46129 char buf[8];
46130 - int buf_size;
46131 + size_t buf_size;
46132 int clear;
46133
46134 memset(buf, 0, sizeof(buf));
46135 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46136 {
46137 struct iwl_priv *priv = file->private_data;
46138 char buf[8];
46139 - int buf_size;
46140 + size_t buf_size;
46141 int trace;
46142
46143 memset(buf, 0, sizeof(buf));
46144 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46145 {
46146 struct iwl_priv *priv = file->private_data;
46147 char buf[8];
46148 - int buf_size;
46149 + size_t buf_size;
46150 int missed;
46151
46152 memset(buf, 0, sizeof(buf));
46153 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46154
46155 struct iwl_priv *priv = file->private_data;
46156 char buf[8];
46157 - int buf_size;
46158 + size_t buf_size;
46159 int plcp;
46160
46161 memset(buf, 0, sizeof(buf));
46162 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46163
46164 struct iwl_priv *priv = file->private_data;
46165 char buf[8];
46166 - int buf_size;
46167 + size_t buf_size;
46168 int flush;
46169
46170 memset(buf, 0, sizeof(buf));
46171 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46172
46173 struct iwl_priv *priv = file->private_data;
46174 char buf[8];
46175 - int buf_size;
46176 + size_t buf_size;
46177 int rts;
46178
46179 if (!priv->cfg->ht_params)
46180 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46181 {
46182 struct iwl_priv *priv = file->private_data;
46183 char buf[8];
46184 - int buf_size;
46185 + size_t buf_size;
46186
46187 memset(buf, 0, sizeof(buf));
46188 buf_size = min(count, sizeof(buf) - 1);
46189 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46190 struct iwl_priv *priv = file->private_data;
46191 u32 event_log_flag;
46192 char buf[8];
46193 - int buf_size;
46194 + size_t buf_size;
46195
46196 /* check that the interface is up */
46197 if (!iwl_is_ready(priv))
46198 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46199 struct iwl_priv *priv = file->private_data;
46200 char buf[8];
46201 u32 calib_disabled;
46202 - int buf_size;
46203 + size_t buf_size;
46204
46205 memset(buf, 0, sizeof(buf));
46206 buf_size = min(count, sizeof(buf) - 1);
46207 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46208 index 7aad766..06addb4 100644
46209 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
46210 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46211 @@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46212 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46213 {
46214 struct iwl_nvm_data *data = priv->nvm_data;
46215 - char *debug_msg;
46216 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46217
46218 if (data->sku_cap_11n_enable &&
46219 !priv->cfg->ht_params) {
46220 @@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46221 return -EINVAL;
46222 }
46223
46224 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46225 IWL_DEBUG_INFO(priv, debug_msg,
46226 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
46227 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
46228 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
46229 index cde9c16..e485cfe 100644
46230 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
46231 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
46232 @@ -1368,7 +1368,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
46233 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
46234
46235 char buf[8];
46236 - int buf_size;
46237 + size_t buf_size;
46238 u32 reset_flag;
46239
46240 memset(buf, 0, sizeof(buf));
46241 @@ -1389,7 +1389,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
46242 {
46243 struct iwl_trans *trans = file->private_data;
46244 char buf[8];
46245 - int buf_size;
46246 + size_t buf_size;
46247 int csr;
46248
46249 memset(buf, 0, sizeof(buf));
46250 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
46251 index a1b32ee..94b3c3d 100644
46252 --- a/drivers/net/wireless/mac80211_hwsim.c
46253 +++ b/drivers/net/wireless/mac80211_hwsim.c
46254 @@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
46255
46256 if (channels > 1) {
46257 hwsim_if_comb.num_different_channels = channels;
46258 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46259 - mac80211_hwsim_ops.cancel_hw_scan =
46260 - mac80211_hwsim_cancel_hw_scan;
46261 - mac80211_hwsim_ops.sw_scan_start = NULL;
46262 - mac80211_hwsim_ops.sw_scan_complete = NULL;
46263 - mac80211_hwsim_ops.remain_on_channel =
46264 - mac80211_hwsim_roc;
46265 - mac80211_hwsim_ops.cancel_remain_on_channel =
46266 - mac80211_hwsim_croc;
46267 - mac80211_hwsim_ops.add_chanctx =
46268 - mac80211_hwsim_add_chanctx;
46269 - mac80211_hwsim_ops.remove_chanctx =
46270 - mac80211_hwsim_remove_chanctx;
46271 - mac80211_hwsim_ops.change_chanctx =
46272 - mac80211_hwsim_change_chanctx;
46273 - mac80211_hwsim_ops.assign_vif_chanctx =
46274 - mac80211_hwsim_assign_vif_chanctx;
46275 - mac80211_hwsim_ops.unassign_vif_chanctx =
46276 - mac80211_hwsim_unassign_vif_chanctx;
46277 + pax_open_kernel();
46278 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46279 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
46280 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
46281 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
46282 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
46283 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
46284 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
46285 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
46286 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
46287 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
46288 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
46289 + pax_close_kernel();
46290 }
46291
46292 spin_lock_init(&hwsim_radio_lock);
46293 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
46294 index 8169a85..7fa3b47 100644
46295 --- a/drivers/net/wireless/rndis_wlan.c
46296 +++ b/drivers/net/wireless/rndis_wlan.c
46297 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
46298
46299 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
46300
46301 - if (rts_threshold < 0 || rts_threshold > 2347)
46302 + if (rts_threshold > 2347)
46303 rts_threshold = 2347;
46304
46305 tmp = cpu_to_le32(rts_threshold);
46306 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
46307 index e4ba2ce..63d7417 100644
46308 --- a/drivers/net/wireless/rt2x00/rt2x00.h
46309 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
46310 @@ -377,7 +377,7 @@ struct rt2x00_intf {
46311 * for hardware which doesn't support hardware
46312 * sequence counting.
46313 */
46314 - atomic_t seqno;
46315 + atomic_unchecked_t seqno;
46316 };
46317
46318 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
46319 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
46320 index a5d38e8..d3c24ea 100644
46321 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
46322 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
46323 @@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
46324 * sequence counter given by mac80211.
46325 */
46326 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
46327 - seqno = atomic_add_return(0x10, &intf->seqno);
46328 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
46329 else
46330 - seqno = atomic_read(&intf->seqno);
46331 + seqno = atomic_read_unchecked(&intf->seqno);
46332
46333 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
46334 hdr->seq_ctrl |= cpu_to_le16(seqno);
46335 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
46336 index e2b3d9c..67a5184 100644
46337 --- a/drivers/net/wireless/ti/wl1251/sdio.c
46338 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
46339 @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
46340
46341 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
46342
46343 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46344 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46345 + pax_open_kernel();
46346 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46347 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46348 + pax_close_kernel();
46349
46350 wl1251_info("using dedicated interrupt line");
46351 } else {
46352 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46353 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46354 + pax_open_kernel();
46355 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46356 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46357 + pax_close_kernel();
46358
46359 wl1251_info("using SDIO interrupt");
46360 }
46361 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
46362 index be7129b..4161356 100644
46363 --- a/drivers/net/wireless/ti/wl12xx/main.c
46364 +++ b/drivers/net/wireless/ti/wl12xx/main.c
46365 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46366 sizeof(wl->conf.mem));
46367
46368 /* read data preparation is only needed by wl127x */
46369 - wl->ops->prepare_read = wl127x_prepare_read;
46370 + pax_open_kernel();
46371 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46372 + pax_close_kernel();
46373
46374 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46375 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46376 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46377 sizeof(wl->conf.mem));
46378
46379 /* read data preparation is only needed by wl127x */
46380 - wl->ops->prepare_read = wl127x_prepare_read;
46381 + pax_open_kernel();
46382 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46383 + pax_close_kernel();
46384
46385 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46386 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46387 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
46388 index ec37b16..7e34d66 100644
46389 --- a/drivers/net/wireless/ti/wl18xx/main.c
46390 +++ b/drivers/net/wireless/ti/wl18xx/main.c
46391 @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
46392 }
46393
46394 if (!checksum_param) {
46395 - wl18xx_ops.set_rx_csum = NULL;
46396 - wl18xx_ops.init_vif = NULL;
46397 + pax_open_kernel();
46398 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
46399 + *(void **)&wl18xx_ops.init_vif = NULL;
46400 + pax_close_kernel();
46401 }
46402
46403 /* Enable 11a Band only if we have 5G antennas */
46404 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
46405 index 84d94f5..bd6c61c 100644
46406 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
46407 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
46408 @@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
46409 {
46410 struct zd_usb *usb = urb->context;
46411 struct zd_usb_interrupt *intr = &usb->intr;
46412 - int len;
46413 + unsigned int len;
46414 u16 int_num;
46415
46416 ZD_ASSERT(in_interrupt());
46417 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
46418 index 7130864..00e64de 100644
46419 --- a/drivers/nfc/nfcwilink.c
46420 +++ b/drivers/nfc/nfcwilink.c
46421 @@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
46422
46423 static int nfcwilink_probe(struct platform_device *pdev)
46424 {
46425 - static struct nfcwilink *drv;
46426 + struct nfcwilink *drv;
46427 int rc;
46428 __u32 protocols;
46429
46430 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
46431 index d93b2b6..ae50401 100644
46432 --- a/drivers/oprofile/buffer_sync.c
46433 +++ b/drivers/oprofile/buffer_sync.c
46434 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
46435 if (cookie == NO_COOKIE)
46436 offset = pc;
46437 if (cookie == INVALID_COOKIE) {
46438 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46439 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46440 offset = pc;
46441 }
46442 if (cookie != last_cookie) {
46443 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
46444 /* add userspace sample */
46445
46446 if (!mm) {
46447 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
46448 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
46449 return 0;
46450 }
46451
46452 cookie = lookup_dcookie(mm, s->eip, &offset);
46453
46454 if (cookie == INVALID_COOKIE) {
46455 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46456 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46457 return 0;
46458 }
46459
46460 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
46461 /* ignore backtraces if failed to add a sample */
46462 if (state == sb_bt_start) {
46463 state = sb_bt_ignore;
46464 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
46465 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
46466 }
46467 }
46468 release_mm(mm);
46469 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
46470 index c0cc4e7..44d4e54 100644
46471 --- a/drivers/oprofile/event_buffer.c
46472 +++ b/drivers/oprofile/event_buffer.c
46473 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
46474 }
46475
46476 if (buffer_pos == buffer_size) {
46477 - atomic_inc(&oprofile_stats.event_lost_overflow);
46478 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
46479 return;
46480 }
46481
46482 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
46483 index ed2c3ec..deda85a 100644
46484 --- a/drivers/oprofile/oprof.c
46485 +++ b/drivers/oprofile/oprof.c
46486 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
46487 if (oprofile_ops.switch_events())
46488 return;
46489
46490 - atomic_inc(&oprofile_stats.multiplex_counter);
46491 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
46492 start_switch_worker();
46493 }
46494
46495 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
46496 index ee2cfce..7f8f699 100644
46497 --- a/drivers/oprofile/oprofile_files.c
46498 +++ b/drivers/oprofile/oprofile_files.c
46499 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
46500
46501 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
46502
46503 -static ssize_t timeout_read(struct file *file, char __user *buf,
46504 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
46505 size_t count, loff_t *offset)
46506 {
46507 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
46508 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
46509 index 59659ce..6c860a0 100644
46510 --- a/drivers/oprofile/oprofile_stats.c
46511 +++ b/drivers/oprofile/oprofile_stats.c
46512 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
46513 cpu_buf->sample_invalid_eip = 0;
46514 }
46515
46516 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
46517 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
46518 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
46519 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
46520 - atomic_set(&oprofile_stats.multiplex_counter, 0);
46521 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
46522 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
46523 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
46524 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
46525 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
46526 }
46527
46528
46529 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
46530 index 1fc622b..8c48fc3 100644
46531 --- a/drivers/oprofile/oprofile_stats.h
46532 +++ b/drivers/oprofile/oprofile_stats.h
46533 @@ -13,11 +13,11 @@
46534 #include <linux/atomic.h>
46535
46536 struct oprofile_stat_struct {
46537 - atomic_t sample_lost_no_mm;
46538 - atomic_t sample_lost_no_mapping;
46539 - atomic_t bt_lost_no_mapping;
46540 - atomic_t event_lost_overflow;
46541 - atomic_t multiplex_counter;
46542 + atomic_unchecked_t sample_lost_no_mm;
46543 + atomic_unchecked_t sample_lost_no_mapping;
46544 + atomic_unchecked_t bt_lost_no_mapping;
46545 + atomic_unchecked_t event_lost_overflow;
46546 + atomic_unchecked_t multiplex_counter;
46547 };
46548
46549 extern struct oprofile_stat_struct oprofile_stats;
46550 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
46551 index 3f49345..c750d0b 100644
46552 --- a/drivers/oprofile/oprofilefs.c
46553 +++ b/drivers/oprofile/oprofilefs.c
46554 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
46555
46556 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
46557 {
46558 - atomic_t *val = file->private_data;
46559 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
46560 + atomic_unchecked_t *val = file->private_data;
46561 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
46562 }
46563
46564
46565 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
46566
46567
46568 int oprofilefs_create_ro_atomic(struct dentry *root,
46569 - char const *name, atomic_t *val)
46570 + char const *name, atomic_unchecked_t *val)
46571 {
46572 return __oprofilefs_create_file(root, name,
46573 &atomic_ro_fops, 0444, val);
46574 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
46575 index 61be1d9..dec05d7 100644
46576 --- a/drivers/oprofile/timer_int.c
46577 +++ b/drivers/oprofile/timer_int.c
46578 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
46579 return NOTIFY_OK;
46580 }
46581
46582 -static struct notifier_block __refdata oprofile_cpu_notifier = {
46583 +static struct notifier_block oprofile_cpu_notifier = {
46584 .notifier_call = oprofile_cpu_notify,
46585 };
46586
46587 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
46588 index 92ed045..62d39bd7 100644
46589 --- a/drivers/parport/procfs.c
46590 +++ b/drivers/parport/procfs.c
46591 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
46592
46593 *ppos += len;
46594
46595 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
46596 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
46597 }
46598
46599 #ifdef CONFIG_PARPORT_1284
46600 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
46601
46602 *ppos += len;
46603
46604 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
46605 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
46606 }
46607 #endif /* IEEE1284.3 support. */
46608
46609 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
46610 index ecfac7e..41be7028 100644
46611 --- a/drivers/pci/hotplug/acpiphp_ibm.c
46612 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
46613 @@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
46614 goto init_cleanup;
46615 }
46616
46617 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46618 + pax_open_kernel();
46619 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46620 + pax_close_kernel();
46621 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
46622
46623 return retval;
46624 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
46625 index 7536eef..52dc8fa 100644
46626 --- a/drivers/pci/hotplug/cpcihp_generic.c
46627 +++ b/drivers/pci/hotplug/cpcihp_generic.c
46628 @@ -73,7 +73,6 @@ static u16 port;
46629 static unsigned int enum_bit;
46630 static u8 enum_mask;
46631
46632 -static struct cpci_hp_controller_ops generic_hpc_ops;
46633 static struct cpci_hp_controller generic_hpc;
46634
46635 static int __init validate_parameters(void)
46636 @@ -139,6 +138,10 @@ static int query_enum(void)
46637 return ((value & enum_mask) == enum_mask);
46638 }
46639
46640 +static struct cpci_hp_controller_ops generic_hpc_ops = {
46641 + .query_enum = query_enum,
46642 +};
46643 +
46644 static int __init cpcihp_generic_init(void)
46645 {
46646 int status;
46647 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
46648 pci_dev_put(dev);
46649
46650 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
46651 - generic_hpc_ops.query_enum = query_enum;
46652 generic_hpc.ops = &generic_hpc_ops;
46653
46654 status = cpci_hp_register_controller(&generic_hpc);
46655 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
46656 index e8c4a7c..7046f5c 100644
46657 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
46658 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
46659 @@ -59,7 +59,6 @@
46660 /* local variables */
46661 static bool debug;
46662 static bool poll;
46663 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
46664 static struct cpci_hp_controller zt5550_hpc;
46665
46666 /* Primary cPCI bus bridge device */
46667 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
46668 return 0;
46669 }
46670
46671 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
46672 + .query_enum = zt5550_hc_query_enum,
46673 +};
46674 +
46675 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
46676 {
46677 int status;
46678 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
46679 dbg("returned from zt5550_hc_config");
46680
46681 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
46682 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
46683 zt5550_hpc.ops = &zt5550_hpc_ops;
46684 if(!poll) {
46685 zt5550_hpc.irq = hc_dev->irq;
46686 zt5550_hpc.irq_flags = IRQF_SHARED;
46687 zt5550_hpc.dev_id = hc_dev;
46688
46689 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46690 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46691 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46692 + pax_open_kernel();
46693 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46694 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46695 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46696 + pax_open_kernel();
46697 } else {
46698 info("using ENUM# polling mode");
46699 }
46700 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
46701 index 76ba8a1..20ca857 100644
46702 --- a/drivers/pci/hotplug/cpqphp_nvram.c
46703 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
46704 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
46705
46706 void compaq_nvram_init (void __iomem *rom_start)
46707 {
46708 +
46709 +#ifndef CONFIG_PAX_KERNEXEC
46710 if (rom_start) {
46711 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
46712 }
46713 +#endif
46714 +
46715 dbg("int15 entry = %p\n", compaq_int15_entry_point);
46716
46717 /* initialize our int15 lock */
46718 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
46719 index cfa92a9..29539c5 100644
46720 --- a/drivers/pci/hotplug/pci_hotplug_core.c
46721 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
46722 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
46723 return -EINVAL;
46724 }
46725
46726 - slot->ops->owner = owner;
46727 - slot->ops->mod_name = mod_name;
46728 + pax_open_kernel();
46729 + *(struct module **)&slot->ops->owner = owner;
46730 + *(const char **)&slot->ops->mod_name = mod_name;
46731 + pax_close_kernel();
46732
46733 mutex_lock(&pci_hp_mutex);
46734 /*
46735 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
46736 index bbd48bb..6907ef4 100644
46737 --- a/drivers/pci/hotplug/pciehp_core.c
46738 +++ b/drivers/pci/hotplug/pciehp_core.c
46739 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
46740 struct slot *slot = ctrl->slot;
46741 struct hotplug_slot *hotplug = NULL;
46742 struct hotplug_slot_info *info = NULL;
46743 - struct hotplug_slot_ops *ops = NULL;
46744 + hotplug_slot_ops_no_const *ops = NULL;
46745 char name[SLOT_NAME_SIZE];
46746 int retval = -ENOMEM;
46747
46748 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
46749 index c91e6c1..5c723ef 100644
46750 --- a/drivers/pci/pci-sysfs.c
46751 +++ b/drivers/pci/pci-sysfs.c
46752 @@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
46753 {
46754 /* allocate attribute structure, piggyback attribute name */
46755 int name_len = write_combine ? 13 : 10;
46756 - struct bin_attribute *res_attr;
46757 + bin_attribute_no_const *res_attr;
46758 int retval;
46759
46760 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
46761 @@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
46762 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
46763 {
46764 int retval;
46765 - struct bin_attribute *attr;
46766 + bin_attribute_no_const *attr;
46767
46768 /* If the device has VPD, try to expose it in sysfs. */
46769 if (dev->vpd) {
46770 @@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
46771 {
46772 int retval;
46773 int rom_size = 0;
46774 - struct bin_attribute *attr;
46775 + bin_attribute_no_const *attr;
46776
46777 if (!sysfs_initialized)
46778 return -EACCES;
46779 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
46780 index 9c91ecc..bda4796 100644
46781 --- a/drivers/pci/pci.h
46782 +++ b/drivers/pci/pci.h
46783 @@ -95,7 +95,7 @@ struct pci_vpd_ops {
46784 struct pci_vpd {
46785 unsigned int len;
46786 const struct pci_vpd_ops *ops;
46787 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
46788 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
46789 };
46790
46791 int pci_vpd_pci22_init(struct pci_dev *dev);
46792 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
46793 index f1272dc..e92a1ac 100644
46794 --- a/drivers/pci/pcie/aspm.c
46795 +++ b/drivers/pci/pcie/aspm.c
46796 @@ -27,9 +27,9 @@
46797 #define MODULE_PARAM_PREFIX "pcie_aspm."
46798
46799 /* Note: those are not register definitions */
46800 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
46801 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
46802 -#define ASPM_STATE_L1 (4) /* L1 state */
46803 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
46804 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
46805 +#define ASPM_STATE_L1 (4U) /* L1 state */
46806 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
46807 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
46808
46809 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
46810 index 38e403d..a2ce55a 100644
46811 --- a/drivers/pci/probe.c
46812 +++ b/drivers/pci/probe.c
46813 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
46814 struct pci_bus_region region, inverted_region;
46815 bool bar_too_big = false, bar_disabled = false;
46816
46817 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
46818 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
46819
46820 /* No printks while decoding is disabled! */
46821 if (!dev->mmio_always_on) {
46822 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
46823 index 46d1378..30e452b 100644
46824 --- a/drivers/pci/proc.c
46825 +++ b/drivers/pci/proc.c
46826 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
46827 static int __init pci_proc_init(void)
46828 {
46829 struct pci_dev *dev = NULL;
46830 +
46831 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46832 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46833 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
46834 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46835 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
46836 +#endif
46837 +#else
46838 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
46839 +#endif
46840 proc_create("devices", 0, proc_bus_pci_dir,
46841 &proc_bus_pci_dev_operations);
46842 proc_initialized = 1;
46843 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
46844 index 3e5b4497..dcdfb70 100644
46845 --- a/drivers/platform/chrome/chromeos_laptop.c
46846 +++ b/drivers/platform/chrome/chromeos_laptop.c
46847 @@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
46848 return 0;
46849 }
46850
46851 -static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
46852 +static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
46853 {
46854 .ident = "Samsung Series 5 550 - Touchpad",
46855 .matches = {
46856 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
46857 index 19c313b..ed28b38 100644
46858 --- a/drivers/platform/x86/asus-wmi.c
46859 +++ b/drivers/platform/x86/asus-wmi.c
46860 @@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
46861 int err;
46862 u32 retval = -1;
46863
46864 +#ifdef CONFIG_GRKERNSEC_KMEM
46865 + return -EPERM;
46866 +#endif
46867 +
46868 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
46869
46870 if (err < 0)
46871 @@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
46872 int err;
46873 u32 retval = -1;
46874
46875 +#ifdef CONFIG_GRKERNSEC_KMEM
46876 + return -EPERM;
46877 +#endif
46878 +
46879 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
46880 &retval);
46881
46882 @@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
46883 union acpi_object *obj;
46884 acpi_status status;
46885
46886 +#ifdef CONFIG_GRKERNSEC_KMEM
46887 + return -EPERM;
46888 +#endif
46889 +
46890 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
46891 1, asus->debug.method_id,
46892 &input, &output);
46893 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
46894 index 62f8030..c7f2a45 100644
46895 --- a/drivers/platform/x86/msi-laptop.c
46896 +++ b/drivers/platform/x86/msi-laptop.c
46897 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
46898
46899 if (!quirks->ec_read_only) {
46900 /* allow userland write sysfs file */
46901 - dev_attr_bluetooth.store = store_bluetooth;
46902 - dev_attr_wlan.store = store_wlan;
46903 - dev_attr_threeg.store = store_threeg;
46904 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
46905 - dev_attr_wlan.attr.mode |= S_IWUSR;
46906 - dev_attr_threeg.attr.mode |= S_IWUSR;
46907 + pax_open_kernel();
46908 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
46909 + *(void **)&dev_attr_wlan.store = store_wlan;
46910 + *(void **)&dev_attr_threeg.store = store_threeg;
46911 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
46912 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
46913 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
46914 + pax_close_kernel();
46915 }
46916
46917 /* disable hardware control by fn key */
46918 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
46919 index 70222f2..8c8ce66 100644
46920 --- a/drivers/platform/x86/msi-wmi.c
46921 +++ b/drivers/platform/x86/msi-wmi.c
46922 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
46923 static void msi_wmi_notify(u32 value, void *context)
46924 {
46925 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
46926 - static struct key_entry *key;
46927 + struct key_entry *key;
46928 union acpi_object *obj;
46929 acpi_status status;
46930
46931 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
46932 index fb233ae..23a325c 100644
46933 --- a/drivers/platform/x86/sony-laptop.c
46934 +++ b/drivers/platform/x86/sony-laptop.c
46935 @@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
46936 }
46937
46938 /* High speed charging function */
46939 -static struct device_attribute *hsc_handle;
46940 +static device_attribute_no_const *hsc_handle;
46941
46942 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
46943 struct device_attribute *attr,
46944 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
46945 index 58b0274..6704626 100644
46946 --- a/drivers/platform/x86/thinkpad_acpi.c
46947 +++ b/drivers/platform/x86/thinkpad_acpi.c
46948 @@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
46949 return 0;
46950 }
46951
46952 -void static hotkey_mask_warn_incomplete_mask(void)
46953 +static void hotkey_mask_warn_incomplete_mask(void)
46954 {
46955 /* log only what the user can fix... */
46956 const u32 wantedmask = hotkey_driver_mask &
46957 @@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
46958 }
46959 }
46960
46961 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46962 - struct tp_nvram_state *newn,
46963 - const u32 event_mask)
46964 -{
46965 -
46966 #define TPACPI_COMPARE_KEY(__scancode, __member) \
46967 do { \
46968 if ((event_mask & (1 << __scancode)) && \
46969 @@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46970 tpacpi_hotkey_send_key(__scancode); \
46971 } while (0)
46972
46973 - void issue_volchange(const unsigned int oldvol,
46974 - const unsigned int newvol)
46975 - {
46976 - unsigned int i = oldvol;
46977 +static void issue_volchange(const unsigned int oldvol,
46978 + const unsigned int newvol,
46979 + const u32 event_mask)
46980 +{
46981 + unsigned int i = oldvol;
46982
46983 - while (i > newvol) {
46984 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46985 - i--;
46986 - }
46987 - while (i < newvol) {
46988 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46989 - i++;
46990 - }
46991 + while (i > newvol) {
46992 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46993 + i--;
46994 }
46995 + while (i < newvol) {
46996 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46997 + i++;
46998 + }
46999 +}
47000
47001 - void issue_brightnesschange(const unsigned int oldbrt,
47002 - const unsigned int newbrt)
47003 - {
47004 - unsigned int i = oldbrt;
47005 +static void issue_brightnesschange(const unsigned int oldbrt,
47006 + const unsigned int newbrt,
47007 + const u32 event_mask)
47008 +{
47009 + unsigned int i = oldbrt;
47010
47011 - while (i > newbrt) {
47012 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47013 - i--;
47014 - }
47015 - while (i < newbrt) {
47016 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47017 - i++;
47018 - }
47019 + while (i > newbrt) {
47020 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47021 + i--;
47022 + }
47023 + while (i < newbrt) {
47024 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47025 + i++;
47026 }
47027 +}
47028
47029 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47030 + struct tp_nvram_state *newn,
47031 + const u32 event_mask)
47032 +{
47033 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47034 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47035 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47036 @@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47037 oldn->volume_level != newn->volume_level) {
47038 /* recently muted, or repeated mute keypress, or
47039 * multiple presses ending in mute */
47040 - issue_volchange(oldn->volume_level, newn->volume_level);
47041 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47042 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47043 }
47044 } else {
47045 @@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47046 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47047 }
47048 if (oldn->volume_level != newn->volume_level) {
47049 - issue_volchange(oldn->volume_level, newn->volume_level);
47050 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47051 } else if (oldn->volume_toggle != newn->volume_toggle) {
47052 /* repeated vol up/down keypress at end of scale ? */
47053 if (newn->volume_level == 0)
47054 @@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47055 /* handle brightness */
47056 if (oldn->brightness_level != newn->brightness_level) {
47057 issue_brightnesschange(oldn->brightness_level,
47058 - newn->brightness_level);
47059 + newn->brightness_level,
47060 + event_mask);
47061 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47062 /* repeated key presses that didn't change state */
47063 if (newn->brightness_level == 0)
47064 @@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47065 && !tp_features.bright_unkfw)
47066 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47067 }
47068 +}
47069
47070 #undef TPACPI_COMPARE_KEY
47071 #undef TPACPI_MAY_SEND_KEY
47072 -}
47073
47074 /*
47075 * Polling driver
47076 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47077 index 769d265..a3a05ca 100644
47078 --- a/drivers/pnp/pnpbios/bioscalls.c
47079 +++ b/drivers/pnp/pnpbios/bioscalls.c
47080 @@ -58,7 +58,7 @@ do { \
47081 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47082 } while(0)
47083
47084 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47085 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47086 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47087
47088 /*
47089 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47090
47091 cpu = get_cpu();
47092 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47093 +
47094 + pax_open_kernel();
47095 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47096 + pax_close_kernel();
47097
47098 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47099 spin_lock_irqsave(&pnp_bios_lock, flags);
47100 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47101 :"memory");
47102 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47103
47104 + pax_open_kernel();
47105 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47106 + pax_close_kernel();
47107 +
47108 put_cpu();
47109
47110 /* If we get here and this is set then the PnP BIOS faulted on us. */
47111 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47112 return status;
47113 }
47114
47115 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
47116 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47117 {
47118 int i;
47119
47120 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47121 pnp_bios_callpoint.offset = header->fields.pm16offset;
47122 pnp_bios_callpoint.segment = PNP_CS16;
47123
47124 + pax_open_kernel();
47125 +
47126 for_each_possible_cpu(i) {
47127 struct desc_struct *gdt = get_cpu_gdt_table(i);
47128 if (!gdt)
47129 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47130 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47131 (unsigned long)__va(header->fields.pm16dseg));
47132 }
47133 +
47134 + pax_close_kernel();
47135 }
47136 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47137 index d95e101..67f0c3f 100644
47138 --- a/drivers/pnp/resource.c
47139 +++ b/drivers/pnp/resource.c
47140 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47141 return 1;
47142
47143 /* check if the resource is valid */
47144 - if (*irq < 0 || *irq > 15)
47145 + if (*irq > 15)
47146 return 0;
47147
47148 /* check if the resource is reserved */
47149 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47150 return 1;
47151
47152 /* check if the resource is valid */
47153 - if (*dma < 0 || *dma == 4 || *dma > 7)
47154 + if (*dma == 4 || *dma > 7)
47155 return 0;
47156
47157 /* check if the resource is reserved */
47158 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47159 index 0c52e2a..3421ab7 100644
47160 --- a/drivers/power/pda_power.c
47161 +++ b/drivers/power/pda_power.c
47162 @@ -37,7 +37,11 @@ static int polling;
47163
47164 #if IS_ENABLED(CONFIG_USB_PHY)
47165 static struct usb_phy *transceiver;
47166 -static struct notifier_block otg_nb;
47167 +static int otg_handle_notification(struct notifier_block *nb,
47168 + unsigned long event, void *unused);
47169 +static struct notifier_block otg_nb = {
47170 + .notifier_call = otg_handle_notification
47171 +};
47172 #endif
47173
47174 static struct regulator *ac_draw;
47175 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47176
47177 #if IS_ENABLED(CONFIG_USB_PHY)
47178 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47179 - otg_nb.notifier_call = otg_handle_notification;
47180 ret = usb_register_notifier(transceiver, &otg_nb);
47181 if (ret) {
47182 dev_err(dev, "failure to register otg notifier\n");
47183 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47184 index cc439fd..8fa30df 100644
47185 --- a/drivers/power/power_supply.h
47186 +++ b/drivers/power/power_supply.h
47187 @@ -16,12 +16,12 @@ struct power_supply;
47188
47189 #ifdef CONFIG_SYSFS
47190
47191 -extern void power_supply_init_attrs(struct device_type *dev_type);
47192 +extern void power_supply_init_attrs(void);
47193 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47194
47195 #else
47196
47197 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47198 +static inline void power_supply_init_attrs(void) {}
47199 #define power_supply_uevent NULL
47200
47201 #endif /* CONFIG_SYSFS */
47202 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47203 index 557af94..84dc1fe 100644
47204 --- a/drivers/power/power_supply_core.c
47205 +++ b/drivers/power/power_supply_core.c
47206 @@ -24,7 +24,10 @@
47207 struct class *power_supply_class;
47208 EXPORT_SYMBOL_GPL(power_supply_class);
47209
47210 -static struct device_type power_supply_dev_type;
47211 +extern const struct attribute_group *power_supply_attr_groups[];
47212 +static struct device_type power_supply_dev_type = {
47213 + .groups = power_supply_attr_groups,
47214 +};
47215
47216 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47217 struct power_supply *supply)
47218 @@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
47219 return PTR_ERR(power_supply_class);
47220
47221 power_supply_class->dev_uevent = power_supply_uevent;
47222 - power_supply_init_attrs(&power_supply_dev_type);
47223 + power_supply_init_attrs();
47224
47225 return 0;
47226 }
47227 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
47228 index 44420d1..967126e 100644
47229 --- a/drivers/power/power_supply_sysfs.c
47230 +++ b/drivers/power/power_supply_sysfs.c
47231 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
47232 .is_visible = power_supply_attr_is_visible,
47233 };
47234
47235 -static const struct attribute_group *power_supply_attr_groups[] = {
47236 +const struct attribute_group *power_supply_attr_groups[] = {
47237 &power_supply_attr_group,
47238 NULL,
47239 };
47240
47241 -void power_supply_init_attrs(struct device_type *dev_type)
47242 +void power_supply_init_attrs(void)
47243 {
47244 int i;
47245
47246 - dev_type->groups = power_supply_attr_groups;
47247 -
47248 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
47249 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
47250 }
47251 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
47252 index 84419af..268ede8 100644
47253 --- a/drivers/powercap/powercap_sys.c
47254 +++ b/drivers/powercap/powercap_sys.c
47255 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
47256 struct device_attribute name_attr;
47257 };
47258
47259 +static ssize_t show_constraint_name(struct device *dev,
47260 + struct device_attribute *dev_attr,
47261 + char *buf);
47262 +
47263 static struct powercap_constraint_attr
47264 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
47265 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
47266 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
47267 + .power_limit_attr = {
47268 + .attr = {
47269 + .name = NULL,
47270 + .mode = S_IWUSR | S_IRUGO
47271 + },
47272 + .show = show_constraint_power_limit_uw,
47273 + .store = store_constraint_power_limit_uw
47274 + },
47275 +
47276 + .time_window_attr = {
47277 + .attr = {
47278 + .name = NULL,
47279 + .mode = S_IWUSR | S_IRUGO
47280 + },
47281 + .show = show_constraint_time_window_us,
47282 + .store = store_constraint_time_window_us
47283 + },
47284 +
47285 + .max_power_attr = {
47286 + .attr = {
47287 + .name = NULL,
47288 + .mode = S_IRUGO
47289 + },
47290 + .show = show_constraint_max_power_uw,
47291 + .store = NULL
47292 + },
47293 +
47294 + .min_power_attr = {
47295 + .attr = {
47296 + .name = NULL,
47297 + .mode = S_IRUGO
47298 + },
47299 + .show = show_constraint_min_power_uw,
47300 + .store = NULL
47301 + },
47302 +
47303 + .max_time_window_attr = {
47304 + .attr = {
47305 + .name = NULL,
47306 + .mode = S_IRUGO
47307 + },
47308 + .show = show_constraint_max_time_window_us,
47309 + .store = NULL
47310 + },
47311 +
47312 + .min_time_window_attr = {
47313 + .attr = {
47314 + .name = NULL,
47315 + .mode = S_IRUGO
47316 + },
47317 + .show = show_constraint_min_time_window_us,
47318 + .store = NULL
47319 + },
47320 +
47321 + .name_attr = {
47322 + .attr = {
47323 + .name = NULL,
47324 + .mode = S_IRUGO
47325 + },
47326 + .show = show_constraint_name,
47327 + .store = NULL
47328 + }
47329 + }
47330 +};
47331
47332 /* A list of powercap control_types */
47333 static LIST_HEAD(powercap_cntrl_list);
47334 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
47335 }
47336
47337 static int create_constraint_attribute(int id, const char *name,
47338 - int mode,
47339 - struct device_attribute *dev_attr,
47340 - ssize_t (*show)(struct device *,
47341 - struct device_attribute *, char *),
47342 - ssize_t (*store)(struct device *,
47343 - struct device_attribute *,
47344 - const char *, size_t)
47345 - )
47346 + struct device_attribute *dev_attr)
47347 {
47348 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
47349
47350 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
47351 - id, name);
47352 - if (!dev_attr->attr.name)
47353 + if (!name)
47354 return -ENOMEM;
47355 - dev_attr->attr.mode = mode;
47356 - dev_attr->show = show;
47357 - dev_attr->store = store;
47358 +
47359 + pax_open_kernel();
47360 + *(const char **)&dev_attr->attr.name = name;
47361 + pax_close_kernel();
47362
47363 return 0;
47364 }
47365 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
47366
47367 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
47368 ret = create_constraint_attribute(i, "power_limit_uw",
47369 - S_IWUSR | S_IRUGO,
47370 - &constraint_attrs[i].power_limit_attr,
47371 - show_constraint_power_limit_uw,
47372 - store_constraint_power_limit_uw);
47373 + &constraint_attrs[i].power_limit_attr);
47374 if (ret)
47375 goto err_alloc;
47376 ret = create_constraint_attribute(i, "time_window_us",
47377 - S_IWUSR | S_IRUGO,
47378 - &constraint_attrs[i].time_window_attr,
47379 - show_constraint_time_window_us,
47380 - store_constraint_time_window_us);
47381 + &constraint_attrs[i].time_window_attr);
47382 if (ret)
47383 goto err_alloc;
47384 - ret = create_constraint_attribute(i, "name", S_IRUGO,
47385 - &constraint_attrs[i].name_attr,
47386 - show_constraint_name,
47387 - NULL);
47388 + ret = create_constraint_attribute(i, "name",
47389 + &constraint_attrs[i].name_attr);
47390 if (ret)
47391 goto err_alloc;
47392 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
47393 - &constraint_attrs[i].max_power_attr,
47394 - show_constraint_max_power_uw,
47395 - NULL);
47396 + ret = create_constraint_attribute(i, "max_power_uw",
47397 + &constraint_attrs[i].max_power_attr);
47398 if (ret)
47399 goto err_alloc;
47400 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
47401 - &constraint_attrs[i].min_power_attr,
47402 - show_constraint_min_power_uw,
47403 - NULL);
47404 + ret = create_constraint_attribute(i, "min_power_uw",
47405 + &constraint_attrs[i].min_power_attr);
47406 if (ret)
47407 goto err_alloc;
47408 ret = create_constraint_attribute(i, "max_time_window_us",
47409 - S_IRUGO,
47410 - &constraint_attrs[i].max_time_window_attr,
47411 - show_constraint_max_time_window_us,
47412 - NULL);
47413 + &constraint_attrs[i].max_time_window_attr);
47414 if (ret)
47415 goto err_alloc;
47416 ret = create_constraint_attribute(i, "min_time_window_us",
47417 - S_IRUGO,
47418 - &constraint_attrs[i].min_time_window_attr,
47419 - show_constraint_min_time_window_us,
47420 - NULL);
47421 + &constraint_attrs[i].min_time_window_attr);
47422 if (ret)
47423 goto err_alloc;
47424
47425 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
47426 power_zone->zone_dev_attrs[count++] =
47427 &dev_attr_max_energy_range_uj.attr;
47428 if (power_zone->ops->get_energy_uj) {
47429 + pax_open_kernel();
47430 if (power_zone->ops->reset_energy_uj)
47431 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
47432 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
47433 else
47434 - dev_attr_energy_uj.attr.mode = S_IRUGO;
47435 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
47436 + pax_close_kernel();
47437 power_zone->zone_dev_attrs[count++] =
47438 &dev_attr_energy_uj.attr;
47439 }
47440 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
47441 index d85f313..ae857d0 100644
47442 --- a/drivers/regulator/core.c
47443 +++ b/drivers/regulator/core.c
47444 @@ -3362,7 +3362,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47445 {
47446 const struct regulation_constraints *constraints = NULL;
47447 const struct regulator_init_data *init_data;
47448 - static atomic_t regulator_no = ATOMIC_INIT(0);
47449 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
47450 struct regulator_dev *rdev;
47451 struct device *dev;
47452 int ret, i;
47453 @@ -3432,7 +3432,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47454 rdev->dev.of_node = config->of_node;
47455 rdev->dev.parent = dev;
47456 dev_set_name(&rdev->dev, "regulator.%d",
47457 - atomic_inc_return(&regulator_no) - 1);
47458 + atomic_inc_return_unchecked(&regulator_no) - 1);
47459 ret = device_register(&rdev->dev);
47460 if (ret != 0) {
47461 put_device(&rdev->dev);
47462 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
47463 index 8d94d3d..653b623 100644
47464 --- a/drivers/regulator/max8660.c
47465 +++ b/drivers/regulator/max8660.c
47466 @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
47467 max8660->shadow_regs[MAX8660_OVER1] = 5;
47468 } else {
47469 /* Otherwise devices can be toggled via software */
47470 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
47471 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
47472 + pax_open_kernel();
47473 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
47474 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
47475 + pax_close_kernel();
47476 }
47477
47478 /*
47479 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
47480 index 892aa1e..ebd1b9c 100644
47481 --- a/drivers/regulator/max8973-regulator.c
47482 +++ b/drivers/regulator/max8973-regulator.c
47483 @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
47484 if (!pdata || !pdata->enable_ext_control) {
47485 max->desc.enable_reg = MAX8973_VOUT;
47486 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
47487 - max->ops.enable = regulator_enable_regmap;
47488 - max->ops.disable = regulator_disable_regmap;
47489 - max->ops.is_enabled = regulator_is_enabled_regmap;
47490 + pax_open_kernel();
47491 + *(void **)&max->ops.enable = regulator_enable_regmap;
47492 + *(void **)&max->ops.disable = regulator_disable_regmap;
47493 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
47494 + pax_close_kernel();
47495 }
47496
47497 if (pdata) {
47498 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
47499 index 96c9f80..90974ca 100644
47500 --- a/drivers/regulator/mc13892-regulator.c
47501 +++ b/drivers/regulator/mc13892-regulator.c
47502 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
47503 }
47504 mc13xxx_unlock(mc13892);
47505
47506 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47507 + pax_open_kernel();
47508 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47509 = mc13892_vcam_set_mode;
47510 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47511 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47512 = mc13892_vcam_get_mode;
47513 + pax_close_kernel();
47514
47515 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
47516 ARRAY_SIZE(mc13892_regulators));
47517 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
47518 index f148762..5a6d1e5 100644
47519 --- a/drivers/rtc/rtc-cmos.c
47520 +++ b/drivers/rtc/rtc-cmos.c
47521 @@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
47522 hpet_rtc_timer_init();
47523
47524 /* export at least the first block of NVRAM */
47525 - nvram.size = address_space - NVRAM_OFFSET;
47526 + pax_open_kernel();
47527 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
47528 + pax_close_kernel();
47529 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
47530 if (retval < 0) {
47531 dev_dbg(dev, "can't create nvram file? %d\n", retval);
47532 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
47533 index d049393..bb20be0 100644
47534 --- a/drivers/rtc/rtc-dev.c
47535 +++ b/drivers/rtc/rtc-dev.c
47536 @@ -16,6 +16,7 @@
47537 #include <linux/module.h>
47538 #include <linux/rtc.h>
47539 #include <linux/sched.h>
47540 +#include <linux/grsecurity.h>
47541 #include "rtc-core.h"
47542
47543 static dev_t rtc_devt;
47544 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
47545 if (copy_from_user(&tm, uarg, sizeof(tm)))
47546 return -EFAULT;
47547
47548 + gr_log_timechange();
47549 +
47550 return rtc_set_time(rtc, &tm);
47551
47552 case RTC_PIE_ON:
47553 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
47554 index 4e75345..09f8663 100644
47555 --- a/drivers/rtc/rtc-ds1307.c
47556 +++ b/drivers/rtc/rtc-ds1307.c
47557 @@ -107,7 +107,7 @@ struct ds1307 {
47558 u8 offset; /* register's offset */
47559 u8 regs[11];
47560 u16 nvram_offset;
47561 - struct bin_attribute *nvram;
47562 + bin_attribute_no_const *nvram;
47563 enum ds_type type;
47564 unsigned long flags;
47565 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
47566 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
47567 index 11880c1..b823aa4 100644
47568 --- a/drivers/rtc/rtc-m48t59.c
47569 +++ b/drivers/rtc/rtc-m48t59.c
47570 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
47571 if (IS_ERR(m48t59->rtc))
47572 return PTR_ERR(m48t59->rtc);
47573
47574 - m48t59_nvram_attr.size = pdata->offset;
47575 + pax_open_kernel();
47576 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
47577 + pax_close_kernel();
47578
47579 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
47580 if (ret)
47581 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
47582 index 14b5f8d..cc9bd26 100644
47583 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
47584 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
47585 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
47586 for (bit = 0; bit < 8; bit++) {
47587
47588 if ((pci_status[i] & (0x1 << bit)) != 0) {
47589 - static const char *s;
47590 + const char *s;
47591
47592 s = pci_status_strings[bit];
47593 if (i == 7/*TARG*/ && bit == 3)
47594 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
47595
47596 for (bit = 0; bit < 8; bit++) {
47597
47598 - if ((split_status[i] & (0x1 << bit)) != 0) {
47599 - static const char *s;
47600 -
47601 - s = split_status_strings[bit];
47602 - printk(s, ahd_name(ahd),
47603 + if ((split_status[i] & (0x1 << bit)) != 0)
47604 + printk(split_status_strings[bit], ahd_name(ahd),
47605 split_status_source[i]);
47606 - }
47607
47608 if (i > 1)
47609 continue;
47610
47611 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
47612 - static const char *s;
47613 -
47614 - s = split_status_strings[bit];
47615 - printk(s, ahd_name(ahd), "SG");
47616 - }
47617 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
47618 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
47619 }
47620 }
47621 /*
47622 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
47623 index e693af6..2e525b6 100644
47624 --- a/drivers/scsi/bfa/bfa_fcpim.h
47625 +++ b/drivers/scsi/bfa/bfa_fcpim.h
47626 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
47627
47628 struct bfa_itn_s {
47629 bfa_isr_func_t isr;
47630 -};
47631 +} __no_const;
47632
47633 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
47634 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
47635 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
47636 index a3ab5cc..8143622 100644
47637 --- a/drivers/scsi/bfa/bfa_fcs.c
47638 +++ b/drivers/scsi/bfa/bfa_fcs.c
47639 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
47640 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
47641
47642 static struct bfa_fcs_mod_s fcs_modules[] = {
47643 - { bfa_fcs_port_attach, NULL, NULL },
47644 - { bfa_fcs_uf_attach, NULL, NULL },
47645 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
47646 - bfa_fcs_fabric_modexit },
47647 + {
47648 + .attach = bfa_fcs_port_attach,
47649 + .modinit = NULL,
47650 + .modexit = NULL
47651 + },
47652 + {
47653 + .attach = bfa_fcs_uf_attach,
47654 + .modinit = NULL,
47655 + .modexit = NULL
47656 + },
47657 + {
47658 + .attach = bfa_fcs_fabric_attach,
47659 + .modinit = bfa_fcs_fabric_modinit,
47660 + .modexit = bfa_fcs_fabric_modexit
47661 + },
47662 };
47663
47664 /*
47665 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
47666 index f5e4e61..a0acaf6 100644
47667 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
47668 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
47669 @@ -89,15 +89,26 @@ static struct {
47670 void (*offline) (struct bfa_fcs_lport_s *port);
47671 } __port_action[] = {
47672 {
47673 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
47674 - bfa_fcs_lport_unknown_offline}, {
47675 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
47676 - bfa_fcs_lport_fab_offline}, {
47677 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
47678 - bfa_fcs_lport_n2n_offline}, {
47679 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
47680 - bfa_fcs_lport_loop_offline},
47681 - };
47682 + .init = bfa_fcs_lport_unknown_init,
47683 + .online = bfa_fcs_lport_unknown_online,
47684 + .offline = bfa_fcs_lport_unknown_offline
47685 + },
47686 + {
47687 + .init = bfa_fcs_lport_fab_init,
47688 + .online = bfa_fcs_lport_fab_online,
47689 + .offline = bfa_fcs_lport_fab_offline
47690 + },
47691 + {
47692 + .init = bfa_fcs_lport_n2n_init,
47693 + .online = bfa_fcs_lport_n2n_online,
47694 + .offline = bfa_fcs_lport_n2n_offline
47695 + },
47696 + {
47697 + .init = bfa_fcs_lport_loop_init,
47698 + .online = bfa_fcs_lport_loop_online,
47699 + .offline = bfa_fcs_lport_loop_offline
47700 + },
47701 +};
47702
47703 /*
47704 * fcs_port_sm FCS logical port state machine
47705 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
47706 index 90814fe..4384138 100644
47707 --- a/drivers/scsi/bfa/bfa_ioc.h
47708 +++ b/drivers/scsi/bfa/bfa_ioc.h
47709 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
47710 bfa_ioc_disable_cbfn_t disable_cbfn;
47711 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
47712 bfa_ioc_reset_cbfn_t reset_cbfn;
47713 -};
47714 +} __no_const;
47715
47716 /*
47717 * IOC event notification mechanism.
47718 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
47719 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
47720 enum bfi_ioc_state fwstate);
47721 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
47722 -};
47723 +} __no_const;
47724
47725 /*
47726 * Queue element to wait for room in request queue. FIFO order is
47727 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
47728 index a14c784..6de6790 100644
47729 --- a/drivers/scsi/bfa/bfa_modules.h
47730 +++ b/drivers/scsi/bfa/bfa_modules.h
47731 @@ -78,12 +78,12 @@ enum {
47732 \
47733 extern struct bfa_module_s hal_mod_ ## __mod; \
47734 struct bfa_module_s hal_mod_ ## __mod = { \
47735 - bfa_ ## __mod ## _meminfo, \
47736 - bfa_ ## __mod ## _attach, \
47737 - bfa_ ## __mod ## _detach, \
47738 - bfa_ ## __mod ## _start, \
47739 - bfa_ ## __mod ## _stop, \
47740 - bfa_ ## __mod ## _iocdisable, \
47741 + .meminfo = bfa_ ## __mod ## _meminfo, \
47742 + .attach = bfa_ ## __mod ## _attach, \
47743 + .detach = bfa_ ## __mod ## _detach, \
47744 + .start = bfa_ ## __mod ## _start, \
47745 + .stop = bfa_ ## __mod ## _stop, \
47746 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
47747 }
47748
47749 #define BFA_CACHELINE_SZ (256)
47750 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
47751 index 045c4e1..13de803 100644
47752 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
47753 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
47754 @@ -33,8 +33,8 @@
47755 */
47756 #include "libfcoe.h"
47757
47758 -static atomic_t ctlr_num;
47759 -static atomic_t fcf_num;
47760 +static atomic_unchecked_t ctlr_num;
47761 +static atomic_unchecked_t fcf_num;
47762
47763 /*
47764 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
47765 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
47766 if (!ctlr)
47767 goto out;
47768
47769 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
47770 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
47771 ctlr->f = f;
47772 ctlr->mode = FIP_CONN_TYPE_FABRIC;
47773 INIT_LIST_HEAD(&ctlr->fcfs);
47774 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
47775 fcf->dev.parent = &ctlr->dev;
47776 fcf->dev.bus = &fcoe_bus_type;
47777 fcf->dev.type = &fcoe_fcf_device_type;
47778 - fcf->id = atomic_inc_return(&fcf_num) - 1;
47779 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
47780 fcf->state = FCOE_FCF_STATE_UNKNOWN;
47781
47782 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
47783 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
47784 {
47785 int error;
47786
47787 - atomic_set(&ctlr_num, 0);
47788 - atomic_set(&fcf_num, 0);
47789 + atomic_set_unchecked(&ctlr_num, 0);
47790 + atomic_set_unchecked(&fcf_num, 0);
47791
47792 error = bus_register(&fcoe_bus_type);
47793 if (error)
47794 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
47795 index f2c5005..db36c02 100644
47796 --- a/drivers/scsi/hosts.c
47797 +++ b/drivers/scsi/hosts.c
47798 @@ -42,7 +42,7 @@
47799 #include "scsi_logging.h"
47800
47801
47802 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47803 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47804
47805
47806 static void scsi_host_cls_release(struct device *dev)
47807 @@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
47808 * subtract one because we increment first then return, but we need to
47809 * know what the next host number was before increment
47810 */
47811 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
47812 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
47813 shost->dma_channel = 0xff;
47814
47815 /* These three are default values which can be overridden */
47816 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
47817 index 20a5e6e..8b23cea 100644
47818 --- a/drivers/scsi/hpsa.c
47819 +++ b/drivers/scsi/hpsa.c
47820 @@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
47821 unsigned long flags;
47822
47823 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
47824 - return h->access.command_completed(h, q);
47825 + return h->access->command_completed(h, q);
47826
47827 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
47828 a = rq->head[rq->current_entry];
47829 @@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
47830 while (!list_empty(&h->reqQ)) {
47831 c = list_entry(h->reqQ.next, struct CommandList, list);
47832 /* can't do anything if fifo is full */
47833 - if ((h->access.fifo_full(h))) {
47834 + if ((h->access->fifo_full(h))) {
47835 dev_warn(&h->pdev->dev, "fifo full\n");
47836 break;
47837 }
47838 @@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
47839
47840 /* Tell the controller execute command */
47841 spin_unlock_irqrestore(&h->lock, flags);
47842 - h->access.submit_command(h, c);
47843 + h->access->submit_command(h, c);
47844 spin_lock_irqsave(&h->lock, flags);
47845 }
47846 spin_unlock_irqrestore(&h->lock, flags);
47847 @@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
47848
47849 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
47850 {
47851 - return h->access.command_completed(h, q);
47852 + return h->access->command_completed(h, q);
47853 }
47854
47855 static inline bool interrupt_pending(struct ctlr_info *h)
47856 {
47857 - return h->access.intr_pending(h);
47858 + return h->access->intr_pending(h);
47859 }
47860
47861 static inline long interrupt_not_for_us(struct ctlr_info *h)
47862 {
47863 - return (h->access.intr_pending(h) == 0) ||
47864 + return (h->access->intr_pending(h) == 0) ||
47865 (h->interrupts_enabled == 0);
47866 }
47867
47868 @@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
47869 if (prod_index < 0)
47870 return -ENODEV;
47871 h->product_name = products[prod_index].product_name;
47872 - h->access = *(products[prod_index].access);
47873 + h->access = products[prod_index].access;
47874
47875 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
47876 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
47877 @@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
47878
47879 assert_spin_locked(&lockup_detector_lock);
47880 remove_ctlr_from_lockup_detector_list(h);
47881 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
47882 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
47883 spin_lock_irqsave(&h->lock, flags);
47884 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
47885 spin_unlock_irqrestore(&h->lock, flags);
47886 @@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
47887 }
47888
47889 /* make sure the board interrupts are off */
47890 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
47891 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
47892
47893 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
47894 goto clean2;
47895 @@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
47896 * fake ones to scoop up any residual completions.
47897 */
47898 spin_lock_irqsave(&h->lock, flags);
47899 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
47900 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
47901 spin_unlock_irqrestore(&h->lock, flags);
47902 free_irqs(h);
47903 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
47904 @@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
47905 dev_info(&h->pdev->dev, "Board READY.\n");
47906 dev_info(&h->pdev->dev,
47907 "Waiting for stale completions to drain.\n");
47908 - h->access.set_intr_mask(h, HPSA_INTR_ON);
47909 + h->access->set_intr_mask(h, HPSA_INTR_ON);
47910 msleep(10000);
47911 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
47912 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
47913
47914 rc = controller_reset_failed(h->cfgtable);
47915 if (rc)
47916 @@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
47917 }
47918
47919 /* Turn the interrupts on so we can service requests */
47920 - h->access.set_intr_mask(h, HPSA_INTR_ON);
47921 + h->access->set_intr_mask(h, HPSA_INTR_ON);
47922
47923 hpsa_hba_inquiry(h);
47924 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
47925 @@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
47926 * To write all data in the battery backed cache to disks
47927 */
47928 hpsa_flush_cache(h);
47929 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
47930 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
47931 hpsa_free_irqs_and_disable_msix(h);
47932 }
47933
47934 @@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
47935 return;
47936 }
47937 /* Change the access methods to the performant access methods */
47938 - h->access = SA5_performant_access;
47939 + h->access = &SA5_performant_access;
47940 h->transMethod = CFGTBL_Trans_Performant;
47941 }
47942
47943 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
47944 index bc85e72..d463049 100644
47945 --- a/drivers/scsi/hpsa.h
47946 +++ b/drivers/scsi/hpsa.h
47947 @@ -79,7 +79,7 @@ struct ctlr_info {
47948 unsigned int msix_vector;
47949 unsigned int msi_vector;
47950 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
47951 - struct access_method access;
47952 + struct access_method *access;
47953
47954 /* queue and queue Info */
47955 struct list_head reqQ;
47956 @@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
47957 }
47958
47959 static struct access_method SA5_access = {
47960 - SA5_submit_command,
47961 - SA5_intr_mask,
47962 - SA5_fifo_full,
47963 - SA5_intr_pending,
47964 - SA5_completed,
47965 + .submit_command = SA5_submit_command,
47966 + .set_intr_mask = SA5_intr_mask,
47967 + .fifo_full = SA5_fifo_full,
47968 + .intr_pending = SA5_intr_pending,
47969 + .command_completed = SA5_completed,
47970 };
47971
47972 static struct access_method SA5_performant_access = {
47973 - SA5_submit_command,
47974 - SA5_performant_intr_mask,
47975 - SA5_fifo_full,
47976 - SA5_performant_intr_pending,
47977 - SA5_performant_completed,
47978 + .submit_command = SA5_submit_command,
47979 + .set_intr_mask = SA5_performant_intr_mask,
47980 + .fifo_full = SA5_fifo_full,
47981 + .intr_pending = SA5_performant_intr_pending,
47982 + .command_completed = SA5_performant_completed,
47983 };
47984
47985 struct board_type {
47986 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
47987 index 1b3a094..068e683 100644
47988 --- a/drivers/scsi/libfc/fc_exch.c
47989 +++ b/drivers/scsi/libfc/fc_exch.c
47990 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
47991 u16 pool_max_index;
47992
47993 struct {
47994 - atomic_t no_free_exch;
47995 - atomic_t no_free_exch_xid;
47996 - atomic_t xid_not_found;
47997 - atomic_t xid_busy;
47998 - atomic_t seq_not_found;
47999 - atomic_t non_bls_resp;
48000 + atomic_unchecked_t no_free_exch;
48001 + atomic_unchecked_t no_free_exch_xid;
48002 + atomic_unchecked_t xid_not_found;
48003 + atomic_unchecked_t xid_busy;
48004 + atomic_unchecked_t seq_not_found;
48005 + atomic_unchecked_t non_bls_resp;
48006 } stats;
48007 };
48008
48009 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48010 /* allocate memory for exchange */
48011 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48012 if (!ep) {
48013 - atomic_inc(&mp->stats.no_free_exch);
48014 + atomic_inc_unchecked(&mp->stats.no_free_exch);
48015 goto out;
48016 }
48017 memset(ep, 0, sizeof(*ep));
48018 @@ -874,7 +874,7 @@ out:
48019 return ep;
48020 err:
48021 spin_unlock_bh(&pool->lock);
48022 - atomic_inc(&mp->stats.no_free_exch_xid);
48023 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48024 mempool_free(ep, mp->ep_pool);
48025 return NULL;
48026 }
48027 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48028 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48029 ep = fc_exch_find(mp, xid);
48030 if (!ep) {
48031 - atomic_inc(&mp->stats.xid_not_found);
48032 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48033 reject = FC_RJT_OX_ID;
48034 goto out;
48035 }
48036 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48037 ep = fc_exch_find(mp, xid);
48038 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48039 if (ep) {
48040 - atomic_inc(&mp->stats.xid_busy);
48041 + atomic_inc_unchecked(&mp->stats.xid_busy);
48042 reject = FC_RJT_RX_ID;
48043 goto rel;
48044 }
48045 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48046 }
48047 xid = ep->xid; /* get our XID */
48048 } else if (!ep) {
48049 - atomic_inc(&mp->stats.xid_not_found);
48050 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48051 reject = FC_RJT_RX_ID; /* XID not found */
48052 goto out;
48053 }
48054 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48055 } else {
48056 sp = &ep->seq;
48057 if (sp->id != fh->fh_seq_id) {
48058 - atomic_inc(&mp->stats.seq_not_found);
48059 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48060 if (f_ctl & FC_FC_END_SEQ) {
48061 /*
48062 * Update sequence_id based on incoming last
48063 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48064
48065 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48066 if (!ep) {
48067 - atomic_inc(&mp->stats.xid_not_found);
48068 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48069 goto out;
48070 }
48071 if (ep->esb_stat & ESB_ST_COMPLETE) {
48072 - atomic_inc(&mp->stats.xid_not_found);
48073 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48074 goto rel;
48075 }
48076 if (ep->rxid == FC_XID_UNKNOWN)
48077 ep->rxid = ntohs(fh->fh_rx_id);
48078 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48079 - atomic_inc(&mp->stats.xid_not_found);
48080 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48081 goto rel;
48082 }
48083 if (ep->did != ntoh24(fh->fh_s_id) &&
48084 ep->did != FC_FID_FLOGI) {
48085 - atomic_inc(&mp->stats.xid_not_found);
48086 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48087 goto rel;
48088 }
48089 sof = fr_sof(fp);
48090 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48091 sp->ssb_stat |= SSB_ST_RESP;
48092 sp->id = fh->fh_seq_id;
48093 } else if (sp->id != fh->fh_seq_id) {
48094 - atomic_inc(&mp->stats.seq_not_found);
48095 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48096 goto rel;
48097 }
48098
48099 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48100 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48101
48102 if (!sp)
48103 - atomic_inc(&mp->stats.xid_not_found);
48104 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48105 else
48106 - atomic_inc(&mp->stats.non_bls_resp);
48107 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
48108
48109 fc_frame_free(fp);
48110 }
48111 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48112
48113 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48114 mp = ema->mp;
48115 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48116 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48117 st->fc_no_free_exch_xid +=
48118 - atomic_read(&mp->stats.no_free_exch_xid);
48119 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48120 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48121 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48122 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48123 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48124 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48125 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48126 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48127 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48128 }
48129 }
48130 EXPORT_SYMBOL(fc_exch_update_stats);
48131 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48132 index d289583..b745eec 100644
48133 --- a/drivers/scsi/libsas/sas_ata.c
48134 +++ b/drivers/scsi/libsas/sas_ata.c
48135 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48136 .postreset = ata_std_postreset,
48137 .error_handler = ata_std_error_handler,
48138 .post_internal_cmd = sas_ata_post_internal,
48139 - .qc_defer = ata_std_qc_defer,
48140 + .qc_defer = ata_std_qc_defer,
48141 .qc_prep = ata_noop_qc_prep,
48142 .qc_issue = sas_ata_qc_issue,
48143 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48144 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48145 index 4e1b75c..0bbdfa9 100644
48146 --- a/drivers/scsi/lpfc/lpfc.h
48147 +++ b/drivers/scsi/lpfc/lpfc.h
48148 @@ -432,7 +432,7 @@ struct lpfc_vport {
48149 struct dentry *debug_nodelist;
48150 struct dentry *vport_debugfs_root;
48151 struct lpfc_debugfs_trc *disc_trc;
48152 - atomic_t disc_trc_cnt;
48153 + atomic_unchecked_t disc_trc_cnt;
48154 #endif
48155 uint8_t stat_data_enabled;
48156 uint8_t stat_data_blocked;
48157 @@ -865,8 +865,8 @@ struct lpfc_hba {
48158 struct timer_list fabric_block_timer;
48159 unsigned long bit_flags;
48160 #define FABRIC_COMANDS_BLOCKED 0
48161 - atomic_t num_rsrc_err;
48162 - atomic_t num_cmd_success;
48163 + atomic_unchecked_t num_rsrc_err;
48164 + atomic_unchecked_t num_cmd_success;
48165 unsigned long last_rsrc_error_time;
48166 unsigned long last_ramp_down_time;
48167 unsigned long last_ramp_up_time;
48168 @@ -902,7 +902,7 @@ struct lpfc_hba {
48169
48170 struct dentry *debug_slow_ring_trc;
48171 struct lpfc_debugfs_trc *slow_ring_trc;
48172 - atomic_t slow_ring_trc_cnt;
48173 + atomic_unchecked_t slow_ring_trc_cnt;
48174 /* iDiag debugfs sub-directory */
48175 struct dentry *idiag_root;
48176 struct dentry *idiag_pci_cfg;
48177 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48178 index 60084e6..0e2e700 100644
48179 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
48180 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48181 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48182
48183 #include <linux/debugfs.h>
48184
48185 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48186 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48187 static unsigned long lpfc_debugfs_start_time = 0L;
48188
48189 /* iDiag */
48190 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48191 lpfc_debugfs_enable = 0;
48192
48193 len = 0;
48194 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48195 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48196 (lpfc_debugfs_max_disc_trc - 1);
48197 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48198 dtp = vport->disc_trc + i;
48199 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48200 lpfc_debugfs_enable = 0;
48201
48202 len = 0;
48203 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48204 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48205 (lpfc_debugfs_max_slow_ring_trc - 1);
48206 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48207 dtp = phba->slow_ring_trc + i;
48208 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48209 !vport || !vport->disc_trc)
48210 return;
48211
48212 - index = atomic_inc_return(&vport->disc_trc_cnt) &
48213 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48214 (lpfc_debugfs_max_disc_trc - 1);
48215 dtp = vport->disc_trc + index;
48216 dtp->fmt = fmt;
48217 dtp->data1 = data1;
48218 dtp->data2 = data2;
48219 dtp->data3 = data3;
48220 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48221 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48222 dtp->jif = jiffies;
48223 #endif
48224 return;
48225 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
48226 !phba || !phba->slow_ring_trc)
48227 return;
48228
48229 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
48230 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
48231 (lpfc_debugfs_max_slow_ring_trc - 1);
48232 dtp = phba->slow_ring_trc + index;
48233 dtp->fmt = fmt;
48234 dtp->data1 = data1;
48235 dtp->data2 = data2;
48236 dtp->data3 = data3;
48237 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48238 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48239 dtp->jif = jiffies;
48240 #endif
48241 return;
48242 @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48243 "slow_ring buffer\n");
48244 goto debug_failed;
48245 }
48246 - atomic_set(&phba->slow_ring_trc_cnt, 0);
48247 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
48248 memset(phba->slow_ring_trc, 0,
48249 (sizeof(struct lpfc_debugfs_trc) *
48250 lpfc_debugfs_max_slow_ring_trc));
48251 @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48252 "buffer\n");
48253 goto debug_failed;
48254 }
48255 - atomic_set(&vport->disc_trc_cnt, 0);
48256 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
48257
48258 snprintf(name, sizeof(name), "discovery_trace");
48259 vport->debug_disc_trc =
48260 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
48261 index 68c94cc..8c27be5 100644
48262 --- a/drivers/scsi/lpfc/lpfc_init.c
48263 +++ b/drivers/scsi/lpfc/lpfc_init.c
48264 @@ -10949,8 +10949,10 @@ lpfc_init(void)
48265 "misc_register returned with status %d", error);
48266
48267 if (lpfc_enable_npiv) {
48268 - lpfc_transport_functions.vport_create = lpfc_vport_create;
48269 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48270 + pax_open_kernel();
48271 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
48272 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48273 + pax_close_kernel();
48274 }
48275 lpfc_transport_template =
48276 fc_attach_transport(&lpfc_transport_functions);
48277 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
48278 index b2ede05..aaf482ca 100644
48279 --- a/drivers/scsi/lpfc/lpfc_scsi.c
48280 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
48281 @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
48282 uint32_t evt_posted;
48283
48284 spin_lock_irqsave(&phba->hbalock, flags);
48285 - atomic_inc(&phba->num_rsrc_err);
48286 + atomic_inc_unchecked(&phba->num_rsrc_err);
48287 phba->last_rsrc_error_time = jiffies;
48288
48289 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
48290 @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
48291 unsigned long flags;
48292 struct lpfc_hba *phba = vport->phba;
48293 uint32_t evt_posted;
48294 - atomic_inc(&phba->num_cmd_success);
48295 + atomic_inc_unchecked(&phba->num_cmd_success);
48296
48297 if (vport->cfg_lun_queue_depth <= queue_depth)
48298 return;
48299 @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48300 unsigned long num_rsrc_err, num_cmd_success;
48301 int i;
48302
48303 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
48304 - num_cmd_success = atomic_read(&phba->num_cmd_success);
48305 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
48306 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
48307
48308 /*
48309 * The error and success command counters are global per
48310 @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48311 }
48312 }
48313 lpfc_destroy_vport_work_array(phba, vports);
48314 - atomic_set(&phba->num_rsrc_err, 0);
48315 - atomic_set(&phba->num_cmd_success, 0);
48316 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
48317 + atomic_set_unchecked(&phba->num_cmd_success, 0);
48318 }
48319
48320 /**
48321 @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
48322 }
48323 }
48324 lpfc_destroy_vport_work_array(phba, vports);
48325 - atomic_set(&phba->num_rsrc_err, 0);
48326 - atomic_set(&phba->num_cmd_success, 0);
48327 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
48328 + atomic_set_unchecked(&phba->num_cmd_success, 0);
48329 }
48330
48331 /**
48332 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48333 index 7f0af4f..193ac3e 100644
48334 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48335 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48336 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
48337 {
48338 struct scsi_device *sdev = to_scsi_device(dev);
48339 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48340 - static struct _raid_device *raid_device;
48341 + struct _raid_device *raid_device;
48342 unsigned long flags;
48343 Mpi2RaidVolPage0_t vol_pg0;
48344 Mpi2ConfigReply_t mpi_reply;
48345 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
48346 {
48347 struct scsi_device *sdev = to_scsi_device(dev);
48348 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48349 - static struct _raid_device *raid_device;
48350 + struct _raid_device *raid_device;
48351 unsigned long flags;
48352 Mpi2RaidVolPage0_t vol_pg0;
48353 Mpi2ConfigReply_t mpi_reply;
48354 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
48355 struct fw_event_work *fw_event)
48356 {
48357 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
48358 - static struct _raid_device *raid_device;
48359 + struct _raid_device *raid_device;
48360 unsigned long flags;
48361 u16 handle;
48362
48363 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
48364 u64 sas_address;
48365 struct _sas_device *sas_device;
48366 struct _sas_node *expander_device;
48367 - static struct _raid_device *raid_device;
48368 + struct _raid_device *raid_device;
48369 u8 retry_count;
48370 unsigned long flags;
48371
48372 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
48373 index be8ce54..94ed33a 100644
48374 --- a/drivers/scsi/pmcraid.c
48375 +++ b/drivers/scsi/pmcraid.c
48376 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
48377 res->scsi_dev = scsi_dev;
48378 scsi_dev->hostdata = res;
48379 res->change_detected = 0;
48380 - atomic_set(&res->read_failures, 0);
48381 - atomic_set(&res->write_failures, 0);
48382 + atomic_set_unchecked(&res->read_failures, 0);
48383 + atomic_set_unchecked(&res->write_failures, 0);
48384 rc = 0;
48385 }
48386 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
48387 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
48388
48389 /* If this was a SCSI read/write command keep count of errors */
48390 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
48391 - atomic_inc(&res->read_failures);
48392 + atomic_inc_unchecked(&res->read_failures);
48393 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
48394 - atomic_inc(&res->write_failures);
48395 + atomic_inc_unchecked(&res->write_failures);
48396
48397 if (!RES_IS_GSCSI(res->cfg_entry) &&
48398 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
48399 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
48400 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48401 * hrrq_id assigned here in queuecommand
48402 */
48403 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48404 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48405 pinstance->num_hrrq;
48406 cmd->cmd_done = pmcraid_io_done;
48407
48408 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
48409 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48410 * hrrq_id assigned here in queuecommand
48411 */
48412 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48413 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48414 pinstance->num_hrrq;
48415
48416 if (request_size) {
48417 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
48418
48419 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
48420 /* add resources only after host is added into system */
48421 - if (!atomic_read(&pinstance->expose_resources))
48422 + if (!atomic_read_unchecked(&pinstance->expose_resources))
48423 return;
48424
48425 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
48426 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
48427 init_waitqueue_head(&pinstance->reset_wait_q);
48428
48429 atomic_set(&pinstance->outstanding_cmds, 0);
48430 - atomic_set(&pinstance->last_message_id, 0);
48431 - atomic_set(&pinstance->expose_resources, 0);
48432 + atomic_set_unchecked(&pinstance->last_message_id, 0);
48433 + atomic_set_unchecked(&pinstance->expose_resources, 0);
48434
48435 INIT_LIST_HEAD(&pinstance->free_res_q);
48436 INIT_LIST_HEAD(&pinstance->used_res_q);
48437 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
48438 /* Schedule worker thread to handle CCN and take care of adding and
48439 * removing devices to OS
48440 */
48441 - atomic_set(&pinstance->expose_resources, 1);
48442 + atomic_set_unchecked(&pinstance->expose_resources, 1);
48443 schedule_work(&pinstance->worker_q);
48444 return rc;
48445
48446 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
48447 index e1d150f..6c6df44 100644
48448 --- a/drivers/scsi/pmcraid.h
48449 +++ b/drivers/scsi/pmcraid.h
48450 @@ -748,7 +748,7 @@ struct pmcraid_instance {
48451 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
48452
48453 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
48454 - atomic_t last_message_id;
48455 + atomic_unchecked_t last_message_id;
48456
48457 /* configuration table */
48458 struct pmcraid_config_table *cfg_table;
48459 @@ -777,7 +777,7 @@ struct pmcraid_instance {
48460 atomic_t outstanding_cmds;
48461
48462 /* should add/delete resources to mid-layer now ?*/
48463 - atomic_t expose_resources;
48464 + atomic_unchecked_t expose_resources;
48465
48466
48467
48468 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
48469 struct pmcraid_config_table_entry_ext cfg_entry_ext;
48470 };
48471 struct scsi_device *scsi_dev; /* Link scsi_device structure */
48472 - atomic_t read_failures; /* count of failed READ commands */
48473 - atomic_t write_failures; /* count of failed WRITE commands */
48474 + atomic_unchecked_t read_failures; /* count of failed READ commands */
48475 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
48476
48477 /* To indicate add/delete/modify during CCN */
48478 u8 change_detected;
48479 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
48480 index 5f174b8..98d32b0 100644
48481 --- a/drivers/scsi/qla2xxx/qla_attr.c
48482 +++ b/drivers/scsi/qla2xxx/qla_attr.c
48483 @@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
48484 return 0;
48485 }
48486
48487 -struct fc_function_template qla2xxx_transport_functions = {
48488 +fc_function_template_no_const qla2xxx_transport_functions = {
48489
48490 .show_host_node_name = 1,
48491 .show_host_port_name = 1,
48492 @@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
48493 .bsg_timeout = qla24xx_bsg_timeout,
48494 };
48495
48496 -struct fc_function_template qla2xxx_transport_vport_functions = {
48497 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
48498
48499 .show_host_node_name = 1,
48500 .show_host_port_name = 1,
48501 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
48502 index 4446bf5..9a3574d 100644
48503 --- a/drivers/scsi/qla2xxx/qla_gbl.h
48504 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
48505 @@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
48506 struct device_attribute;
48507 extern struct device_attribute *qla2x00_host_attrs[];
48508 struct fc_function_template;
48509 -extern struct fc_function_template qla2xxx_transport_functions;
48510 -extern struct fc_function_template qla2xxx_transport_vport_functions;
48511 +extern fc_function_template_no_const qla2xxx_transport_functions;
48512 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
48513 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
48514 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
48515 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
48516 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
48517 index 52be35e..b933907 100644
48518 --- a/drivers/scsi/qla2xxx/qla_os.c
48519 +++ b/drivers/scsi/qla2xxx/qla_os.c
48520 @@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
48521 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
48522 /* Ok, a 64bit DMA mask is applicable. */
48523 ha->flags.enable_64bit_addressing = 1;
48524 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48525 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48526 + pax_open_kernel();
48527 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48528 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48529 + pax_close_kernel();
48530 return;
48531 }
48532 }
48533 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
48534 index 084d1fd..9f939eb 100644
48535 --- a/drivers/scsi/qla4xxx/ql4_def.h
48536 +++ b/drivers/scsi/qla4xxx/ql4_def.h
48537 @@ -296,7 +296,7 @@ struct ddb_entry {
48538 * (4000 only) */
48539 atomic_t relogin_timer; /* Max Time to wait for
48540 * relogin to complete */
48541 - atomic_t relogin_retry_count; /* Num of times relogin has been
48542 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
48543 * retried */
48544 uint32_t default_time2wait; /* Default Min time between
48545 * relogins (+aens) */
48546 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
48547 index a28d5e6..000a8af 100644
48548 --- a/drivers/scsi/qla4xxx/ql4_os.c
48549 +++ b/drivers/scsi/qla4xxx/ql4_os.c
48550 @@ -3308,12 +3308,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
48551 */
48552 if (!iscsi_is_session_online(cls_sess)) {
48553 /* Reset retry relogin timer */
48554 - atomic_inc(&ddb_entry->relogin_retry_count);
48555 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
48556 DEBUG2(ql4_printk(KERN_INFO, ha,
48557 "%s: index[%d] relogin timed out-retrying"
48558 " relogin (%d), retry (%d)\n", __func__,
48559 ddb_entry->fw_ddb_index,
48560 - atomic_read(&ddb_entry->relogin_retry_count),
48561 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
48562 ddb_entry->default_time2wait + 4));
48563 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
48564 atomic_set(&ddb_entry->retry_relogin_timer,
48565 @@ -5455,7 +5455,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
48566
48567 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
48568 atomic_set(&ddb_entry->relogin_timer, 0);
48569 - atomic_set(&ddb_entry->relogin_retry_count, 0);
48570 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
48571 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
48572 ddb_entry->default_relogin_timeout =
48573 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
48574 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
48575 index fe0bcb1..c9255be 100644
48576 --- a/drivers/scsi/scsi.c
48577 +++ b/drivers/scsi/scsi.c
48578 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
48579 struct Scsi_Host *host = cmd->device->host;
48580 int rtn = 0;
48581
48582 - atomic_inc(&cmd->device->iorequest_cnt);
48583 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48584
48585 /* check if the device is still usable */
48586 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
48587 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
48588 index 7bd7f0d..44147bf 100644
48589 --- a/drivers/scsi/scsi_lib.c
48590 +++ b/drivers/scsi/scsi_lib.c
48591 @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
48592 shost = sdev->host;
48593 scsi_init_cmd_errh(cmd);
48594 cmd->result = DID_NO_CONNECT << 16;
48595 - atomic_inc(&cmd->device->iorequest_cnt);
48596 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48597
48598 /*
48599 * SCSI request completion path will do scsi_device_unbusy(),
48600 @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
48601
48602 INIT_LIST_HEAD(&cmd->eh_entry);
48603
48604 - atomic_inc(&cmd->device->iodone_cnt);
48605 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
48606 if (cmd->result)
48607 - atomic_inc(&cmd->device->ioerr_cnt);
48608 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
48609
48610 disposition = scsi_decide_disposition(cmd);
48611 if (disposition != SUCCESS &&
48612 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
48613 index 8ff62c2..693b6f7 100644
48614 --- a/drivers/scsi/scsi_sysfs.c
48615 +++ b/drivers/scsi/scsi_sysfs.c
48616 @@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
48617 char *buf) \
48618 { \
48619 struct scsi_device *sdev = to_scsi_device(dev); \
48620 - unsigned long long count = atomic_read(&sdev->field); \
48621 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
48622 return snprintf(buf, 20, "0x%llx\n", count); \
48623 } \
48624 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
48625 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
48626 index 84a1fdf..693b0d6 100644
48627 --- a/drivers/scsi/scsi_tgt_lib.c
48628 +++ b/drivers/scsi/scsi_tgt_lib.c
48629 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
48630 int err;
48631
48632 dprintk("%lx %u\n", uaddr, len);
48633 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
48634 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
48635 if (err) {
48636 /*
48637 * TODO: need to fixup sg_tablesize, max_segment_size,
48638 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
48639 index 4628fd5..a94a1c2 100644
48640 --- a/drivers/scsi/scsi_transport_fc.c
48641 +++ b/drivers/scsi/scsi_transport_fc.c
48642 @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
48643 * Netlink Infrastructure
48644 */
48645
48646 -static atomic_t fc_event_seq;
48647 +static atomic_unchecked_t fc_event_seq;
48648
48649 /**
48650 * fc_get_event_number - Obtain the next sequential FC event number
48651 @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
48652 u32
48653 fc_get_event_number(void)
48654 {
48655 - return atomic_add_return(1, &fc_event_seq);
48656 + return atomic_add_return_unchecked(1, &fc_event_seq);
48657 }
48658 EXPORT_SYMBOL(fc_get_event_number);
48659
48660 @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
48661 {
48662 int error;
48663
48664 - atomic_set(&fc_event_seq, 0);
48665 + atomic_set_unchecked(&fc_event_seq, 0);
48666
48667 error = transport_class_register(&fc_host_class);
48668 if (error)
48669 @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
48670 char *cp;
48671
48672 *val = simple_strtoul(buf, &cp, 0);
48673 - if ((*cp && (*cp != '\n')) || (*val < 0))
48674 + if (*cp && (*cp != '\n'))
48675 return -EINVAL;
48676 /*
48677 * Check for overflow; dev_loss_tmo is u32
48678 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
48679 index 63a6ca4..5d5cadd 100644
48680 --- a/drivers/scsi/scsi_transport_iscsi.c
48681 +++ b/drivers/scsi/scsi_transport_iscsi.c
48682 @@ -79,7 +79,7 @@ struct iscsi_internal {
48683 struct transport_container session_cont;
48684 };
48685
48686 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
48687 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
48688 static struct workqueue_struct *iscsi_eh_timer_workq;
48689
48690 static DEFINE_IDA(iscsi_sess_ida);
48691 @@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
48692 int err;
48693
48694 ihost = shost->shost_data;
48695 - session->sid = atomic_add_return(1, &iscsi_session_nr);
48696 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
48697
48698 if (target_id == ISCSI_MAX_TARGET) {
48699 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
48700 @@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
48701 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
48702 ISCSI_TRANSPORT_VERSION);
48703
48704 - atomic_set(&iscsi_session_nr, 0);
48705 + atomic_set_unchecked(&iscsi_session_nr, 0);
48706
48707 err = class_register(&iscsi_transport_class);
48708 if (err)
48709 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
48710 index 2700a5a..752ec38 100644
48711 --- a/drivers/scsi/scsi_transport_srp.c
48712 +++ b/drivers/scsi/scsi_transport_srp.c
48713 @@ -36,7 +36,7 @@
48714 #include "scsi_transport_srp_internal.h"
48715
48716 struct srp_host_attrs {
48717 - atomic_t next_port_id;
48718 + atomic_unchecked_t next_port_id;
48719 };
48720 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
48721
48722 @@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
48723 struct Scsi_Host *shost = dev_to_shost(dev);
48724 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
48725
48726 - atomic_set(&srp_host->next_port_id, 0);
48727 + atomic_set_unchecked(&srp_host->next_port_id, 0);
48728 return 0;
48729 }
48730
48731 @@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
48732 rport_fast_io_fail_timedout);
48733 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
48734
48735 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
48736 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
48737 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
48738
48739 transport_setup_device(&rport->dev);
48740 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
48741 index 69725f7..03aaee1 100644
48742 --- a/drivers/scsi/sd.c
48743 +++ b/drivers/scsi/sd.c
48744 @@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
48745 sdkp->disk = gd;
48746 sdkp->index = index;
48747 atomic_set(&sdkp->openers, 0);
48748 - atomic_set(&sdkp->device->ioerr_cnt, 0);
48749 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
48750
48751 if (!sdp->request_queue->rq_timeout) {
48752 if (sdp->type != TYPE_MOD)
48753 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
48754 index df5e961..df6b97f 100644
48755 --- a/drivers/scsi/sg.c
48756 +++ b/drivers/scsi/sg.c
48757 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
48758 sdp->disk->disk_name,
48759 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
48760 NULL,
48761 - (char *)arg);
48762 + (char __user *)arg);
48763 case BLKTRACESTART:
48764 return blk_trace_startstop(sdp->device->request_queue, 1);
48765 case BLKTRACESTOP:
48766 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
48767 index 349ebba..ff2a249 100644
48768 --- a/drivers/spi/spi.c
48769 +++ b/drivers/spi/spi.c
48770 @@ -1945,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master)
48771 EXPORT_SYMBOL_GPL(spi_bus_unlock);
48772
48773 /* portable code must never pass more than 32 bytes */
48774 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
48775 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
48776
48777 static u8 *buf;
48778
48779 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
48780 index 2c61783..4d49e4e 100644
48781 --- a/drivers/staging/android/timed_output.c
48782 +++ b/drivers/staging/android/timed_output.c
48783 @@ -25,7 +25,7 @@
48784 #include "timed_output.h"
48785
48786 static struct class *timed_output_class;
48787 -static atomic_t device_count;
48788 +static atomic_unchecked_t device_count;
48789
48790 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
48791 char *buf)
48792 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
48793 timed_output_class = class_create(THIS_MODULE, "timed_output");
48794 if (IS_ERR(timed_output_class))
48795 return PTR_ERR(timed_output_class);
48796 - atomic_set(&device_count, 0);
48797 + atomic_set_unchecked(&device_count, 0);
48798 timed_output_class->dev_groups = timed_output_groups;
48799 }
48800
48801 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
48802 if (ret < 0)
48803 return ret;
48804
48805 - tdev->index = atomic_inc_return(&device_count);
48806 + tdev->index = atomic_inc_return_unchecked(&device_count);
48807 tdev->dev = device_create(timed_output_class, NULL,
48808 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
48809 if (IS_ERR(tdev->dev))
48810 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
48811 index c0f7cd7..5424212 100644
48812 --- a/drivers/staging/gdm724x/gdm_tty.c
48813 +++ b/drivers/staging/gdm724x/gdm_tty.c
48814 @@ -45,7 +45,7 @@
48815 #define gdm_tty_send_control(n, r, v, d, l) (\
48816 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
48817
48818 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
48819 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
48820
48821 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
48822 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
48823 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
48824 index b7613c8..c302392 100644
48825 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
48826 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
48827 @@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
48828 return 0;
48829 }
48830
48831 -sfw_test_client_ops_t brw_test_client;
48832 -void brw_init_test_client(void)
48833 -{
48834 - brw_test_client.tso_init = brw_client_init;
48835 - brw_test_client.tso_fini = brw_client_fini;
48836 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
48837 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
48838 +sfw_test_client_ops_t brw_test_client = {
48839 + .tso_init = brw_client_init,
48840 + .tso_fini = brw_client_fini,
48841 + .tso_prep_rpc = brw_client_prep_rpc,
48842 + .tso_done_rpc = brw_client_done_rpc,
48843 };
48844
48845 srpc_service_t brw_test_service;
48846 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
48847 index 483c785..e1a2a7b 100644
48848 --- a/drivers/staging/lustre/lnet/selftest/framework.c
48849 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
48850 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
48851
48852 extern sfw_test_client_ops_t ping_test_client;
48853 extern srpc_service_t ping_test_service;
48854 -extern void ping_init_test_client(void);
48855 extern void ping_init_test_service(void);
48856
48857 extern sfw_test_client_ops_t brw_test_client;
48858 extern srpc_service_t brw_test_service;
48859 -extern void brw_init_test_client(void);
48860 extern void brw_init_test_service(void);
48861
48862
48863 @@ -1684,12 +1682,10 @@ sfw_startup (void)
48864 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
48865 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
48866
48867 - brw_init_test_client();
48868 brw_init_test_service();
48869 rc = sfw_register_test(&brw_test_service, &brw_test_client);
48870 LASSERT (rc == 0);
48871
48872 - ping_init_test_client();
48873 ping_init_test_service();
48874 rc = sfw_register_test(&ping_test_service, &ping_test_client);
48875 LASSERT (rc == 0);
48876 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
48877 index f0f9194..b589047 100644
48878 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
48879 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
48880 @@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
48881 return 0;
48882 }
48883
48884 -sfw_test_client_ops_t ping_test_client;
48885 -void ping_init_test_client(void)
48886 -{
48887 - ping_test_client.tso_init = ping_client_init;
48888 - ping_test_client.tso_fini = ping_client_fini;
48889 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
48890 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
48891 -}
48892 +sfw_test_client_ops_t ping_test_client = {
48893 + .tso_init = ping_client_init,
48894 + .tso_fini = ping_client_fini,
48895 + .tso_prep_rpc = ping_client_prep_rpc,
48896 + .tso_done_rpc = ping_client_done_rpc,
48897 +};
48898
48899 srpc_service_t ping_test_service;
48900 void ping_init_test_service(void)
48901 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
48902 index bc2b82f..67fd598 100644
48903 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
48904 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
48905 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
48906 ldlm_completion_callback lcs_completion;
48907 ldlm_blocking_callback lcs_blocking;
48908 ldlm_glimpse_callback lcs_glimpse;
48909 -};
48910 +} __no_const;
48911
48912 /* ldlm_lockd.c */
48913 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
48914 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
48915 index d0aea15..7af68e1 100644
48916 --- a/drivers/staging/lustre/lustre/include/obd.h
48917 +++ b/drivers/staging/lustre/lustre/include/obd.h
48918 @@ -1417,7 +1417,7 @@ struct md_ops {
48919 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
48920 * wrapper function in include/linux/obd_class.h.
48921 */
48922 -};
48923 +} __no_const;
48924
48925 struct lsm_operations {
48926 void (*lsm_free)(struct lov_stripe_md *);
48927 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
48928 index 39fcdac..222780f 100644
48929 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
48930 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
48931 @@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
48932 int added = (mode == LCK_NL);
48933 int overlaps = 0;
48934 int splitted = 0;
48935 - const struct ldlm_callback_suite null_cbs = { NULL };
48936 + const struct ldlm_callback_suite null_cbs = { };
48937 int rc;
48938
48939 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
48940 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
48941 index fc6c977..df1f956 100644
48942 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
48943 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
48944 @@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
48945 int LL_PROC_PROTO(proc_console_max_delay_cs)
48946 {
48947 int rc, max_delay_cs;
48948 - ctl_table_t dummy = *table;
48949 + ctl_table_no_const dummy = *table;
48950 cfs_duration_t d;
48951
48952 dummy.data = &max_delay_cs;
48953 @@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
48954 int LL_PROC_PROTO(proc_console_min_delay_cs)
48955 {
48956 int rc, min_delay_cs;
48957 - ctl_table_t dummy = *table;
48958 + ctl_table_no_const dummy = *table;
48959 cfs_duration_t d;
48960
48961 dummy.data = &min_delay_cs;
48962 @@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
48963 int LL_PROC_PROTO(proc_console_backoff)
48964 {
48965 int rc, backoff;
48966 - ctl_table_t dummy = *table;
48967 + ctl_table_no_const dummy = *table;
48968
48969 dummy.data = &backoff;
48970 dummy.proc_handler = &proc_dointvec;
48971 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
48972 index f3108c7..cd4f9da 100644
48973 --- a/drivers/staging/lustre/lustre/libcfs/module.c
48974 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
48975 @@ -348,11 +348,11 @@ out:
48976
48977
48978 struct cfs_psdev_ops libcfs_psdev_ops = {
48979 - libcfs_psdev_open,
48980 - libcfs_psdev_release,
48981 - NULL,
48982 - NULL,
48983 - libcfs_ioctl
48984 + .p_open = libcfs_psdev_open,
48985 + .p_close = libcfs_psdev_release,
48986 + .p_read = NULL,
48987 + .p_write = NULL,
48988 + .p_ioctl = libcfs_ioctl
48989 };
48990
48991 extern int insert_proc(void);
48992 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
48993 index 3675020..e80d92c 100644
48994 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
48995 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
48996 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
48997
48998 static int solo_sysfs_init(struct solo_dev *solo_dev)
48999 {
49000 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49001 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49002 struct device *dev = &solo_dev->dev;
49003 const char *driver;
49004 int i;
49005 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49006 index 1db18c7..35e6afc 100644
49007 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49008 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49009 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49010
49011 int solo_g723_init(struct solo_dev *solo_dev)
49012 {
49013 - static struct snd_device_ops ops = { NULL };
49014 + static struct snd_device_ops ops = { };
49015 struct snd_card *card;
49016 struct snd_kcontrol_new kctl;
49017 char name[32];
49018 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49019 index 7f2f247..d999137 100644
49020 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49021 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49022 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49023
49024 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49025 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49026 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49027 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49028 if (p2m_id < 0)
49029 p2m_id = -p2m_id;
49030 }
49031 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49032 index f1bbb8c..a73eaba 100644
49033 --- a/drivers/staging/media/solo6x10/solo6x10.h
49034 +++ b/drivers/staging/media/solo6x10/solo6x10.h
49035 @@ -237,7 +237,7 @@ struct solo_dev {
49036
49037 /* P2M DMA Engine */
49038 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49039 - atomic_t p2m_count;
49040 + atomic_unchecked_t p2m_count;
49041 int p2m_jiffies;
49042 unsigned int p2m_timeouts;
49043
49044 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49045 index 0315f60..2ecae10 100644
49046 --- a/drivers/staging/octeon/ethernet-rx.c
49047 +++ b/drivers/staging/octeon/ethernet-rx.c
49048 @@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49049 /* Increment RX stats for virtual ports */
49050 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49051 #ifdef CONFIG_64BIT
49052 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49053 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49054 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49055 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49056 #else
49057 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49058 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49059 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49060 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49061 #endif
49062 }
49063 netif_receive_skb(skb);
49064 @@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49065 dev->name);
49066 */
49067 #ifdef CONFIG_64BIT
49068 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49069 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49070 #else
49071 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49072 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49073 #endif
49074 dev_kfree_skb_irq(skb);
49075 }
49076 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49077 index bd6ca71..8f0961e 100644
49078 --- a/drivers/staging/octeon/ethernet.c
49079 +++ b/drivers/staging/octeon/ethernet.c
49080 @@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49081 * since the RX tasklet also increments it.
49082 */
49083 #ifdef CONFIG_64BIT
49084 - atomic64_add(rx_status.dropped_packets,
49085 - (atomic64_t *)&priv->stats.rx_dropped);
49086 + atomic64_add_unchecked(rx_status.dropped_packets,
49087 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49088 #else
49089 - atomic_add(rx_status.dropped_packets,
49090 - (atomic_t *)&priv->stats.rx_dropped);
49091 + atomic_add_unchecked(rx_status.dropped_packets,
49092 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
49093 #endif
49094 }
49095
49096 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49097 index 439c3c9..2d74293 100644
49098 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
49099 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49100 @@ -271,7 +271,7 @@ struct hal_ops {
49101 s32 (*c2h_handler)(struct adapter *padapter,
49102 struct c2h_evt_hdr *c2h_evt);
49103 c2h_id_filter c2h_id_filter_ccx;
49104 -};
49105 +} __no_const;
49106
49107 enum rt_eeprom_type {
49108 EEPROM_93C46,
49109 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49110 index eb6f0e5..e6a0958 100644
49111 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
49112 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49113 @@ -126,7 +126,7 @@ struct _io_ops {
49114 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
49115 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49116 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49117 -};
49118 +} __no_const;
49119
49120 struct io_req {
49121 struct list_head list;
49122 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49123 index dc23395..cf7e9b1 100644
49124 --- a/drivers/staging/rtl8712/rtl871x_io.h
49125 +++ b/drivers/staging/rtl8712/rtl871x_io.h
49126 @@ -108,7 +108,7 @@ struct _io_ops {
49127 u8 *pmem);
49128 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49129 u8 *pmem);
49130 -};
49131 +} __no_const;
49132
49133 struct io_req {
49134 struct list_head list;
49135 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49136 index 1f5088b..0e59820 100644
49137 --- a/drivers/staging/sbe-2t3e3/netdev.c
49138 +++ b/drivers/staging/sbe-2t3e3/netdev.c
49139 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49140 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49141
49142 if (rlen)
49143 - if (copy_to_user(data, &resp, rlen))
49144 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49145 return -EFAULT;
49146
49147 return 0;
49148 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49149 index a863a98..d272795 100644
49150 --- a/drivers/staging/usbip/vhci.h
49151 +++ b/drivers/staging/usbip/vhci.h
49152 @@ -83,7 +83,7 @@ struct vhci_hcd {
49153 unsigned resuming:1;
49154 unsigned long re_timeout;
49155
49156 - atomic_t seqnum;
49157 + atomic_unchecked_t seqnum;
49158
49159 /*
49160 * NOTE:
49161 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49162 index e810ad5..931336f 100644
49163 --- a/drivers/staging/usbip/vhci_hcd.c
49164 +++ b/drivers/staging/usbip/vhci_hcd.c
49165 @@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
49166
49167 spin_lock(&vdev->priv_lock);
49168
49169 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49170 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49171 if (priv->seqnum == 0xffff)
49172 dev_info(&urb->dev->dev, "seqnum max\n");
49173
49174 @@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49175 return -ENOMEM;
49176 }
49177
49178 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
49179 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49180 if (unlink->seqnum == 0xffff)
49181 pr_info("seqnum max\n");
49182
49183 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
49184 vdev->rhport = rhport;
49185 }
49186
49187 - atomic_set(&vhci->seqnum, 0);
49188 + atomic_set_unchecked(&vhci->seqnum, 0);
49189 spin_lock_init(&vhci->lock);
49190
49191 hcd->power_budget = 0; /* no limit */
49192 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
49193 index d07fcb5..358e1e1 100644
49194 --- a/drivers/staging/usbip/vhci_rx.c
49195 +++ b/drivers/staging/usbip/vhci_rx.c
49196 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
49197 if (!urb) {
49198 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
49199 pr_info("max seqnum %d\n",
49200 - atomic_read(&the_controller->seqnum));
49201 + atomic_read_unchecked(&the_controller->seqnum));
49202 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
49203 return;
49204 }
49205 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
49206 index ab8b2ba..99184aa 100644
49207 --- a/drivers/staging/vt6655/hostap.c
49208 +++ b/drivers/staging/vt6655/hostap.c
49209 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
49210 *
49211 */
49212
49213 +static net_device_ops_no_const apdev_netdev_ops;
49214 +
49215 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49216 {
49217 PSDevice apdev_priv;
49218 struct net_device *dev = pDevice->dev;
49219 int ret;
49220 - const struct net_device_ops apdev_netdev_ops = {
49221 - .ndo_start_xmit = pDevice->tx_80211,
49222 - };
49223
49224 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49225
49226 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49227 *apdev_priv = *pDevice;
49228 eth_hw_addr_inherit(pDevice->apdev, dev);
49229
49230 + /* only half broken now */
49231 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49232 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49233
49234 pDevice->apdev->type = ARPHRD_IEEE80211;
49235 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
49236 index 67ba48b..24e602f 100644
49237 --- a/drivers/staging/vt6656/hostap.c
49238 +++ b/drivers/staging/vt6656/hostap.c
49239 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
49240 *
49241 */
49242
49243 +static net_device_ops_no_const apdev_netdev_ops;
49244 +
49245 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
49246 {
49247 struct vnt_private *apdev_priv;
49248 struct net_device *dev = pDevice->dev;
49249 int ret;
49250 - const struct net_device_ops apdev_netdev_ops = {
49251 - .ndo_start_xmit = pDevice->tx_80211,
49252 - };
49253
49254 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49255
49256 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
49257 *apdev_priv = *pDevice;
49258 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
49259
49260 + /* only half broken now */
49261 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49262 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49263
49264 pDevice->apdev->type = ARPHRD_IEEE80211;
49265 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
49266 index 24884ca..26c8220 100644
49267 --- a/drivers/target/sbp/sbp_target.c
49268 +++ b/drivers/target/sbp/sbp_target.c
49269 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
49270
49271 #define SESSION_MAINTENANCE_INTERVAL HZ
49272
49273 -static atomic_t login_id = ATOMIC_INIT(0);
49274 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
49275
49276 static void session_maintenance_work(struct work_struct *);
49277 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
49278 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
49279 login->lun = se_lun;
49280 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
49281 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
49282 - login->login_id = atomic_inc_return(&login_id);
49283 + login->login_id = atomic_inc_return_unchecked(&login_id);
49284
49285 login->tgt_agt = sbp_target_agent_register(login);
49286 if (IS_ERR(login->tgt_agt)) {
49287 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
49288 index d06de84..fd38c9b 100644
49289 --- a/drivers/target/target_core_device.c
49290 +++ b/drivers/target/target_core_device.c
49291 @@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
49292 spin_lock_init(&dev->se_tmr_lock);
49293 spin_lock_init(&dev->qf_cmd_lock);
49294 sema_init(&dev->caw_sem, 1);
49295 - atomic_set(&dev->dev_ordered_id, 0);
49296 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
49297 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
49298 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
49299 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
49300 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
49301 index 91953da..a842b90 100644
49302 --- a/drivers/target/target_core_transport.c
49303 +++ b/drivers/target/target_core_transport.c
49304 @@ -1112,7 +1112,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
49305 * Used to determine when ORDERED commands should go from
49306 * Dormant to Active status.
49307 */
49308 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
49309 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
49310 smp_mb__after_atomic_inc();
49311 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
49312 cmd->se_ordered_id, cmd->sam_task_attr,
49313 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
49314 index 33f83fe..d80f8e1 100644
49315 --- a/drivers/tty/cyclades.c
49316 +++ b/drivers/tty/cyclades.c
49317 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
49318 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
49319 info->port.count);
49320 #endif
49321 - info->port.count++;
49322 + atomic_inc(&info->port.count);
49323 #ifdef CY_DEBUG_COUNT
49324 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
49325 - current->pid, info->port.count);
49326 + current->pid, atomic_read(&info->port.count));
49327 #endif
49328
49329 /*
49330 @@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
49331 for (j = 0; j < cy_card[i].nports; j++) {
49332 info = &cy_card[i].ports[j];
49333
49334 - if (info->port.count) {
49335 + if (atomic_read(&info->port.count)) {
49336 /* XXX is the ldisc num worth this? */
49337 struct tty_struct *tty;
49338 struct tty_ldisc *ld;
49339 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
49340 index 9eba119..5070303 100644
49341 --- a/drivers/tty/hvc/hvc_console.c
49342 +++ b/drivers/tty/hvc/hvc_console.c
49343 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
49344
49345 spin_lock_irqsave(&hp->port.lock, flags);
49346 /* Check and then increment for fast path open. */
49347 - if (hp->port.count++ > 0) {
49348 + if (atomic_inc_return(&hp->port.count) > 1) {
49349 spin_unlock_irqrestore(&hp->port.lock, flags);
49350 hvc_kick();
49351 return 0;
49352 @@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49353
49354 spin_lock_irqsave(&hp->port.lock, flags);
49355
49356 - if (--hp->port.count == 0) {
49357 + if (atomic_dec_return(&hp->port.count) == 0) {
49358 spin_unlock_irqrestore(&hp->port.lock, flags);
49359 /* We are done with the tty pointer now. */
49360 tty_port_tty_set(&hp->port, NULL);
49361 @@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49362 */
49363 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
49364 } else {
49365 - if (hp->port.count < 0)
49366 + if (atomic_read(&hp->port.count) < 0)
49367 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
49368 - hp->vtermno, hp->port.count);
49369 + hp->vtermno, atomic_read(&hp->port.count));
49370 spin_unlock_irqrestore(&hp->port.lock, flags);
49371 }
49372 }
49373 @@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
49374 * open->hangup case this can be called after the final close so prevent
49375 * that from happening for now.
49376 */
49377 - if (hp->port.count <= 0) {
49378 + if (atomic_read(&hp->port.count) <= 0) {
49379 spin_unlock_irqrestore(&hp->port.lock, flags);
49380 return;
49381 }
49382
49383 - hp->port.count = 0;
49384 + atomic_set(&hp->port.count, 0);
49385 spin_unlock_irqrestore(&hp->port.lock, flags);
49386 tty_port_tty_set(&hp->port, NULL);
49387
49388 @@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
49389 return -EPIPE;
49390
49391 /* FIXME what's this (unprotected) check for? */
49392 - if (hp->port.count <= 0)
49393 + if (atomic_read(&hp->port.count) <= 0)
49394 return -EIO;
49395
49396 spin_lock_irqsave(&hp->lock, flags);
49397 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
49398 index 81e939e..95ead10 100644
49399 --- a/drivers/tty/hvc/hvcs.c
49400 +++ b/drivers/tty/hvc/hvcs.c
49401 @@ -83,6 +83,7 @@
49402 #include <asm/hvcserver.h>
49403 #include <asm/uaccess.h>
49404 #include <asm/vio.h>
49405 +#include <asm/local.h>
49406
49407 /*
49408 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
49409 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
49410
49411 spin_lock_irqsave(&hvcsd->lock, flags);
49412
49413 - if (hvcsd->port.count > 0) {
49414 + if (atomic_read(&hvcsd->port.count) > 0) {
49415 spin_unlock_irqrestore(&hvcsd->lock, flags);
49416 printk(KERN_INFO "HVCS: vterm state unchanged. "
49417 "The hvcs device node is still in use.\n");
49418 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
49419 }
49420 }
49421
49422 - hvcsd->port.count = 0;
49423 + atomic_set(&hvcsd->port.count, 0);
49424 hvcsd->port.tty = tty;
49425 tty->driver_data = hvcsd;
49426
49427 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
49428 unsigned long flags;
49429
49430 spin_lock_irqsave(&hvcsd->lock, flags);
49431 - hvcsd->port.count++;
49432 + atomic_inc(&hvcsd->port.count);
49433 hvcsd->todo_mask |= HVCS_SCHED_READ;
49434 spin_unlock_irqrestore(&hvcsd->lock, flags);
49435
49436 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49437 hvcsd = tty->driver_data;
49438
49439 spin_lock_irqsave(&hvcsd->lock, flags);
49440 - if (--hvcsd->port.count == 0) {
49441 + if (atomic_dec_and_test(&hvcsd->port.count)) {
49442
49443 vio_disable_interrupts(hvcsd->vdev);
49444
49445 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49446
49447 free_irq(irq, hvcsd);
49448 return;
49449 - } else if (hvcsd->port.count < 0) {
49450 + } else if (atomic_read(&hvcsd->port.count) < 0) {
49451 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
49452 " is missmanaged.\n",
49453 - hvcsd->vdev->unit_address, hvcsd->port.count);
49454 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
49455 }
49456
49457 spin_unlock_irqrestore(&hvcsd->lock, flags);
49458 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49459
49460 spin_lock_irqsave(&hvcsd->lock, flags);
49461 /* Preserve this so that we know how many kref refs to put */
49462 - temp_open_count = hvcsd->port.count;
49463 + temp_open_count = atomic_read(&hvcsd->port.count);
49464
49465 /*
49466 * Don't kref put inside the spinlock because the destruction
49467 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49468 tty->driver_data = NULL;
49469 hvcsd->port.tty = NULL;
49470
49471 - hvcsd->port.count = 0;
49472 + atomic_set(&hvcsd->port.count, 0);
49473
49474 /* This will drop any buffered data on the floor which is OK in a hangup
49475 * scenario. */
49476 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
49477 * the middle of a write operation? This is a crummy place to do this
49478 * but we want to keep it all in the spinlock.
49479 */
49480 - if (hvcsd->port.count <= 0) {
49481 + if (atomic_read(&hvcsd->port.count) <= 0) {
49482 spin_unlock_irqrestore(&hvcsd->lock, flags);
49483 return -ENODEV;
49484 }
49485 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
49486 {
49487 struct hvcs_struct *hvcsd = tty->driver_data;
49488
49489 - if (!hvcsd || hvcsd->port.count <= 0)
49490 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
49491 return 0;
49492
49493 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
49494 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
49495 index 4190199..48f2920 100644
49496 --- a/drivers/tty/hvc/hvsi.c
49497 +++ b/drivers/tty/hvc/hvsi.c
49498 @@ -85,7 +85,7 @@ struct hvsi_struct {
49499 int n_outbuf;
49500 uint32_t vtermno;
49501 uint32_t virq;
49502 - atomic_t seqno; /* HVSI packet sequence number */
49503 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
49504 uint16_t mctrl;
49505 uint8_t state; /* HVSI protocol state */
49506 uint8_t flags;
49507 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
49508
49509 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
49510 packet.hdr.len = sizeof(struct hvsi_query_response);
49511 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49512 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49513 packet.verb = VSV_SEND_VERSION_NUMBER;
49514 packet.u.version = HVSI_VERSION;
49515 packet.query_seqno = query_seqno+1;
49516 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
49517
49518 packet.hdr.type = VS_QUERY_PACKET_HEADER;
49519 packet.hdr.len = sizeof(struct hvsi_query);
49520 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49521 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49522 packet.verb = verb;
49523
49524 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
49525 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
49526 int wrote;
49527
49528 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
49529 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49530 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49531 packet.hdr.len = sizeof(struct hvsi_control);
49532 packet.verb = VSV_SET_MODEM_CTL;
49533 packet.mask = HVSI_TSDTR;
49534 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
49535 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
49536
49537 packet.hdr.type = VS_DATA_PACKET_HEADER;
49538 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49539 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49540 packet.hdr.len = count + sizeof(struct hvsi_header);
49541 memcpy(&packet.data, buf, count);
49542
49543 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
49544 struct hvsi_control packet __ALIGNED__;
49545
49546 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
49547 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49548 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49549 packet.hdr.len = 6;
49550 packet.verb = VSV_CLOSE_PROTOCOL;
49551
49552 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
49553 index 347050e..14f8fbf 100644
49554 --- a/drivers/tty/hvc/hvsi_lib.c
49555 +++ b/drivers/tty/hvc/hvsi_lib.c
49556 @@ -9,7 +9,7 @@
49557
49558 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
49559 {
49560 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
49561 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
49562
49563 /* Assumes that always succeeds, works in practice */
49564 return pv->put_chars(pv->termno, (char *)packet, packet->len);
49565 @@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
49566
49567 /* Reset state */
49568 pv->established = 0;
49569 - atomic_set(&pv->seqno, 0);
49570 + atomic_set_unchecked(&pv->seqno, 0);
49571
49572 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
49573
49574 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
49575 index 8fd72ff..34a0bed 100644
49576 --- a/drivers/tty/ipwireless/tty.c
49577 +++ b/drivers/tty/ipwireless/tty.c
49578 @@ -29,6 +29,7 @@
49579 #include <linux/tty_driver.h>
49580 #include <linux/tty_flip.h>
49581 #include <linux/uaccess.h>
49582 +#include <asm/local.h>
49583
49584 #include "tty.h"
49585 #include "network.h"
49586 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49587 mutex_unlock(&tty->ipw_tty_mutex);
49588 return -ENODEV;
49589 }
49590 - if (tty->port.count == 0)
49591 + if (atomic_read(&tty->port.count) == 0)
49592 tty->tx_bytes_queued = 0;
49593
49594 - tty->port.count++;
49595 + atomic_inc(&tty->port.count);
49596
49597 tty->port.tty = linux_tty;
49598 linux_tty->driver_data = tty;
49599 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49600
49601 static void do_ipw_close(struct ipw_tty *tty)
49602 {
49603 - tty->port.count--;
49604 -
49605 - if (tty->port.count == 0) {
49606 + if (atomic_dec_return(&tty->port.count) == 0) {
49607 struct tty_struct *linux_tty = tty->port.tty;
49608
49609 if (linux_tty != NULL) {
49610 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
49611 return;
49612
49613 mutex_lock(&tty->ipw_tty_mutex);
49614 - if (tty->port.count == 0) {
49615 + if (atomic_read(&tty->port.count) == 0) {
49616 mutex_unlock(&tty->ipw_tty_mutex);
49617 return;
49618 }
49619 @@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
49620
49621 mutex_lock(&tty->ipw_tty_mutex);
49622
49623 - if (!tty->port.count) {
49624 + if (!atomic_read(&tty->port.count)) {
49625 mutex_unlock(&tty->ipw_tty_mutex);
49626 return;
49627 }
49628 @@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
49629 return -ENODEV;
49630
49631 mutex_lock(&tty->ipw_tty_mutex);
49632 - if (!tty->port.count) {
49633 + if (!atomic_read(&tty->port.count)) {
49634 mutex_unlock(&tty->ipw_tty_mutex);
49635 return -EINVAL;
49636 }
49637 @@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
49638 if (!tty)
49639 return -ENODEV;
49640
49641 - if (!tty->port.count)
49642 + if (!atomic_read(&tty->port.count))
49643 return -EINVAL;
49644
49645 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
49646 @@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
49647 if (!tty)
49648 return 0;
49649
49650 - if (!tty->port.count)
49651 + if (!atomic_read(&tty->port.count))
49652 return 0;
49653
49654 return tty->tx_bytes_queued;
49655 @@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
49656 if (!tty)
49657 return -ENODEV;
49658
49659 - if (!tty->port.count)
49660 + if (!atomic_read(&tty->port.count))
49661 return -EINVAL;
49662
49663 return get_control_lines(tty);
49664 @@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
49665 if (!tty)
49666 return -ENODEV;
49667
49668 - if (!tty->port.count)
49669 + if (!atomic_read(&tty->port.count))
49670 return -EINVAL;
49671
49672 return set_control_lines(tty, set, clear);
49673 @@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
49674 if (!tty)
49675 return -ENODEV;
49676
49677 - if (!tty->port.count)
49678 + if (!atomic_read(&tty->port.count))
49679 return -EINVAL;
49680
49681 /* FIXME: Exactly how is the tty object locked here .. */
49682 @@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
49683 * are gone */
49684 mutex_lock(&ttyj->ipw_tty_mutex);
49685 }
49686 - while (ttyj->port.count)
49687 + while (atomic_read(&ttyj->port.count))
49688 do_ipw_close(ttyj);
49689 ipwireless_disassociate_network_ttys(network,
49690 ttyj->channel_idx);
49691 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
49692 index 1deaca4..c8582d4 100644
49693 --- a/drivers/tty/moxa.c
49694 +++ b/drivers/tty/moxa.c
49695 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
49696 }
49697
49698 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
49699 - ch->port.count++;
49700 + atomic_inc(&ch->port.count);
49701 tty->driver_data = ch;
49702 tty_port_tty_set(&ch->port, tty);
49703 mutex_lock(&ch->port.mutex);
49704 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
49705 index c0f76da..d974c32 100644
49706 --- a/drivers/tty/n_gsm.c
49707 +++ b/drivers/tty/n_gsm.c
49708 @@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
49709 spin_lock_init(&dlci->lock);
49710 mutex_init(&dlci->mutex);
49711 dlci->fifo = &dlci->_fifo;
49712 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
49713 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
49714 kfree(dlci);
49715 return NULL;
49716 }
49717 @@ -2935,7 +2935,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
49718 struct gsm_dlci *dlci = tty->driver_data;
49719 struct tty_port *port = &dlci->port;
49720
49721 - port->count++;
49722 + atomic_inc(&port->count);
49723 dlci_get(dlci);
49724 dlci_get(dlci->gsm->dlci[0]);
49725 mux_get(dlci->gsm);
49726 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
49727 index 34aacaa..dad073b 100644
49728 --- a/drivers/tty/n_tty.c
49729 +++ b/drivers/tty/n_tty.c
49730 @@ -114,7 +114,7 @@ struct n_tty_data {
49731 int minimum_to_wake;
49732
49733 /* consumer-published */
49734 - size_t read_tail;
49735 + size_t read_tail __intentional_overflow(-1);
49736 size_t line_start;
49737
49738 /* protected by output lock */
49739 @@ -2502,6 +2502,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
49740 {
49741 *ops = tty_ldisc_N_TTY;
49742 ops->owner = NULL;
49743 - ops->refcount = ops->flags = 0;
49744 + atomic_set(&ops->refcount, 0);
49745 + ops->flags = 0;
49746 }
49747 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
49748 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
49749 index 25c9bc7..24077b7 100644
49750 --- a/drivers/tty/pty.c
49751 +++ b/drivers/tty/pty.c
49752 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
49753 panic("Couldn't register Unix98 pts driver");
49754
49755 /* Now create the /dev/ptmx special device */
49756 + pax_open_kernel();
49757 tty_default_fops(&ptmx_fops);
49758 - ptmx_fops.open = ptmx_open;
49759 + *(void **)&ptmx_fops.open = ptmx_open;
49760 + pax_close_kernel();
49761
49762 cdev_init(&ptmx_cdev, &ptmx_fops);
49763 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
49764 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
49765 index 354564e..fe50d9a 100644
49766 --- a/drivers/tty/rocket.c
49767 +++ b/drivers/tty/rocket.c
49768 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49769 tty->driver_data = info;
49770 tty_port_tty_set(port, tty);
49771
49772 - if (port->count++ == 0) {
49773 + if (atomic_inc_return(&port->count) == 1) {
49774 atomic_inc(&rp_num_ports_open);
49775
49776 #ifdef ROCKET_DEBUG_OPEN
49777 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49778 #endif
49779 }
49780 #ifdef ROCKET_DEBUG_OPEN
49781 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
49782 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
49783 #endif
49784
49785 /*
49786 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
49787 spin_unlock_irqrestore(&info->port.lock, flags);
49788 return;
49789 }
49790 - if (info->port.count)
49791 + if (atomic_read(&info->port.count))
49792 atomic_dec(&rp_num_ports_open);
49793 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
49794 spin_unlock_irqrestore(&info->port.lock, flags);
49795 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
49796 index 1274499..f541382 100644
49797 --- a/drivers/tty/serial/ioc4_serial.c
49798 +++ b/drivers/tty/serial/ioc4_serial.c
49799 @@ -437,7 +437,7 @@ struct ioc4_soft {
49800 } is_intr_info[MAX_IOC4_INTR_ENTS];
49801
49802 /* Number of entries active in the above array */
49803 - atomic_t is_num_intrs;
49804 + atomic_unchecked_t is_num_intrs;
49805 } is_intr_type[IOC4_NUM_INTR_TYPES];
49806
49807 /* is_ir_lock must be held while
49808 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
49809 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
49810 || (type == IOC4_OTHER_INTR_TYPE)));
49811
49812 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
49813 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
49814 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
49815
49816 /* Save off the lower level interrupt handler */
49817 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
49818
49819 soft = arg;
49820 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
49821 - num_intrs = (int)atomic_read(
49822 + num_intrs = (int)atomic_read_unchecked(
49823 &soft->is_intr_type[intr_type].is_num_intrs);
49824
49825 this_mir = this_ir = pending_intrs(soft, intr_type);
49826 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
49827 index a260cde..6b2b5ce 100644
49828 --- a/drivers/tty/serial/kgdboc.c
49829 +++ b/drivers/tty/serial/kgdboc.c
49830 @@ -24,8 +24,9 @@
49831 #define MAX_CONFIG_LEN 40
49832
49833 static struct kgdb_io kgdboc_io_ops;
49834 +static struct kgdb_io kgdboc_io_ops_console;
49835
49836 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
49837 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
49838 static int configured = -1;
49839
49840 static char config[MAX_CONFIG_LEN];
49841 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
49842 kgdboc_unregister_kbd();
49843 if (configured == 1)
49844 kgdb_unregister_io_module(&kgdboc_io_ops);
49845 + else if (configured == 2)
49846 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
49847 }
49848
49849 static int configure_kgdboc(void)
49850 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
49851 int err;
49852 char *cptr = config;
49853 struct console *cons;
49854 + int is_console = 0;
49855
49856 err = kgdboc_option_setup(config);
49857 if (err || !strlen(config) || isspace(config[0]))
49858 goto noconfig;
49859
49860 err = -ENODEV;
49861 - kgdboc_io_ops.is_console = 0;
49862 kgdb_tty_driver = NULL;
49863
49864 kgdboc_use_kms = 0;
49865 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
49866 int idx;
49867 if (cons->device && cons->device(cons, &idx) == p &&
49868 idx == tty_line) {
49869 - kgdboc_io_ops.is_console = 1;
49870 + is_console = 1;
49871 break;
49872 }
49873 cons = cons->next;
49874 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
49875 kgdb_tty_line = tty_line;
49876
49877 do_register:
49878 - err = kgdb_register_io_module(&kgdboc_io_ops);
49879 + if (is_console) {
49880 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
49881 + configured = 2;
49882 + } else {
49883 + err = kgdb_register_io_module(&kgdboc_io_ops);
49884 + configured = 1;
49885 + }
49886 if (err)
49887 goto noconfig;
49888
49889 @@ -205,8 +214,6 @@ do_register:
49890 if (err)
49891 goto nmi_con_failed;
49892
49893 - configured = 1;
49894 -
49895 return 0;
49896
49897 nmi_con_failed:
49898 @@ -223,7 +230,7 @@ noconfig:
49899 static int __init init_kgdboc(void)
49900 {
49901 /* Already configured? */
49902 - if (configured == 1)
49903 + if (configured >= 1)
49904 return 0;
49905
49906 return configure_kgdboc();
49907 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
49908 if (config[len - 1] == '\n')
49909 config[len - 1] = '\0';
49910
49911 - if (configured == 1)
49912 + if (configured >= 1)
49913 cleanup_kgdboc();
49914
49915 /* Go and configure with the new params. */
49916 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
49917 .post_exception = kgdboc_post_exp_handler,
49918 };
49919
49920 +static struct kgdb_io kgdboc_io_ops_console = {
49921 + .name = "kgdboc",
49922 + .read_char = kgdboc_get_char,
49923 + .write_char = kgdboc_put_char,
49924 + .pre_exception = kgdboc_pre_exp_handler,
49925 + .post_exception = kgdboc_post_exp_handler,
49926 + .is_console = 1
49927 +};
49928 +
49929 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
49930 /* This is only available if kgdboc is a built in for early debugging */
49931 static int __init kgdboc_early_init(char *opt)
49932 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
49933 index b5d779c..3622cfe 100644
49934 --- a/drivers/tty/serial/msm_serial.c
49935 +++ b/drivers/tty/serial/msm_serial.c
49936 @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
49937 .cons = MSM_CONSOLE,
49938 };
49939
49940 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
49941 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
49942
49943 static const struct of_device_id msm_uartdm_table[] = {
49944 { .compatible = "qcom,msm-uartdm" },
49945 @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
49946 int irq;
49947
49948 if (pdev->id == -1)
49949 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
49950 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
49951
49952 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
49953 return -ENXIO;
49954 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
49955 index c1af04d..0815c8a 100644
49956 --- a/drivers/tty/serial/samsung.c
49957 +++ b/drivers/tty/serial/samsung.c
49958 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
49959 }
49960 }
49961
49962 +static int s3c64xx_serial_startup(struct uart_port *port);
49963 static int s3c24xx_serial_startup(struct uart_port *port)
49964 {
49965 struct s3c24xx_uart_port *ourport = to_ourport(port);
49966 int ret;
49967
49968 + /* Startup sequence is different for s3c64xx and higher SoC's */
49969 + if (s3c24xx_serial_has_interrupt_mask(port))
49970 + return s3c64xx_serial_startup(port);
49971 +
49972 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
49973 port->mapbase, port->membase);
49974
49975 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
49976 /* setup info for port */
49977 port->dev = &platdev->dev;
49978
49979 - /* Startup sequence is different for s3c64xx and higher SoC's */
49980 - if (s3c24xx_serial_has_interrupt_mask(port))
49981 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
49982 -
49983 port->uartclk = 1;
49984
49985 if (cfg->uart_flags & UPF_CONS_FLOW) {
49986 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
49987 index 0f02351..07c59c5 100644
49988 --- a/drivers/tty/serial/serial_core.c
49989 +++ b/drivers/tty/serial/serial_core.c
49990 @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
49991 uart_flush_buffer(tty);
49992 uart_shutdown(tty, state);
49993 spin_lock_irqsave(&port->lock, flags);
49994 - port->count = 0;
49995 + atomic_set(&port->count, 0);
49996 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
49997 spin_unlock_irqrestore(&port->lock, flags);
49998 tty_port_tty_set(port, NULL);
49999 @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50000 goto end;
50001 }
50002
50003 - port->count++;
50004 + atomic_inc(&port->count);
50005 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50006 retval = -ENXIO;
50007 goto err_dec_count;
50008 @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50009 /*
50010 * Make sure the device is in D0 state.
50011 */
50012 - if (port->count == 1)
50013 + if (atomic_read(&port->count) == 1)
50014 uart_change_pm(state, UART_PM_STATE_ON);
50015
50016 /*
50017 @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50018 end:
50019 return retval;
50020 err_dec_count:
50021 - port->count--;
50022 + atomic_inc(&port->count);
50023 mutex_unlock(&port->mutex);
50024 goto end;
50025 }
50026 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50027 index e1ce141..6d4ed80 100644
50028 --- a/drivers/tty/synclink.c
50029 +++ b/drivers/tty/synclink.c
50030 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50031
50032 if (debug_level >= DEBUG_LEVEL_INFO)
50033 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50034 - __FILE__,__LINE__, info->device_name, info->port.count);
50035 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50036
50037 if (tty_port_close_start(&info->port, tty, filp) == 0)
50038 goto cleanup;
50039 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50040 cleanup:
50041 if (debug_level >= DEBUG_LEVEL_INFO)
50042 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50043 - tty->driver->name, info->port.count);
50044 + tty->driver->name, atomic_read(&info->port.count));
50045
50046 } /* end of mgsl_close() */
50047
50048 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50049
50050 mgsl_flush_buffer(tty);
50051 shutdown(info);
50052 -
50053 - info->port.count = 0;
50054 +
50055 + atomic_set(&info->port.count, 0);
50056 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50057 info->port.tty = NULL;
50058
50059 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50060
50061 if (debug_level >= DEBUG_LEVEL_INFO)
50062 printk("%s(%d):block_til_ready before block on %s count=%d\n",
50063 - __FILE__,__LINE__, tty->driver->name, port->count );
50064 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50065
50066 spin_lock_irqsave(&info->irq_spinlock, flags);
50067 if (!tty_hung_up_p(filp)) {
50068 extra_count = true;
50069 - port->count--;
50070 + atomic_dec(&port->count);
50071 }
50072 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50073 port->blocked_open++;
50074 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50075
50076 if (debug_level >= DEBUG_LEVEL_INFO)
50077 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
50078 - __FILE__,__LINE__, tty->driver->name, port->count );
50079 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50080
50081 tty_unlock(tty);
50082 schedule();
50083 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50084
50085 /* FIXME: Racy on hangup during close wait */
50086 if (extra_count)
50087 - port->count++;
50088 + atomic_inc(&port->count);
50089 port->blocked_open--;
50090
50091 if (debug_level >= DEBUG_LEVEL_INFO)
50092 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50093 - __FILE__,__LINE__, tty->driver->name, port->count );
50094 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50095
50096 if (!retval)
50097 port->flags |= ASYNC_NORMAL_ACTIVE;
50098 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50099
50100 if (debug_level >= DEBUG_LEVEL_INFO)
50101 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50102 - __FILE__,__LINE__,tty->driver->name, info->port.count);
50103 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50104
50105 /* If port is closing, signal caller to try again */
50106 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50107 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50108 spin_unlock_irqrestore(&info->netlock, flags);
50109 goto cleanup;
50110 }
50111 - info->port.count++;
50112 + atomic_inc(&info->port.count);
50113 spin_unlock_irqrestore(&info->netlock, flags);
50114
50115 - if (info->port.count == 1) {
50116 + if (atomic_read(&info->port.count) == 1) {
50117 /* 1st open on this device, init hardware */
50118 retval = startup(info);
50119 if (retval < 0)
50120 @@ -3446,8 +3446,8 @@ cleanup:
50121 if (retval) {
50122 if (tty->count == 1)
50123 info->port.tty = NULL; /* tty layer will release tty struct */
50124 - if(info->port.count)
50125 - info->port.count--;
50126 + if (atomic_read(&info->port.count))
50127 + atomic_dec(&info->port.count);
50128 }
50129
50130 return retval;
50131 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50132 unsigned short new_crctype;
50133
50134 /* return error if TTY interface open */
50135 - if (info->port.count)
50136 + if (atomic_read(&info->port.count))
50137 return -EBUSY;
50138
50139 switch (encoding)
50140 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
50141
50142 /* arbitrate between network and tty opens */
50143 spin_lock_irqsave(&info->netlock, flags);
50144 - if (info->port.count != 0 || info->netcount != 0) {
50145 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50146 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50147 spin_unlock_irqrestore(&info->netlock, flags);
50148 return -EBUSY;
50149 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50150 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50151
50152 /* return error if TTY interface open */
50153 - if (info->port.count)
50154 + if (atomic_read(&info->port.count))
50155 return -EBUSY;
50156
50157 if (cmd != SIOCWANDEV)
50158 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
50159 index 1abf946..1ee34fc 100644
50160 --- a/drivers/tty/synclink_gt.c
50161 +++ b/drivers/tty/synclink_gt.c
50162 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50163 tty->driver_data = info;
50164 info->port.tty = tty;
50165
50166 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
50167 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
50168
50169 /* If port is closing, signal caller to try again */
50170 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50171 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50172 mutex_unlock(&info->port.mutex);
50173 goto cleanup;
50174 }
50175 - info->port.count++;
50176 + atomic_inc(&info->port.count);
50177 spin_unlock_irqrestore(&info->netlock, flags);
50178
50179 - if (info->port.count == 1) {
50180 + if (atomic_read(&info->port.count) == 1) {
50181 /* 1st open on this device, init hardware */
50182 retval = startup(info);
50183 if (retval < 0) {
50184 @@ -715,8 +715,8 @@ cleanup:
50185 if (retval) {
50186 if (tty->count == 1)
50187 info->port.tty = NULL; /* tty layer will release tty struct */
50188 - if(info->port.count)
50189 - info->port.count--;
50190 + if(atomic_read(&info->port.count))
50191 + atomic_dec(&info->port.count);
50192 }
50193
50194 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
50195 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50196
50197 if (sanity_check(info, tty->name, "close"))
50198 return;
50199 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
50200 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
50201
50202 if (tty_port_close_start(&info->port, tty, filp) == 0)
50203 goto cleanup;
50204 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50205 tty_port_close_end(&info->port, tty);
50206 info->port.tty = NULL;
50207 cleanup:
50208 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
50209 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
50210 }
50211
50212 static void hangup(struct tty_struct *tty)
50213 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
50214 shutdown(info);
50215
50216 spin_lock_irqsave(&info->port.lock, flags);
50217 - info->port.count = 0;
50218 + atomic_set(&info->port.count, 0);
50219 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50220 info->port.tty = NULL;
50221 spin_unlock_irqrestore(&info->port.lock, flags);
50222 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50223 unsigned short new_crctype;
50224
50225 /* return error if TTY interface open */
50226 - if (info->port.count)
50227 + if (atomic_read(&info->port.count))
50228 return -EBUSY;
50229
50230 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
50231 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
50232
50233 /* arbitrate between network and tty opens */
50234 spin_lock_irqsave(&info->netlock, flags);
50235 - if (info->port.count != 0 || info->netcount != 0) {
50236 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50237 DBGINFO(("%s hdlc_open busy\n", dev->name));
50238 spin_unlock_irqrestore(&info->netlock, flags);
50239 return -EBUSY;
50240 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50241 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
50242
50243 /* return error if TTY interface open */
50244 - if (info->port.count)
50245 + if (atomic_read(&info->port.count))
50246 return -EBUSY;
50247
50248 if (cmd != SIOCWANDEV)
50249 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
50250 if (port == NULL)
50251 continue;
50252 spin_lock(&port->lock);
50253 - if ((port->port.count || port->netcount) &&
50254 + if ((atomic_read(&port->port.count) || port->netcount) &&
50255 port->pending_bh && !port->bh_running &&
50256 !port->bh_requested) {
50257 DBGISR(("%s bh queued\n", port->device_name));
50258 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50259 spin_lock_irqsave(&info->lock, flags);
50260 if (!tty_hung_up_p(filp)) {
50261 extra_count = true;
50262 - port->count--;
50263 + atomic_dec(&port->count);
50264 }
50265 spin_unlock_irqrestore(&info->lock, flags);
50266 port->blocked_open++;
50267 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50268 remove_wait_queue(&port->open_wait, &wait);
50269
50270 if (extra_count)
50271 - port->count++;
50272 + atomic_inc(&port->count);
50273 port->blocked_open--;
50274
50275 if (!retval)
50276 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
50277 index dc6e969..5dc8786 100644
50278 --- a/drivers/tty/synclinkmp.c
50279 +++ b/drivers/tty/synclinkmp.c
50280 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50281
50282 if (debug_level >= DEBUG_LEVEL_INFO)
50283 printk("%s(%d):%s open(), old ref count = %d\n",
50284 - __FILE__,__LINE__,tty->driver->name, info->port.count);
50285 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50286
50287 /* If port is closing, signal caller to try again */
50288 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50289 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50290 spin_unlock_irqrestore(&info->netlock, flags);
50291 goto cleanup;
50292 }
50293 - info->port.count++;
50294 + atomic_inc(&info->port.count);
50295 spin_unlock_irqrestore(&info->netlock, flags);
50296
50297 - if (info->port.count == 1) {
50298 + if (atomic_read(&info->port.count) == 1) {
50299 /* 1st open on this device, init hardware */
50300 retval = startup(info);
50301 if (retval < 0)
50302 @@ -796,8 +796,8 @@ cleanup:
50303 if (retval) {
50304 if (tty->count == 1)
50305 info->port.tty = NULL; /* tty layer will release tty struct */
50306 - if(info->port.count)
50307 - info->port.count--;
50308 + if(atomic_read(&info->port.count))
50309 + atomic_dec(&info->port.count);
50310 }
50311
50312 return retval;
50313 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50314
50315 if (debug_level >= DEBUG_LEVEL_INFO)
50316 printk("%s(%d):%s close() entry, count=%d\n",
50317 - __FILE__,__LINE__, info->device_name, info->port.count);
50318 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50319
50320 if (tty_port_close_start(&info->port, tty, filp) == 0)
50321 goto cleanup;
50322 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50323 cleanup:
50324 if (debug_level >= DEBUG_LEVEL_INFO)
50325 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
50326 - tty->driver->name, info->port.count);
50327 + tty->driver->name, atomic_read(&info->port.count));
50328 }
50329
50330 /* Called by tty_hangup() when a hangup is signaled.
50331 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
50332 shutdown(info);
50333
50334 spin_lock_irqsave(&info->port.lock, flags);
50335 - info->port.count = 0;
50336 + atomic_set(&info->port.count, 0);
50337 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50338 info->port.tty = NULL;
50339 spin_unlock_irqrestore(&info->port.lock, flags);
50340 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50341 unsigned short new_crctype;
50342
50343 /* return error if TTY interface open */
50344 - if (info->port.count)
50345 + if (atomic_read(&info->port.count))
50346 return -EBUSY;
50347
50348 switch (encoding)
50349 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
50350
50351 /* arbitrate between network and tty opens */
50352 spin_lock_irqsave(&info->netlock, flags);
50353 - if (info->port.count != 0 || info->netcount != 0) {
50354 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50355 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50356 spin_unlock_irqrestore(&info->netlock, flags);
50357 return -EBUSY;
50358 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50359 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50360
50361 /* return error if TTY interface open */
50362 - if (info->port.count)
50363 + if (atomic_read(&info->port.count))
50364 return -EBUSY;
50365
50366 if (cmd != SIOCWANDEV)
50367 @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
50368 * do not request bottom half processing if the
50369 * device is not open in a normal mode.
50370 */
50371 - if ( port && (port->port.count || port->netcount) &&
50372 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
50373 port->pending_bh && !port->bh_running &&
50374 !port->bh_requested ) {
50375 if ( debug_level >= DEBUG_LEVEL_ISR )
50376 @@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50377
50378 if (debug_level >= DEBUG_LEVEL_INFO)
50379 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
50380 - __FILE__,__LINE__, tty->driver->name, port->count );
50381 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50382
50383 spin_lock_irqsave(&info->lock, flags);
50384 if (!tty_hung_up_p(filp)) {
50385 extra_count = true;
50386 - port->count--;
50387 + atomic_dec(&port->count);
50388 }
50389 spin_unlock_irqrestore(&info->lock, flags);
50390 port->blocked_open++;
50391 @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50392
50393 if (debug_level >= DEBUG_LEVEL_INFO)
50394 printk("%s(%d):%s block_til_ready() count=%d\n",
50395 - __FILE__,__LINE__, tty->driver->name, port->count );
50396 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50397
50398 tty_unlock(tty);
50399 schedule();
50400 @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50401 remove_wait_queue(&port->open_wait, &wait);
50402
50403 if (extra_count)
50404 - port->count++;
50405 + atomic_inc(&port->count);
50406 port->blocked_open--;
50407
50408 if (debug_level >= DEBUG_LEVEL_INFO)
50409 printk("%s(%d):%s block_til_ready() after, count=%d\n",
50410 - __FILE__,__LINE__, tty->driver->name, port->count );
50411 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50412
50413 if (!retval)
50414 port->flags |= ASYNC_NORMAL_ACTIVE;
50415 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
50416 index ce396ec..04a37be 100644
50417 --- a/drivers/tty/sysrq.c
50418 +++ b/drivers/tty/sysrq.c
50419 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
50420 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
50421 size_t count, loff_t *ppos)
50422 {
50423 - if (count) {
50424 + if (count && capable(CAP_SYS_ADMIN)) {
50425 char c;
50426
50427 if (get_user(c, buf))
50428 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
50429 index c74a00a..02cf211a 100644
50430 --- a/drivers/tty/tty_io.c
50431 +++ b/drivers/tty/tty_io.c
50432 @@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
50433
50434 void tty_default_fops(struct file_operations *fops)
50435 {
50436 - *fops = tty_fops;
50437 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
50438 }
50439
50440 /*
50441 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
50442 index 6458e11..6cfc218 100644
50443 --- a/drivers/tty/tty_ldisc.c
50444 +++ b/drivers/tty/tty_ldisc.c
50445 @@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
50446 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50447 tty_ldiscs[disc] = new_ldisc;
50448 new_ldisc->num = disc;
50449 - new_ldisc->refcount = 0;
50450 + atomic_set(&new_ldisc->refcount, 0);
50451 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50452
50453 return ret;
50454 @@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
50455 return -EINVAL;
50456
50457 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50458 - if (tty_ldiscs[disc]->refcount)
50459 + if (atomic_read(&tty_ldiscs[disc]->refcount))
50460 ret = -EBUSY;
50461 else
50462 tty_ldiscs[disc] = NULL;
50463 @@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
50464 if (ldops) {
50465 ret = ERR_PTR(-EAGAIN);
50466 if (try_module_get(ldops->owner)) {
50467 - ldops->refcount++;
50468 + atomic_inc(&ldops->refcount);
50469 ret = ldops;
50470 }
50471 }
50472 @@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
50473 unsigned long flags;
50474
50475 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50476 - ldops->refcount--;
50477 + atomic_dec(&ldops->refcount);
50478 module_put(ldops->owner);
50479 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50480 }
50481 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
50482 index c94d234..8210f2d 100644
50483 --- a/drivers/tty/tty_port.c
50484 +++ b/drivers/tty/tty_port.c
50485 @@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
50486 unsigned long flags;
50487
50488 spin_lock_irqsave(&port->lock, flags);
50489 - port->count = 0;
50490 + atomic_set(&port->count, 0);
50491 port->flags &= ~ASYNC_NORMAL_ACTIVE;
50492 tty = port->tty;
50493 if (tty)
50494 @@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50495 /* The port lock protects the port counts */
50496 spin_lock_irqsave(&port->lock, flags);
50497 if (!tty_hung_up_p(filp))
50498 - port->count--;
50499 + atomic_dec(&port->count);
50500 port->blocked_open++;
50501 spin_unlock_irqrestore(&port->lock, flags);
50502
50503 @@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50504 we must not mess that up further */
50505 spin_lock_irqsave(&port->lock, flags);
50506 if (!tty_hung_up_p(filp))
50507 - port->count++;
50508 + atomic_inc(&port->count);
50509 port->blocked_open--;
50510 if (retval == 0)
50511 port->flags |= ASYNC_NORMAL_ACTIVE;
50512 @@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
50513 return 0;
50514 }
50515
50516 - if (tty->count == 1 && port->count != 1) {
50517 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
50518 printk(KERN_WARNING
50519 "tty_port_close_start: tty->count = 1 port count = %d.\n",
50520 - port->count);
50521 - port->count = 1;
50522 + atomic_read(&port->count));
50523 + atomic_set(&port->count, 1);
50524 }
50525 - if (--port->count < 0) {
50526 + if (atomic_dec_return(&port->count) < 0) {
50527 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
50528 - port->count);
50529 - port->count = 0;
50530 + atomic_read(&port->count));
50531 + atomic_set(&port->count, 0);
50532 }
50533
50534 - if (port->count) {
50535 + if (atomic_read(&port->count)) {
50536 spin_unlock_irqrestore(&port->lock, flags);
50537 return 0;
50538 }
50539 @@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
50540 {
50541 spin_lock_irq(&port->lock);
50542 if (!tty_hung_up_p(filp))
50543 - ++port->count;
50544 + atomic_inc(&port->count);
50545 spin_unlock_irq(&port->lock);
50546 tty_port_tty_set(port, tty);
50547
50548 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
50549 index d0e3a44..5f8b754 100644
50550 --- a/drivers/tty/vt/keyboard.c
50551 +++ b/drivers/tty/vt/keyboard.c
50552 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
50553 kbd->kbdmode == VC_OFF) &&
50554 value != KVAL(K_SAK))
50555 return; /* SAK is allowed even in raw mode */
50556 +
50557 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50558 + {
50559 + void *func = fn_handler[value];
50560 + if (func == fn_show_state || func == fn_show_ptregs ||
50561 + func == fn_show_mem)
50562 + return;
50563 + }
50564 +#endif
50565 +
50566 fn_handler[value](vc);
50567 }
50568
50569 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50570 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
50571 return -EFAULT;
50572
50573 - if (!capable(CAP_SYS_TTY_CONFIG))
50574 - perm = 0;
50575 -
50576 switch (cmd) {
50577 case KDGKBENT:
50578 /* Ensure another thread doesn't free it under us */
50579 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50580 spin_unlock_irqrestore(&kbd_event_lock, flags);
50581 return put_user(val, &user_kbe->kb_value);
50582 case KDSKBENT:
50583 + if (!capable(CAP_SYS_TTY_CONFIG))
50584 + perm = 0;
50585 +
50586 if (!perm)
50587 return -EPERM;
50588 if (!i && v == K_NOSUCHMAP) {
50589 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50590 int i, j, k;
50591 int ret;
50592
50593 - if (!capable(CAP_SYS_TTY_CONFIG))
50594 - perm = 0;
50595 -
50596 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
50597 if (!kbs) {
50598 ret = -ENOMEM;
50599 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50600 kfree(kbs);
50601 return ((p && *p) ? -EOVERFLOW : 0);
50602 case KDSKBSENT:
50603 + if (!capable(CAP_SYS_TTY_CONFIG))
50604 + perm = 0;
50605 +
50606 if (!perm) {
50607 ret = -EPERM;
50608 goto reterr;
50609 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
50610 index f7beb6e..8c0bbd0 100644
50611 --- a/drivers/uio/uio.c
50612 +++ b/drivers/uio/uio.c
50613 @@ -25,6 +25,7 @@
50614 #include <linux/kobject.h>
50615 #include <linux/cdev.h>
50616 #include <linux/uio_driver.h>
50617 +#include <asm/local.h>
50618
50619 #define UIO_MAX_DEVICES (1U << MINORBITS)
50620
50621 @@ -32,7 +33,7 @@ struct uio_device {
50622 struct module *owner;
50623 struct device *dev;
50624 int minor;
50625 - atomic_t event;
50626 + atomic_unchecked_t event;
50627 struct fasync_struct *async_queue;
50628 wait_queue_head_t wait;
50629 struct uio_info *info;
50630 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
50631 struct device_attribute *attr, char *buf)
50632 {
50633 struct uio_device *idev = dev_get_drvdata(dev);
50634 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
50635 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
50636 }
50637 static DEVICE_ATTR_RO(event);
50638
50639 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
50640 {
50641 struct uio_device *idev = info->uio_dev;
50642
50643 - atomic_inc(&idev->event);
50644 + atomic_inc_unchecked(&idev->event);
50645 wake_up_interruptible(&idev->wait);
50646 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
50647 }
50648 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
50649 }
50650
50651 listener->dev = idev;
50652 - listener->event_count = atomic_read(&idev->event);
50653 + listener->event_count = atomic_read_unchecked(&idev->event);
50654 filep->private_data = listener;
50655
50656 if (idev->info->open) {
50657 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
50658 return -EIO;
50659
50660 poll_wait(filep, &idev->wait, wait);
50661 - if (listener->event_count != atomic_read(&idev->event))
50662 + if (listener->event_count != atomic_read_unchecked(&idev->event))
50663 return POLLIN | POLLRDNORM;
50664 return 0;
50665 }
50666 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
50667 do {
50668 set_current_state(TASK_INTERRUPTIBLE);
50669
50670 - event_count = atomic_read(&idev->event);
50671 + event_count = atomic_read_unchecked(&idev->event);
50672 if (event_count != listener->event_count) {
50673 if (copy_to_user(buf, &event_count, count))
50674 retval = -EFAULT;
50675 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
50676 static int uio_find_mem_index(struct vm_area_struct *vma)
50677 {
50678 struct uio_device *idev = vma->vm_private_data;
50679 + unsigned long size;
50680
50681 if (vma->vm_pgoff < MAX_UIO_MAPS) {
50682 - if (idev->info->mem[vma->vm_pgoff].size == 0)
50683 + size = idev->info->mem[vma->vm_pgoff].size;
50684 + if (size == 0)
50685 + return -1;
50686 + if (vma->vm_end - vma->vm_start > size)
50687 return -1;
50688 return (int)vma->vm_pgoff;
50689 }
50690 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
50691 idev->owner = owner;
50692 idev->info = info;
50693 init_waitqueue_head(&idev->wait);
50694 - atomic_set(&idev->event, 0);
50695 + atomic_set_unchecked(&idev->event, 0);
50696
50697 ret = uio_get_minor(idev);
50698 if (ret)
50699 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
50700 index 8a7eb77..c00402f 100644
50701 --- a/drivers/usb/atm/cxacru.c
50702 +++ b/drivers/usb/atm/cxacru.c
50703 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
50704 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
50705 if (ret < 2)
50706 return -EINVAL;
50707 - if (index < 0 || index > 0x7f)
50708 + if (index > 0x7f)
50709 return -EINVAL;
50710 pos += tmp;
50711
50712 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
50713 index 25a7bfc..57f3cf5 100644
50714 --- a/drivers/usb/atm/usbatm.c
50715 +++ b/drivers/usb/atm/usbatm.c
50716 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50717 if (printk_ratelimit())
50718 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
50719 __func__, vpi, vci);
50720 - atomic_inc(&vcc->stats->rx_err);
50721 + atomic_inc_unchecked(&vcc->stats->rx_err);
50722 return;
50723 }
50724
50725 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50726 if (length > ATM_MAX_AAL5_PDU) {
50727 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
50728 __func__, length, vcc);
50729 - atomic_inc(&vcc->stats->rx_err);
50730 + atomic_inc_unchecked(&vcc->stats->rx_err);
50731 goto out;
50732 }
50733
50734 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50735 if (sarb->len < pdu_length) {
50736 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
50737 __func__, pdu_length, sarb->len, vcc);
50738 - atomic_inc(&vcc->stats->rx_err);
50739 + atomic_inc_unchecked(&vcc->stats->rx_err);
50740 goto out;
50741 }
50742
50743 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
50744 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
50745 __func__, vcc);
50746 - atomic_inc(&vcc->stats->rx_err);
50747 + atomic_inc_unchecked(&vcc->stats->rx_err);
50748 goto out;
50749 }
50750
50751 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50752 if (printk_ratelimit())
50753 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
50754 __func__, length);
50755 - atomic_inc(&vcc->stats->rx_drop);
50756 + atomic_inc_unchecked(&vcc->stats->rx_drop);
50757 goto out;
50758 }
50759
50760 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50761
50762 vcc->push(vcc, skb);
50763
50764 - atomic_inc(&vcc->stats->rx);
50765 + atomic_inc_unchecked(&vcc->stats->rx);
50766 out:
50767 skb_trim(sarb, 0);
50768 }
50769 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
50770 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
50771
50772 usbatm_pop(vcc, skb);
50773 - atomic_inc(&vcc->stats->tx);
50774 + atomic_inc_unchecked(&vcc->stats->tx);
50775
50776 skb = skb_dequeue(&instance->sndqueue);
50777 }
50778 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
50779 if (!left--)
50780 return sprintf(page,
50781 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
50782 - atomic_read(&atm_dev->stats.aal5.tx),
50783 - atomic_read(&atm_dev->stats.aal5.tx_err),
50784 - atomic_read(&atm_dev->stats.aal5.rx),
50785 - atomic_read(&atm_dev->stats.aal5.rx_err),
50786 - atomic_read(&atm_dev->stats.aal5.rx_drop));
50787 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
50788 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
50789 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
50790 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
50791 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
50792
50793 if (!left--) {
50794 if (instance->disconnected)
50795 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
50796 index 2a3bbdf..91d72cf 100644
50797 --- a/drivers/usb/core/devices.c
50798 +++ b/drivers/usb/core/devices.c
50799 @@ -126,7 +126,7 @@ static const char format_endpt[] =
50800 * time it gets called.
50801 */
50802 static struct device_connect_event {
50803 - atomic_t count;
50804 + atomic_unchecked_t count;
50805 wait_queue_head_t wait;
50806 } device_event = {
50807 .count = ATOMIC_INIT(1),
50808 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
50809
50810 void usbfs_conn_disc_event(void)
50811 {
50812 - atomic_add(2, &device_event.count);
50813 + atomic_add_unchecked(2, &device_event.count);
50814 wake_up(&device_event.wait);
50815 }
50816
50817 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
50818
50819 poll_wait(file, &device_event.wait, wait);
50820
50821 - event_count = atomic_read(&device_event.count);
50822 + event_count = atomic_read_unchecked(&device_event.count);
50823 if (file->f_version != event_count) {
50824 file->f_version = event_count;
50825 return POLLIN | POLLRDNORM;
50826 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
50827 index 967152a..16fa2e5 100644
50828 --- a/drivers/usb/core/devio.c
50829 +++ b/drivers/usb/core/devio.c
50830 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
50831 struct dev_state *ps = file->private_data;
50832 struct usb_device *dev = ps->dev;
50833 ssize_t ret = 0;
50834 - unsigned len;
50835 + size_t len;
50836 loff_t pos;
50837 int i;
50838
50839 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
50840 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
50841 struct usb_config_descriptor *config =
50842 (struct usb_config_descriptor *)dev->rawdescriptors[i];
50843 - unsigned int length = le16_to_cpu(config->wTotalLength);
50844 + size_t length = le16_to_cpu(config->wTotalLength);
50845
50846 if (*ppos < pos + length) {
50847
50848 /* The descriptor may claim to be longer than it
50849 * really is. Here is the actual allocated length. */
50850 - unsigned alloclen =
50851 + size_t alloclen =
50852 le16_to_cpu(dev->config[i].desc.wTotalLength);
50853
50854 - len = length - (*ppos - pos);
50855 + len = length + pos - *ppos;
50856 if (len > nbytes)
50857 len = nbytes;
50858
50859 /* Simply don't write (skip over) unallocated parts */
50860 if (alloclen > (*ppos - pos)) {
50861 - alloclen -= (*ppos - pos);
50862 + alloclen = alloclen + pos - *ppos;
50863 if (copy_to_user(buf,
50864 dev->rawdescriptors[i] + (*ppos - pos),
50865 min(len, alloclen))) {
50866 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
50867 index 6bffb8c..b404e8b 100644
50868 --- a/drivers/usb/core/hcd.c
50869 +++ b/drivers/usb/core/hcd.c
50870 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
50871 */
50872 usb_get_urb(urb);
50873 atomic_inc(&urb->use_count);
50874 - atomic_inc(&urb->dev->urbnum);
50875 + atomic_inc_unchecked(&urb->dev->urbnum);
50876 usbmon_urb_submit(&hcd->self, urb);
50877
50878 /* NOTE requirements on root-hub callers (usbfs and the hub
50879 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
50880 urb->hcpriv = NULL;
50881 INIT_LIST_HEAD(&urb->urb_list);
50882 atomic_dec(&urb->use_count);
50883 - atomic_dec(&urb->dev->urbnum);
50884 + atomic_dec_unchecked(&urb->dev->urbnum);
50885 if (atomic_read(&urb->reject))
50886 wake_up(&usb_kill_urb_queue);
50887 usb_put_urb(urb);
50888 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
50889 index bd9dc35..c04ae2f 100644
50890 --- a/drivers/usb/core/hub.c
50891 +++ b/drivers/usb/core/hub.c
50892 @@ -27,6 +27,7 @@
50893 #include <linux/freezer.h>
50894 #include <linux/random.h>
50895 #include <linux/pm_qos.h>
50896 +#include <linux/grsecurity.h>
50897
50898 #include <asm/uaccess.h>
50899 #include <asm/byteorder.h>
50900 @@ -4463,6 +4464,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
50901 goto done;
50902 return;
50903 }
50904 +
50905 + if (gr_handle_new_usb())
50906 + goto done;
50907 +
50908 if (hub_is_superspeed(hub->hdev))
50909 unit_load = 150;
50910 else
50911 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
50912 index bb31597..6c5ef8b 100644
50913 --- a/drivers/usb/core/message.c
50914 +++ b/drivers/usb/core/message.c
50915 @@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
50916 * Return: If successful, the number of bytes transferred. Otherwise, a negative
50917 * error number.
50918 */
50919 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
50920 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
50921 __u8 requesttype, __u16 value, __u16 index, void *data,
50922 __u16 size, int timeout)
50923 {
50924 @@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
50925 * If successful, 0. Otherwise a negative error number. The number of actual
50926 * bytes transferred will be stored in the @actual_length paramater.
50927 */
50928 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
50929 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
50930 void *data, int len, int *actual_length, int timeout)
50931 {
50932 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
50933 @@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
50934 * bytes transferred will be stored in the @actual_length paramater.
50935 *
50936 */
50937 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
50938 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
50939 void *data, int len, int *actual_length, int timeout)
50940 {
50941 struct urb *urb;
50942 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
50943 index 52a97ad..e73330f 100644
50944 --- a/drivers/usb/core/sysfs.c
50945 +++ b/drivers/usb/core/sysfs.c
50946 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
50947 struct usb_device *udev;
50948
50949 udev = to_usb_device(dev);
50950 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
50951 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
50952 }
50953 static DEVICE_ATTR_RO(urbnum);
50954
50955 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
50956 index 4d11449..f4ccabf 100644
50957 --- a/drivers/usb/core/usb.c
50958 +++ b/drivers/usb/core/usb.c
50959 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
50960 set_dev_node(&dev->dev, dev_to_node(bus->controller));
50961 dev->state = USB_STATE_ATTACHED;
50962 dev->lpm_disable_count = 1;
50963 - atomic_set(&dev->urbnum, 0);
50964 + atomic_set_unchecked(&dev->urbnum, 0);
50965
50966 INIT_LIST_HEAD(&dev->ep0.urb_list);
50967 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
50968 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
50969 index 02e44fc..3c4fe64 100644
50970 --- a/drivers/usb/dwc3/gadget.c
50971 +++ b/drivers/usb/dwc3/gadget.c
50972 @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
50973 if (!usb_endpoint_xfer_isoc(desc))
50974 return 0;
50975
50976 - memset(&trb_link, 0, sizeof(trb_link));
50977 -
50978 /* Link TRB for ISOC. The HWO bit is never reset */
50979 trb_st_hw = &dep->trb_pool[0];
50980
50981 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
50982 index 8cfc319..4868255 100644
50983 --- a/drivers/usb/early/ehci-dbgp.c
50984 +++ b/drivers/usb/early/ehci-dbgp.c
50985 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
50986
50987 #ifdef CONFIG_KGDB
50988 static struct kgdb_io kgdbdbgp_io_ops;
50989 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
50990 +static struct kgdb_io kgdbdbgp_io_ops_console;
50991 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
50992 #else
50993 #define dbgp_kgdb_mode (0)
50994 #endif
50995 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
50996 .write_char = kgdbdbgp_write_char,
50997 };
50998
50999 +static struct kgdb_io kgdbdbgp_io_ops_console = {
51000 + .name = "kgdbdbgp",
51001 + .read_char = kgdbdbgp_read_char,
51002 + .write_char = kgdbdbgp_write_char,
51003 + .is_console = 1
51004 +};
51005 +
51006 static int kgdbdbgp_wait_time;
51007
51008 static int __init kgdbdbgp_parse_config(char *str)
51009 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51010 ptr++;
51011 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51012 }
51013 - kgdb_register_io_module(&kgdbdbgp_io_ops);
51014 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51015 + if (early_dbgp_console.index != -1)
51016 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51017 + else
51018 + kgdb_register_io_module(&kgdbdbgp_io_ops);
51019
51020 return 0;
51021 }
51022 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51023 index b369292..9f3ba40 100644
51024 --- a/drivers/usb/gadget/u_serial.c
51025 +++ b/drivers/usb/gadget/u_serial.c
51026 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51027 spin_lock_irq(&port->port_lock);
51028
51029 /* already open? Great. */
51030 - if (port->port.count) {
51031 + if (atomic_read(&port->port.count)) {
51032 status = 0;
51033 - port->port.count++;
51034 + atomic_inc(&port->port.count);
51035
51036 /* currently opening/closing? wait ... */
51037 } else if (port->openclose) {
51038 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51039 tty->driver_data = port;
51040 port->port.tty = tty;
51041
51042 - port->port.count = 1;
51043 + atomic_set(&port->port.count, 1);
51044 port->openclose = false;
51045
51046 /* if connected, start the I/O stream */
51047 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51048
51049 spin_lock_irq(&port->port_lock);
51050
51051 - if (port->port.count != 1) {
51052 - if (port->port.count == 0)
51053 + if (atomic_read(&port->port.count) != 1) {
51054 + if (atomic_read(&port->port.count) == 0)
51055 WARN_ON(1);
51056 else
51057 - --port->port.count;
51058 + atomic_dec(&port->port.count);
51059 goto exit;
51060 }
51061
51062 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51063 * and sleep if necessary
51064 */
51065 port->openclose = true;
51066 - port->port.count = 0;
51067 + atomic_set(&port->port.count, 0);
51068
51069 gser = port->port_usb;
51070 if (gser && gser->disconnect)
51071 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51072 int cond;
51073
51074 spin_lock_irq(&port->port_lock);
51075 - cond = (port->port.count == 0) && !port->openclose;
51076 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51077 spin_unlock_irq(&port->port_lock);
51078 return cond;
51079 }
51080 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51081 /* if it's already open, start I/O ... and notify the serial
51082 * protocol about open/close status (connect/disconnect).
51083 */
51084 - if (port->port.count) {
51085 + if (atomic_read(&port->port.count)) {
51086 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51087 gs_start_io(port);
51088 if (gser->connect)
51089 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51090
51091 port->port_usb = NULL;
51092 gser->ioport = NULL;
51093 - if (port->port.count > 0 || port->openclose) {
51094 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
51095 wake_up_interruptible(&port->drain_wait);
51096 if (port->port.tty)
51097 tty_hangup(port->port.tty);
51098 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51099
51100 /* finally, free any unused/unusable I/O buffers */
51101 spin_lock_irqsave(&port->port_lock, flags);
51102 - if (port->port.count == 0 && !port->openclose)
51103 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
51104 gs_buf_free(&port->port_write_buf);
51105 gs_free_requests(gser->out, &port->read_pool, NULL);
51106 gs_free_requests(gser->out, &port->read_queue, NULL);
51107 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51108 index 835fc08..f8b22bf 100644
51109 --- a/drivers/usb/host/ehci-hub.c
51110 +++ b/drivers/usb/host/ehci-hub.c
51111 @@ -762,7 +762,7 @@ static struct urb *request_single_step_set_feature_urb(
51112 urb->transfer_flags = URB_DIR_IN;
51113 usb_get_urb(urb);
51114 atomic_inc(&urb->use_count);
51115 - atomic_inc(&urb->dev->urbnum);
51116 + atomic_inc_unchecked(&urb->dev->urbnum);
51117 urb->setup_dma = dma_map_single(
51118 hcd->self.controller,
51119 urb->setup_packet,
51120 @@ -829,7 +829,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51121 urb->status = -EINPROGRESS;
51122 usb_get_urb(urb);
51123 atomic_inc(&urb->use_count);
51124 - atomic_inc(&urb->dev->urbnum);
51125 + atomic_inc_unchecked(&urb->dev->urbnum);
51126 retval = submit_single_step_set_feature(hcd, urb, 0);
51127 if (!retval && !wait_for_completion_timeout(&done,
51128 msecs_to_jiffies(2000))) {
51129 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51130 index ba6a5d6..f88f7f3 100644
51131 --- a/drivers/usb/misc/appledisplay.c
51132 +++ b/drivers/usb/misc/appledisplay.c
51133 @@ -83,7 +83,7 @@ struct appledisplay {
51134 spinlock_t lock;
51135 };
51136
51137 -static atomic_t count_displays = ATOMIC_INIT(0);
51138 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51139 static struct workqueue_struct *wq;
51140
51141 static void appledisplay_complete(struct urb *urb)
51142 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
51143
51144 /* Register backlight device */
51145 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
51146 - atomic_inc_return(&count_displays) - 1);
51147 + atomic_inc_return_unchecked(&count_displays) - 1);
51148 memset(&props, 0, sizeof(struct backlight_properties));
51149 props.type = BACKLIGHT_RAW;
51150 props.max_brightness = 0xff;
51151 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
51152 index c69bb50..215ef37 100644
51153 --- a/drivers/usb/serial/console.c
51154 +++ b/drivers/usb/serial/console.c
51155 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
51156
51157 info->port = port;
51158
51159 - ++port->port.count;
51160 + atomic_inc(&port->port.count);
51161 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
51162 if (serial->type->set_termios) {
51163 /*
51164 @@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
51165 }
51166 /* Now that any required fake tty operations are completed restore
51167 * the tty port count */
51168 - --port->port.count;
51169 + atomic_dec(&port->port.count);
51170 /* The console is special in terms of closing the device so
51171 * indicate this port is now acting as a system console. */
51172 port->port.console = 1;
51173 @@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
51174 free_tty:
51175 kfree(tty);
51176 reset_open_count:
51177 - port->port.count = 0;
51178 + atomic_set(&port->port.count, 0);
51179 usb_autopm_put_interface(serial->interface);
51180 error_get_interface:
51181 usb_serial_put(serial);
51182 @@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
51183 static void usb_console_write(struct console *co,
51184 const char *buf, unsigned count)
51185 {
51186 - static struct usbcons_info *info = &usbcons_info;
51187 + struct usbcons_info *info = &usbcons_info;
51188 struct usb_serial_port *port = info->port;
51189 struct usb_serial *serial;
51190 int retval = -ENODEV;
51191 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
51192 index 75f70f0..d467e1a 100644
51193 --- a/drivers/usb/storage/usb.h
51194 +++ b/drivers/usb/storage/usb.h
51195 @@ -63,7 +63,7 @@ struct us_unusual_dev {
51196 __u8 useProtocol;
51197 __u8 useTransport;
51198 int (*initFunction)(struct us_data *);
51199 -};
51200 +} __do_const;
51201
51202
51203 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
51204 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
51205 index e614f02..3fd60e2 100644
51206 --- a/drivers/usb/wusbcore/wa-hc.h
51207 +++ b/drivers/usb/wusbcore/wa-hc.h
51208 @@ -225,7 +225,7 @@ struct wahc {
51209 spinlock_t xfer_list_lock;
51210 struct work_struct xfer_enqueue_work;
51211 struct work_struct xfer_error_work;
51212 - atomic_t xfer_id_count;
51213 + atomic_unchecked_t xfer_id_count;
51214
51215 kernel_ulong_t quirks;
51216 };
51217 @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
51218 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
51219 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
51220 wa->dto_in_use = 0;
51221 - atomic_set(&wa->xfer_id_count, 1);
51222 + atomic_set_unchecked(&wa->xfer_id_count, 1);
51223 }
51224
51225 /**
51226 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
51227 index ed5abe8..7036400 100644
51228 --- a/drivers/usb/wusbcore/wa-xfer.c
51229 +++ b/drivers/usb/wusbcore/wa-xfer.c
51230 @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
51231 */
51232 static void wa_xfer_id_init(struct wa_xfer *xfer)
51233 {
51234 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
51235 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
51236 }
51237
51238 /* Return the xfer's ID. */
51239 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
51240 index 1eab4ac..e21efc9 100644
51241 --- a/drivers/vfio/vfio.c
51242 +++ b/drivers/vfio/vfio.c
51243 @@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
51244 return 0;
51245
51246 /* TODO Prevent device auto probing */
51247 - WARN("Device %s added to live group %d!\n", dev_name(dev),
51248 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
51249 iommu_group_id(group->iommu_group));
51250
51251 return 0;
51252 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
51253 index 5174eba..451e6bc 100644
51254 --- a/drivers/vhost/vringh.c
51255 +++ b/drivers/vhost/vringh.c
51256 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
51257 /* Userspace access helpers: in this case, addresses are really userspace. */
51258 static inline int getu16_user(u16 *val, const u16 *p)
51259 {
51260 - return get_user(*val, (__force u16 __user *)p);
51261 + return get_user(*val, (u16 __force_user *)p);
51262 }
51263
51264 static inline int putu16_user(u16 *p, u16 val)
51265 {
51266 - return put_user(val, (__force u16 __user *)p);
51267 + return put_user(val, (u16 __force_user *)p);
51268 }
51269
51270 static inline int copydesc_user(void *dst, const void *src, size_t len)
51271 {
51272 - return copy_from_user(dst, (__force void __user *)src, len) ?
51273 + return copy_from_user(dst, (void __force_user *)src, len) ?
51274 -EFAULT : 0;
51275 }
51276
51277 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
51278 const struct vring_used_elem *src,
51279 unsigned int num)
51280 {
51281 - return copy_to_user((__force void __user *)dst, src,
51282 + return copy_to_user((void __force_user *)dst, src,
51283 sizeof(*dst) * num) ? -EFAULT : 0;
51284 }
51285
51286 static inline int xfer_from_user(void *src, void *dst, size_t len)
51287 {
51288 - return copy_from_user(dst, (__force void __user *)src, len) ?
51289 + return copy_from_user(dst, (void __force_user *)src, len) ?
51290 -EFAULT : 0;
51291 }
51292
51293 static inline int xfer_to_user(void *dst, void *src, size_t len)
51294 {
51295 - return copy_to_user((__force void __user *)dst, src, len) ?
51296 + return copy_to_user((void __force_user *)dst, src, len) ?
51297 -EFAULT : 0;
51298 }
51299
51300 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
51301 vrh->last_used_idx = 0;
51302 vrh->vring.num = num;
51303 /* vring expects kernel addresses, but only used via accessors. */
51304 - vrh->vring.desc = (__force struct vring_desc *)desc;
51305 - vrh->vring.avail = (__force struct vring_avail *)avail;
51306 - vrh->vring.used = (__force struct vring_used *)used;
51307 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
51308 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
51309 + vrh->vring.used = (__force_kernel struct vring_used *)used;
51310 return 0;
51311 }
51312 EXPORT_SYMBOL(vringh_init_user);
51313 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
51314
51315 static inline int putu16_kern(u16 *p, u16 val)
51316 {
51317 - ACCESS_ONCE(*p) = val;
51318 + ACCESS_ONCE_RW(*p) = val;
51319 return 0;
51320 }
51321
51322 diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
51323 index 1b0b233..6f34c2c 100644
51324 --- a/drivers/video/arcfb.c
51325 +++ b/drivers/video/arcfb.c
51326 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
51327 return -ENOSPC;
51328
51329 err = 0;
51330 - if ((count + p) > fbmemlength) {
51331 + if (count > (fbmemlength - p)) {
51332 count = fbmemlength - p;
51333 err = -ENOSPC;
51334 }
51335 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
51336 index 12ca031..84a8a74 100644
51337 --- a/drivers/video/aty/aty128fb.c
51338 +++ b/drivers/video/aty/aty128fb.c
51339 @@ -149,7 +149,7 @@ enum {
51340 };
51341
51342 /* Must match above enum */
51343 -static char * const r128_family[] = {
51344 +static const char * const r128_family[] = {
51345 "AGP",
51346 "PCI",
51347 "PRO AGP",
51348 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
51349 index 28fafbf..ae91651 100644
51350 --- a/drivers/video/aty/atyfb_base.c
51351 +++ b/drivers/video/aty/atyfb_base.c
51352 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
51353 par->accel_flags = var->accel_flags; /* hack */
51354
51355 if (var->accel_flags) {
51356 - info->fbops->fb_sync = atyfb_sync;
51357 + pax_open_kernel();
51358 + *(void **)&info->fbops->fb_sync = atyfb_sync;
51359 + pax_close_kernel();
51360 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51361 } else {
51362 - info->fbops->fb_sync = NULL;
51363 + pax_open_kernel();
51364 + *(void **)&info->fbops->fb_sync = NULL;
51365 + pax_close_kernel();
51366 info->flags |= FBINFO_HWACCEL_DISABLED;
51367 }
51368
51369 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
51370 index 95ec042..e6affdd 100644
51371 --- a/drivers/video/aty/mach64_cursor.c
51372 +++ b/drivers/video/aty/mach64_cursor.c
51373 @@ -7,6 +7,7 @@
51374 #include <linux/string.h>
51375
51376 #include <asm/io.h>
51377 +#include <asm/pgtable.h>
51378
51379 #ifdef __sparc__
51380 #include <asm/fbio.h>
51381 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
51382 info->sprite.buf_align = 16; /* and 64 lines tall. */
51383 info->sprite.flags = FB_PIXMAP_IO;
51384
51385 - info->fbops->fb_cursor = atyfb_cursor;
51386 + pax_open_kernel();
51387 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
51388 + pax_close_kernel();
51389
51390 return 0;
51391 }
51392 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
51393 index 7592cc2..92feb56 100644
51394 --- a/drivers/video/backlight/kb3886_bl.c
51395 +++ b/drivers/video/backlight/kb3886_bl.c
51396 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
51397 static unsigned long kb3886bl_flags;
51398 #define KB3886BL_SUSPENDED 0x01
51399
51400 -static struct dmi_system_id __initdata kb3886bl_device_table[] = {
51401 +static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
51402 {
51403 .ident = "Sahara Touch-iT",
51404 .matches = {
51405 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
51406 index 900aa4e..6d49418 100644
51407 --- a/drivers/video/fb_defio.c
51408 +++ b/drivers/video/fb_defio.c
51409 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
51410
51411 BUG_ON(!fbdefio);
51412 mutex_init(&fbdefio->lock);
51413 - info->fbops->fb_mmap = fb_deferred_io_mmap;
51414 + pax_open_kernel();
51415 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
51416 + pax_close_kernel();
51417 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
51418 INIT_LIST_HEAD(&fbdefio->pagelist);
51419 if (fbdefio->delay == 0) /* set a default of 1 s */
51420 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
51421 page->mapping = NULL;
51422 }
51423
51424 - info->fbops->fb_mmap = NULL;
51425 + *(void **)&info->fbops->fb_mmap = NULL;
51426 mutex_destroy(&fbdefio->lock);
51427 }
51428 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
51429 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
51430 index 010d191..7b8235a 100644
51431 --- a/drivers/video/fbmem.c
51432 +++ b/drivers/video/fbmem.c
51433 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51434 image->dx += image->width + 8;
51435 }
51436 } else if (rotate == FB_ROTATE_UD) {
51437 - for (x = 0; x < num && image->dx >= 0; x++) {
51438 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
51439 info->fbops->fb_imageblit(info, image);
51440 image->dx -= image->width + 8;
51441 }
51442 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51443 image->dy += image->height + 8;
51444 }
51445 } else if (rotate == FB_ROTATE_CCW) {
51446 - for (x = 0; x < num && image->dy >= 0; x++) {
51447 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
51448 info->fbops->fb_imageblit(info, image);
51449 image->dy -= image->height + 8;
51450 }
51451 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
51452 return -EFAULT;
51453 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
51454 return -EINVAL;
51455 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
51456 + if (con2fb.framebuffer >= FB_MAX)
51457 return -EINVAL;
51458 if (!registered_fb[con2fb.framebuffer])
51459 request_module("fb%d", con2fb.framebuffer);
51460 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
51461 __u32 data;
51462 int err;
51463
51464 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
51465 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
51466
51467 data = (__u32) (unsigned long) fix->smem_start;
51468 err |= put_user(data, &fix32->smem_start);
51469 diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
51470 index 130708f..cdac1a9 100644
51471 --- a/drivers/video/hyperv_fb.c
51472 +++ b/drivers/video/hyperv_fb.c
51473 @@ -233,7 +233,7 @@ static uint screen_fb_size;
51474 static inline int synthvid_send(struct hv_device *hdev,
51475 struct synthvid_msg *msg)
51476 {
51477 - static atomic64_t request_id = ATOMIC64_INIT(0);
51478 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
51479 int ret;
51480
51481 msg->pipe_hdr.type = PIPE_MSG_DATA;
51482 @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
51483
51484 ret = vmbus_sendpacket(hdev->channel, msg,
51485 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
51486 - atomic64_inc_return(&request_id),
51487 + atomic64_inc_return_unchecked(&request_id),
51488 VM_PKT_DATA_INBAND, 0);
51489
51490 if (ret)
51491 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
51492 index 7672d2e..b56437f 100644
51493 --- a/drivers/video/i810/i810_accel.c
51494 +++ b/drivers/video/i810/i810_accel.c
51495 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
51496 }
51497 }
51498 printk("ringbuffer lockup!!!\n");
51499 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
51500 i810_report_error(mmio);
51501 par->dev_flags |= LOCKUP;
51502 info->pixmap.scan_align = 1;
51503 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
51504 index 3c14e43..2630570 100644
51505 --- a/drivers/video/logo/logo_linux_clut224.ppm
51506 +++ b/drivers/video/logo/logo_linux_clut224.ppm
51507 @@ -2,1603 +2,1123 @@ P3
51508 # Standard 224-color Linux logo
51509 80 80
51510 255
51511 - 0 0 0 0 0 0 0 0 0 0 0 0
51512 - 0 0 0 0 0 0 0 0 0 0 0 0
51513 - 0 0 0 0 0 0 0 0 0 0 0 0
51514 - 0 0 0 0 0 0 0 0 0 0 0 0
51515 - 0 0 0 0 0 0 0 0 0 0 0 0
51516 - 0 0 0 0 0 0 0 0 0 0 0 0
51517 - 0 0 0 0 0 0 0 0 0 0 0 0
51518 - 0 0 0 0 0 0 0 0 0 0 0 0
51519 - 0 0 0 0 0 0 0 0 0 0 0 0
51520 - 6 6 6 6 6 6 10 10 10 10 10 10
51521 - 10 10 10 6 6 6 6 6 6 6 6 6
51522 - 0 0 0 0 0 0 0 0 0 0 0 0
51523 - 0 0 0 0 0 0 0 0 0 0 0 0
51524 - 0 0 0 0 0 0 0 0 0 0 0 0
51525 - 0 0 0 0 0 0 0 0 0 0 0 0
51526 - 0 0 0 0 0 0 0 0 0 0 0 0
51527 - 0 0 0 0 0 0 0 0 0 0 0 0
51528 - 0 0 0 0 0 0 0 0 0 0 0 0
51529 - 0 0 0 0 0 0 0 0 0 0 0 0
51530 - 0 0 0 0 0 0 0 0 0 0 0 0
51531 - 0 0 0 0 0 0 0 0 0 0 0 0
51532 - 0 0 0 0 0 0 0 0 0 0 0 0
51533 - 0 0 0 0 0 0 0 0 0 0 0 0
51534 - 0 0 0 0 0 0 0 0 0 0 0 0
51535 - 0 0 0 0 0 0 0 0 0 0 0 0
51536 - 0 0 0 0 0 0 0 0 0 0 0 0
51537 - 0 0 0 0 0 0 0 0 0 0 0 0
51538 - 0 0 0 0 0 0 0 0 0 0 0 0
51539 - 0 0 0 6 6 6 10 10 10 14 14 14
51540 - 22 22 22 26 26 26 30 30 30 34 34 34
51541 - 30 30 30 30 30 30 26 26 26 18 18 18
51542 - 14 14 14 10 10 10 6 6 6 0 0 0
51543 - 0 0 0 0 0 0 0 0 0 0 0 0
51544 - 0 0 0 0 0 0 0 0 0 0 0 0
51545 - 0 0 0 0 0 0 0 0 0 0 0 0
51546 - 0 0 0 0 0 0 0 0 0 0 0 0
51547 - 0 0 0 0 0 0 0 0 0 0 0 0
51548 - 0 0 0 0 0 0 0 0 0 0 0 0
51549 - 0 0 0 0 0 0 0 0 0 0 0 0
51550 - 0 0 0 0 0 0 0 0 0 0 0 0
51551 - 0 0 0 0 0 0 0 0 0 0 0 0
51552 - 0 0 0 0 0 1 0 0 1 0 0 0
51553 - 0 0 0 0 0 0 0 0 0 0 0 0
51554 - 0 0 0 0 0 0 0 0 0 0 0 0
51555 - 0 0 0 0 0 0 0 0 0 0 0 0
51556 - 0 0 0 0 0 0 0 0 0 0 0 0
51557 - 0 0 0 0 0 0 0 0 0 0 0 0
51558 - 0 0 0 0 0 0 0 0 0 0 0 0
51559 - 6 6 6 14 14 14 26 26 26 42 42 42
51560 - 54 54 54 66 66 66 78 78 78 78 78 78
51561 - 78 78 78 74 74 74 66 66 66 54 54 54
51562 - 42 42 42 26 26 26 18 18 18 10 10 10
51563 - 6 6 6 0 0 0 0 0 0 0 0 0
51564 - 0 0 0 0 0 0 0 0 0 0 0 0
51565 - 0 0 0 0 0 0 0 0 0 0 0 0
51566 - 0 0 0 0 0 0 0 0 0 0 0 0
51567 - 0 0 0 0 0 0 0 0 0 0 0 0
51568 - 0 0 0 0 0 0 0 0 0 0 0 0
51569 - 0 0 0 0 0 0 0 0 0 0 0 0
51570 - 0 0 0 0 0 0 0 0 0 0 0 0
51571 - 0 0 0 0 0 0 0 0 0 0 0 0
51572 - 0 0 1 0 0 0 0 0 0 0 0 0
51573 - 0 0 0 0 0 0 0 0 0 0 0 0
51574 - 0 0 0 0 0 0 0 0 0 0 0 0
51575 - 0 0 0 0 0 0 0 0 0 0 0 0
51576 - 0 0 0 0 0 0 0 0 0 0 0 0
51577 - 0 0 0 0 0 0 0 0 0 0 0 0
51578 - 0 0 0 0 0 0 0 0 0 10 10 10
51579 - 22 22 22 42 42 42 66 66 66 86 86 86
51580 - 66 66 66 38 38 38 38 38 38 22 22 22
51581 - 26 26 26 34 34 34 54 54 54 66 66 66
51582 - 86 86 86 70 70 70 46 46 46 26 26 26
51583 - 14 14 14 6 6 6 0 0 0 0 0 0
51584 - 0 0 0 0 0 0 0 0 0 0 0 0
51585 - 0 0 0 0 0 0 0 0 0 0 0 0
51586 - 0 0 0 0 0 0 0 0 0 0 0 0
51587 - 0 0 0 0 0 0 0 0 0 0 0 0
51588 - 0 0 0 0 0 0 0 0 0 0 0 0
51589 - 0 0 0 0 0 0 0 0 0 0 0 0
51590 - 0 0 0 0 0 0 0 0 0 0 0 0
51591 - 0 0 0 0 0 0 0 0 0 0 0 0
51592 - 0 0 1 0 0 1 0 0 1 0 0 0
51593 - 0 0 0 0 0 0 0 0 0 0 0 0
51594 - 0 0 0 0 0 0 0 0 0 0 0 0
51595 - 0 0 0 0 0 0 0 0 0 0 0 0
51596 - 0 0 0 0 0 0 0 0 0 0 0 0
51597 - 0 0 0 0 0 0 0 0 0 0 0 0
51598 - 0 0 0 0 0 0 10 10 10 26 26 26
51599 - 50 50 50 82 82 82 58 58 58 6 6 6
51600 - 2 2 6 2 2 6 2 2 6 2 2 6
51601 - 2 2 6 2 2 6 2 2 6 2 2 6
51602 - 6 6 6 54 54 54 86 86 86 66 66 66
51603 - 38 38 38 18 18 18 6 6 6 0 0 0
51604 - 0 0 0 0 0 0 0 0 0 0 0 0
51605 - 0 0 0 0 0 0 0 0 0 0 0 0
51606 - 0 0 0 0 0 0 0 0 0 0 0 0
51607 - 0 0 0 0 0 0 0 0 0 0 0 0
51608 - 0 0 0 0 0 0 0 0 0 0 0 0
51609 - 0 0 0 0 0 0 0 0 0 0 0 0
51610 - 0 0 0 0 0 0 0 0 0 0 0 0
51611 - 0 0 0 0 0 0 0 0 0 0 0 0
51612 - 0 0 0 0 0 0 0 0 0 0 0 0
51613 - 0 0 0 0 0 0 0 0 0 0 0 0
51614 - 0 0 0 0 0 0 0 0 0 0 0 0
51615 - 0 0 0 0 0 0 0 0 0 0 0 0
51616 - 0 0 0 0 0 0 0 0 0 0 0 0
51617 - 0 0 0 0 0 0 0 0 0 0 0 0
51618 - 0 0 0 6 6 6 22 22 22 50 50 50
51619 - 78 78 78 34 34 34 2 2 6 2 2 6
51620 - 2 2 6 2 2 6 2 2 6 2 2 6
51621 - 2 2 6 2 2 6 2 2 6 2 2 6
51622 - 2 2 6 2 2 6 6 6 6 70 70 70
51623 - 78 78 78 46 46 46 22 22 22 6 6 6
51624 - 0 0 0 0 0 0 0 0 0 0 0 0
51625 - 0 0 0 0 0 0 0 0 0 0 0 0
51626 - 0 0 0 0 0 0 0 0 0 0 0 0
51627 - 0 0 0 0 0 0 0 0 0 0 0 0
51628 - 0 0 0 0 0 0 0 0 0 0 0 0
51629 - 0 0 0 0 0 0 0 0 0 0 0 0
51630 - 0 0 0 0 0 0 0 0 0 0 0 0
51631 - 0 0 0 0 0 0 0 0 0 0 0 0
51632 - 0 0 1 0 0 1 0 0 1 0 0 0
51633 - 0 0 0 0 0 0 0 0 0 0 0 0
51634 - 0 0 0 0 0 0 0 0 0 0 0 0
51635 - 0 0 0 0 0 0 0 0 0 0 0 0
51636 - 0 0 0 0 0 0 0 0 0 0 0 0
51637 - 0 0 0 0 0 0 0 0 0 0 0 0
51638 - 6 6 6 18 18 18 42 42 42 82 82 82
51639 - 26 26 26 2 2 6 2 2 6 2 2 6
51640 - 2 2 6 2 2 6 2 2 6 2 2 6
51641 - 2 2 6 2 2 6 2 2 6 14 14 14
51642 - 46 46 46 34 34 34 6 6 6 2 2 6
51643 - 42 42 42 78 78 78 42 42 42 18 18 18
51644 - 6 6 6 0 0 0 0 0 0 0 0 0
51645 - 0 0 0 0 0 0 0 0 0 0 0 0
51646 - 0 0 0 0 0 0 0 0 0 0 0 0
51647 - 0 0 0 0 0 0 0 0 0 0 0 0
51648 - 0 0 0 0 0 0 0 0 0 0 0 0
51649 - 0 0 0 0 0 0 0 0 0 0 0 0
51650 - 0 0 0 0 0 0 0 0 0 0 0 0
51651 - 0 0 0 0 0 0 0 0 0 0 0 0
51652 - 0 0 1 0 0 0 0 0 1 0 0 0
51653 - 0 0 0 0 0 0 0 0 0 0 0 0
51654 - 0 0 0 0 0 0 0 0 0 0 0 0
51655 - 0 0 0 0 0 0 0 0 0 0 0 0
51656 - 0 0 0 0 0 0 0 0 0 0 0 0
51657 - 0 0 0 0 0 0 0 0 0 0 0 0
51658 - 10 10 10 30 30 30 66 66 66 58 58 58
51659 - 2 2 6 2 2 6 2 2 6 2 2 6
51660 - 2 2 6 2 2 6 2 2 6 2 2 6
51661 - 2 2 6 2 2 6 2 2 6 26 26 26
51662 - 86 86 86 101 101 101 46 46 46 10 10 10
51663 - 2 2 6 58 58 58 70 70 70 34 34 34
51664 - 10 10 10 0 0 0 0 0 0 0 0 0
51665 - 0 0 0 0 0 0 0 0 0 0 0 0
51666 - 0 0 0 0 0 0 0 0 0 0 0 0
51667 - 0 0 0 0 0 0 0 0 0 0 0 0
51668 - 0 0 0 0 0 0 0 0 0 0 0 0
51669 - 0 0 0 0 0 0 0 0 0 0 0 0
51670 - 0 0 0 0 0 0 0 0 0 0 0 0
51671 - 0 0 0 0 0 0 0 0 0 0 0 0
51672 - 0 0 1 0 0 1 0 0 1 0 0 0
51673 - 0 0 0 0 0 0 0 0 0 0 0 0
51674 - 0 0 0 0 0 0 0 0 0 0 0 0
51675 - 0 0 0 0 0 0 0 0 0 0 0 0
51676 - 0 0 0 0 0 0 0 0 0 0 0 0
51677 - 0 0 0 0 0 0 0 0 0 0 0 0
51678 - 14 14 14 42 42 42 86 86 86 10 10 10
51679 - 2 2 6 2 2 6 2 2 6 2 2 6
51680 - 2 2 6 2 2 6 2 2 6 2 2 6
51681 - 2 2 6 2 2 6 2 2 6 30 30 30
51682 - 94 94 94 94 94 94 58 58 58 26 26 26
51683 - 2 2 6 6 6 6 78 78 78 54 54 54
51684 - 22 22 22 6 6 6 0 0 0 0 0 0
51685 - 0 0 0 0 0 0 0 0 0 0 0 0
51686 - 0 0 0 0 0 0 0 0 0 0 0 0
51687 - 0 0 0 0 0 0 0 0 0 0 0 0
51688 - 0 0 0 0 0 0 0 0 0 0 0 0
51689 - 0 0 0 0 0 0 0 0 0 0 0 0
51690 - 0 0 0 0 0 0 0 0 0 0 0 0
51691 - 0 0 0 0 0 0 0 0 0 0 0 0
51692 - 0 0 0 0 0 0 0 0 0 0 0 0
51693 - 0 0 0 0 0 0 0 0 0 0 0 0
51694 - 0 0 0 0 0 0 0 0 0 0 0 0
51695 - 0 0 0 0 0 0 0 0 0 0 0 0
51696 - 0 0 0 0 0 0 0 0 0 0 0 0
51697 - 0 0 0 0 0 0 0 0 0 6 6 6
51698 - 22 22 22 62 62 62 62 62 62 2 2 6
51699 - 2 2 6 2 2 6 2 2 6 2 2 6
51700 - 2 2 6 2 2 6 2 2 6 2 2 6
51701 - 2 2 6 2 2 6 2 2 6 26 26 26
51702 - 54 54 54 38 38 38 18 18 18 10 10 10
51703 - 2 2 6 2 2 6 34 34 34 82 82 82
51704 - 38 38 38 14 14 14 0 0 0 0 0 0
51705 - 0 0 0 0 0 0 0 0 0 0 0 0
51706 - 0 0 0 0 0 0 0 0 0 0 0 0
51707 - 0 0 0 0 0 0 0 0 0 0 0 0
51708 - 0 0 0 0 0 0 0 0 0 0 0 0
51709 - 0 0 0 0 0 0 0 0 0 0 0 0
51710 - 0 0 0 0 0 0 0 0 0 0 0 0
51711 - 0 0 0 0 0 0 0 0 0 0 0 0
51712 - 0 0 0 0 0 1 0 0 1 0 0 0
51713 - 0 0 0 0 0 0 0 0 0 0 0 0
51714 - 0 0 0 0 0 0 0 0 0 0 0 0
51715 - 0 0 0 0 0 0 0 0 0 0 0 0
51716 - 0 0 0 0 0 0 0 0 0 0 0 0
51717 - 0 0 0 0 0 0 0 0 0 6 6 6
51718 - 30 30 30 78 78 78 30 30 30 2 2 6
51719 - 2 2 6 2 2 6 2 2 6 2 2 6
51720 - 2 2 6 2 2 6 2 2 6 2 2 6
51721 - 2 2 6 2 2 6 2 2 6 10 10 10
51722 - 10 10 10 2 2 6 2 2 6 2 2 6
51723 - 2 2 6 2 2 6 2 2 6 78 78 78
51724 - 50 50 50 18 18 18 6 6 6 0 0 0
51725 - 0 0 0 0 0 0 0 0 0 0 0 0
51726 - 0 0 0 0 0 0 0 0 0 0 0 0
51727 - 0 0 0 0 0 0 0 0 0 0 0 0
51728 - 0 0 0 0 0 0 0 0 0 0 0 0
51729 - 0 0 0 0 0 0 0 0 0 0 0 0
51730 - 0 0 0 0 0 0 0 0 0 0 0 0
51731 - 0 0 0 0 0 0 0 0 0 0 0 0
51732 - 0 0 1 0 0 0 0 0 0 0 0 0
51733 - 0 0 0 0 0 0 0 0 0 0 0 0
51734 - 0 0 0 0 0 0 0 0 0 0 0 0
51735 - 0 0 0 0 0 0 0 0 0 0 0 0
51736 - 0 0 0 0 0 0 0 0 0 0 0 0
51737 - 0 0 0 0 0 0 0 0 0 10 10 10
51738 - 38 38 38 86 86 86 14 14 14 2 2 6
51739 - 2 2 6 2 2 6 2 2 6 2 2 6
51740 - 2 2 6 2 2 6 2 2 6 2 2 6
51741 - 2 2 6 2 2 6 2 2 6 2 2 6
51742 - 2 2 6 2 2 6 2 2 6 2 2 6
51743 - 2 2 6 2 2 6 2 2 6 54 54 54
51744 - 66 66 66 26 26 26 6 6 6 0 0 0
51745 - 0 0 0 0 0 0 0 0 0 0 0 0
51746 - 0 0 0 0 0 0 0 0 0 0 0 0
51747 - 0 0 0 0 0 0 0 0 0 0 0 0
51748 - 0 0 0 0 0 0 0 0 0 0 0 0
51749 - 0 0 0 0 0 0 0 0 0 0 0 0
51750 - 0 0 0 0 0 0 0 0 0 0 0 0
51751 - 0 0 0 0 0 0 0 0 0 0 0 0
51752 - 0 0 0 0 0 1 0 0 1 0 0 0
51753 - 0 0 0 0 0 0 0 0 0 0 0 0
51754 - 0 0 0 0 0 0 0 0 0 0 0 0
51755 - 0 0 0 0 0 0 0 0 0 0 0 0
51756 - 0 0 0 0 0 0 0 0 0 0 0 0
51757 - 0 0 0 0 0 0 0 0 0 14 14 14
51758 - 42 42 42 82 82 82 2 2 6 2 2 6
51759 - 2 2 6 6 6 6 10 10 10 2 2 6
51760 - 2 2 6 2 2 6 2 2 6 2 2 6
51761 - 2 2 6 2 2 6 2 2 6 6 6 6
51762 - 14 14 14 10 10 10 2 2 6 2 2 6
51763 - 2 2 6 2 2 6 2 2 6 18 18 18
51764 - 82 82 82 34 34 34 10 10 10 0 0 0
51765 - 0 0 0 0 0 0 0 0 0 0 0 0
51766 - 0 0 0 0 0 0 0 0 0 0 0 0
51767 - 0 0 0 0 0 0 0 0 0 0 0 0
51768 - 0 0 0 0 0 0 0 0 0 0 0 0
51769 - 0 0 0 0 0 0 0 0 0 0 0 0
51770 - 0 0 0 0 0 0 0 0 0 0 0 0
51771 - 0 0 0 0 0 0 0 0 0 0 0 0
51772 - 0 0 1 0 0 0 0 0 0 0 0 0
51773 - 0 0 0 0 0 0 0 0 0 0 0 0
51774 - 0 0 0 0 0 0 0 0 0 0 0 0
51775 - 0 0 0 0 0 0 0 0 0 0 0 0
51776 - 0 0 0 0 0 0 0 0 0 0 0 0
51777 - 0 0 0 0 0 0 0 0 0 14 14 14
51778 - 46 46 46 86 86 86 2 2 6 2 2 6
51779 - 6 6 6 6 6 6 22 22 22 34 34 34
51780 - 6 6 6 2 2 6 2 2 6 2 2 6
51781 - 2 2 6 2 2 6 18 18 18 34 34 34
51782 - 10 10 10 50 50 50 22 22 22 2 2 6
51783 - 2 2 6 2 2 6 2 2 6 10 10 10
51784 - 86 86 86 42 42 42 14 14 14 0 0 0
51785 - 0 0 0 0 0 0 0 0 0 0 0 0
51786 - 0 0 0 0 0 0 0 0 0 0 0 0
51787 - 0 0 0 0 0 0 0 0 0 0 0 0
51788 - 0 0 0 0 0 0 0 0 0 0 0 0
51789 - 0 0 0 0 0 0 0 0 0 0 0 0
51790 - 0 0 0 0 0 0 0 0 0 0 0 0
51791 - 0 0 0 0 0 0 0 0 0 0 0 0
51792 - 0 0 1 0 0 1 0 0 1 0 0 0
51793 - 0 0 0 0 0 0 0 0 0 0 0 0
51794 - 0 0 0 0 0 0 0 0 0 0 0 0
51795 - 0 0 0 0 0 0 0 0 0 0 0 0
51796 - 0 0 0 0 0 0 0 0 0 0 0 0
51797 - 0 0 0 0 0 0 0 0 0 14 14 14
51798 - 46 46 46 86 86 86 2 2 6 2 2 6
51799 - 38 38 38 116 116 116 94 94 94 22 22 22
51800 - 22 22 22 2 2 6 2 2 6 2 2 6
51801 - 14 14 14 86 86 86 138 138 138 162 162 162
51802 -154 154 154 38 38 38 26 26 26 6 6 6
51803 - 2 2 6 2 2 6 2 2 6 2 2 6
51804 - 86 86 86 46 46 46 14 14 14 0 0 0
51805 - 0 0 0 0 0 0 0 0 0 0 0 0
51806 - 0 0 0 0 0 0 0 0 0 0 0 0
51807 - 0 0 0 0 0 0 0 0 0 0 0 0
51808 - 0 0 0 0 0 0 0 0 0 0 0 0
51809 - 0 0 0 0 0 0 0 0 0 0 0 0
51810 - 0 0 0 0 0 0 0 0 0 0 0 0
51811 - 0 0 0 0 0 0 0 0 0 0 0 0
51812 - 0 0 0 0 0 0 0 0 0 0 0 0
51813 - 0 0 0 0 0 0 0 0 0 0 0 0
51814 - 0 0 0 0 0 0 0 0 0 0 0 0
51815 - 0 0 0 0 0 0 0 0 0 0 0 0
51816 - 0 0 0 0 0 0 0 0 0 0 0 0
51817 - 0 0 0 0 0 0 0 0 0 14 14 14
51818 - 46 46 46 86 86 86 2 2 6 14 14 14
51819 -134 134 134 198 198 198 195 195 195 116 116 116
51820 - 10 10 10 2 2 6 2 2 6 6 6 6
51821 -101 98 89 187 187 187 210 210 210 218 218 218
51822 -214 214 214 134 134 134 14 14 14 6 6 6
51823 - 2 2 6 2 2 6 2 2 6 2 2 6
51824 - 86 86 86 50 50 50 18 18 18 6 6 6
51825 - 0 0 0 0 0 0 0 0 0 0 0 0
51826 - 0 0 0 0 0 0 0 0 0 0 0 0
51827 - 0 0 0 0 0 0 0 0 0 0 0 0
51828 - 0 0 0 0 0 0 0 0 0 0 0 0
51829 - 0 0 0 0 0 0 0 0 0 0 0 0
51830 - 0 0 0 0 0 0 0 0 0 0 0 0
51831 - 0 0 0 0 0 0 0 0 1 0 0 0
51832 - 0 0 1 0 0 1 0 0 1 0 0 0
51833 - 0 0 0 0 0 0 0 0 0 0 0 0
51834 - 0 0 0 0 0 0 0 0 0 0 0 0
51835 - 0 0 0 0 0 0 0 0 0 0 0 0
51836 - 0 0 0 0 0 0 0 0 0 0 0 0
51837 - 0 0 0 0 0 0 0 0 0 14 14 14
51838 - 46 46 46 86 86 86 2 2 6 54 54 54
51839 -218 218 218 195 195 195 226 226 226 246 246 246
51840 - 58 58 58 2 2 6 2 2 6 30 30 30
51841 -210 210 210 253 253 253 174 174 174 123 123 123
51842 -221 221 221 234 234 234 74 74 74 2 2 6
51843 - 2 2 6 2 2 6 2 2 6 2 2 6
51844 - 70 70 70 58 58 58 22 22 22 6 6 6
51845 - 0 0 0 0 0 0 0 0 0 0 0 0
51846 - 0 0 0 0 0 0 0 0 0 0 0 0
51847 - 0 0 0 0 0 0 0 0 0 0 0 0
51848 - 0 0 0 0 0 0 0 0 0 0 0 0
51849 - 0 0 0 0 0 0 0 0 0 0 0 0
51850 - 0 0 0 0 0 0 0 0 0 0 0 0
51851 - 0 0 0 0 0 0 0 0 0 0 0 0
51852 - 0 0 0 0 0 0 0 0 0 0 0 0
51853 - 0 0 0 0 0 0 0 0 0 0 0 0
51854 - 0 0 0 0 0 0 0 0 0 0 0 0
51855 - 0 0 0 0 0 0 0 0 0 0 0 0
51856 - 0 0 0 0 0 0 0 0 0 0 0 0
51857 - 0 0 0 0 0 0 0 0 0 14 14 14
51858 - 46 46 46 82 82 82 2 2 6 106 106 106
51859 -170 170 170 26 26 26 86 86 86 226 226 226
51860 -123 123 123 10 10 10 14 14 14 46 46 46
51861 -231 231 231 190 190 190 6 6 6 70 70 70
51862 - 90 90 90 238 238 238 158 158 158 2 2 6
51863 - 2 2 6 2 2 6 2 2 6 2 2 6
51864 - 70 70 70 58 58 58 22 22 22 6 6 6
51865 - 0 0 0 0 0 0 0 0 0 0 0 0
51866 - 0 0 0 0 0 0 0 0 0 0 0 0
51867 - 0 0 0 0 0 0 0 0 0 0 0 0
51868 - 0 0 0 0 0 0 0 0 0 0 0 0
51869 - 0 0 0 0 0 0 0 0 0 0 0 0
51870 - 0 0 0 0 0 0 0 0 0 0 0 0
51871 - 0 0 0 0 0 0 0 0 1 0 0 0
51872 - 0 0 1 0 0 1 0 0 1 0 0 0
51873 - 0 0 0 0 0 0 0 0 0 0 0 0
51874 - 0 0 0 0 0 0 0 0 0 0 0 0
51875 - 0 0 0 0 0 0 0 0 0 0 0 0
51876 - 0 0 0 0 0 0 0 0 0 0 0 0
51877 - 0 0 0 0 0 0 0 0 0 14 14 14
51878 - 42 42 42 86 86 86 6 6 6 116 116 116
51879 -106 106 106 6 6 6 70 70 70 149 149 149
51880 -128 128 128 18 18 18 38 38 38 54 54 54
51881 -221 221 221 106 106 106 2 2 6 14 14 14
51882 - 46 46 46 190 190 190 198 198 198 2 2 6
51883 - 2 2 6 2 2 6 2 2 6 2 2 6
51884 - 74 74 74 62 62 62 22 22 22 6 6 6
51885 - 0 0 0 0 0 0 0 0 0 0 0 0
51886 - 0 0 0 0 0 0 0 0 0 0 0 0
51887 - 0 0 0 0 0 0 0 0 0 0 0 0
51888 - 0 0 0 0 0 0 0 0 0 0 0 0
51889 - 0 0 0 0 0 0 0 0 0 0 0 0
51890 - 0 0 0 0 0 0 0 0 0 0 0 0
51891 - 0 0 0 0 0 0 0 0 1 0 0 0
51892 - 0 0 1 0 0 0 0 0 1 0 0 0
51893 - 0 0 0 0 0 0 0 0 0 0 0 0
51894 - 0 0 0 0 0 0 0 0 0 0 0 0
51895 - 0 0 0 0 0 0 0 0 0 0 0 0
51896 - 0 0 0 0 0 0 0 0 0 0 0 0
51897 - 0 0 0 0 0 0 0 0 0 14 14 14
51898 - 42 42 42 94 94 94 14 14 14 101 101 101
51899 -128 128 128 2 2 6 18 18 18 116 116 116
51900 -118 98 46 121 92 8 121 92 8 98 78 10
51901 -162 162 162 106 106 106 2 2 6 2 2 6
51902 - 2 2 6 195 195 195 195 195 195 6 6 6
51903 - 2 2 6 2 2 6 2 2 6 2 2 6
51904 - 74 74 74 62 62 62 22 22 22 6 6 6
51905 - 0 0 0 0 0 0 0 0 0 0 0 0
51906 - 0 0 0 0 0 0 0 0 0 0 0 0
51907 - 0 0 0 0 0 0 0 0 0 0 0 0
51908 - 0 0 0 0 0 0 0 0 0 0 0 0
51909 - 0 0 0 0 0 0 0 0 0 0 0 0
51910 - 0 0 0 0 0 0 0 0 0 0 0 0
51911 - 0 0 0 0 0 0 0 0 1 0 0 1
51912 - 0 0 1 0 0 0 0 0 1 0 0 0
51913 - 0 0 0 0 0 0 0 0 0 0 0 0
51914 - 0 0 0 0 0 0 0 0 0 0 0 0
51915 - 0 0 0 0 0 0 0 0 0 0 0 0
51916 - 0 0 0 0 0 0 0 0 0 0 0 0
51917 - 0 0 0 0 0 0 0 0 0 10 10 10
51918 - 38 38 38 90 90 90 14 14 14 58 58 58
51919 -210 210 210 26 26 26 54 38 6 154 114 10
51920 -226 170 11 236 186 11 225 175 15 184 144 12
51921 -215 174 15 175 146 61 37 26 9 2 2 6
51922 - 70 70 70 246 246 246 138 138 138 2 2 6
51923 - 2 2 6 2 2 6 2 2 6 2 2 6
51924 - 70 70 70 66 66 66 26 26 26 6 6 6
51925 - 0 0 0 0 0 0 0 0 0 0 0 0
51926 - 0 0 0 0 0 0 0 0 0 0 0 0
51927 - 0 0 0 0 0 0 0 0 0 0 0 0
51928 - 0 0 0 0 0 0 0 0 0 0 0 0
51929 - 0 0 0 0 0 0 0 0 0 0 0 0
51930 - 0 0 0 0 0 0 0 0 0 0 0 0
51931 - 0 0 0 0 0 0 0 0 0 0 0 0
51932 - 0 0 0 0 0 0 0 0 0 0 0 0
51933 - 0 0 0 0 0 0 0 0 0 0 0 0
51934 - 0 0 0 0 0 0 0 0 0 0 0 0
51935 - 0 0 0 0 0 0 0 0 0 0 0 0
51936 - 0 0 0 0 0 0 0 0 0 0 0 0
51937 - 0 0 0 0 0 0 0 0 0 10 10 10
51938 - 38 38 38 86 86 86 14 14 14 10 10 10
51939 -195 195 195 188 164 115 192 133 9 225 175 15
51940 -239 182 13 234 190 10 232 195 16 232 200 30
51941 -245 207 45 241 208 19 232 195 16 184 144 12
51942 -218 194 134 211 206 186 42 42 42 2 2 6
51943 - 2 2 6 2 2 6 2 2 6 2 2 6
51944 - 50 50 50 74 74 74 30 30 30 6 6 6
51945 - 0 0 0 0 0 0 0 0 0 0 0 0
51946 - 0 0 0 0 0 0 0 0 0 0 0 0
51947 - 0 0 0 0 0 0 0 0 0 0 0 0
51948 - 0 0 0 0 0 0 0 0 0 0 0 0
51949 - 0 0 0 0 0 0 0 0 0 0 0 0
51950 - 0 0 0 0 0 0 0 0 0 0 0 0
51951 - 0 0 0 0 0 0 0 0 0 0 0 0
51952 - 0 0 0 0 0 0 0 0 0 0 0 0
51953 - 0 0 0 0 0 0 0 0 0 0 0 0
51954 - 0 0 0 0 0 0 0 0 0 0 0 0
51955 - 0 0 0 0 0 0 0 0 0 0 0 0
51956 - 0 0 0 0 0 0 0 0 0 0 0 0
51957 - 0 0 0 0 0 0 0 0 0 10 10 10
51958 - 34 34 34 86 86 86 14 14 14 2 2 6
51959 -121 87 25 192 133 9 219 162 10 239 182 13
51960 -236 186 11 232 195 16 241 208 19 244 214 54
51961 -246 218 60 246 218 38 246 215 20 241 208 19
51962 -241 208 19 226 184 13 121 87 25 2 2 6
51963 - 2 2 6 2 2 6 2 2 6 2 2 6
51964 - 50 50 50 82 82 82 34 34 34 10 10 10
51965 - 0 0 0 0 0 0 0 0 0 0 0 0
51966 - 0 0 0 0 0 0 0 0 0 0 0 0
51967 - 0 0 0 0 0 0 0 0 0 0 0 0
51968 - 0 0 0 0 0 0 0 0 0 0 0 0
51969 - 0 0 0 0 0 0 0 0 0 0 0 0
51970 - 0 0 0 0 0 0 0 0 0 0 0 0
51971 - 0 0 0 0 0 0 0 0 0 0 0 0
51972 - 0 0 0 0 0 0 0 0 0 0 0 0
51973 - 0 0 0 0 0 0 0 0 0 0 0 0
51974 - 0 0 0 0 0 0 0 0 0 0 0 0
51975 - 0 0 0 0 0 0 0 0 0 0 0 0
51976 - 0 0 0 0 0 0 0 0 0 0 0 0
51977 - 0 0 0 0 0 0 0 0 0 10 10 10
51978 - 34 34 34 82 82 82 30 30 30 61 42 6
51979 -180 123 7 206 145 10 230 174 11 239 182 13
51980 -234 190 10 238 202 15 241 208 19 246 218 74
51981 -246 218 38 246 215 20 246 215 20 246 215 20
51982 -226 184 13 215 174 15 184 144 12 6 6 6
51983 - 2 2 6 2 2 6 2 2 6 2 2 6
51984 - 26 26 26 94 94 94 42 42 42 14 14 14
51985 - 0 0 0 0 0 0 0 0 0 0 0 0
51986 - 0 0 0 0 0 0 0 0 0 0 0 0
51987 - 0 0 0 0 0 0 0 0 0 0 0 0
51988 - 0 0 0 0 0 0 0 0 0 0 0 0
51989 - 0 0 0 0 0 0 0 0 0 0 0 0
51990 - 0 0 0 0 0 0 0 0 0 0 0 0
51991 - 0 0 0 0 0 0 0 0 0 0 0 0
51992 - 0 0 0 0 0 0 0 0 0 0 0 0
51993 - 0 0 0 0 0 0 0 0 0 0 0 0
51994 - 0 0 0 0 0 0 0 0 0 0 0 0
51995 - 0 0 0 0 0 0 0 0 0 0 0 0
51996 - 0 0 0 0 0 0 0 0 0 0 0 0
51997 - 0 0 0 0 0 0 0 0 0 10 10 10
51998 - 30 30 30 78 78 78 50 50 50 104 69 6
51999 -192 133 9 216 158 10 236 178 12 236 186 11
52000 -232 195 16 241 208 19 244 214 54 245 215 43
52001 -246 215 20 246 215 20 241 208 19 198 155 10
52002 -200 144 11 216 158 10 156 118 10 2 2 6
52003 - 2 2 6 2 2 6 2 2 6 2 2 6
52004 - 6 6 6 90 90 90 54 54 54 18 18 18
52005 - 6 6 6 0 0 0 0 0 0 0 0 0
52006 - 0 0 0 0 0 0 0 0 0 0 0 0
52007 - 0 0 0 0 0 0 0 0 0 0 0 0
52008 - 0 0 0 0 0 0 0 0 0 0 0 0
52009 - 0 0 0 0 0 0 0 0 0 0 0 0
52010 - 0 0 0 0 0 0 0 0 0 0 0 0
52011 - 0 0 0 0 0 0 0 0 0 0 0 0
52012 - 0 0 0 0 0 0 0 0 0 0 0 0
52013 - 0 0 0 0 0 0 0 0 0 0 0 0
52014 - 0 0 0 0 0 0 0 0 0 0 0 0
52015 - 0 0 0 0 0 0 0 0 0 0 0 0
52016 - 0 0 0 0 0 0 0 0 0 0 0 0
52017 - 0 0 0 0 0 0 0 0 0 10 10 10
52018 - 30 30 30 78 78 78 46 46 46 22 22 22
52019 -137 92 6 210 162 10 239 182 13 238 190 10
52020 -238 202 15 241 208 19 246 215 20 246 215 20
52021 -241 208 19 203 166 17 185 133 11 210 150 10
52022 -216 158 10 210 150 10 102 78 10 2 2 6
52023 - 6 6 6 54 54 54 14 14 14 2 2 6
52024 - 2 2 6 62 62 62 74 74 74 30 30 30
52025 - 10 10 10 0 0 0 0 0 0 0 0 0
52026 - 0 0 0 0 0 0 0 0 0 0 0 0
52027 - 0 0 0 0 0 0 0 0 0 0 0 0
52028 - 0 0 0 0 0 0 0 0 0 0 0 0
52029 - 0 0 0 0 0 0 0 0 0 0 0 0
52030 - 0 0 0 0 0 0 0 0 0 0 0 0
52031 - 0 0 0 0 0 0 0 0 0 0 0 0
52032 - 0 0 0 0 0 0 0 0 0 0 0 0
52033 - 0 0 0 0 0 0 0 0 0 0 0 0
52034 - 0 0 0 0 0 0 0 0 0 0 0 0
52035 - 0 0 0 0 0 0 0 0 0 0 0 0
52036 - 0 0 0 0 0 0 0 0 0 0 0 0
52037 - 0 0 0 0 0 0 0 0 0 10 10 10
52038 - 34 34 34 78 78 78 50 50 50 6 6 6
52039 - 94 70 30 139 102 15 190 146 13 226 184 13
52040 -232 200 30 232 195 16 215 174 15 190 146 13
52041 -168 122 10 192 133 9 210 150 10 213 154 11
52042 -202 150 34 182 157 106 101 98 89 2 2 6
52043 - 2 2 6 78 78 78 116 116 116 58 58 58
52044 - 2 2 6 22 22 22 90 90 90 46 46 46
52045 - 18 18 18 6 6 6 0 0 0 0 0 0
52046 - 0 0 0 0 0 0 0 0 0 0 0 0
52047 - 0 0 0 0 0 0 0 0 0 0 0 0
52048 - 0 0 0 0 0 0 0 0 0 0 0 0
52049 - 0 0 0 0 0 0 0 0 0 0 0 0
52050 - 0 0 0 0 0 0 0 0 0 0 0 0
52051 - 0 0 0 0 0 0 0 0 0 0 0 0
52052 - 0 0 0 0 0 0 0 0 0 0 0 0
52053 - 0 0 0 0 0 0 0 0 0 0 0 0
52054 - 0 0 0 0 0 0 0 0 0 0 0 0
52055 - 0 0 0 0 0 0 0 0 0 0 0 0
52056 - 0 0 0 0 0 0 0 0 0 0 0 0
52057 - 0 0 0 0 0 0 0 0 0 10 10 10
52058 - 38 38 38 86 86 86 50 50 50 6 6 6
52059 -128 128 128 174 154 114 156 107 11 168 122 10
52060 -198 155 10 184 144 12 197 138 11 200 144 11
52061 -206 145 10 206 145 10 197 138 11 188 164 115
52062 -195 195 195 198 198 198 174 174 174 14 14 14
52063 - 2 2 6 22 22 22 116 116 116 116 116 116
52064 - 22 22 22 2 2 6 74 74 74 70 70 70
52065 - 30 30 30 10 10 10 0 0 0 0 0 0
52066 - 0 0 0 0 0 0 0 0 0 0 0 0
52067 - 0 0 0 0 0 0 0 0 0 0 0 0
52068 - 0 0 0 0 0 0 0 0 0 0 0 0
52069 - 0 0 0 0 0 0 0 0 0 0 0 0
52070 - 0 0 0 0 0 0 0 0 0 0 0 0
52071 - 0 0 0 0 0 0 0 0 0 0 0 0
52072 - 0 0 0 0 0 0 0 0 0 0 0 0
52073 - 0 0 0 0 0 0 0 0 0 0 0 0
52074 - 0 0 0 0 0 0 0 0 0 0 0 0
52075 - 0 0 0 0 0 0 0 0 0 0 0 0
52076 - 0 0 0 0 0 0 0 0 0 0 0 0
52077 - 0 0 0 0 0 0 6 6 6 18 18 18
52078 - 50 50 50 101 101 101 26 26 26 10 10 10
52079 -138 138 138 190 190 190 174 154 114 156 107 11
52080 -197 138 11 200 144 11 197 138 11 192 133 9
52081 -180 123 7 190 142 34 190 178 144 187 187 187
52082 -202 202 202 221 221 221 214 214 214 66 66 66
52083 - 2 2 6 2 2 6 50 50 50 62 62 62
52084 - 6 6 6 2 2 6 10 10 10 90 90 90
52085 - 50 50 50 18 18 18 6 6 6 0 0 0
52086 - 0 0 0 0 0 0 0 0 0 0 0 0
52087 - 0 0 0 0 0 0 0 0 0 0 0 0
52088 - 0 0 0 0 0 0 0 0 0 0 0 0
52089 - 0 0 0 0 0 0 0 0 0 0 0 0
52090 - 0 0 0 0 0 0 0 0 0 0 0 0
52091 - 0 0 0 0 0 0 0 0 0 0 0 0
52092 - 0 0 0 0 0 0 0 0 0 0 0 0
52093 - 0 0 0 0 0 0 0 0 0 0 0 0
52094 - 0 0 0 0 0 0 0 0 0 0 0 0
52095 - 0 0 0 0 0 0 0 0 0 0 0 0
52096 - 0 0 0 0 0 0 0 0 0 0 0 0
52097 - 0 0 0 0 0 0 10 10 10 34 34 34
52098 - 74 74 74 74 74 74 2 2 6 6 6 6
52099 -144 144 144 198 198 198 190 190 190 178 166 146
52100 -154 121 60 156 107 11 156 107 11 168 124 44
52101 -174 154 114 187 187 187 190 190 190 210 210 210
52102 -246 246 246 253 253 253 253 253 253 182 182 182
52103 - 6 6 6 2 2 6 2 2 6 2 2 6
52104 - 2 2 6 2 2 6 2 2 6 62 62 62
52105 - 74 74 74 34 34 34 14 14 14 0 0 0
52106 - 0 0 0 0 0 0 0 0 0 0 0 0
52107 - 0 0 0 0 0 0 0 0 0 0 0 0
52108 - 0 0 0 0 0 0 0 0 0 0 0 0
52109 - 0 0 0 0 0 0 0 0 0 0 0 0
52110 - 0 0 0 0 0 0 0 0 0 0 0 0
52111 - 0 0 0 0 0 0 0 0 0 0 0 0
52112 - 0 0 0 0 0 0 0 0 0 0 0 0
52113 - 0 0 0 0 0 0 0 0 0 0 0 0
52114 - 0 0 0 0 0 0 0 0 0 0 0 0
52115 - 0 0 0 0 0 0 0 0 0 0 0 0
52116 - 0 0 0 0 0 0 0 0 0 0 0 0
52117 - 0 0 0 10 10 10 22 22 22 54 54 54
52118 - 94 94 94 18 18 18 2 2 6 46 46 46
52119 -234 234 234 221 221 221 190 190 190 190 190 190
52120 -190 190 190 187 187 187 187 187 187 190 190 190
52121 -190 190 190 195 195 195 214 214 214 242 242 242
52122 -253 253 253 253 253 253 253 253 253 253 253 253
52123 - 82 82 82 2 2 6 2 2 6 2 2 6
52124 - 2 2 6 2 2 6 2 2 6 14 14 14
52125 - 86 86 86 54 54 54 22 22 22 6 6 6
52126 - 0 0 0 0 0 0 0 0 0 0 0 0
52127 - 0 0 0 0 0 0 0 0 0 0 0 0
52128 - 0 0 0 0 0 0 0 0 0 0 0 0
52129 - 0 0 0 0 0 0 0 0 0 0 0 0
52130 - 0 0 0 0 0 0 0 0 0 0 0 0
52131 - 0 0 0 0 0 0 0 0 0 0 0 0
52132 - 0 0 0 0 0 0 0 0 0 0 0 0
52133 - 0 0 0 0 0 0 0 0 0 0 0 0
52134 - 0 0 0 0 0 0 0 0 0 0 0 0
52135 - 0 0 0 0 0 0 0 0 0 0 0 0
52136 - 0 0 0 0 0 0 0 0 0 0 0 0
52137 - 6 6 6 18 18 18 46 46 46 90 90 90
52138 - 46 46 46 18 18 18 6 6 6 182 182 182
52139 -253 253 253 246 246 246 206 206 206 190 190 190
52140 -190 190 190 190 190 190 190 190 190 190 190 190
52141 -206 206 206 231 231 231 250 250 250 253 253 253
52142 -253 253 253 253 253 253 253 253 253 253 253 253
52143 -202 202 202 14 14 14 2 2 6 2 2 6
52144 - 2 2 6 2 2 6 2 2 6 2 2 6
52145 - 42 42 42 86 86 86 42 42 42 18 18 18
52146 - 6 6 6 0 0 0 0 0 0 0 0 0
52147 - 0 0 0 0 0 0 0 0 0 0 0 0
52148 - 0 0 0 0 0 0 0 0 0 0 0 0
52149 - 0 0 0 0 0 0 0 0 0 0 0 0
52150 - 0 0 0 0 0 0 0 0 0 0 0 0
52151 - 0 0 0 0 0 0 0 0 0 0 0 0
52152 - 0 0 0 0 0 0 0 0 0 0 0 0
52153 - 0 0 0 0 0 0 0 0 0 0 0 0
52154 - 0 0 0 0 0 0 0 0 0 0 0 0
52155 - 0 0 0 0 0 0 0 0 0 0 0 0
52156 - 0 0 0 0 0 0 0 0 0 6 6 6
52157 - 14 14 14 38 38 38 74 74 74 66 66 66
52158 - 2 2 6 6 6 6 90 90 90 250 250 250
52159 -253 253 253 253 253 253 238 238 238 198 198 198
52160 -190 190 190 190 190 190 195 195 195 221 221 221
52161 -246 246 246 253 253 253 253 253 253 253 253 253
52162 -253 253 253 253 253 253 253 253 253 253 253 253
52163 -253 253 253 82 82 82 2 2 6 2 2 6
52164 - 2 2 6 2 2 6 2 2 6 2 2 6
52165 - 2 2 6 78 78 78 70 70 70 34 34 34
52166 - 14 14 14 6 6 6 0 0 0 0 0 0
52167 - 0 0 0 0 0 0 0 0 0 0 0 0
52168 - 0 0 0 0 0 0 0 0 0 0 0 0
52169 - 0 0 0 0 0 0 0 0 0 0 0 0
52170 - 0 0 0 0 0 0 0 0 0 0 0 0
52171 - 0 0 0 0 0 0 0 0 0 0 0 0
52172 - 0 0 0 0 0 0 0 0 0 0 0 0
52173 - 0 0 0 0 0 0 0 0 0 0 0 0
52174 - 0 0 0 0 0 0 0 0 0 0 0 0
52175 - 0 0 0 0 0 0 0 0 0 0 0 0
52176 - 0 0 0 0 0 0 0 0 0 14 14 14
52177 - 34 34 34 66 66 66 78 78 78 6 6 6
52178 - 2 2 6 18 18 18 218 218 218 253 253 253
52179 -253 253 253 253 253 253 253 253 253 246 246 246
52180 -226 226 226 231 231 231 246 246 246 253 253 253
52181 -253 253 253 253 253 253 253 253 253 253 253 253
52182 -253 253 253 253 253 253 253 253 253 253 253 253
52183 -253 253 253 178 178 178 2 2 6 2 2 6
52184 - 2 2 6 2 2 6 2 2 6 2 2 6
52185 - 2 2 6 18 18 18 90 90 90 62 62 62
52186 - 30 30 30 10 10 10 0 0 0 0 0 0
52187 - 0 0 0 0 0 0 0 0 0 0 0 0
52188 - 0 0 0 0 0 0 0 0 0 0 0 0
52189 - 0 0 0 0 0 0 0 0 0 0 0 0
52190 - 0 0 0 0 0 0 0 0 0 0 0 0
52191 - 0 0 0 0 0 0 0 0 0 0 0 0
52192 - 0 0 0 0 0 0 0 0 0 0 0 0
52193 - 0 0 0 0 0 0 0 0 0 0 0 0
52194 - 0 0 0 0 0 0 0 0 0 0 0 0
52195 - 0 0 0 0 0 0 0 0 0 0 0 0
52196 - 0 0 0 0 0 0 10 10 10 26 26 26
52197 - 58 58 58 90 90 90 18 18 18 2 2 6
52198 - 2 2 6 110 110 110 253 253 253 253 253 253
52199 -253 253 253 253 253 253 253 253 253 253 253 253
52200 -250 250 250 253 253 253 253 253 253 253 253 253
52201 -253 253 253 253 253 253 253 253 253 253 253 253
52202 -253 253 253 253 253 253 253 253 253 253 253 253
52203 -253 253 253 231 231 231 18 18 18 2 2 6
52204 - 2 2 6 2 2 6 2 2 6 2 2 6
52205 - 2 2 6 2 2 6 18 18 18 94 94 94
52206 - 54 54 54 26 26 26 10 10 10 0 0 0
52207 - 0 0 0 0 0 0 0 0 0 0 0 0
52208 - 0 0 0 0 0 0 0 0 0 0 0 0
52209 - 0 0 0 0 0 0 0 0 0 0 0 0
52210 - 0 0 0 0 0 0 0 0 0 0 0 0
52211 - 0 0 0 0 0 0 0 0 0 0 0 0
52212 - 0 0 0 0 0 0 0 0 0 0 0 0
52213 - 0 0 0 0 0 0 0 0 0 0 0 0
52214 - 0 0 0 0 0 0 0 0 0 0 0 0
52215 - 0 0 0 0 0 0 0 0 0 0 0 0
52216 - 0 0 0 6 6 6 22 22 22 50 50 50
52217 - 90 90 90 26 26 26 2 2 6 2 2 6
52218 - 14 14 14 195 195 195 250 250 250 253 253 253
52219 -253 253 253 253 253 253 253 253 253 253 253 253
52220 -253 253 253 253 253 253 253 253 253 253 253 253
52221 -253 253 253 253 253 253 253 253 253 253 253 253
52222 -253 253 253 253 253 253 253 253 253 253 253 253
52223 -250 250 250 242 242 242 54 54 54 2 2 6
52224 - 2 2 6 2 2 6 2 2 6 2 2 6
52225 - 2 2 6 2 2 6 2 2 6 38 38 38
52226 - 86 86 86 50 50 50 22 22 22 6 6 6
52227 - 0 0 0 0 0 0 0 0 0 0 0 0
52228 - 0 0 0 0 0 0 0 0 0 0 0 0
52229 - 0 0 0 0 0 0 0 0 0 0 0 0
52230 - 0 0 0 0 0 0 0 0 0 0 0 0
52231 - 0 0 0 0 0 0 0 0 0 0 0 0
52232 - 0 0 0 0 0 0 0 0 0 0 0 0
52233 - 0 0 0 0 0 0 0 0 0 0 0 0
52234 - 0 0 0 0 0 0 0 0 0 0 0 0
52235 - 0 0 0 0 0 0 0 0 0 0 0 0
52236 - 6 6 6 14 14 14 38 38 38 82 82 82
52237 - 34 34 34 2 2 6 2 2 6 2 2 6
52238 - 42 42 42 195 195 195 246 246 246 253 253 253
52239 -253 253 253 253 253 253 253 253 253 250 250 250
52240 -242 242 242 242 242 242 250 250 250 253 253 253
52241 -253 253 253 253 253 253 253 253 253 253 253 253
52242 -253 253 253 250 250 250 246 246 246 238 238 238
52243 -226 226 226 231 231 231 101 101 101 6 6 6
52244 - 2 2 6 2 2 6 2 2 6 2 2 6
52245 - 2 2 6 2 2 6 2 2 6 2 2 6
52246 - 38 38 38 82 82 82 42 42 42 14 14 14
52247 - 6 6 6 0 0 0 0 0 0 0 0 0
52248 - 0 0 0 0 0 0 0 0 0 0 0 0
52249 - 0 0 0 0 0 0 0 0 0 0 0 0
52250 - 0 0 0 0 0 0 0 0 0 0 0 0
52251 - 0 0 0 0 0 0 0 0 0 0 0 0
52252 - 0 0 0 0 0 0 0 0 0 0 0 0
52253 - 0 0 0 0 0 0 0 0 0 0 0 0
52254 - 0 0 0 0 0 0 0 0 0 0 0 0
52255 - 0 0 0 0 0 0 0 0 0 0 0 0
52256 - 10 10 10 26 26 26 62 62 62 66 66 66
52257 - 2 2 6 2 2 6 2 2 6 6 6 6
52258 - 70 70 70 170 170 170 206 206 206 234 234 234
52259 -246 246 246 250 250 250 250 250 250 238 238 238
52260 -226 226 226 231 231 231 238 238 238 250 250 250
52261 -250 250 250 250 250 250 246 246 246 231 231 231
52262 -214 214 214 206 206 206 202 202 202 202 202 202
52263 -198 198 198 202 202 202 182 182 182 18 18 18
52264 - 2 2 6 2 2 6 2 2 6 2 2 6
52265 - 2 2 6 2 2 6 2 2 6 2 2 6
52266 - 2 2 6 62 62 62 66 66 66 30 30 30
52267 - 10 10 10 0 0 0 0 0 0 0 0 0
52268 - 0 0 0 0 0 0 0 0 0 0 0 0
52269 - 0 0 0 0 0 0 0 0 0 0 0 0
52270 - 0 0 0 0 0 0 0 0 0 0 0 0
52271 - 0 0 0 0 0 0 0 0 0 0 0 0
52272 - 0 0 0 0 0 0 0 0 0 0 0 0
52273 - 0 0 0 0 0 0 0 0 0 0 0 0
52274 - 0 0 0 0 0 0 0 0 0 0 0 0
52275 - 0 0 0 0 0 0 0 0 0 0 0 0
52276 - 14 14 14 42 42 42 82 82 82 18 18 18
52277 - 2 2 6 2 2 6 2 2 6 10 10 10
52278 - 94 94 94 182 182 182 218 218 218 242 242 242
52279 -250 250 250 253 253 253 253 253 253 250 250 250
52280 -234 234 234 253 253 253 253 253 253 253 253 253
52281 -253 253 253 253 253 253 253 253 253 246 246 246
52282 -238 238 238 226 226 226 210 210 210 202 202 202
52283 -195 195 195 195 195 195 210 210 210 158 158 158
52284 - 6 6 6 14 14 14 50 50 50 14 14 14
52285 - 2 2 6 2 2 6 2 2 6 2 2 6
52286 - 2 2 6 6 6 6 86 86 86 46 46 46
52287 - 18 18 18 6 6 6 0 0 0 0 0 0
52288 - 0 0 0 0 0 0 0 0 0 0 0 0
52289 - 0 0 0 0 0 0 0 0 0 0 0 0
52290 - 0 0 0 0 0 0 0 0 0 0 0 0
52291 - 0 0 0 0 0 0 0 0 0 0 0 0
52292 - 0 0 0 0 0 0 0 0 0 0 0 0
52293 - 0 0 0 0 0 0 0 0 0 0 0 0
52294 - 0 0 0 0 0 0 0 0 0 0 0 0
52295 - 0 0 0 0 0 0 0 0 0 6 6 6
52296 - 22 22 22 54 54 54 70 70 70 2 2 6
52297 - 2 2 6 10 10 10 2 2 6 22 22 22
52298 -166 166 166 231 231 231 250 250 250 253 253 253
52299 -253 253 253 253 253 253 253 253 253 250 250 250
52300 -242 242 242 253 253 253 253 253 253 253 253 253
52301 -253 253 253 253 253 253 253 253 253 253 253 253
52302 -253 253 253 253 253 253 253 253 253 246 246 246
52303 -231 231 231 206 206 206 198 198 198 226 226 226
52304 - 94 94 94 2 2 6 6 6 6 38 38 38
52305 - 30 30 30 2 2 6 2 2 6 2 2 6
52306 - 2 2 6 2 2 6 62 62 62 66 66 66
52307 - 26 26 26 10 10 10 0 0 0 0 0 0
52308 - 0 0 0 0 0 0 0 0 0 0 0 0
52309 - 0 0 0 0 0 0 0 0 0 0 0 0
52310 - 0 0 0 0 0 0 0 0 0 0 0 0
52311 - 0 0 0 0 0 0 0 0 0 0 0 0
52312 - 0 0 0 0 0 0 0 0 0 0 0 0
52313 - 0 0 0 0 0 0 0 0 0 0 0 0
52314 - 0 0 0 0 0 0 0 0 0 0 0 0
52315 - 0 0 0 0 0 0 0 0 0 10 10 10
52316 - 30 30 30 74 74 74 50 50 50 2 2 6
52317 - 26 26 26 26 26 26 2 2 6 106 106 106
52318 -238 238 238 253 253 253 253 253 253 253 253 253
52319 -253 253 253 253 253 253 253 253 253 253 253 253
52320 -253 253 253 253 253 253 253 253 253 253 253 253
52321 -253 253 253 253 253 253 253 253 253 253 253 253
52322 -253 253 253 253 253 253 253 253 253 253 253 253
52323 -253 253 253 246 246 246 218 218 218 202 202 202
52324 -210 210 210 14 14 14 2 2 6 2 2 6
52325 - 30 30 30 22 22 22 2 2 6 2 2 6
52326 - 2 2 6 2 2 6 18 18 18 86 86 86
52327 - 42 42 42 14 14 14 0 0 0 0 0 0
52328 - 0 0 0 0 0 0 0 0 0 0 0 0
52329 - 0 0 0 0 0 0 0 0 0 0 0 0
52330 - 0 0 0 0 0 0 0 0 0 0 0 0
52331 - 0 0 0 0 0 0 0 0 0 0 0 0
52332 - 0 0 0 0 0 0 0 0 0 0 0 0
52333 - 0 0 0 0 0 0 0 0 0 0 0 0
52334 - 0 0 0 0 0 0 0 0 0 0 0 0
52335 - 0 0 0 0 0 0 0 0 0 14 14 14
52336 - 42 42 42 90 90 90 22 22 22 2 2 6
52337 - 42 42 42 2 2 6 18 18 18 218 218 218
52338 -253 253 253 253 253 253 253 253 253 253 253 253
52339 -253 253 253 253 253 253 253 253 253 253 253 253
52340 -253 253 253 253 253 253 253 253 253 253 253 253
52341 -253 253 253 253 253 253 253 253 253 253 253 253
52342 -253 253 253 253 253 253 253 253 253 253 253 253
52343 -253 253 253 253 253 253 250 250 250 221 221 221
52344 -218 218 218 101 101 101 2 2 6 14 14 14
52345 - 18 18 18 38 38 38 10 10 10 2 2 6
52346 - 2 2 6 2 2 6 2 2 6 78 78 78
52347 - 58 58 58 22 22 22 6 6 6 0 0 0
52348 - 0 0 0 0 0 0 0 0 0 0 0 0
52349 - 0 0 0 0 0 0 0 0 0 0 0 0
52350 - 0 0 0 0 0 0 0 0 0 0 0 0
52351 - 0 0 0 0 0 0 0 0 0 0 0 0
52352 - 0 0 0 0 0 0 0 0 0 0 0 0
52353 - 0 0 0 0 0 0 0 0 0 0 0 0
52354 - 0 0 0 0 0 0 0 0 0 0 0 0
52355 - 0 0 0 0 0 0 6 6 6 18 18 18
52356 - 54 54 54 82 82 82 2 2 6 26 26 26
52357 - 22 22 22 2 2 6 123 123 123 253 253 253
52358 -253 253 253 253 253 253 253 253 253 253 253 253
52359 -253 253 253 253 253 253 253 253 253 253 253 253
52360 -253 253 253 253 253 253 253 253 253 253 253 253
52361 -253 253 253 253 253 253 253 253 253 253 253 253
52362 -253 253 253 253 253 253 253 253 253 253 253 253
52363 -253 253 253 253 253 253 253 253 253 250 250 250
52364 -238 238 238 198 198 198 6 6 6 38 38 38
52365 - 58 58 58 26 26 26 38 38 38 2 2 6
52366 - 2 2 6 2 2 6 2 2 6 46 46 46
52367 - 78 78 78 30 30 30 10 10 10 0 0 0
52368 - 0 0 0 0 0 0 0 0 0 0 0 0
52369 - 0 0 0 0 0 0 0 0 0 0 0 0
52370 - 0 0 0 0 0 0 0 0 0 0 0 0
52371 - 0 0 0 0 0 0 0 0 0 0 0 0
52372 - 0 0 0 0 0 0 0 0 0 0 0 0
52373 - 0 0 0 0 0 0 0 0 0 0 0 0
52374 - 0 0 0 0 0 0 0 0 0 0 0 0
52375 - 0 0 0 0 0 0 10 10 10 30 30 30
52376 - 74 74 74 58 58 58 2 2 6 42 42 42
52377 - 2 2 6 22 22 22 231 231 231 253 253 253
52378 -253 253 253 253 253 253 253 253 253 253 253 253
52379 -253 253 253 253 253 253 253 253 253 250 250 250
52380 -253 253 253 253 253 253 253 253 253 253 253 253
52381 -253 253 253 253 253 253 253 253 253 253 253 253
52382 -253 253 253 253 253 253 253 253 253 253 253 253
52383 -253 253 253 253 253 253 253 253 253 253 253 253
52384 -253 253 253 246 246 246 46 46 46 38 38 38
52385 - 42 42 42 14 14 14 38 38 38 14 14 14
52386 - 2 2 6 2 2 6 2 2 6 6 6 6
52387 - 86 86 86 46 46 46 14 14 14 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 6 6 6 14 14 14 42 42 42
52396 - 90 90 90 18 18 18 18 18 18 26 26 26
52397 - 2 2 6 116 116 116 253 253 253 253 253 253
52398 -253 253 253 253 253 253 253 253 253 253 253 253
52399 -253 253 253 253 253 253 250 250 250 238 238 238
52400 -253 253 253 253 253 253 253 253 253 253 253 253
52401 -253 253 253 253 253 253 253 253 253 253 253 253
52402 -253 253 253 253 253 253 253 253 253 253 253 253
52403 -253 253 253 253 253 253 253 253 253 253 253 253
52404 -253 253 253 253 253 253 94 94 94 6 6 6
52405 - 2 2 6 2 2 6 10 10 10 34 34 34
52406 - 2 2 6 2 2 6 2 2 6 2 2 6
52407 - 74 74 74 58 58 58 22 22 22 6 6 6
52408 - 0 0 0 0 0 0 0 0 0 0 0 0
52409 - 0 0 0 0 0 0 0 0 0 0 0 0
52410 - 0 0 0 0 0 0 0 0 0 0 0 0
52411 - 0 0 0 0 0 0 0 0 0 0 0 0
52412 - 0 0 0 0 0 0 0 0 0 0 0 0
52413 - 0 0 0 0 0 0 0 0 0 0 0 0
52414 - 0 0 0 0 0 0 0 0 0 0 0 0
52415 - 0 0 0 10 10 10 26 26 26 66 66 66
52416 - 82 82 82 2 2 6 38 38 38 6 6 6
52417 - 14 14 14 210 210 210 253 253 253 253 253 253
52418 -253 253 253 253 253 253 253 253 253 253 253 253
52419 -253 253 253 253 253 253 246 246 246 242 242 242
52420 -253 253 253 253 253 253 253 253 253 253 253 253
52421 -253 253 253 253 253 253 253 253 253 253 253 253
52422 -253 253 253 253 253 253 253 253 253 253 253 253
52423 -253 253 253 253 253 253 253 253 253 253 253 253
52424 -253 253 253 253 253 253 144 144 144 2 2 6
52425 - 2 2 6 2 2 6 2 2 6 46 46 46
52426 - 2 2 6 2 2 6 2 2 6 2 2 6
52427 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0 0 0 0 0 0 0 0
52433 - 0 0 0 0 0 0 0 0 0 0 0 0
52434 - 0 0 0 0 0 0 0 0 0 0 0 0
52435 - 6 6 6 14 14 14 42 42 42 90 90 90
52436 - 26 26 26 6 6 6 42 42 42 2 2 6
52437 - 74 74 74 250 250 250 253 253 253 253 253 253
52438 -253 253 253 253 253 253 253 253 253 253 253 253
52439 -253 253 253 253 253 253 242 242 242 242 242 242
52440 -253 253 253 253 253 253 253 253 253 253 253 253
52441 -253 253 253 253 253 253 253 253 253 253 253 253
52442 -253 253 253 253 253 253 253 253 253 253 253 253
52443 -253 253 253 253 253 253 253 253 253 253 253 253
52444 -253 253 253 253 253 253 182 182 182 2 2 6
52445 - 2 2 6 2 2 6 2 2 6 46 46 46
52446 - 2 2 6 2 2 6 2 2 6 2 2 6
52447 - 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0 0 0 0 0 0 0 0
52453 - 0 0 0 0 0 0 0 0 0 0 0 0
52454 - 0 0 0 0 0 0 0 0 0 0 0 0
52455 - 10 10 10 26 26 26 66 66 66 82 82 82
52456 - 2 2 6 22 22 22 18 18 18 2 2 6
52457 -149 149 149 253 253 253 253 253 253 253 253 253
52458 -253 253 253 253 253 253 253 253 253 253 253 253
52459 -253 253 253 253 253 253 234 234 234 242 242 242
52460 -253 253 253 253 253 253 253 253 253 253 253 253
52461 -253 253 253 253 253 253 253 253 253 253 253 253
52462 -253 253 253 253 253 253 253 253 253 253 253 253
52463 -253 253 253 253 253 253 253 253 253 253 253 253
52464 -253 253 253 253 253 253 206 206 206 2 2 6
52465 - 2 2 6 2 2 6 2 2 6 38 38 38
52466 - 2 2 6 2 2 6 2 2 6 2 2 6
52467 - 6 6 6 86 86 86 46 46 46 14 14 14
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 6 6 6
52475 - 18 18 18 46 46 46 86 86 86 18 18 18
52476 - 2 2 6 34 34 34 10 10 10 6 6 6
52477 -210 210 210 253 253 253 253 253 253 253 253 253
52478 -253 253 253 253 253 253 253 253 253 253 253 253
52479 -253 253 253 253 253 253 234 234 234 242 242 242
52480 -253 253 253 253 253 253 253 253 253 253 253 253
52481 -253 253 253 253 253 253 253 253 253 253 253 253
52482 -253 253 253 253 253 253 253 253 253 253 253 253
52483 -253 253 253 253 253 253 253 253 253 253 253 253
52484 -253 253 253 253 253 253 221 221 221 6 6 6
52485 - 2 2 6 2 2 6 6 6 6 30 30 30
52486 - 2 2 6 2 2 6 2 2 6 2 2 6
52487 - 2 2 6 82 82 82 54 54 54 18 18 18
52488 - 6 6 6 0 0 0 0 0 0 0 0 0
52489 - 0 0 0 0 0 0 0 0 0 0 0 0
52490 - 0 0 0 0 0 0 0 0 0 0 0 0
52491 - 0 0 0 0 0 0 0 0 0 0 0 0
52492 - 0 0 0 0 0 0 0 0 0 0 0 0
52493 - 0 0 0 0 0 0 0 0 0 0 0 0
52494 - 0 0 0 0 0 0 0 0 0 10 10 10
52495 - 26 26 26 66 66 66 62 62 62 2 2 6
52496 - 2 2 6 38 38 38 10 10 10 26 26 26
52497 -238 238 238 253 253 253 253 253 253 253 253 253
52498 -253 253 253 253 253 253 253 253 253 253 253 253
52499 -253 253 253 253 253 253 231 231 231 238 238 238
52500 -253 253 253 253 253 253 253 253 253 253 253 253
52501 -253 253 253 253 253 253 253 253 253 253 253 253
52502 -253 253 253 253 253 253 253 253 253 253 253 253
52503 -253 253 253 253 253 253 253 253 253 253 253 253
52504 -253 253 253 253 253 253 231 231 231 6 6 6
52505 - 2 2 6 2 2 6 10 10 10 30 30 30
52506 - 2 2 6 2 2 6 2 2 6 2 2 6
52507 - 2 2 6 66 66 66 58 58 58 22 22 22
52508 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
52513 - 0 0 0 0 0 0 0 0 0 0 0 0
52514 - 0 0 0 0 0 0 0 0 0 10 10 10
52515 - 38 38 38 78 78 78 6 6 6 2 2 6
52516 - 2 2 6 46 46 46 14 14 14 42 42 42
52517 -246 246 246 253 253 253 253 253 253 253 253 253
52518 -253 253 253 253 253 253 253 253 253 253 253 253
52519 -253 253 253 253 253 253 231 231 231 242 242 242
52520 -253 253 253 253 253 253 253 253 253 253 253 253
52521 -253 253 253 253 253 253 253 253 253 253 253 253
52522 -253 253 253 253 253 253 253 253 253 253 253 253
52523 -253 253 253 253 253 253 253 253 253 253 253 253
52524 -253 253 253 253 253 253 234 234 234 10 10 10
52525 - 2 2 6 2 2 6 22 22 22 14 14 14
52526 - 2 2 6 2 2 6 2 2 6 2 2 6
52527 - 2 2 6 66 66 66 62 62 62 22 22 22
52528 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
52533 - 0 0 0 0 0 0 0 0 0 0 0 0
52534 - 0 0 0 0 0 0 6 6 6 18 18 18
52535 - 50 50 50 74 74 74 2 2 6 2 2 6
52536 - 14 14 14 70 70 70 34 34 34 62 62 62
52537 -250 250 250 253 253 253 253 253 253 253 253 253
52538 -253 253 253 253 253 253 253 253 253 253 253 253
52539 -253 253 253 253 253 253 231 231 231 246 246 246
52540 -253 253 253 253 253 253 253 253 253 253 253 253
52541 -253 253 253 253 253 253 253 253 253 253 253 253
52542 -253 253 253 253 253 253 253 253 253 253 253 253
52543 -253 253 253 253 253 253 253 253 253 253 253 253
52544 -253 253 253 253 253 253 234 234 234 14 14 14
52545 - 2 2 6 2 2 6 30 30 30 2 2 6
52546 - 2 2 6 2 2 6 2 2 6 2 2 6
52547 - 2 2 6 66 66 66 62 62 62 22 22 22
52548 - 6 6 6 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 6 6 6 18 18 18
52555 - 54 54 54 62 62 62 2 2 6 2 2 6
52556 - 2 2 6 30 30 30 46 46 46 70 70 70
52557 -250 250 250 253 253 253 253 253 253 253 253 253
52558 -253 253 253 253 253 253 253 253 253 253 253 253
52559 -253 253 253 253 253 253 231 231 231 246 246 246
52560 -253 253 253 253 253 253 253 253 253 253 253 253
52561 -253 253 253 253 253 253 253 253 253 253 253 253
52562 -253 253 253 253 253 253 253 253 253 253 253 253
52563 -253 253 253 253 253 253 253 253 253 253 253 253
52564 -253 253 253 253 253 253 226 226 226 10 10 10
52565 - 2 2 6 6 6 6 30 30 30 2 2 6
52566 - 2 2 6 2 2 6 2 2 6 2 2 6
52567 - 2 2 6 66 66 66 58 58 58 22 22 22
52568 - 6 6 6 0 0 0 0 0 0 0 0 0
52569 - 0 0 0 0 0 0 0 0 0 0 0 0
52570 - 0 0 0 0 0 0 0 0 0 0 0 0
52571 - 0 0 0 0 0 0 0 0 0 0 0 0
52572 - 0 0 0 0 0 0 0 0 0 0 0 0
52573 - 0 0 0 0 0 0 0 0 0 0 0 0
52574 - 0 0 0 0 0 0 6 6 6 22 22 22
52575 - 58 58 58 62 62 62 2 2 6 2 2 6
52576 - 2 2 6 2 2 6 30 30 30 78 78 78
52577 -250 250 250 253 253 253 253 253 253 253 253 253
52578 -253 253 253 253 253 253 253 253 253 253 253 253
52579 -253 253 253 253 253 253 231 231 231 246 246 246
52580 -253 253 253 253 253 253 253 253 253 253 253 253
52581 -253 253 253 253 253 253 253 253 253 253 253 253
52582 -253 253 253 253 253 253 253 253 253 253 253 253
52583 -253 253 253 253 253 253 253 253 253 253 253 253
52584 -253 253 253 253 253 253 206 206 206 2 2 6
52585 - 22 22 22 34 34 34 18 14 6 22 22 22
52586 - 26 26 26 18 18 18 6 6 6 2 2 6
52587 - 2 2 6 82 82 82 54 54 54 18 18 18
52588 - 6 6 6 0 0 0 0 0 0 0 0 0
52589 - 0 0 0 0 0 0 0 0 0 0 0 0
52590 - 0 0 0 0 0 0 0 0 0 0 0 0
52591 - 0 0 0 0 0 0 0 0 0 0 0 0
52592 - 0 0 0 0 0 0 0 0 0 0 0 0
52593 - 0 0 0 0 0 0 0 0 0 0 0 0
52594 - 0 0 0 0 0 0 6 6 6 26 26 26
52595 - 62 62 62 106 106 106 74 54 14 185 133 11
52596 -210 162 10 121 92 8 6 6 6 62 62 62
52597 -238 238 238 253 253 253 253 253 253 253 253 253
52598 -253 253 253 253 253 253 253 253 253 253 253 253
52599 -253 253 253 253 253 253 231 231 231 246 246 246
52600 -253 253 253 253 253 253 253 253 253 253 253 253
52601 -253 253 253 253 253 253 253 253 253 253 253 253
52602 -253 253 253 253 253 253 253 253 253 253 253 253
52603 -253 253 253 253 253 253 253 253 253 253 253 253
52604 -253 253 253 253 253 253 158 158 158 18 18 18
52605 - 14 14 14 2 2 6 2 2 6 2 2 6
52606 - 6 6 6 18 18 18 66 66 66 38 38 38
52607 - 6 6 6 94 94 94 50 50 50 18 18 18
52608 - 6 6 6 0 0 0 0 0 0 0 0 0
52609 - 0 0 0 0 0 0 0 0 0 0 0 0
52610 - 0 0 0 0 0 0 0 0 0 0 0 0
52611 - 0 0 0 0 0 0 0 0 0 0 0 0
52612 - 0 0 0 0 0 0 0 0 0 0 0 0
52613 - 0 0 0 0 0 0 0 0 0 6 6 6
52614 - 10 10 10 10 10 10 18 18 18 38 38 38
52615 - 78 78 78 142 134 106 216 158 10 242 186 14
52616 -246 190 14 246 190 14 156 118 10 10 10 10
52617 - 90 90 90 238 238 238 253 253 253 253 253 253
52618 -253 253 253 253 253 253 253 253 253 253 253 253
52619 -253 253 253 253 253 253 231 231 231 250 250 250
52620 -253 253 253 253 253 253 253 253 253 253 253 253
52621 -253 253 253 253 253 253 253 253 253 253 253 253
52622 -253 253 253 253 253 253 253 253 253 253 253 253
52623 -253 253 253 253 253 253 253 253 253 246 230 190
52624 -238 204 91 238 204 91 181 142 44 37 26 9
52625 - 2 2 6 2 2 6 2 2 6 2 2 6
52626 - 2 2 6 2 2 6 38 38 38 46 46 46
52627 - 26 26 26 106 106 106 54 54 54 18 18 18
52628 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
52633 - 0 0 0 6 6 6 14 14 14 22 22 22
52634 - 30 30 30 38 38 38 50 50 50 70 70 70
52635 -106 106 106 190 142 34 226 170 11 242 186 14
52636 -246 190 14 246 190 14 246 190 14 154 114 10
52637 - 6 6 6 74 74 74 226 226 226 253 253 253
52638 -253 253 253 253 253 253 253 253 253 253 253 253
52639 -253 253 253 253 253 253 231 231 231 250 250 250
52640 -253 253 253 253 253 253 253 253 253 253 253 253
52641 -253 253 253 253 253 253 253 253 253 253 253 253
52642 -253 253 253 253 253 253 253 253 253 253 253 253
52643 -253 253 253 253 253 253 253 253 253 228 184 62
52644 -241 196 14 241 208 19 232 195 16 38 30 10
52645 - 2 2 6 2 2 6 2 2 6 2 2 6
52646 - 2 2 6 6 6 6 30 30 30 26 26 26
52647 -203 166 17 154 142 90 66 66 66 26 26 26
52648 - 6 6 6 0 0 0 0 0 0 0 0 0
52649 - 0 0 0 0 0 0 0 0 0 0 0 0
52650 - 0 0 0 0 0 0 0 0 0 0 0 0
52651 - 0 0 0 0 0 0 0 0 0 0 0 0
52652 - 0 0 0 0 0 0 0 0 0 0 0 0
52653 - 6 6 6 18 18 18 38 38 38 58 58 58
52654 - 78 78 78 86 86 86 101 101 101 123 123 123
52655 -175 146 61 210 150 10 234 174 13 246 186 14
52656 -246 190 14 246 190 14 246 190 14 238 190 10
52657 -102 78 10 2 2 6 46 46 46 198 198 198
52658 -253 253 253 253 253 253 253 253 253 253 253 253
52659 -253 253 253 253 253 253 234 234 234 242 242 242
52660 -253 253 253 253 253 253 253 253 253 253 253 253
52661 -253 253 253 253 253 253 253 253 253 253 253 253
52662 -253 253 253 253 253 253 253 253 253 253 253 253
52663 -253 253 253 253 253 253 253 253 253 224 178 62
52664 -242 186 14 241 196 14 210 166 10 22 18 6
52665 - 2 2 6 2 2 6 2 2 6 2 2 6
52666 - 2 2 6 2 2 6 6 6 6 121 92 8
52667 -238 202 15 232 195 16 82 82 82 34 34 34
52668 - 10 10 10 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 - 14 14 14 38 38 38 70 70 70 154 122 46
52674 -190 142 34 200 144 11 197 138 11 197 138 11
52675 -213 154 11 226 170 11 242 186 14 246 190 14
52676 -246 190 14 246 190 14 246 190 14 246 190 14
52677 -225 175 15 46 32 6 2 2 6 22 22 22
52678 -158 158 158 250 250 250 253 253 253 253 253 253
52679 -253 253 253 253 253 253 253 253 253 253 253 253
52680 -253 253 253 253 253 253 253 253 253 253 253 253
52681 -253 253 253 253 253 253 253 253 253 253 253 253
52682 -253 253 253 253 253 253 253 253 253 253 253 253
52683 -253 253 253 250 250 250 242 242 242 224 178 62
52684 -239 182 13 236 186 11 213 154 11 46 32 6
52685 - 2 2 6 2 2 6 2 2 6 2 2 6
52686 - 2 2 6 2 2 6 61 42 6 225 175 15
52687 -238 190 10 236 186 11 112 100 78 42 42 42
52688 - 14 14 14 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 0 0 0 0
52692 - 0 0 0 0 0 0 0 0 0 6 6 6
52693 - 22 22 22 54 54 54 154 122 46 213 154 11
52694 -226 170 11 230 174 11 226 170 11 226 170 11
52695 -236 178 12 242 186 14 246 190 14 246 190 14
52696 -246 190 14 246 190 14 246 190 14 246 190 14
52697 -241 196 14 184 144 12 10 10 10 2 2 6
52698 - 6 6 6 116 116 116 242 242 242 253 253 253
52699 -253 253 253 253 253 253 253 253 253 253 253 253
52700 -253 253 253 253 253 253 253 253 253 253 253 253
52701 -253 253 253 253 253 253 253 253 253 253 253 253
52702 -253 253 253 253 253 253 253 253 253 253 253 253
52703 -253 253 253 231 231 231 198 198 198 214 170 54
52704 -236 178 12 236 178 12 210 150 10 137 92 6
52705 - 18 14 6 2 2 6 2 2 6 2 2 6
52706 - 6 6 6 70 47 6 200 144 11 236 178 12
52707 -239 182 13 239 182 13 124 112 88 58 58 58
52708 - 22 22 22 6 6 6 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 10 10 10
52713 - 30 30 30 70 70 70 180 133 36 226 170 11
52714 -239 182 13 242 186 14 242 186 14 246 186 14
52715 -246 190 14 246 190 14 246 190 14 246 190 14
52716 -246 190 14 246 190 14 246 190 14 246 190 14
52717 -246 190 14 232 195 16 98 70 6 2 2 6
52718 - 2 2 6 2 2 6 66 66 66 221 221 221
52719 -253 253 253 253 253 253 253 253 253 253 253 253
52720 -253 253 253 253 253 253 253 253 253 253 253 253
52721 -253 253 253 253 253 253 253 253 253 253 253 253
52722 -253 253 253 253 253 253 253 253 253 253 253 253
52723 -253 253 253 206 206 206 198 198 198 214 166 58
52724 -230 174 11 230 174 11 216 158 10 192 133 9
52725 -163 110 8 116 81 8 102 78 10 116 81 8
52726 -167 114 7 197 138 11 226 170 11 239 182 13
52727 -242 186 14 242 186 14 162 146 94 78 78 78
52728 - 34 34 34 14 14 14 6 6 6 0 0 0
52729 - 0 0 0 0 0 0 0 0 0 0 0 0
52730 - 0 0 0 0 0 0 0 0 0 0 0 0
52731 - 0 0 0 0 0 0 0 0 0 0 0 0
52732 - 0 0 0 0 0 0 0 0 0 6 6 6
52733 - 30 30 30 78 78 78 190 142 34 226 170 11
52734 -239 182 13 246 190 14 246 190 14 246 190 14
52735 -246 190 14 246 190 14 246 190 14 246 190 14
52736 -246 190 14 246 190 14 246 190 14 246 190 14
52737 -246 190 14 241 196 14 203 166 17 22 18 6
52738 - 2 2 6 2 2 6 2 2 6 38 38 38
52739 -218 218 218 253 253 253 253 253 253 253 253 253
52740 -253 253 253 253 253 253 253 253 253 253 253 253
52741 -253 253 253 253 253 253 253 253 253 253 253 253
52742 -253 253 253 253 253 253 253 253 253 253 253 253
52743 -250 250 250 206 206 206 198 198 198 202 162 69
52744 -226 170 11 236 178 12 224 166 10 210 150 10
52745 -200 144 11 197 138 11 192 133 9 197 138 11
52746 -210 150 10 226 170 11 242 186 14 246 190 14
52747 -246 190 14 246 186 14 225 175 15 124 112 88
52748 - 62 62 62 30 30 30 14 14 14 6 6 6
52749 - 0 0 0 0 0 0 0 0 0 0 0 0
52750 - 0 0 0 0 0 0 0 0 0 0 0 0
52751 - 0 0 0 0 0 0 0 0 0 0 0 0
52752 - 0 0 0 0 0 0 0 0 0 10 10 10
52753 - 30 30 30 78 78 78 174 135 50 224 166 10
52754 -239 182 13 246 190 14 246 190 14 246 190 14
52755 -246 190 14 246 190 14 246 190 14 246 190 14
52756 -246 190 14 246 190 14 246 190 14 246 190 14
52757 -246 190 14 246 190 14 241 196 14 139 102 15
52758 - 2 2 6 2 2 6 2 2 6 2 2 6
52759 - 78 78 78 250 250 250 253 253 253 253 253 253
52760 -253 253 253 253 253 253 253 253 253 253 253 253
52761 -253 253 253 253 253 253 253 253 253 253 253 253
52762 -253 253 253 253 253 253 253 253 253 253 253 253
52763 -250 250 250 214 214 214 198 198 198 190 150 46
52764 -219 162 10 236 178 12 234 174 13 224 166 10
52765 -216 158 10 213 154 11 213 154 11 216 158 10
52766 -226 170 11 239 182 13 246 190 14 246 190 14
52767 -246 190 14 246 190 14 242 186 14 206 162 42
52768 -101 101 101 58 58 58 30 30 30 14 14 14
52769 - 6 6 6 0 0 0 0 0 0 0 0 0
52770 - 0 0 0 0 0 0 0 0 0 0 0 0
52771 - 0 0 0 0 0 0 0 0 0 0 0 0
52772 - 0 0 0 0 0 0 0 0 0 10 10 10
52773 - 30 30 30 74 74 74 174 135 50 216 158 10
52774 -236 178 12 246 190 14 246 190 14 246 190 14
52775 -246 190 14 246 190 14 246 190 14 246 190 14
52776 -246 190 14 246 190 14 246 190 14 246 190 14
52777 -246 190 14 246 190 14 241 196 14 226 184 13
52778 - 61 42 6 2 2 6 2 2 6 2 2 6
52779 - 22 22 22 238 238 238 253 253 253 253 253 253
52780 -253 253 253 253 253 253 253 253 253 253 253 253
52781 -253 253 253 253 253 253 253 253 253 253 253 253
52782 -253 253 253 253 253 253 253 253 253 253 253 253
52783 -253 253 253 226 226 226 187 187 187 180 133 36
52784 -216 158 10 236 178 12 239 182 13 236 178 12
52785 -230 174 11 226 170 11 226 170 11 230 174 11
52786 -236 178 12 242 186 14 246 190 14 246 190 14
52787 -246 190 14 246 190 14 246 186 14 239 182 13
52788 -206 162 42 106 106 106 66 66 66 34 34 34
52789 - 14 14 14 6 6 6 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 6 6 6
52793 - 26 26 26 70 70 70 163 133 67 213 154 11
52794 -236 178 12 246 190 14 246 190 14 246 190 14
52795 -246 190 14 246 190 14 246 190 14 246 190 14
52796 -246 190 14 246 190 14 246 190 14 246 190 14
52797 -246 190 14 246 190 14 246 190 14 241 196 14
52798 -190 146 13 18 14 6 2 2 6 2 2 6
52799 - 46 46 46 246 246 246 253 253 253 253 253 253
52800 -253 253 253 253 253 253 253 253 253 253 253 253
52801 -253 253 253 253 253 253 253 253 253 253 253 253
52802 -253 253 253 253 253 253 253 253 253 253 253 253
52803 -253 253 253 221 221 221 86 86 86 156 107 11
52804 -216 158 10 236 178 12 242 186 14 246 186 14
52805 -242 186 14 239 182 13 239 182 13 242 186 14
52806 -242 186 14 246 186 14 246 190 14 246 190 14
52807 -246 190 14 246 190 14 246 190 14 246 190 14
52808 -242 186 14 225 175 15 142 122 72 66 66 66
52809 - 30 30 30 10 10 10 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 6 6 6
52813 - 26 26 26 70 70 70 163 133 67 210 150 10
52814 -236 178 12 246 190 14 246 190 14 246 190 14
52815 -246 190 14 246 190 14 246 190 14 246 190 14
52816 -246 190 14 246 190 14 246 190 14 246 190 14
52817 -246 190 14 246 190 14 246 190 14 246 190 14
52818 -232 195 16 121 92 8 34 34 34 106 106 106
52819 -221 221 221 253 253 253 253 253 253 253 253 253
52820 -253 253 253 253 253 253 253 253 253 253 253 253
52821 -253 253 253 253 253 253 253 253 253 253 253 253
52822 -253 253 253 253 253 253 253 253 253 253 253 253
52823 -242 242 242 82 82 82 18 14 6 163 110 8
52824 -216 158 10 236 178 12 242 186 14 246 190 14
52825 -246 190 14 246 190 14 246 190 14 246 190 14
52826 -246 190 14 246 190 14 246 190 14 246 190 14
52827 -246 190 14 246 190 14 246 190 14 246 190 14
52828 -246 190 14 246 190 14 242 186 14 163 133 67
52829 - 46 46 46 18 18 18 6 6 6 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 10 10 10
52833 - 30 30 30 78 78 78 163 133 67 210 150 10
52834 -236 178 12 246 186 14 246 190 14 246 190 14
52835 -246 190 14 246 190 14 246 190 14 246 190 14
52836 -246 190 14 246 190 14 246 190 14 246 190 14
52837 -246 190 14 246 190 14 246 190 14 246 190 14
52838 -241 196 14 215 174 15 190 178 144 253 253 253
52839 -253 253 253 253 253 253 253 253 253 253 253 253
52840 -253 253 253 253 253 253 253 253 253 253 253 253
52841 -253 253 253 253 253 253 253 253 253 253 253 253
52842 -253 253 253 253 253 253 253 253 253 218 218 218
52843 - 58 58 58 2 2 6 22 18 6 167 114 7
52844 -216 158 10 236 178 12 246 186 14 246 190 14
52845 -246 190 14 246 190 14 246 190 14 246 190 14
52846 -246 190 14 246 190 14 246 190 14 246 190 14
52847 -246 190 14 246 190 14 246 190 14 246 190 14
52848 -246 190 14 246 186 14 242 186 14 190 150 46
52849 - 54 54 54 22 22 22 6 6 6 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 14 14 14
52853 - 38 38 38 86 86 86 180 133 36 213 154 11
52854 -236 178 12 246 186 14 246 190 14 246 190 14
52855 -246 190 14 246 190 14 246 190 14 246 190 14
52856 -246 190 14 246 190 14 246 190 14 246 190 14
52857 -246 190 14 246 190 14 246 190 14 246 190 14
52858 -246 190 14 232 195 16 190 146 13 214 214 214
52859 -253 253 253 253 253 253 253 253 253 253 253 253
52860 -253 253 253 253 253 253 253 253 253 253 253 253
52861 -253 253 253 253 253 253 253 253 253 253 253 253
52862 -253 253 253 250 250 250 170 170 170 26 26 26
52863 - 2 2 6 2 2 6 37 26 9 163 110 8
52864 -219 162 10 239 182 13 246 186 14 246 190 14
52865 -246 190 14 246 190 14 246 190 14 246 190 14
52866 -246 190 14 246 190 14 246 190 14 246 190 14
52867 -246 190 14 246 190 14 246 190 14 246 190 14
52868 -246 186 14 236 178 12 224 166 10 142 122 72
52869 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
52873 - 50 50 50 109 106 95 192 133 9 224 166 10
52874 -242 186 14 246 190 14 246 190 14 246 190 14
52875 -246 190 14 246 190 14 246 190 14 246 190 14
52876 -246 190 14 246 190 14 246 190 14 246 190 14
52877 -246 190 14 246 190 14 246 190 14 246 190 14
52878 -242 186 14 226 184 13 210 162 10 142 110 46
52879 -226 226 226 253 253 253 253 253 253 253 253 253
52880 -253 253 253 253 253 253 253 253 253 253 253 253
52881 -253 253 253 253 253 253 253 253 253 253 253 253
52882 -198 198 198 66 66 66 2 2 6 2 2 6
52883 - 2 2 6 2 2 6 50 34 6 156 107 11
52884 -219 162 10 239 182 13 246 186 14 246 190 14
52885 -246 190 14 246 190 14 246 190 14 246 190 14
52886 -246 190 14 246 190 14 246 190 14 246 190 14
52887 -246 190 14 246 190 14 246 190 14 242 186 14
52888 -234 174 13 213 154 11 154 122 46 66 66 66
52889 - 30 30 30 10 10 10 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 6 6 6 22 22 22
52893 - 58 58 58 154 121 60 206 145 10 234 174 13
52894 -242 186 14 246 186 14 246 190 14 246 190 14
52895 -246 190 14 246 190 14 246 190 14 246 190 14
52896 -246 190 14 246 190 14 246 190 14 246 190 14
52897 -246 190 14 246 190 14 246 190 14 246 190 14
52898 -246 186 14 236 178 12 210 162 10 163 110 8
52899 - 61 42 6 138 138 138 218 218 218 250 250 250
52900 -253 253 253 253 253 253 253 253 253 250 250 250
52901 -242 242 242 210 210 210 144 144 144 66 66 66
52902 - 6 6 6 2 2 6 2 2 6 2 2 6
52903 - 2 2 6 2 2 6 61 42 6 163 110 8
52904 -216 158 10 236 178 12 246 190 14 246 190 14
52905 -246 190 14 246 190 14 246 190 14 246 190 14
52906 -246 190 14 246 190 14 246 190 14 246 190 14
52907 -246 190 14 239 182 13 230 174 11 216 158 10
52908 -190 142 34 124 112 88 70 70 70 38 38 38
52909 - 18 18 18 6 6 6 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 6 6 6 22 22 22
52913 - 62 62 62 168 124 44 206 145 10 224 166 10
52914 -236 178 12 239 182 13 242 186 14 242 186 14
52915 -246 186 14 246 190 14 246 190 14 246 190 14
52916 -246 190 14 246 190 14 246 190 14 246 190 14
52917 -246 190 14 246 190 14 246 190 14 246 190 14
52918 -246 190 14 236 178 12 216 158 10 175 118 6
52919 - 80 54 7 2 2 6 6 6 6 30 30 30
52920 - 54 54 54 62 62 62 50 50 50 38 38 38
52921 - 14 14 14 2 2 6 2 2 6 2 2 6
52922 - 2 2 6 2 2 6 2 2 6 2 2 6
52923 - 2 2 6 6 6 6 80 54 7 167 114 7
52924 -213 154 11 236 178 12 246 190 14 246 190 14
52925 -246 190 14 246 190 14 246 190 14 246 190 14
52926 -246 190 14 242 186 14 239 182 13 239 182 13
52927 -230 174 11 210 150 10 174 135 50 124 112 88
52928 - 82 82 82 54 54 54 34 34 34 18 18 18
52929 - 6 6 6 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 6 6 6 18 18 18
52933 - 50 50 50 158 118 36 192 133 9 200 144 11
52934 -216 158 10 219 162 10 224 166 10 226 170 11
52935 -230 174 11 236 178 12 239 182 13 239 182 13
52936 -242 186 14 246 186 14 246 190 14 246 190 14
52937 -246 190 14 246 190 14 246 190 14 246 190 14
52938 -246 186 14 230 174 11 210 150 10 163 110 8
52939 -104 69 6 10 10 10 2 2 6 2 2 6
52940 - 2 2 6 2 2 6 2 2 6 2 2 6
52941 - 2 2 6 2 2 6 2 2 6 2 2 6
52942 - 2 2 6 2 2 6 2 2 6 2 2 6
52943 - 2 2 6 6 6 6 91 60 6 167 114 7
52944 -206 145 10 230 174 11 242 186 14 246 190 14
52945 -246 190 14 246 190 14 246 186 14 242 186 14
52946 -239 182 13 230 174 11 224 166 10 213 154 11
52947 -180 133 36 124 112 88 86 86 86 58 58 58
52948 - 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
52953 - 34 34 34 70 70 70 138 110 50 158 118 36
52954 -167 114 7 180 123 7 192 133 9 197 138 11
52955 -200 144 11 206 145 10 213 154 11 219 162 10
52956 -224 166 10 230 174 11 239 182 13 242 186 14
52957 -246 186 14 246 186 14 246 186 14 246 186 14
52958 -239 182 13 216 158 10 185 133 11 152 99 6
52959 -104 69 6 18 14 6 2 2 6 2 2 6
52960 - 2 2 6 2 2 6 2 2 6 2 2 6
52961 - 2 2 6 2 2 6 2 2 6 2 2 6
52962 - 2 2 6 2 2 6 2 2 6 2 2 6
52963 - 2 2 6 6 6 6 80 54 7 152 99 6
52964 -192 133 9 219 162 10 236 178 12 239 182 13
52965 -246 186 14 242 186 14 239 182 13 236 178 12
52966 -224 166 10 206 145 10 192 133 9 154 121 60
52967 - 94 94 94 62 62 62 42 42 42 22 22 22
52968 - 14 14 14 6 6 6 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 6 6 6
52973 - 18 18 18 34 34 34 58 58 58 78 78 78
52974 -101 98 89 124 112 88 142 110 46 156 107 11
52975 -163 110 8 167 114 7 175 118 6 180 123 7
52976 -185 133 11 197 138 11 210 150 10 219 162 10
52977 -226 170 11 236 178 12 236 178 12 234 174 13
52978 -219 162 10 197 138 11 163 110 8 130 83 6
52979 - 91 60 6 10 10 10 2 2 6 2 2 6
52980 - 18 18 18 38 38 38 38 38 38 38 38 38
52981 - 38 38 38 38 38 38 38 38 38 38 38 38
52982 - 38 38 38 38 38 38 26 26 26 2 2 6
52983 - 2 2 6 6 6 6 70 47 6 137 92 6
52984 -175 118 6 200 144 11 219 162 10 230 174 11
52985 -234 174 13 230 174 11 219 162 10 210 150 10
52986 -192 133 9 163 110 8 124 112 88 82 82 82
52987 - 50 50 50 30 30 30 14 14 14 6 6 6
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 - 6 6 6 14 14 14 22 22 22 34 34 34
52994 - 42 42 42 58 58 58 74 74 74 86 86 86
52995 -101 98 89 122 102 70 130 98 46 121 87 25
52996 -137 92 6 152 99 6 163 110 8 180 123 7
52997 -185 133 11 197 138 11 206 145 10 200 144 11
52998 -180 123 7 156 107 11 130 83 6 104 69 6
52999 - 50 34 6 54 54 54 110 110 110 101 98 89
53000 - 86 86 86 82 82 82 78 78 78 78 78 78
53001 - 78 78 78 78 78 78 78 78 78 78 78 78
53002 - 78 78 78 82 82 82 86 86 86 94 94 94
53003 -106 106 106 101 101 101 86 66 34 124 80 6
53004 -156 107 11 180 123 7 192 133 9 200 144 11
53005 -206 145 10 200 144 11 192 133 9 175 118 6
53006 -139 102 15 109 106 95 70 70 70 42 42 42
53007 - 22 22 22 10 10 10 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 6 6 6 10 10 10
53014 - 14 14 14 22 22 22 30 30 30 38 38 38
53015 - 50 50 50 62 62 62 74 74 74 90 90 90
53016 -101 98 89 112 100 78 121 87 25 124 80 6
53017 -137 92 6 152 99 6 152 99 6 152 99 6
53018 -138 86 6 124 80 6 98 70 6 86 66 30
53019 -101 98 89 82 82 82 58 58 58 46 46 46
53020 - 38 38 38 34 34 34 34 34 34 34 34 34
53021 - 34 34 34 34 34 34 34 34 34 34 34 34
53022 - 34 34 34 34 34 34 38 38 38 42 42 42
53023 - 54 54 54 82 82 82 94 86 76 91 60 6
53024 -134 86 6 156 107 11 167 114 7 175 118 6
53025 -175 118 6 167 114 7 152 99 6 121 87 25
53026 -101 98 89 62 62 62 34 34 34 18 18 18
53027 - 6 6 6 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 6 6 6 6 6 6 10 10 10
53035 - 18 18 18 22 22 22 30 30 30 42 42 42
53036 - 50 50 50 66 66 66 86 86 86 101 98 89
53037 -106 86 58 98 70 6 104 69 6 104 69 6
53038 -104 69 6 91 60 6 82 62 34 90 90 90
53039 - 62 62 62 38 38 38 22 22 22 14 14 14
53040 - 10 10 10 10 10 10 10 10 10 10 10 10
53041 - 10 10 10 10 10 10 6 6 6 10 10 10
53042 - 10 10 10 10 10 10 10 10 10 14 14 14
53043 - 22 22 22 42 42 42 70 70 70 89 81 66
53044 - 80 54 7 104 69 6 124 80 6 137 92 6
53045 -134 86 6 116 81 8 100 82 52 86 86 86
53046 - 58 58 58 30 30 30 14 14 14 6 6 6
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 6 6 6 10 10 10 14 14 14
53056 - 18 18 18 26 26 26 38 38 38 54 54 54
53057 - 70 70 70 86 86 86 94 86 76 89 81 66
53058 - 89 81 66 86 86 86 74 74 74 50 50 50
53059 - 30 30 30 14 14 14 6 6 6 0 0 0
53060 - 0 0 0 0 0 0 0 0 0 0 0 0
53061 - 0 0 0 0 0 0 0 0 0 0 0 0
53062 - 0 0 0 0 0 0 0 0 0 0 0 0
53063 - 6 6 6 18 18 18 34 34 34 58 58 58
53064 - 82 82 82 89 81 66 89 81 66 89 81 66
53065 - 94 86 66 94 86 76 74 74 74 50 50 50
53066 - 26 26 26 14 14 14 6 6 6 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 - 6 6 6 6 6 6 14 14 14 18 18 18
53077 - 30 30 30 38 38 38 46 46 46 54 54 54
53078 - 50 50 50 42 42 42 30 30 30 18 18 18
53079 - 10 10 10 0 0 0 0 0 0 0 0 0
53080 - 0 0 0 0 0 0 0 0 0 0 0 0
53081 - 0 0 0 0 0 0 0 0 0 0 0 0
53082 - 0 0 0 0 0 0 0 0 0 0 0 0
53083 - 0 0 0 6 6 6 14 14 14 26 26 26
53084 - 38 38 38 50 50 50 58 58 58 58 58 58
53085 - 54 54 54 42 42 42 30 30 30 18 18 18
53086 - 10 10 10 0 0 0 0 0 0 0 0 0
53087 - 0 0 0 0 0 0 0 0 0 0 0 0
53088 - 0 0 0 0 0 0 0 0 0 0 0 0
53089 - 0 0 0 0 0 0 0 0 0 0 0 0
53090 - 0 0 0 0 0 0 0 0 0 0 0 0
53091 - 0 0 0 0 0 0 0 0 0 0 0 0
53092 - 0 0 0 0 0 0 0 0 0 0 0 0
53093 - 0 0 0 0 0 0 0 0 0 0 0 0
53094 - 0 0 0 0 0 0 0 0 0 0 0 0
53095 - 0 0 0 0 0 0 0 0 0 0 0 0
53096 - 0 0 0 0 0 0 0 0 0 6 6 6
53097 - 6 6 6 10 10 10 14 14 14 18 18 18
53098 - 18 18 18 14 14 14 10 10 10 6 6 6
53099 - 0 0 0 0 0 0 0 0 0 0 0 0
53100 - 0 0 0 0 0 0 0 0 0 0 0 0
53101 - 0 0 0 0 0 0 0 0 0 0 0 0
53102 - 0 0 0 0 0 0 0 0 0 0 0 0
53103 - 0 0 0 0 0 0 0 0 0 6 6 6
53104 - 14 14 14 18 18 18 22 22 22 22 22 22
53105 - 18 18 18 14 14 14 10 10 10 6 6 6
53106 - 0 0 0 0 0 0 0 0 0 0 0 0
53107 - 0 0 0 0 0 0 0 0 0 0 0 0
53108 - 0 0 0 0 0 0 0 0 0 0 0 0
53109 - 0 0 0 0 0 0 0 0 0 0 0 0
53110 - 0 0 0 0 0 0 0 0 0 0 0 0
53111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53124 +4 4 4 4 4 4
53125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53138 +4 4 4 4 4 4
53139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53152 +4 4 4 4 4 4
53153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53166 +4 4 4 4 4 4
53167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53180 +4 4 4 4 4 4
53181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53194 +4 4 4 4 4 4
53195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53199 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
53200 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
53201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53204 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
53205 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53206 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
53207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53208 +4 4 4 4 4 4
53209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53213 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
53214 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
53215 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53218 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
53219 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
53220 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
53221 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53222 +4 4 4 4 4 4
53223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53227 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
53228 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
53229 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53232 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
53233 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
53234 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
53235 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
53236 +4 4 4 4 4 4
53237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53240 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
53241 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
53242 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
53243 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
53244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53245 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53246 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
53247 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
53248 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
53249 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
53250 +4 4 4 4 4 4
53251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53254 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
53255 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
53256 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
53257 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
53258 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53259 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
53260 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
53261 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
53262 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
53263 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
53264 +4 4 4 4 4 4
53265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
53268 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
53269 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
53270 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
53271 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
53272 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
53273 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
53274 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
53275 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
53276 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
53277 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
53278 +4 4 4 4 4 4
53279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53281 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
53282 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
53283 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
53284 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
53285 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
53286 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
53287 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
53288 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
53289 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
53290 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
53291 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
53292 +4 4 4 4 4 4
53293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53295 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
53296 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
53297 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
53298 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
53299 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
53300 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
53301 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
53302 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
53303 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
53304 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
53305 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
53306 +4 4 4 4 4 4
53307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53309 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
53310 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
53311 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
53312 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
53313 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
53314 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
53315 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
53316 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
53317 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
53318 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
53319 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53320 +4 4 4 4 4 4
53321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53323 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
53324 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
53325 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
53326 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
53327 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
53328 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
53329 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
53330 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
53331 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
53332 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
53333 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
53334 +4 4 4 4 4 4
53335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53336 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
53337 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
53338 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
53339 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
53340 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
53341 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
53342 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
53343 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
53344 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
53345 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
53346 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
53347 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
53348 +4 4 4 4 4 4
53349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53350 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
53351 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
53352 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
53353 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
53354 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
53355 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
53356 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
53357 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
53358 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
53359 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
53360 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
53361 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
53362 +0 0 0 4 4 4
53363 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53364 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
53365 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
53366 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
53367 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
53368 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
53369 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
53370 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
53371 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
53372 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
53373 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
53374 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
53375 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
53376 +2 0 0 0 0 0
53377 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
53378 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
53379 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
53380 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
53381 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
53382 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
53383 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
53384 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
53385 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
53386 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
53387 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
53388 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
53389 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
53390 +37 38 37 0 0 0
53391 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53392 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
53393 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
53394 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
53395 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
53396 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
53397 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
53398 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
53399 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
53400 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
53401 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
53402 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
53403 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
53404 +85 115 134 4 0 0
53405 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
53406 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
53407 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
53408 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
53409 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
53410 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
53411 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
53412 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
53413 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
53414 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
53415 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
53416 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
53417 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
53418 +60 73 81 4 0 0
53419 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
53420 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
53421 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
53422 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
53423 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
53424 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
53425 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
53426 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
53427 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
53428 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
53429 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
53430 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
53431 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
53432 +16 19 21 4 0 0
53433 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
53434 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
53435 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
53436 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
53437 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
53438 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
53439 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
53440 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
53441 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
53442 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
53443 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
53444 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
53445 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
53446 +4 0 0 4 3 3
53447 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
53448 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
53449 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
53450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
53451 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
53452 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
53453 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
53454 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
53455 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
53456 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
53457 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
53458 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
53459 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
53460 +3 2 2 4 4 4
53461 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
53462 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
53463 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
53464 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53465 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
53466 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
53467 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
53468 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
53469 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
53470 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
53471 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
53472 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
53473 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
53474 +4 4 4 4 4 4
53475 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
53476 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
53477 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
53478 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
53479 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
53480 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
53481 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
53482 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
53483 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
53484 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
53485 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
53486 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
53487 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
53488 +4 4 4 4 4 4
53489 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
53490 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
53491 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
53492 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
53493 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
53494 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53495 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
53496 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
53497 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
53498 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
53499 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
53500 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
53501 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
53502 +5 5 5 5 5 5
53503 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
53504 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
53505 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
53506 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
53507 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
53508 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53509 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
53510 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
53511 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
53512 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
53513 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
53514 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
53515 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
53516 +5 5 5 4 4 4
53517 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
53518 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
53519 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
53520 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
53521 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53522 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
53523 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
53524 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
53525 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
53526 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
53527 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
53528 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
53529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53530 +4 4 4 4 4 4
53531 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
53532 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
53533 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
53534 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
53535 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
53536 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53537 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53538 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
53539 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
53540 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
53541 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
53542 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
53543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53544 +4 4 4 4 4 4
53545 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
53546 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
53547 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
53548 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
53549 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53550 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
53551 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
53552 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
53553 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
53554 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
53555 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
53556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53558 +4 4 4 4 4 4
53559 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
53560 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
53561 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
53562 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
53563 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53564 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53565 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53566 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
53567 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
53568 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
53569 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
53570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53572 +4 4 4 4 4 4
53573 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
53574 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
53575 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
53576 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
53577 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53578 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
53579 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53580 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
53581 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
53582 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
53583 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53586 +4 4 4 4 4 4
53587 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
53588 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
53589 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
53590 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
53591 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53592 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
53593 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
53594 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
53595 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
53596 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
53597 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
53598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53600 +4 4 4 4 4 4
53601 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
53602 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
53603 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
53604 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
53605 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53606 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
53607 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
53608 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
53609 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
53610 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
53611 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
53612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53614 +4 4 4 4 4 4
53615 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
53616 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
53617 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
53618 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53619 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
53620 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
53621 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
53622 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
53623 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
53624 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
53625 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53628 +4 4 4 4 4 4
53629 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
53630 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
53631 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
53632 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53633 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53634 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
53635 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
53636 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
53637 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
53638 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
53639 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53642 +4 4 4 4 4 4
53643 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
53644 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
53645 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53646 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53647 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53648 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
53649 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
53650 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
53651 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
53652 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
53653 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53656 +4 4 4 4 4 4
53657 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
53658 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
53659 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53660 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53661 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53662 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
53663 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
53664 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
53665 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53666 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53667 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53670 +4 4 4 4 4 4
53671 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53672 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
53673 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53674 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
53675 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
53676 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
53677 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
53678 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
53679 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53680 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53681 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53684 +4 4 4 4 4 4
53685 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53686 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
53687 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53688 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
53689 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53690 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
53691 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
53692 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
53693 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53694 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53695 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53698 +4 4 4 4 4 4
53699 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
53700 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
53701 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53702 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
53703 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
53704 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
53705 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
53706 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
53707 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53708 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53709 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53712 +4 4 4 4 4 4
53713 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
53714 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
53715 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53716 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
53717 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
53718 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
53719 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
53720 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
53721 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53722 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53723 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53726 +4 4 4 4 4 4
53727 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53728 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
53729 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53730 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
53731 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
53732 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
53733 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
53734 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
53735 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53736 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53737 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53740 +4 4 4 4 4 4
53741 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
53742 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
53743 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53744 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
53745 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
53746 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
53747 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
53748 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
53749 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
53750 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53751 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53754 +4 4 4 4 4 4
53755 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53756 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
53757 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
53758 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
53759 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
53760 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
53761 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
53762 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
53763 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53764 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53765 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53768 +4 4 4 4 4 4
53769 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53770 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
53771 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53772 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
53773 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
53774 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
53775 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
53776 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
53777 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53778 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53779 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53782 +4 4 4 4 4 4
53783 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53784 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
53785 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
53786 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
53787 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
53788 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
53789 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53790 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
53791 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53792 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53793 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53796 +4 4 4 4 4 4
53797 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53798 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
53799 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
53800 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53801 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
53802 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
53803 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53804 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
53805 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53806 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53807 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53810 +4 4 4 4 4 4
53811 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53812 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
53813 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
53814 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
53815 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
53816 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
53817 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
53818 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
53819 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
53820 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53821 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53824 +4 4 4 4 4 4
53825 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53826 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
53827 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
53828 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
53829 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
53830 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
53831 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
53832 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
53833 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
53834 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53835 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53838 +4 4 4 4 4 4
53839 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
53840 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
53841 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
53842 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
53843 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53844 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
53845 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
53846 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
53847 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
53848 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53849 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53852 +4 4 4 4 4 4
53853 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53854 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
53855 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
53856 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
53857 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
53858 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
53859 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
53860 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
53861 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
53862 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53863 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53866 +4 4 4 4 4 4
53867 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
53868 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
53869 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
53870 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
53871 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
53872 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
53873 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
53874 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
53875 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
53876 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
53877 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53880 +4 4 4 4 4 4
53881 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
53882 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
53883 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
53884 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
53885 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
53886 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
53887 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
53888 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
53889 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
53890 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
53891 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53894 +4 4 4 4 4 4
53895 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
53896 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
53897 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
53898 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
53899 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
53900 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
53901 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53902 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
53903 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
53904 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
53905 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53908 +4 4 4 4 4 4
53909 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
53910 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
53911 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
53912 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
53913 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
53914 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
53915 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
53916 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
53917 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
53918 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
53919 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53922 +4 4 4 4 4 4
53923 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
53924 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
53925 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
53926 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
53927 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
53928 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
53929 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
53930 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
53931 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
53932 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
53933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53936 +4 4 4 4 4 4
53937 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
53938 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
53939 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
53940 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
53941 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
53942 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
53943 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
53944 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
53945 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
53946 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
53947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53950 +4 4 4 4 4 4
53951 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
53952 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
53953 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
53954 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
53955 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
53956 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
53957 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
53958 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
53959 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
53960 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
53961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53964 +4 4 4 4 4 4
53965 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
53966 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
53967 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
53968 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
53969 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
53970 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
53971 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
53972 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
53973 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
53974 +4 3 3 5 5 5 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
53979 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
53980 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
53981 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
53982 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
53983 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
53984 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
53985 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
53986 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
53987 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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
53993 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
53994 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
53995 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
53996 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
53997 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
53998 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
53999 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54000 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54001 +4 0 0 4 0 0 4 0 0 6 6 6 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
54007 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54008 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54009 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54010 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54011 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54012 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54013 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54014 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54015 +4 0 0 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
54021 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54022 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54023 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54024 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54025 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54026 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54027 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54028 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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
54035 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54036 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54037 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54038 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54039 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54040 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54041 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54042 +6 6 6 4 0 0 4 0 0 4 3 3 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
54049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54050 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54051 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54052 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54053 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54054 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54055 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54056 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4
54060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54062 +4 4 4 4 4 4
54063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54064 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54065 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54066 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54067 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54068 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54069 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54070 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54076 +4 4 4 4 4 4
54077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54078 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54079 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54080 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54081 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54082 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54083 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54084 +5 5 5 5 5 5 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54090 +4 4 4 4 4 4
54091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54093 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54094 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54095 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54096 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54097 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54098 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
54101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54104 +4 4 4 4 4 4
54105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54108 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54109 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54110 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54111 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54118 +4 4 4 4 4 4
54119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54122 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54123 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54124 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
54125 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4
54128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54132 +4 4 4 4 4 4
54133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54136 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54137 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54138 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54139 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4
54142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54146 +4 4 4 4 4 4
54147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54150 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
54151 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
54152 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
54153 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
54156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54160 +4 4 4 4 4 4
54161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54165 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
54166 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54167 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54174 +4 4 4 4 4 4
54175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54179 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
54180 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
54181 +4 3 3 5 5 5 5 5 5 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54188 +4 4 4 4 4 4
54189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54193 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
54194 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
54195 +5 5 5 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 4 4 4 4 4 4
54197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54202 +4 4 4 4 4 4
54203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54207 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
54208 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
54209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54216 +4 4 4 4 4 4
54217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54221 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54222 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
54223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54230 +4 4 4 4 4 4
54231 diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
54232 index a01147f..5d896f8 100644
54233 --- a/drivers/video/matrox/matroxfb_DAC1064.c
54234 +++ b/drivers/video/matrox/matroxfb_DAC1064.c
54235 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
54236
54237 #ifdef CONFIG_FB_MATROX_MYSTIQUE
54238 struct matrox_switch matrox_mystique = {
54239 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
54240 + .preinit = MGA1064_preinit,
54241 + .reset = MGA1064_reset,
54242 + .init = MGA1064_init,
54243 + .restore = MGA1064_restore,
54244 };
54245 EXPORT_SYMBOL(matrox_mystique);
54246 #endif
54247
54248 #ifdef CONFIG_FB_MATROX_G
54249 struct matrox_switch matrox_G100 = {
54250 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
54251 + .preinit = MGAG100_preinit,
54252 + .reset = MGAG100_reset,
54253 + .init = MGAG100_init,
54254 + .restore = MGAG100_restore,
54255 };
54256 EXPORT_SYMBOL(matrox_G100);
54257 #endif
54258 diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
54259 index 195ad7c..09743fc 100644
54260 --- a/drivers/video/matrox/matroxfb_Ti3026.c
54261 +++ b/drivers/video/matrox/matroxfb_Ti3026.c
54262 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
54263 }
54264
54265 struct matrox_switch matrox_millennium = {
54266 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
54267 + .preinit = Ti3026_preinit,
54268 + .reset = Ti3026_reset,
54269 + .init = Ti3026_init,
54270 + .restore = Ti3026_restore
54271 };
54272 EXPORT_SYMBOL(matrox_millennium);
54273 #endif
54274 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
54275 index fe92eed..106e085 100644
54276 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
54277 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
54278 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
54279 struct mb862xxfb_par *par = info->par;
54280
54281 if (info->var.bits_per_pixel == 32) {
54282 - info->fbops->fb_fillrect = cfb_fillrect;
54283 - info->fbops->fb_copyarea = cfb_copyarea;
54284 - info->fbops->fb_imageblit = cfb_imageblit;
54285 + pax_open_kernel();
54286 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54287 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54288 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54289 + pax_close_kernel();
54290 } else {
54291 outreg(disp, GC_L0EM, 3);
54292 - info->fbops->fb_fillrect = mb86290fb_fillrect;
54293 - info->fbops->fb_copyarea = mb86290fb_copyarea;
54294 - info->fbops->fb_imageblit = mb86290fb_imageblit;
54295 + pax_open_kernel();
54296 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
54297 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
54298 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
54299 + pax_close_kernel();
54300 }
54301 outreg(draw, GDC_REG_DRAW_BASE, 0);
54302 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
54303 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
54304 index ff22871..b129bed 100644
54305 --- a/drivers/video/nvidia/nvidia.c
54306 +++ b/drivers/video/nvidia/nvidia.c
54307 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
54308 info->fix.line_length = (info->var.xres_virtual *
54309 info->var.bits_per_pixel) >> 3;
54310 if (info->var.accel_flags) {
54311 - info->fbops->fb_imageblit = nvidiafb_imageblit;
54312 - info->fbops->fb_fillrect = nvidiafb_fillrect;
54313 - info->fbops->fb_copyarea = nvidiafb_copyarea;
54314 - info->fbops->fb_sync = nvidiafb_sync;
54315 + pax_open_kernel();
54316 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
54317 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
54318 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
54319 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
54320 + pax_close_kernel();
54321 info->pixmap.scan_align = 4;
54322 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54323 info->flags |= FBINFO_READS_FAST;
54324 NVResetGraphics(info);
54325 } else {
54326 - info->fbops->fb_imageblit = cfb_imageblit;
54327 - info->fbops->fb_fillrect = cfb_fillrect;
54328 - info->fbops->fb_copyarea = cfb_copyarea;
54329 - info->fbops->fb_sync = NULL;
54330 + pax_open_kernel();
54331 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54332 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54333 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54334 + *(void **)&info->fbops->fb_sync = NULL;
54335 + pax_close_kernel();
54336 info->pixmap.scan_align = 1;
54337 info->flags |= FBINFO_HWACCEL_DISABLED;
54338 info->flags &= ~FBINFO_READS_FAST;
54339 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
54340 info->pixmap.size = 8 * 1024;
54341 info->pixmap.flags = FB_PIXMAP_SYSTEM;
54342
54343 - if (!hwcur)
54344 - info->fbops->fb_cursor = NULL;
54345 + if (!hwcur) {
54346 + pax_open_kernel();
54347 + *(void **)&info->fbops->fb_cursor = NULL;
54348 + pax_close_kernel();
54349 + }
54350
54351 info->var.accel_flags = (!noaccel);
54352
54353 diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
54354 index 669a81f..e216d76 100644
54355 --- a/drivers/video/omap2/dss/display.c
54356 +++ b/drivers/video/omap2/dss/display.c
54357 @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
54358 snprintf(dssdev->alias, sizeof(dssdev->alias),
54359 "display%d", disp_num_counter++);
54360
54361 + pax_open_kernel();
54362 if (drv && drv->get_resolution == NULL)
54363 - drv->get_resolution = omapdss_default_get_resolution;
54364 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
54365 if (drv && drv->get_recommended_bpp == NULL)
54366 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54367 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54368 if (drv && drv->get_timings == NULL)
54369 - drv->get_timings = omapdss_default_get_timings;
54370 + *(void **)&drv->get_timings = omapdss_default_get_timings;
54371 + pax_close_kernel();
54372
54373 mutex_lock(&panel_list_mutex);
54374 list_add_tail(&dssdev->panel_list, &panel_list);
54375 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
54376 index 83433cb..71e9b98 100644
54377 --- a/drivers/video/s1d13xxxfb.c
54378 +++ b/drivers/video/s1d13xxxfb.c
54379 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
54380
54381 switch(prod_id) {
54382 case S1D13506_PROD_ID: /* activate acceleration */
54383 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54384 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54385 + pax_open_kernel();
54386 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54387 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54388 + pax_close_kernel();
54389 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
54390 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
54391 break;
54392 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
54393 index d513ed6..90b0de9 100644
54394 --- a/drivers/video/smscufx.c
54395 +++ b/drivers/video/smscufx.c
54396 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
54397 fb_deferred_io_cleanup(info);
54398 kfree(info->fbdefio);
54399 info->fbdefio = NULL;
54400 - info->fbops->fb_mmap = ufx_ops_mmap;
54401 + pax_open_kernel();
54402 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
54403 + pax_close_kernel();
54404 }
54405
54406 pr_debug("released /dev/fb%d user=%d count=%d",
54407 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
54408 index 025f14e..20eb4db 100644
54409 --- a/drivers/video/udlfb.c
54410 +++ b/drivers/video/udlfb.c
54411 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
54412 dlfb_urb_completion(urb);
54413
54414 error:
54415 - atomic_add(bytes_sent, &dev->bytes_sent);
54416 - atomic_add(bytes_identical, &dev->bytes_identical);
54417 - atomic_add(width*height*2, &dev->bytes_rendered);
54418 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54419 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54420 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
54421 end_cycles = get_cycles();
54422 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
54423 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54424 >> 10)), /* Kcycles */
54425 &dev->cpu_kcycles_used);
54426
54427 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
54428 dlfb_urb_completion(urb);
54429
54430 error:
54431 - atomic_add(bytes_sent, &dev->bytes_sent);
54432 - atomic_add(bytes_identical, &dev->bytes_identical);
54433 - atomic_add(bytes_rendered, &dev->bytes_rendered);
54434 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54435 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54436 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
54437 end_cycles = get_cycles();
54438 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
54439 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54440 >> 10)), /* Kcycles */
54441 &dev->cpu_kcycles_used);
54442 }
54443 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
54444 fb_deferred_io_cleanup(info);
54445 kfree(info->fbdefio);
54446 info->fbdefio = NULL;
54447 - info->fbops->fb_mmap = dlfb_ops_mmap;
54448 + pax_open_kernel();
54449 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
54450 + pax_close_kernel();
54451 }
54452
54453 pr_warn("released /dev/fb%d user=%d count=%d\n",
54454 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
54455 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54456 struct dlfb_data *dev = fb_info->par;
54457 return snprintf(buf, PAGE_SIZE, "%u\n",
54458 - atomic_read(&dev->bytes_rendered));
54459 + atomic_read_unchecked(&dev->bytes_rendered));
54460 }
54461
54462 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54463 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54464 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54465 struct dlfb_data *dev = fb_info->par;
54466 return snprintf(buf, PAGE_SIZE, "%u\n",
54467 - atomic_read(&dev->bytes_identical));
54468 + atomic_read_unchecked(&dev->bytes_identical));
54469 }
54470
54471 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54472 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54473 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54474 struct dlfb_data *dev = fb_info->par;
54475 return snprintf(buf, PAGE_SIZE, "%u\n",
54476 - atomic_read(&dev->bytes_sent));
54477 + atomic_read_unchecked(&dev->bytes_sent));
54478 }
54479
54480 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54481 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54482 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54483 struct dlfb_data *dev = fb_info->par;
54484 return snprintf(buf, PAGE_SIZE, "%u\n",
54485 - atomic_read(&dev->cpu_kcycles_used));
54486 + atomic_read_unchecked(&dev->cpu_kcycles_used));
54487 }
54488
54489 static ssize_t edid_show(
54490 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
54491 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54492 struct dlfb_data *dev = fb_info->par;
54493
54494 - atomic_set(&dev->bytes_rendered, 0);
54495 - atomic_set(&dev->bytes_identical, 0);
54496 - atomic_set(&dev->bytes_sent, 0);
54497 - atomic_set(&dev->cpu_kcycles_used, 0);
54498 + atomic_set_unchecked(&dev->bytes_rendered, 0);
54499 + atomic_set_unchecked(&dev->bytes_identical, 0);
54500 + atomic_set_unchecked(&dev->bytes_sent, 0);
54501 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
54502
54503 return count;
54504 }
54505 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
54506 index 256fba7..6e75516 100644
54507 --- a/drivers/video/uvesafb.c
54508 +++ b/drivers/video/uvesafb.c
54509 @@ -19,6 +19,7 @@
54510 #include <linux/io.h>
54511 #include <linux/mutex.h>
54512 #include <linux/slab.h>
54513 +#include <linux/moduleloader.h>
54514 #include <video/edid.h>
54515 #include <video/uvesafb.h>
54516 #ifdef CONFIG_X86
54517 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
54518 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
54519 par->pmi_setpal = par->ypan = 0;
54520 } else {
54521 +
54522 +#ifdef CONFIG_PAX_KERNEXEC
54523 +#ifdef CONFIG_MODULES
54524 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
54525 +#endif
54526 + if (!par->pmi_code) {
54527 + par->pmi_setpal = par->ypan = 0;
54528 + return 0;
54529 + }
54530 +#endif
54531 +
54532 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
54533 + task->t.regs.edi);
54534 +
54535 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54536 + pax_open_kernel();
54537 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
54538 + pax_close_kernel();
54539 +
54540 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
54541 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
54542 +#else
54543 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
54544 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
54545 +#endif
54546 +
54547 printk(KERN_INFO "uvesafb: protected mode interface info at "
54548 "%04x:%04x\n",
54549 (u16)task->t.regs.es, (u16)task->t.regs.edi);
54550 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
54551 par->ypan = ypan;
54552
54553 if (par->pmi_setpal || par->ypan) {
54554 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
54555 if (__supported_pte_mask & _PAGE_NX) {
54556 par->pmi_setpal = par->ypan = 0;
54557 printk(KERN_WARNING "uvesafb: NX protection is active, "
54558 "better not use the PMI.\n");
54559 - } else {
54560 + } else
54561 +#endif
54562 uvesafb_vbe_getpmi(task, par);
54563 - }
54564 }
54565 #else
54566 /* The protected mode interface is not available on non-x86. */
54567 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54568 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
54569
54570 /* Disable blanking if the user requested so. */
54571 - if (!blank)
54572 - info->fbops->fb_blank = NULL;
54573 + if (!blank) {
54574 + pax_open_kernel();
54575 + *(void **)&info->fbops->fb_blank = NULL;
54576 + pax_close_kernel();
54577 + }
54578
54579 /*
54580 * Find out how much IO memory is required for the mode with
54581 @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54582 info->flags = FBINFO_FLAG_DEFAULT |
54583 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
54584
54585 - if (!par->ypan)
54586 - info->fbops->fb_pan_display = NULL;
54587 + if (!par->ypan) {
54588 + pax_open_kernel();
54589 + *(void **)&info->fbops->fb_pan_display = NULL;
54590 + pax_close_kernel();
54591 + }
54592 }
54593
54594 static void uvesafb_init_mtrr(struct fb_info *info)
54595 @@ -1792,6 +1822,11 @@ out_mode:
54596 out:
54597 kfree(par->vbe_modes);
54598
54599 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54600 + if (par->pmi_code)
54601 + module_free_exec(NULL, par->pmi_code);
54602 +#endif
54603 +
54604 framebuffer_release(info);
54605 return err;
54606 }
54607 @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
54608 kfree(par->vbe_modes);
54609 kfree(par->vbe_state_orig);
54610 kfree(par->vbe_state_saved);
54611 +
54612 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54613 + if (par->pmi_code)
54614 + module_free_exec(NULL, par->pmi_code);
54615 +#endif
54616 +
54617 }
54618
54619 framebuffer_release(info);
54620 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
54621 index 1c7da3b..56ea0bd 100644
54622 --- a/drivers/video/vesafb.c
54623 +++ b/drivers/video/vesafb.c
54624 @@ -9,6 +9,7 @@
54625 */
54626
54627 #include <linux/module.h>
54628 +#include <linux/moduleloader.h>
54629 #include <linux/kernel.h>
54630 #include <linux/errno.h>
54631 #include <linux/string.h>
54632 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
54633 static int vram_total; /* Set total amount of memory */
54634 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
54635 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
54636 -static void (*pmi_start)(void) __read_mostly;
54637 -static void (*pmi_pal) (void) __read_mostly;
54638 +static void (*pmi_start)(void) __read_only;
54639 +static void (*pmi_pal) (void) __read_only;
54640 static int depth __read_mostly;
54641 static int vga_compat __read_mostly;
54642 /* --------------------------------------------------------------------- */
54643 @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
54644 unsigned int size_remap;
54645 unsigned int size_total;
54646 char *option = NULL;
54647 + void *pmi_code = NULL;
54648
54649 /* ignore error return of fb_get_options */
54650 fb_get_options("vesafb", &option);
54651 @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
54652 size_remap = size_total;
54653 vesafb_fix.smem_len = size_remap;
54654
54655 -#ifndef __i386__
54656 - screen_info.vesapm_seg = 0;
54657 -#endif
54658 -
54659 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
54660 printk(KERN_WARNING
54661 "vesafb: cannot reserve video memory at 0x%lx\n",
54662 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
54663 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
54664 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
54665
54666 +#ifdef __i386__
54667 +
54668 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54669 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
54670 + if (!pmi_code)
54671 +#elif !defined(CONFIG_PAX_KERNEXEC)
54672 + if (0)
54673 +#endif
54674 +
54675 +#endif
54676 + screen_info.vesapm_seg = 0;
54677 +
54678 if (screen_info.vesapm_seg) {
54679 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
54680 - screen_info.vesapm_seg,screen_info.vesapm_off);
54681 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
54682 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
54683 }
54684
54685 if (screen_info.vesapm_seg < 0xc000)
54686 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
54687
54688 if (ypan || pmi_setpal) {
54689 unsigned short *pmi_base;
54690 +
54691 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
54692 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
54693 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
54694 +
54695 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54696 + pax_open_kernel();
54697 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
54698 +#else
54699 + pmi_code = pmi_base;
54700 +#endif
54701 +
54702 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
54703 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
54704 +
54705 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54706 + pmi_start = ktva_ktla(pmi_start);
54707 + pmi_pal = ktva_ktla(pmi_pal);
54708 + pax_close_kernel();
54709 +#endif
54710 +
54711 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
54712 if (pmi_base[3]) {
54713 printk(KERN_INFO "vesafb: pmi: ports = ");
54714 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
54715 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
54716 (ypan ? FBINFO_HWACCEL_YPAN : 0);
54717
54718 - if (!ypan)
54719 - info->fbops->fb_pan_display = NULL;
54720 + if (!ypan) {
54721 + pax_open_kernel();
54722 + *(void **)&info->fbops->fb_pan_display = NULL;
54723 + pax_close_kernel();
54724 + }
54725
54726 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
54727 err = -ENOMEM;
54728 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
54729 fb_info(info, "%s frame buffer device\n", info->fix.id);
54730 return 0;
54731 err:
54732 +
54733 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54734 + module_free_exec(NULL, pmi_code);
54735 +#endif
54736 +
54737 if (info->screen_base)
54738 iounmap(info->screen_base);
54739 framebuffer_release(info);
54740 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
54741 index 88714ae..16c2e11 100644
54742 --- a/drivers/video/via/via_clock.h
54743 +++ b/drivers/video/via/via_clock.h
54744 @@ -56,7 +56,7 @@ struct via_clock {
54745
54746 void (*set_engine_pll_state)(u8 state);
54747 void (*set_engine_pll)(struct via_pll_config config);
54748 -};
54749 +} __no_const;
54750
54751
54752 static inline u32 get_pll_internal_frequency(u32 ref_freq,
54753 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
54754 index fef20db..d28b1ab 100644
54755 --- a/drivers/xen/xenfs/xenstored.c
54756 +++ b/drivers/xen/xenfs/xenstored.c
54757 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
54758 static int xsd_kva_open(struct inode *inode, struct file *file)
54759 {
54760 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
54761 +#ifdef CONFIG_GRKERNSEC_HIDESYM
54762 + NULL);
54763 +#else
54764 xen_store_interface);
54765 +#endif
54766 +
54767 if (!file->private_data)
54768 return -ENOMEM;
54769 return 0;
54770 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
54771 index 9ff073f..05cef23 100644
54772 --- a/fs/9p/vfs_addr.c
54773 +++ b/fs/9p/vfs_addr.c
54774 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
54775
54776 retval = v9fs_file_write_internal(inode,
54777 v9inode->writeback_fid,
54778 - (__force const char __user *)buffer,
54779 + (const char __force_user *)buffer,
54780 len, &offset, 0);
54781 if (retval > 0)
54782 retval = 0;
54783 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
54784 index 4e65aa9..043dc9a 100644
54785 --- a/fs/9p/vfs_inode.c
54786 +++ b/fs/9p/vfs_inode.c
54787 @@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
54788 void
54789 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
54790 {
54791 - char *s = nd_get_link(nd);
54792 + const char *s = nd_get_link(nd);
54793
54794 p9_debug(P9_DEBUG_VFS, " %s %s\n",
54795 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
54796 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
54797 index 370b24c..ff0be7b 100644
54798 --- a/fs/Kconfig.binfmt
54799 +++ b/fs/Kconfig.binfmt
54800 @@ -103,7 +103,7 @@ config HAVE_AOUT
54801
54802 config BINFMT_AOUT
54803 tristate "Kernel support for a.out and ECOFF binaries"
54804 - depends on HAVE_AOUT
54805 + depends on HAVE_AOUT && BROKEN
54806 ---help---
54807 A.out (Assembler.OUTput) is a set of formats for libraries and
54808 executables used in the earliest versions of UNIX. Linux used
54809 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
54810 index ce25d75..dc09eeb 100644
54811 --- a/fs/afs/inode.c
54812 +++ b/fs/afs/inode.c
54813 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54814 struct afs_vnode *vnode;
54815 struct super_block *sb;
54816 struct inode *inode;
54817 - static atomic_t afs_autocell_ino;
54818 + static atomic_unchecked_t afs_autocell_ino;
54819
54820 _enter("{%x:%u},%*.*s,",
54821 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
54822 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54823 data.fid.unique = 0;
54824 data.fid.vnode = 0;
54825
54826 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
54827 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
54828 afs_iget5_autocell_test, afs_iget5_set,
54829 &data);
54830 if (!inode) {
54831 diff --git a/fs/aio.c b/fs/aio.c
54832 index 062a5f6..e5618e0 100644
54833 --- a/fs/aio.c
54834 +++ b/fs/aio.c
54835 @@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
54836 size += sizeof(struct io_event) * nr_events;
54837
54838 nr_pages = PFN_UP(size);
54839 - if (nr_pages < 0)
54840 + if (nr_pages <= 0)
54841 return -EINVAL;
54842
54843 file = aio_private_file(ctx, nr_pages);
54844 diff --git a/fs/attr.c b/fs/attr.c
54845 index 267968d..5dd8f96 100644
54846 --- a/fs/attr.c
54847 +++ b/fs/attr.c
54848 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
54849 unsigned long limit;
54850
54851 limit = rlimit(RLIMIT_FSIZE);
54852 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
54853 if (limit != RLIM_INFINITY && offset > limit)
54854 goto out_sig;
54855 if (offset > inode->i_sb->s_maxbytes)
54856 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
54857 index 689e40d..515cac5 100644
54858 --- a/fs/autofs4/waitq.c
54859 +++ b/fs/autofs4/waitq.c
54860 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
54861 {
54862 unsigned long sigpipe, flags;
54863 mm_segment_t fs;
54864 - const char *data = (const char *)addr;
54865 + const char __user *data = (const char __force_user *)addr;
54866 ssize_t wr = 0;
54867
54868 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
54869 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
54870 return 1;
54871 }
54872
54873 +#ifdef CONFIG_GRKERNSEC_HIDESYM
54874 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
54875 +#endif
54876 +
54877 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
54878 enum autofs_notify notify)
54879 {
54880 @@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
54881
54882 /* If this is a direct mount request create a dummy name */
54883 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
54884 +#ifdef CONFIG_GRKERNSEC_HIDESYM
54885 + /* this name does get written to userland via autofs4_write() */
54886 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
54887 +#else
54888 qstr.len = sprintf(name, "%p", dentry);
54889 +#endif
54890 else {
54891 qstr.len = autofs4_getpath(sbi, dentry, &name);
54892 if (!qstr.len) {
54893 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
54894 index 2722387..56059b5 100644
54895 --- a/fs/befs/endian.h
54896 +++ b/fs/befs/endian.h
54897 @@ -11,7 +11,7 @@
54898
54899 #include <asm/byteorder.h>
54900
54901 -static inline u64
54902 +static inline u64 __intentional_overflow(-1)
54903 fs64_to_cpu(const struct super_block *sb, fs64 n)
54904 {
54905 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
54906 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
54907 return (__force fs64)cpu_to_be64(n);
54908 }
54909
54910 -static inline u32
54911 +static inline u32 __intentional_overflow(-1)
54912 fs32_to_cpu(const struct super_block *sb, fs32 n)
54913 {
54914 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
54915 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
54916 return (__force fs32)cpu_to_be32(n);
54917 }
54918
54919 -static inline u16
54920 +static inline u16 __intentional_overflow(-1)
54921 fs16_to_cpu(const struct super_block *sb, fs16 n)
54922 {
54923 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
54924 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
54925 index ca0ba15..0fa3257 100644
54926 --- a/fs/binfmt_aout.c
54927 +++ b/fs/binfmt_aout.c
54928 @@ -16,6 +16,7 @@
54929 #include <linux/string.h>
54930 #include <linux/fs.h>
54931 #include <linux/file.h>
54932 +#include <linux/security.h>
54933 #include <linux/stat.h>
54934 #include <linux/fcntl.h>
54935 #include <linux/ptrace.h>
54936 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
54937 #endif
54938 # define START_STACK(u) ((void __user *)u.start_stack)
54939
54940 + memset(&dump, 0, sizeof(dump));
54941 +
54942 fs = get_fs();
54943 set_fs(KERNEL_DS);
54944 has_dumped = 1;
54945 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
54946
54947 /* If the size of the dump file exceeds the rlimit, then see what would happen
54948 if we wrote the stack, but not the data area. */
54949 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
54950 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
54951 dump.u_dsize = 0;
54952
54953 /* Make sure we have enough room to write the stack and data areas. */
54954 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
54955 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
54956 dump.u_ssize = 0;
54957
54958 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
54959 rlim = rlimit(RLIMIT_DATA);
54960 if (rlim >= RLIM_INFINITY)
54961 rlim = ~0;
54962 +
54963 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
54964 if (ex.a_data + ex.a_bss > rlim)
54965 return -ENOMEM;
54966
54967 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
54968
54969 install_exec_creds(bprm);
54970
54971 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54972 + current->mm->pax_flags = 0UL;
54973 +#endif
54974 +
54975 +#ifdef CONFIG_PAX_PAGEEXEC
54976 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
54977 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
54978 +
54979 +#ifdef CONFIG_PAX_EMUTRAMP
54980 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
54981 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
54982 +#endif
54983 +
54984 +#ifdef CONFIG_PAX_MPROTECT
54985 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
54986 + current->mm->pax_flags |= MF_PAX_MPROTECT;
54987 +#endif
54988 +
54989 + }
54990 +#endif
54991 +
54992 if (N_MAGIC(ex) == OMAGIC) {
54993 unsigned long text_addr, map_size;
54994 loff_t pos;
54995 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
54996 }
54997
54998 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
54999 - PROT_READ | PROT_WRITE | PROT_EXEC,
55000 + PROT_READ | PROT_WRITE,
55001 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
55002 fd_offset + ex.a_text);
55003 if (error != N_DATADDR(ex)) {
55004 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
55005 index 571a423..dbb9c6c 100644
55006 --- a/fs/binfmt_elf.c
55007 +++ b/fs/binfmt_elf.c
55008 @@ -34,6 +34,7 @@
55009 #include <linux/utsname.h>
55010 #include <linux/coredump.h>
55011 #include <linux/sched.h>
55012 +#include <linux/xattr.h>
55013 #include <asm/uaccess.h>
55014 #include <asm/param.h>
55015 #include <asm/page.h>
55016 @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
55017 #define elf_core_dump NULL
55018 #endif
55019
55020 +#ifdef CONFIG_PAX_MPROTECT
55021 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
55022 +#endif
55023 +
55024 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55025 +static void elf_handle_mmap(struct file *file);
55026 +#endif
55027 +
55028 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
55029 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
55030 #else
55031 @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
55032 .load_binary = load_elf_binary,
55033 .load_shlib = load_elf_library,
55034 .core_dump = elf_core_dump,
55035 +
55036 +#ifdef CONFIG_PAX_MPROTECT
55037 + .handle_mprotect= elf_handle_mprotect,
55038 +#endif
55039 +
55040 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55041 + .handle_mmap = elf_handle_mmap,
55042 +#endif
55043 +
55044 .min_coredump = ELF_EXEC_PAGESIZE,
55045 };
55046
55047 @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
55048
55049 static int set_brk(unsigned long start, unsigned long end)
55050 {
55051 + unsigned long e = end;
55052 +
55053 start = ELF_PAGEALIGN(start);
55054 end = ELF_PAGEALIGN(end);
55055 if (end > start) {
55056 @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
55057 if (BAD_ADDR(addr))
55058 return addr;
55059 }
55060 - current->mm->start_brk = current->mm->brk = end;
55061 + current->mm->start_brk = current->mm->brk = e;
55062 return 0;
55063 }
55064
55065 @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55066 elf_addr_t __user *u_rand_bytes;
55067 const char *k_platform = ELF_PLATFORM;
55068 const char *k_base_platform = ELF_BASE_PLATFORM;
55069 - unsigned char k_rand_bytes[16];
55070 + u32 k_rand_bytes[4];
55071 int items;
55072 elf_addr_t *elf_info;
55073 int ei_index = 0;
55074 const struct cred *cred = current_cred();
55075 struct vm_area_struct *vma;
55076 + unsigned long saved_auxv[AT_VECTOR_SIZE];
55077
55078 /*
55079 * In some cases (e.g. Hyper-Threading), we want to avoid L1
55080 @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55081 * Generate 16 random bytes for userspace PRNG seeding.
55082 */
55083 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
55084 - u_rand_bytes = (elf_addr_t __user *)
55085 - STACK_ALLOC(p, sizeof(k_rand_bytes));
55086 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
55087 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
55088 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
55089 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
55090 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
55091 + u_rand_bytes = (elf_addr_t __user *) p;
55092 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
55093 return -EFAULT;
55094
55095 @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55096 return -EFAULT;
55097 current->mm->env_end = p;
55098
55099 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
55100 +
55101 /* Put the elf_info on the stack in the right place. */
55102 sp = (elf_addr_t __user *)envp + 1;
55103 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
55104 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
55105 return -EFAULT;
55106 return 0;
55107 }
55108 @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
55109 an ELF header */
55110
55111 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55112 - struct file *interpreter, unsigned long *interp_map_addr,
55113 - unsigned long no_base)
55114 + struct file *interpreter, unsigned long no_base)
55115 {
55116 struct elf_phdr *elf_phdata;
55117 struct elf_phdr *eppnt;
55118 - unsigned long load_addr = 0;
55119 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
55120 int load_addr_set = 0;
55121 unsigned long last_bss = 0, elf_bss = 0;
55122 - unsigned long error = ~0UL;
55123 + unsigned long error = -EINVAL;
55124 unsigned long total_size;
55125 int retval, i, size;
55126
55127 @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55128 goto out_close;
55129 }
55130
55131 +#ifdef CONFIG_PAX_SEGMEXEC
55132 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
55133 + pax_task_size = SEGMEXEC_TASK_SIZE;
55134 +#endif
55135 +
55136 eppnt = elf_phdata;
55137 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
55138 if (eppnt->p_type == PT_LOAD) {
55139 @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55140 map_addr = elf_map(interpreter, load_addr + vaddr,
55141 eppnt, elf_prot, elf_type, total_size);
55142 total_size = 0;
55143 - if (!*interp_map_addr)
55144 - *interp_map_addr = map_addr;
55145 error = map_addr;
55146 if (BAD_ADDR(map_addr))
55147 goto out_close;
55148 @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55149 k = load_addr + eppnt->p_vaddr;
55150 if (BAD_ADDR(k) ||
55151 eppnt->p_filesz > eppnt->p_memsz ||
55152 - eppnt->p_memsz > TASK_SIZE ||
55153 - TASK_SIZE - eppnt->p_memsz < k) {
55154 + eppnt->p_memsz > pax_task_size ||
55155 + pax_task_size - eppnt->p_memsz < k) {
55156 error = -ENOMEM;
55157 goto out_close;
55158 }
55159 @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55160 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
55161
55162 /* Map the last of the bss segment */
55163 - error = vm_brk(elf_bss, last_bss - elf_bss);
55164 - if (BAD_ADDR(error))
55165 - goto out_close;
55166 + if (last_bss > elf_bss) {
55167 + error = vm_brk(elf_bss, last_bss - elf_bss);
55168 + if (BAD_ADDR(error))
55169 + goto out_close;
55170 + }
55171 }
55172
55173 error = load_addr;
55174 @@ -538,6 +569,336 @@ out:
55175 return error;
55176 }
55177
55178 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
55179 +#ifdef CONFIG_PAX_SOFTMODE
55180 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
55181 +{
55182 + unsigned long pax_flags = 0UL;
55183 +
55184 +#ifdef CONFIG_PAX_PAGEEXEC
55185 + if (elf_phdata->p_flags & PF_PAGEEXEC)
55186 + pax_flags |= MF_PAX_PAGEEXEC;
55187 +#endif
55188 +
55189 +#ifdef CONFIG_PAX_SEGMEXEC
55190 + if (elf_phdata->p_flags & PF_SEGMEXEC)
55191 + pax_flags |= MF_PAX_SEGMEXEC;
55192 +#endif
55193 +
55194 +#ifdef CONFIG_PAX_EMUTRAMP
55195 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
55196 + pax_flags |= MF_PAX_EMUTRAMP;
55197 +#endif
55198 +
55199 +#ifdef CONFIG_PAX_MPROTECT
55200 + if (elf_phdata->p_flags & PF_MPROTECT)
55201 + pax_flags |= MF_PAX_MPROTECT;
55202 +#endif
55203 +
55204 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55205 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
55206 + pax_flags |= MF_PAX_RANDMMAP;
55207 +#endif
55208 +
55209 + return pax_flags;
55210 +}
55211 +#endif
55212 +
55213 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
55214 +{
55215 + unsigned long pax_flags = 0UL;
55216 +
55217 +#ifdef CONFIG_PAX_PAGEEXEC
55218 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
55219 + pax_flags |= MF_PAX_PAGEEXEC;
55220 +#endif
55221 +
55222 +#ifdef CONFIG_PAX_SEGMEXEC
55223 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
55224 + pax_flags |= MF_PAX_SEGMEXEC;
55225 +#endif
55226 +
55227 +#ifdef CONFIG_PAX_EMUTRAMP
55228 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
55229 + pax_flags |= MF_PAX_EMUTRAMP;
55230 +#endif
55231 +
55232 +#ifdef CONFIG_PAX_MPROTECT
55233 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
55234 + pax_flags |= MF_PAX_MPROTECT;
55235 +#endif
55236 +
55237 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55238 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
55239 + pax_flags |= MF_PAX_RANDMMAP;
55240 +#endif
55241 +
55242 + return pax_flags;
55243 +}
55244 +#endif
55245 +
55246 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55247 +#ifdef CONFIG_PAX_SOFTMODE
55248 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
55249 +{
55250 + unsigned long pax_flags = 0UL;
55251 +
55252 +#ifdef CONFIG_PAX_PAGEEXEC
55253 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
55254 + pax_flags |= MF_PAX_PAGEEXEC;
55255 +#endif
55256 +
55257 +#ifdef CONFIG_PAX_SEGMEXEC
55258 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
55259 + pax_flags |= MF_PAX_SEGMEXEC;
55260 +#endif
55261 +
55262 +#ifdef CONFIG_PAX_EMUTRAMP
55263 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
55264 + pax_flags |= MF_PAX_EMUTRAMP;
55265 +#endif
55266 +
55267 +#ifdef CONFIG_PAX_MPROTECT
55268 + if (pax_flags_softmode & MF_PAX_MPROTECT)
55269 + pax_flags |= MF_PAX_MPROTECT;
55270 +#endif
55271 +
55272 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55273 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
55274 + pax_flags |= MF_PAX_RANDMMAP;
55275 +#endif
55276 +
55277 + return pax_flags;
55278 +}
55279 +#endif
55280 +
55281 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
55282 +{
55283 + unsigned long pax_flags = 0UL;
55284 +
55285 +#ifdef CONFIG_PAX_PAGEEXEC
55286 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
55287 + pax_flags |= MF_PAX_PAGEEXEC;
55288 +#endif
55289 +
55290 +#ifdef CONFIG_PAX_SEGMEXEC
55291 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
55292 + pax_flags |= MF_PAX_SEGMEXEC;
55293 +#endif
55294 +
55295 +#ifdef CONFIG_PAX_EMUTRAMP
55296 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
55297 + pax_flags |= MF_PAX_EMUTRAMP;
55298 +#endif
55299 +
55300 +#ifdef CONFIG_PAX_MPROTECT
55301 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
55302 + pax_flags |= MF_PAX_MPROTECT;
55303 +#endif
55304 +
55305 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55306 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
55307 + pax_flags |= MF_PAX_RANDMMAP;
55308 +#endif
55309 +
55310 + return pax_flags;
55311 +}
55312 +#endif
55313 +
55314 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55315 +static unsigned long pax_parse_defaults(void)
55316 +{
55317 + unsigned long pax_flags = 0UL;
55318 +
55319 +#ifdef CONFIG_PAX_SOFTMODE
55320 + if (pax_softmode)
55321 + return pax_flags;
55322 +#endif
55323 +
55324 +#ifdef CONFIG_PAX_PAGEEXEC
55325 + pax_flags |= MF_PAX_PAGEEXEC;
55326 +#endif
55327 +
55328 +#ifdef CONFIG_PAX_SEGMEXEC
55329 + pax_flags |= MF_PAX_SEGMEXEC;
55330 +#endif
55331 +
55332 +#ifdef CONFIG_PAX_MPROTECT
55333 + pax_flags |= MF_PAX_MPROTECT;
55334 +#endif
55335 +
55336 +#ifdef CONFIG_PAX_RANDMMAP
55337 + if (randomize_va_space)
55338 + pax_flags |= MF_PAX_RANDMMAP;
55339 +#endif
55340 +
55341 + return pax_flags;
55342 +}
55343 +
55344 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
55345 +{
55346 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
55347 +
55348 +#ifdef CONFIG_PAX_EI_PAX
55349 +
55350 +#ifdef CONFIG_PAX_SOFTMODE
55351 + if (pax_softmode)
55352 + return pax_flags;
55353 +#endif
55354 +
55355 + pax_flags = 0UL;
55356 +
55357 +#ifdef CONFIG_PAX_PAGEEXEC
55358 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
55359 + pax_flags |= MF_PAX_PAGEEXEC;
55360 +#endif
55361 +
55362 +#ifdef CONFIG_PAX_SEGMEXEC
55363 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
55364 + pax_flags |= MF_PAX_SEGMEXEC;
55365 +#endif
55366 +
55367 +#ifdef CONFIG_PAX_EMUTRAMP
55368 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
55369 + pax_flags |= MF_PAX_EMUTRAMP;
55370 +#endif
55371 +
55372 +#ifdef CONFIG_PAX_MPROTECT
55373 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
55374 + pax_flags |= MF_PAX_MPROTECT;
55375 +#endif
55376 +
55377 +#ifdef CONFIG_PAX_ASLR
55378 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
55379 + pax_flags |= MF_PAX_RANDMMAP;
55380 +#endif
55381 +
55382 +#endif
55383 +
55384 + return pax_flags;
55385 +
55386 +}
55387 +
55388 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
55389 +{
55390 +
55391 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
55392 + unsigned long i;
55393 +
55394 + for (i = 0UL; i < elf_ex->e_phnum; i++)
55395 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
55396 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
55397 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
55398 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
55399 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
55400 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
55401 + return PAX_PARSE_FLAGS_FALLBACK;
55402 +
55403 +#ifdef CONFIG_PAX_SOFTMODE
55404 + if (pax_softmode)
55405 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
55406 + else
55407 +#endif
55408 +
55409 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
55410 + break;
55411 + }
55412 +#endif
55413 +
55414 + return PAX_PARSE_FLAGS_FALLBACK;
55415 +}
55416 +
55417 +static unsigned long pax_parse_xattr_pax(struct file * const file)
55418 +{
55419 +
55420 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55421 + ssize_t xattr_size, i;
55422 + unsigned char xattr_value[sizeof("pemrs") - 1];
55423 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
55424 +
55425 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
55426 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
55427 + return PAX_PARSE_FLAGS_FALLBACK;
55428 +
55429 + for (i = 0; i < xattr_size; i++)
55430 + switch (xattr_value[i]) {
55431 + default:
55432 + return PAX_PARSE_FLAGS_FALLBACK;
55433 +
55434 +#define parse_flag(option1, option2, flag) \
55435 + case option1: \
55436 + if (pax_flags_hardmode & MF_PAX_##flag) \
55437 + return PAX_PARSE_FLAGS_FALLBACK;\
55438 + pax_flags_hardmode |= MF_PAX_##flag; \
55439 + break; \
55440 + case option2: \
55441 + if (pax_flags_softmode & MF_PAX_##flag) \
55442 + return PAX_PARSE_FLAGS_FALLBACK;\
55443 + pax_flags_softmode |= MF_PAX_##flag; \
55444 + break;
55445 +
55446 + parse_flag('p', 'P', PAGEEXEC);
55447 + parse_flag('e', 'E', EMUTRAMP);
55448 + parse_flag('m', 'M', MPROTECT);
55449 + parse_flag('r', 'R', RANDMMAP);
55450 + parse_flag('s', 'S', SEGMEXEC);
55451 +
55452 +#undef parse_flag
55453 + }
55454 +
55455 + if (pax_flags_hardmode & pax_flags_softmode)
55456 + return PAX_PARSE_FLAGS_FALLBACK;
55457 +
55458 +#ifdef CONFIG_PAX_SOFTMODE
55459 + if (pax_softmode)
55460 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
55461 + else
55462 +#endif
55463 +
55464 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
55465 +#else
55466 + return PAX_PARSE_FLAGS_FALLBACK;
55467 +#endif
55468 +
55469 +}
55470 +
55471 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
55472 +{
55473 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
55474 +
55475 + pax_flags = pax_parse_defaults();
55476 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
55477 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
55478 + xattr_pax_flags = pax_parse_xattr_pax(file);
55479 +
55480 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55481 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55482 + pt_pax_flags != xattr_pax_flags)
55483 + return -EINVAL;
55484 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55485 + pax_flags = xattr_pax_flags;
55486 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55487 + pax_flags = pt_pax_flags;
55488 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55489 + pax_flags = ei_pax_flags;
55490 +
55491 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
55492 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55493 + if ((__supported_pte_mask & _PAGE_NX))
55494 + pax_flags &= ~MF_PAX_SEGMEXEC;
55495 + else
55496 + pax_flags &= ~MF_PAX_PAGEEXEC;
55497 + }
55498 +#endif
55499 +
55500 + if (0 > pax_check_flags(&pax_flags))
55501 + return -EINVAL;
55502 +
55503 + current->mm->pax_flags = pax_flags;
55504 + return 0;
55505 +}
55506 +#endif
55507 +
55508 /*
55509 * These are the functions used to load ELF style executables and shared
55510 * libraries. There is no binary dependent code anywhere else.
55511 @@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
55512 {
55513 unsigned int random_variable = 0;
55514
55515 +#ifdef CONFIG_PAX_RANDUSTACK
55516 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
55517 + return stack_top - current->mm->delta_stack;
55518 +#endif
55519 +
55520 if ((current->flags & PF_RANDOMIZE) &&
55521 !(current->personality & ADDR_NO_RANDOMIZE)) {
55522 random_variable = get_random_int() & STACK_RND_MASK;
55523 @@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
55524 unsigned long load_addr = 0, load_bias = 0;
55525 int load_addr_set = 0;
55526 char * elf_interpreter = NULL;
55527 - unsigned long error;
55528 + unsigned long error = 0;
55529 struct elf_phdr *elf_ppnt, *elf_phdata;
55530 unsigned long elf_bss, elf_brk;
55531 int retval, i;
55532 @@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
55533 unsigned long start_code, end_code, start_data, end_data;
55534 unsigned long reloc_func_desc __maybe_unused = 0;
55535 int executable_stack = EXSTACK_DEFAULT;
55536 - unsigned long def_flags = 0;
55537 struct pt_regs *regs = current_pt_regs();
55538 struct {
55539 struct elfhdr elf_ex;
55540 struct elfhdr interp_elf_ex;
55541 } *loc;
55542 + unsigned long pax_task_size;
55543
55544 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
55545 if (!loc) {
55546 @@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
55547 goto out_free_dentry;
55548
55549 /* OK, This is the point of no return */
55550 - current->mm->def_flags = def_flags;
55551 + current->mm->def_flags = 0;
55552
55553 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
55554 may depend on the personality. */
55555 SET_PERSONALITY(loc->elf_ex);
55556 +
55557 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55558 + current->mm->pax_flags = 0UL;
55559 +#endif
55560 +
55561 +#ifdef CONFIG_PAX_DLRESOLVE
55562 + current->mm->call_dl_resolve = 0UL;
55563 +#endif
55564 +
55565 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
55566 + current->mm->call_syscall = 0UL;
55567 +#endif
55568 +
55569 +#ifdef CONFIG_PAX_ASLR
55570 + current->mm->delta_mmap = 0UL;
55571 + current->mm->delta_stack = 0UL;
55572 +#endif
55573 +
55574 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55575 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
55576 + send_sig(SIGKILL, current, 0);
55577 + goto out_free_dentry;
55578 + }
55579 +#endif
55580 +
55581 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55582 + pax_set_initial_flags(bprm);
55583 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
55584 + if (pax_set_initial_flags_func)
55585 + (pax_set_initial_flags_func)(bprm);
55586 +#endif
55587 +
55588 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55589 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
55590 + current->mm->context.user_cs_limit = PAGE_SIZE;
55591 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
55592 + }
55593 +#endif
55594 +
55595 +#ifdef CONFIG_PAX_SEGMEXEC
55596 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
55597 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
55598 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
55599 + pax_task_size = SEGMEXEC_TASK_SIZE;
55600 + current->mm->def_flags |= VM_NOHUGEPAGE;
55601 + } else
55602 +#endif
55603 +
55604 + pax_task_size = TASK_SIZE;
55605 +
55606 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
55607 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55608 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
55609 + put_cpu();
55610 + }
55611 +#endif
55612 +
55613 +#ifdef CONFIG_PAX_ASLR
55614 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55615 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
55616 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
55617 + }
55618 +#endif
55619 +
55620 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55621 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55622 + executable_stack = EXSTACK_DISABLE_X;
55623 + current->personality &= ~READ_IMPLIES_EXEC;
55624 + } else
55625 +#endif
55626 +
55627 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
55628 current->personality |= READ_IMPLIES_EXEC;
55629
55630 @@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
55631 #else
55632 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
55633 #endif
55634 +
55635 +#ifdef CONFIG_PAX_RANDMMAP
55636 + /* PaX: randomize base address at the default exe base if requested */
55637 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
55638 +#ifdef CONFIG_SPARC64
55639 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
55640 +#else
55641 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
55642 +#endif
55643 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
55644 + elf_flags |= MAP_FIXED;
55645 + }
55646 +#endif
55647 +
55648 }
55649
55650 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
55651 @@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
55652 * allowed task size. Note that p_filesz must always be
55653 * <= p_memsz so it is only necessary to check p_memsz.
55654 */
55655 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55656 - elf_ppnt->p_memsz > TASK_SIZE ||
55657 - TASK_SIZE - elf_ppnt->p_memsz < k) {
55658 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55659 + elf_ppnt->p_memsz > pax_task_size ||
55660 + pax_task_size - elf_ppnt->p_memsz < k) {
55661 /* set_brk can never work. Avoid overflows. */
55662 send_sig(SIGKILL, current, 0);
55663 retval = -EINVAL;
55664 @@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
55665 goto out_free_dentry;
55666 }
55667 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
55668 - send_sig(SIGSEGV, current, 0);
55669 - retval = -EFAULT; /* Nobody gets to see this, but.. */
55670 - goto out_free_dentry;
55671 + /*
55672 + * This bss-zeroing can fail if the ELF
55673 + * file specifies odd protections. So
55674 + * we don't check the return value
55675 + */
55676 }
55677
55678 +#ifdef CONFIG_PAX_RANDMMAP
55679 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55680 + unsigned long start, size, flags;
55681 + vm_flags_t vm_flags;
55682 +
55683 + start = ELF_PAGEALIGN(elf_brk);
55684 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
55685 + flags = MAP_FIXED | MAP_PRIVATE;
55686 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
55687 +
55688 + down_write(&current->mm->mmap_sem);
55689 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
55690 + retval = -ENOMEM;
55691 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
55692 +// if (current->personality & ADDR_NO_RANDOMIZE)
55693 +// vm_flags |= VM_READ | VM_MAYREAD;
55694 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
55695 + retval = IS_ERR_VALUE(start) ? start : 0;
55696 + }
55697 + up_write(&current->mm->mmap_sem);
55698 + if (retval == 0)
55699 + retval = set_brk(start + size, start + size + PAGE_SIZE);
55700 + if (retval < 0) {
55701 + send_sig(SIGKILL, current, 0);
55702 + goto out_free_dentry;
55703 + }
55704 + }
55705 +#endif
55706 +
55707 if (elf_interpreter) {
55708 - unsigned long interp_map_addr = 0;
55709 -
55710 elf_entry = load_elf_interp(&loc->interp_elf_ex,
55711 interpreter,
55712 - &interp_map_addr,
55713 load_bias);
55714 if (!IS_ERR((void *)elf_entry)) {
55715 /*
55716 @@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
55717 * Decide what to dump of a segment, part, all or none.
55718 */
55719 static unsigned long vma_dump_size(struct vm_area_struct *vma,
55720 - unsigned long mm_flags)
55721 + unsigned long mm_flags, long signr)
55722 {
55723 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
55724
55725 @@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
55726 if (vma->vm_file == NULL)
55727 return 0;
55728
55729 - if (FILTER(MAPPED_PRIVATE))
55730 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
55731 goto whole;
55732
55733 /*
55734 @@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
55735 {
55736 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
55737 int i = 0;
55738 - do
55739 + do {
55740 i += 2;
55741 - while (auxv[i - 2] != AT_NULL);
55742 + } while (auxv[i - 2] != AT_NULL);
55743 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
55744 }
55745
55746 @@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
55747 {
55748 mm_segment_t old_fs = get_fs();
55749 set_fs(KERNEL_DS);
55750 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
55751 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
55752 set_fs(old_fs);
55753 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
55754 }
55755 @@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
55756 }
55757
55758 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
55759 - unsigned long mm_flags)
55760 + struct coredump_params *cprm)
55761 {
55762 struct vm_area_struct *vma;
55763 size_t size = 0;
55764
55765 for (vma = first_vma(current, gate_vma); vma != NULL;
55766 vma = next_vma(vma, gate_vma))
55767 - size += vma_dump_size(vma, mm_flags);
55768 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55769 return size;
55770 }
55771
55772 @@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55773
55774 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
55775
55776 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
55777 + offset += elf_core_vma_data_size(gate_vma, cprm);
55778 offset += elf_core_extra_data_size();
55779 e_shoff = offset;
55780
55781 @@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55782 phdr.p_offset = offset;
55783 phdr.p_vaddr = vma->vm_start;
55784 phdr.p_paddr = 0;
55785 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
55786 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55787 phdr.p_memsz = vma->vm_end - vma->vm_start;
55788 offset += phdr.p_filesz;
55789 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
55790 @@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55791 unsigned long addr;
55792 unsigned long end;
55793
55794 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
55795 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55796
55797 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
55798 struct page *page;
55799 @@ -2202,6 +2681,167 @@ out:
55800
55801 #endif /* CONFIG_ELF_CORE */
55802
55803 +#ifdef CONFIG_PAX_MPROTECT
55804 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
55805 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
55806 + * we'll remove VM_MAYWRITE for good on RELRO segments.
55807 + *
55808 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
55809 + * basis because we want to allow the common case and not the special ones.
55810 + */
55811 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
55812 +{
55813 + struct elfhdr elf_h;
55814 + struct elf_phdr elf_p;
55815 + unsigned long i;
55816 + unsigned long oldflags;
55817 + bool is_textrel_rw, is_textrel_rx, is_relro;
55818 +
55819 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
55820 + return;
55821 +
55822 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
55823 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
55824 +
55825 +#ifdef CONFIG_PAX_ELFRELOCS
55826 + /* possible TEXTREL */
55827 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
55828 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
55829 +#else
55830 + is_textrel_rw = false;
55831 + is_textrel_rx = false;
55832 +#endif
55833 +
55834 + /* possible RELRO */
55835 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
55836 +
55837 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
55838 + return;
55839 +
55840 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
55841 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
55842 +
55843 +#ifdef CONFIG_PAX_ETEXECRELOCS
55844 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
55845 +#else
55846 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
55847 +#endif
55848 +
55849 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
55850 + !elf_check_arch(&elf_h) ||
55851 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
55852 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
55853 + return;
55854 +
55855 + for (i = 0UL; i < elf_h.e_phnum; i++) {
55856 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
55857 + return;
55858 + switch (elf_p.p_type) {
55859 + case PT_DYNAMIC:
55860 + if (!is_textrel_rw && !is_textrel_rx)
55861 + continue;
55862 + i = 0UL;
55863 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
55864 + elf_dyn dyn;
55865 +
55866 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
55867 + break;
55868 + if (dyn.d_tag == DT_NULL)
55869 + break;
55870 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
55871 + gr_log_textrel(vma);
55872 + if (is_textrel_rw)
55873 + vma->vm_flags |= VM_MAYWRITE;
55874 + else
55875 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
55876 + vma->vm_flags &= ~VM_MAYWRITE;
55877 + break;
55878 + }
55879 + i++;
55880 + }
55881 + is_textrel_rw = false;
55882 + is_textrel_rx = false;
55883 + continue;
55884 +
55885 + case PT_GNU_RELRO:
55886 + if (!is_relro)
55887 + continue;
55888 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
55889 + vma->vm_flags &= ~VM_MAYWRITE;
55890 + is_relro = false;
55891 + continue;
55892 +
55893 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
55894 + case PT_PAX_FLAGS: {
55895 + const char *msg_mprotect = "", *msg_emutramp = "";
55896 + char *buffer_lib, *buffer_exe;
55897 +
55898 + if (elf_p.p_flags & PF_NOMPROTECT)
55899 + msg_mprotect = "MPROTECT disabled";
55900 +
55901 +#ifdef CONFIG_PAX_EMUTRAMP
55902 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
55903 + msg_emutramp = "EMUTRAMP enabled";
55904 +#endif
55905 +
55906 + if (!msg_mprotect[0] && !msg_emutramp[0])
55907 + continue;
55908 +
55909 + if (!printk_ratelimit())
55910 + continue;
55911 +
55912 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
55913 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
55914 + if (buffer_lib && buffer_exe) {
55915 + char *path_lib, *path_exe;
55916 +
55917 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
55918 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
55919 +
55920 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
55921 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
55922 +
55923 + }
55924 + free_page((unsigned long)buffer_exe);
55925 + free_page((unsigned long)buffer_lib);
55926 + continue;
55927 + }
55928 +#endif
55929 +
55930 + }
55931 + }
55932 +}
55933 +#endif
55934 +
55935 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55936 +
55937 +extern int grsec_enable_log_rwxmaps;
55938 +
55939 +static void elf_handle_mmap(struct file *file)
55940 +{
55941 + struct elfhdr elf_h;
55942 + struct elf_phdr elf_p;
55943 + unsigned long i;
55944 +
55945 + if (!grsec_enable_log_rwxmaps)
55946 + return;
55947 +
55948 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
55949 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
55950 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
55951 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
55952 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
55953 + return;
55954 +
55955 + for (i = 0UL; i < elf_h.e_phnum; i++) {
55956 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
55957 + return;
55958 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
55959 + gr_log_ptgnustack(file);
55960 + }
55961 +}
55962 +#endif
55963 +
55964 static int __init init_elf_binfmt(void)
55965 {
55966 register_binfmt(&elf_format);
55967 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
55968 index d50bbe5..af3b649 100644
55969 --- a/fs/binfmt_flat.c
55970 +++ b/fs/binfmt_flat.c
55971 @@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
55972 realdatastart = (unsigned long) -ENOMEM;
55973 printk("Unable to allocate RAM for process data, errno %d\n",
55974 (int)-realdatastart);
55975 + down_write(&current->mm->mmap_sem);
55976 vm_munmap(textpos, text_len);
55977 + up_write(&current->mm->mmap_sem);
55978 ret = realdatastart;
55979 goto err;
55980 }
55981 @@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
55982 }
55983 if (IS_ERR_VALUE(result)) {
55984 printk("Unable to read data+bss, errno %d\n", (int)-result);
55985 + down_write(&current->mm->mmap_sem);
55986 vm_munmap(textpos, text_len);
55987 vm_munmap(realdatastart, len);
55988 + up_write(&current->mm->mmap_sem);
55989 ret = result;
55990 goto err;
55991 }
55992 @@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
55993 }
55994 if (IS_ERR_VALUE(result)) {
55995 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
55996 + down_write(&current->mm->mmap_sem);
55997 vm_munmap(textpos, text_len + data_len + extra +
55998 MAX_SHARED_LIBS * sizeof(unsigned long));
55999 + up_write(&current->mm->mmap_sem);
56000 ret = result;
56001 goto err;
56002 }
56003 diff --git a/fs/bio.c b/fs/bio.c
56004 index 33d79a4..c3c9893 100644
56005 --- a/fs/bio.c
56006 +++ b/fs/bio.c
56007 @@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
56008 /*
56009 * Overflow, abort
56010 */
56011 - if (end < start)
56012 + if (end < start || end - start > INT_MAX - nr_pages)
56013 return ERR_PTR(-EINVAL);
56014
56015 nr_pages += end - start;
56016 @@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
56017 /*
56018 * Overflow, abort
56019 */
56020 - if (end < start)
56021 + if (end < start || end - start > INT_MAX - nr_pages)
56022 return ERR_PTR(-EINVAL);
56023
56024 nr_pages += end - start;
56025 @@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
56026 const int read = bio_data_dir(bio) == READ;
56027 struct bio_map_data *bmd = bio->bi_private;
56028 int i;
56029 - char *p = bmd->sgvecs[0].iov_base;
56030 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
56031
56032 bio_for_each_segment_all(bvec, bio, i) {
56033 char *addr = page_address(bvec->bv_page);
56034 diff --git a/fs/block_dev.c b/fs/block_dev.c
56035 index 1e86823..8e34695 100644
56036 --- a/fs/block_dev.c
56037 +++ b/fs/block_dev.c
56038 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
56039 else if (bdev->bd_contains == bdev)
56040 return true; /* is a whole device which isn't held */
56041
56042 - else if (whole->bd_holder == bd_may_claim)
56043 + else if (whole->bd_holder == (void *)bd_may_claim)
56044 return true; /* is a partition of a device that is being partitioned */
56045 else if (whole->bd_holder != NULL)
56046 return false; /* is a partition of a held device */
56047 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
56048 index 316136b..e7a3a50 100644
56049 --- a/fs/btrfs/ctree.c
56050 +++ b/fs/btrfs/ctree.c
56051 @@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
56052 free_extent_buffer(buf);
56053 add_root_to_dirty_list(root);
56054 } else {
56055 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
56056 - parent_start = parent->start;
56057 - else
56058 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
56059 + if (parent)
56060 + parent_start = parent->start;
56061 + else
56062 + parent_start = 0;
56063 + } else
56064 parent_start = 0;
56065
56066 WARN_ON(trans->transid != btrfs_header_generation(parent));
56067 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
56068 index 8d292fb..bc205c2 100644
56069 --- a/fs/btrfs/delayed-inode.c
56070 +++ b/fs/btrfs/delayed-inode.c
56071 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
56072
56073 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
56074 {
56075 - int seq = atomic_inc_return(&delayed_root->items_seq);
56076 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
56077 if ((atomic_dec_return(&delayed_root->items) <
56078 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
56079 waitqueue_active(&delayed_root->wait))
56080 @@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
56081 static int refs_newer(struct btrfs_delayed_root *delayed_root,
56082 int seq, int count)
56083 {
56084 - int val = atomic_read(&delayed_root->items_seq);
56085 + int val = atomic_read_unchecked(&delayed_root->items_seq);
56086
56087 if (val < seq || val >= seq + count)
56088 return 1;
56089 @@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
56090 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
56091 return;
56092
56093 - seq = atomic_read(&delayed_root->items_seq);
56094 + seq = atomic_read_unchecked(&delayed_root->items_seq);
56095
56096 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
56097 int ret;
56098 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
56099 index a4b38f9..f86a509 100644
56100 --- a/fs/btrfs/delayed-inode.h
56101 +++ b/fs/btrfs/delayed-inode.h
56102 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
56103 */
56104 struct list_head prepare_list;
56105 atomic_t items; /* for delayed items */
56106 - atomic_t items_seq; /* for delayed items */
56107 + atomic_unchecked_t items_seq; /* for delayed items */
56108 int nodes; /* for delayed nodes */
56109 wait_queue_head_t wait;
56110 };
56111 @@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
56112 struct btrfs_delayed_root *delayed_root)
56113 {
56114 atomic_set(&delayed_root->items, 0);
56115 - atomic_set(&delayed_root->items_seq, 0);
56116 + atomic_set_unchecked(&delayed_root->items_seq, 0);
56117 delayed_root->nodes = 0;
56118 spin_lock_init(&delayed_root->lock);
56119 init_waitqueue_head(&delayed_root->wait);
56120 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
56121 index 21da576..3551e09 100644
56122 --- a/fs/btrfs/ioctl.c
56123 +++ b/fs/btrfs/ioctl.c
56124 @@ -3451,9 +3451,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56125 for (i = 0; i < num_types; i++) {
56126 struct btrfs_space_info *tmp;
56127
56128 + /* Don't copy in more than we allocated */
56129 if (!slot_count)
56130 break;
56131
56132 + slot_count--;
56133 +
56134 info = NULL;
56135 rcu_read_lock();
56136 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
56137 @@ -3475,10 +3478,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56138 memcpy(dest, &space, sizeof(space));
56139 dest++;
56140 space_args.total_spaces++;
56141 - slot_count--;
56142 }
56143 - if (!slot_count)
56144 - break;
56145 }
56146 up_read(&info->groups_sem);
56147 }
56148 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
56149 index d71a11d..384e2c4 100644
56150 --- a/fs/btrfs/super.c
56151 +++ b/fs/btrfs/super.c
56152 @@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
56153 function, line, errstr);
56154 return;
56155 }
56156 - ACCESS_ONCE(trans->transaction->aborted) = errno;
56157 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
56158 /* Wake up anybody who may be waiting on this transaction */
56159 wake_up(&root->fs_info->transaction_wait);
56160 wake_up(&root->fs_info->transaction_blocked_wait);
56161 diff --git a/fs/buffer.c b/fs/buffer.c
56162 index 6024877..7bd000a 100644
56163 --- a/fs/buffer.c
56164 +++ b/fs/buffer.c
56165 @@ -3426,7 +3426,7 @@ void __init buffer_init(void)
56166 bh_cachep = kmem_cache_create("buffer_head",
56167 sizeof(struct buffer_head), 0,
56168 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
56169 - SLAB_MEM_SPREAD),
56170 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
56171 NULL);
56172
56173 /*
56174 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
56175 index 622f469..e8d2d55 100644
56176 --- a/fs/cachefiles/bind.c
56177 +++ b/fs/cachefiles/bind.c
56178 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
56179 args);
56180
56181 /* start by checking things over */
56182 - ASSERT(cache->fstop_percent >= 0 &&
56183 - cache->fstop_percent < cache->fcull_percent &&
56184 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
56185 cache->fcull_percent < cache->frun_percent &&
56186 cache->frun_percent < 100);
56187
56188 - ASSERT(cache->bstop_percent >= 0 &&
56189 - cache->bstop_percent < cache->bcull_percent &&
56190 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
56191 cache->bcull_percent < cache->brun_percent &&
56192 cache->brun_percent < 100);
56193
56194 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
56195 index 0a1467b..6a53245 100644
56196 --- a/fs/cachefiles/daemon.c
56197 +++ b/fs/cachefiles/daemon.c
56198 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
56199 if (n > buflen)
56200 return -EMSGSIZE;
56201
56202 - if (copy_to_user(_buffer, buffer, n) != 0)
56203 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
56204 return -EFAULT;
56205
56206 return n;
56207 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
56208 if (test_bit(CACHEFILES_DEAD, &cache->flags))
56209 return -EIO;
56210
56211 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
56212 + if (datalen > PAGE_SIZE - 1)
56213 return -EOPNOTSUPP;
56214
56215 /* drag the command string into the kernel so we can parse it */
56216 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
56217 if (args[0] != '%' || args[1] != '\0')
56218 return -EINVAL;
56219
56220 - if (fstop < 0 || fstop >= cache->fcull_percent)
56221 + if (fstop >= cache->fcull_percent)
56222 return cachefiles_daemon_range_error(cache, args);
56223
56224 cache->fstop_percent = fstop;
56225 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
56226 if (args[0] != '%' || args[1] != '\0')
56227 return -EINVAL;
56228
56229 - if (bstop < 0 || bstop >= cache->bcull_percent)
56230 + if (bstop >= cache->bcull_percent)
56231 return cachefiles_daemon_range_error(cache, args);
56232
56233 cache->bstop_percent = bstop;
56234 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
56235 index 5349473..d6c0b93 100644
56236 --- a/fs/cachefiles/internal.h
56237 +++ b/fs/cachefiles/internal.h
56238 @@ -59,7 +59,7 @@ struct cachefiles_cache {
56239 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
56240 struct rb_root active_nodes; /* active nodes (can't be culled) */
56241 rwlock_t active_lock; /* lock for active_nodes */
56242 - atomic_t gravecounter; /* graveyard uniquifier */
56243 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
56244 unsigned frun_percent; /* when to stop culling (% files) */
56245 unsigned fcull_percent; /* when to start culling (% files) */
56246 unsigned fstop_percent; /* when to stop allocating (% files) */
56247 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
56248 * proc.c
56249 */
56250 #ifdef CONFIG_CACHEFILES_HISTOGRAM
56251 -extern atomic_t cachefiles_lookup_histogram[HZ];
56252 -extern atomic_t cachefiles_mkdir_histogram[HZ];
56253 -extern atomic_t cachefiles_create_histogram[HZ];
56254 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56255 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56256 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
56257
56258 extern int __init cachefiles_proc_init(void);
56259 extern void cachefiles_proc_cleanup(void);
56260 static inline
56261 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
56262 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
56263 {
56264 unsigned long jif = jiffies - start_jif;
56265 if (jif >= HZ)
56266 jif = HZ - 1;
56267 - atomic_inc(&histogram[jif]);
56268 + atomic_inc_unchecked(&histogram[jif]);
56269 }
56270
56271 #else
56272 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
56273 index ca65f39..48921e3 100644
56274 --- a/fs/cachefiles/namei.c
56275 +++ b/fs/cachefiles/namei.c
56276 @@ -317,7 +317,7 @@ try_again:
56277 /* first step is to make up a grave dentry in the graveyard */
56278 sprintf(nbuffer, "%08x%08x",
56279 (uint32_t) get_seconds(),
56280 - (uint32_t) atomic_inc_return(&cache->gravecounter));
56281 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
56282
56283 /* do the multiway lock magic */
56284 trap = lock_rename(cache->graveyard, dir);
56285 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
56286 index eccd339..4c1d995 100644
56287 --- a/fs/cachefiles/proc.c
56288 +++ b/fs/cachefiles/proc.c
56289 @@ -14,9 +14,9 @@
56290 #include <linux/seq_file.h>
56291 #include "internal.h"
56292
56293 -atomic_t cachefiles_lookup_histogram[HZ];
56294 -atomic_t cachefiles_mkdir_histogram[HZ];
56295 -atomic_t cachefiles_create_histogram[HZ];
56296 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56297 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56298 +atomic_unchecked_t cachefiles_create_histogram[HZ];
56299
56300 /*
56301 * display the latency histogram
56302 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
56303 return 0;
56304 default:
56305 index = (unsigned long) v - 3;
56306 - x = atomic_read(&cachefiles_lookup_histogram[index]);
56307 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
56308 - z = atomic_read(&cachefiles_create_histogram[index]);
56309 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
56310 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
56311 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
56312 if (x == 0 && y == 0 && z == 0)
56313 return 0;
56314
56315 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
56316 index ebaff36..7e3ea26 100644
56317 --- a/fs/cachefiles/rdwr.c
56318 +++ b/fs/cachefiles/rdwr.c
56319 @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
56320 old_fs = get_fs();
56321 set_fs(KERNEL_DS);
56322 ret = file->f_op->write(
56323 - file, (const void __user *) data, len, &pos);
56324 + file, (const void __force_user *) data, len, &pos);
56325 set_fs(old_fs);
56326 kunmap(page);
56327 file_end_write(file);
56328 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
56329 index 2a0bcae..34ec24e 100644
56330 --- a/fs/ceph/dir.c
56331 +++ b/fs/ceph/dir.c
56332 @@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
56333 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
56334 struct ceph_mds_client *mdsc = fsc->mdsc;
56335 unsigned frag = fpos_frag(ctx->pos);
56336 - int off = fpos_off(ctx->pos);
56337 + unsigned int off = fpos_off(ctx->pos);
56338 int err;
56339 u32 ftype;
56340 struct ceph_mds_reply_info_parsed *rinfo;
56341 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
56342 index 6a0951e..03fac6d 100644
56343 --- a/fs/ceph/super.c
56344 +++ b/fs/ceph/super.c
56345 @@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
56346 /*
56347 * construct our own bdi so we can control readahead, etc.
56348 */
56349 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
56350 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
56351
56352 static int ceph_register_bdi(struct super_block *sb,
56353 struct ceph_fs_client *fsc)
56354 @@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
56355 default_backing_dev_info.ra_pages;
56356
56357 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
56358 - atomic_long_inc_return(&bdi_seq));
56359 + atomic_long_inc_return_unchecked(&bdi_seq));
56360 if (!err)
56361 sb->s_bdi = &fsc->backing_dev_info;
56362 return err;
56363 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
56364 index f3ac415..3d2420c 100644
56365 --- a/fs/cifs/cifs_debug.c
56366 +++ b/fs/cifs/cifs_debug.c
56367 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56368
56369 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
56370 #ifdef CONFIG_CIFS_STATS2
56371 - atomic_set(&totBufAllocCount, 0);
56372 - atomic_set(&totSmBufAllocCount, 0);
56373 + atomic_set_unchecked(&totBufAllocCount, 0);
56374 + atomic_set_unchecked(&totSmBufAllocCount, 0);
56375 #endif /* CONFIG_CIFS_STATS2 */
56376 spin_lock(&cifs_tcp_ses_lock);
56377 list_for_each(tmp1, &cifs_tcp_ses_list) {
56378 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56379 tcon = list_entry(tmp3,
56380 struct cifs_tcon,
56381 tcon_list);
56382 - atomic_set(&tcon->num_smbs_sent, 0);
56383 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
56384 if (server->ops->clear_stats)
56385 server->ops->clear_stats(tcon);
56386 }
56387 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56388 smBufAllocCount.counter, cifs_min_small);
56389 #ifdef CONFIG_CIFS_STATS2
56390 seq_printf(m, "Total Large %d Small %d Allocations\n",
56391 - atomic_read(&totBufAllocCount),
56392 - atomic_read(&totSmBufAllocCount));
56393 + atomic_read_unchecked(&totBufAllocCount),
56394 + atomic_read_unchecked(&totSmBufAllocCount));
56395 #endif /* CONFIG_CIFS_STATS2 */
56396
56397 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
56398 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56399 if (tcon->need_reconnect)
56400 seq_puts(m, "\tDISCONNECTED ");
56401 seq_printf(m, "\nSMBs: %d",
56402 - atomic_read(&tcon->num_smbs_sent));
56403 + atomic_read_unchecked(&tcon->num_smbs_sent));
56404 if (server->ops->print_stats)
56405 server->ops->print_stats(m, tcon);
56406 }
56407 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
56408 index 849f613..eae6dec 100644
56409 --- a/fs/cifs/cifsfs.c
56410 +++ b/fs/cifs/cifsfs.c
56411 @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
56412 */
56413 cifs_req_cachep = kmem_cache_create("cifs_request",
56414 CIFSMaxBufSize + max_hdr_size, 0,
56415 - SLAB_HWCACHE_ALIGN, NULL);
56416 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
56417 if (cifs_req_cachep == NULL)
56418 return -ENOMEM;
56419
56420 @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
56421 efficient to alloc 1 per page off the slab compared to 17K (5page)
56422 alloc of large cifs buffers even when page debugging is on */
56423 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
56424 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
56425 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
56426 NULL);
56427 if (cifs_sm_req_cachep == NULL) {
56428 mempool_destroy(cifs_req_poolp);
56429 @@ -1168,8 +1168,8 @@ init_cifs(void)
56430 atomic_set(&bufAllocCount, 0);
56431 atomic_set(&smBufAllocCount, 0);
56432 #ifdef CONFIG_CIFS_STATS2
56433 - atomic_set(&totBufAllocCount, 0);
56434 - atomic_set(&totSmBufAllocCount, 0);
56435 + atomic_set_unchecked(&totBufAllocCount, 0);
56436 + atomic_set_unchecked(&totSmBufAllocCount, 0);
56437 #endif /* CONFIG_CIFS_STATS2 */
56438
56439 atomic_set(&midCount, 0);
56440 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
56441 index f918a99..bb300d5 100644
56442 --- a/fs/cifs/cifsglob.h
56443 +++ b/fs/cifs/cifsglob.h
56444 @@ -787,35 +787,35 @@ struct cifs_tcon {
56445 __u16 Flags; /* optional support bits */
56446 enum statusEnum tidStatus;
56447 #ifdef CONFIG_CIFS_STATS
56448 - atomic_t num_smbs_sent;
56449 + atomic_unchecked_t num_smbs_sent;
56450 union {
56451 struct {
56452 - atomic_t num_writes;
56453 - atomic_t num_reads;
56454 - atomic_t num_flushes;
56455 - atomic_t num_oplock_brks;
56456 - atomic_t num_opens;
56457 - atomic_t num_closes;
56458 - atomic_t num_deletes;
56459 - atomic_t num_mkdirs;
56460 - atomic_t num_posixopens;
56461 - atomic_t num_posixmkdirs;
56462 - atomic_t num_rmdirs;
56463 - atomic_t num_renames;
56464 - atomic_t num_t2renames;
56465 - atomic_t num_ffirst;
56466 - atomic_t num_fnext;
56467 - atomic_t num_fclose;
56468 - atomic_t num_hardlinks;
56469 - atomic_t num_symlinks;
56470 - atomic_t num_locks;
56471 - atomic_t num_acl_get;
56472 - atomic_t num_acl_set;
56473 + atomic_unchecked_t num_writes;
56474 + atomic_unchecked_t num_reads;
56475 + atomic_unchecked_t num_flushes;
56476 + atomic_unchecked_t num_oplock_brks;
56477 + atomic_unchecked_t num_opens;
56478 + atomic_unchecked_t num_closes;
56479 + atomic_unchecked_t num_deletes;
56480 + atomic_unchecked_t num_mkdirs;
56481 + atomic_unchecked_t num_posixopens;
56482 + atomic_unchecked_t num_posixmkdirs;
56483 + atomic_unchecked_t num_rmdirs;
56484 + atomic_unchecked_t num_renames;
56485 + atomic_unchecked_t num_t2renames;
56486 + atomic_unchecked_t num_ffirst;
56487 + atomic_unchecked_t num_fnext;
56488 + atomic_unchecked_t num_fclose;
56489 + atomic_unchecked_t num_hardlinks;
56490 + atomic_unchecked_t num_symlinks;
56491 + atomic_unchecked_t num_locks;
56492 + atomic_unchecked_t num_acl_get;
56493 + atomic_unchecked_t num_acl_set;
56494 } cifs_stats;
56495 #ifdef CONFIG_CIFS_SMB2
56496 struct {
56497 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56498 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56499 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56500 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56501 } smb2_stats;
56502 #endif /* CONFIG_CIFS_SMB2 */
56503 } stats;
56504 @@ -1145,7 +1145,7 @@ convert_delimiter(char *path, char delim)
56505 }
56506
56507 #ifdef CONFIG_CIFS_STATS
56508 -#define cifs_stats_inc atomic_inc
56509 +#define cifs_stats_inc atomic_inc_unchecked
56510
56511 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
56512 unsigned int bytes)
56513 @@ -1511,8 +1511,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
56514 /* Various Debug counters */
56515 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
56516 #ifdef CONFIG_CIFS_STATS2
56517 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
56518 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
56519 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
56520 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
56521 #endif
56522 GLOBAL_EXTERN atomic_t smBufAllocCount;
56523 GLOBAL_EXTERN atomic_t midCount;
56524 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
56525 index 5a5a872..92c3210 100644
56526 --- a/fs/cifs/file.c
56527 +++ b/fs/cifs/file.c
56528 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
56529 index = mapping->writeback_index; /* Start from prev offset */
56530 end = -1;
56531 } else {
56532 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
56533 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
56534 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
56535 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
56536 range_whole = true;
56537 + index = 0;
56538 + end = ULONG_MAX;
56539 + } else {
56540 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
56541 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
56542 + }
56543 scanned = true;
56544 }
56545 retry:
56546 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
56547 index 2f9f379..43f8025 100644
56548 --- a/fs/cifs/misc.c
56549 +++ b/fs/cifs/misc.c
56550 @@ -170,7 +170,7 @@ cifs_buf_get(void)
56551 memset(ret_buf, 0, buf_size + 3);
56552 atomic_inc(&bufAllocCount);
56553 #ifdef CONFIG_CIFS_STATS2
56554 - atomic_inc(&totBufAllocCount);
56555 + atomic_inc_unchecked(&totBufAllocCount);
56556 #endif /* CONFIG_CIFS_STATS2 */
56557 }
56558
56559 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
56560 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
56561 atomic_inc(&smBufAllocCount);
56562 #ifdef CONFIG_CIFS_STATS2
56563 - atomic_inc(&totSmBufAllocCount);
56564 + atomic_inc_unchecked(&totSmBufAllocCount);
56565 #endif /* CONFIG_CIFS_STATS2 */
56566
56567 }
56568 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
56569 index 5f5ba0d..8d6ef7d 100644
56570 --- a/fs/cifs/smb1ops.c
56571 +++ b/fs/cifs/smb1ops.c
56572 @@ -609,27 +609,27 @@ static void
56573 cifs_clear_stats(struct cifs_tcon *tcon)
56574 {
56575 #ifdef CONFIG_CIFS_STATS
56576 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
56577 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
56578 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
56579 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56580 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
56581 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
56582 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56583 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
56584 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
56585 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
56586 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
56587 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
56588 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
56589 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
56590 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
56591 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
56592 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
56593 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
56594 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
56595 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
56596 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
56597 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
56598 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
56599 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
56600 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56601 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
56602 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
56603 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56604 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
56605 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
56606 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
56607 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
56608 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
56609 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
56610 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
56611 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
56612 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
56613 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
56614 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
56615 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
56616 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
56617 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
56618 #endif
56619 }
56620
56621 @@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56622 {
56623 #ifdef CONFIG_CIFS_STATS
56624 seq_printf(m, " Oplocks breaks: %d",
56625 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
56626 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
56627 seq_printf(m, "\nReads: %d Bytes: %llu",
56628 - atomic_read(&tcon->stats.cifs_stats.num_reads),
56629 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
56630 (long long)(tcon->bytes_read));
56631 seq_printf(m, "\nWrites: %d Bytes: %llu",
56632 - atomic_read(&tcon->stats.cifs_stats.num_writes),
56633 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
56634 (long long)(tcon->bytes_written));
56635 seq_printf(m, "\nFlushes: %d",
56636 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
56637 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
56638 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
56639 - atomic_read(&tcon->stats.cifs_stats.num_locks),
56640 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
56641 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
56642 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
56643 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
56644 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
56645 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
56646 - atomic_read(&tcon->stats.cifs_stats.num_opens),
56647 - atomic_read(&tcon->stats.cifs_stats.num_closes),
56648 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
56649 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
56650 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
56651 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
56652 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
56653 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
56654 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
56655 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
56656 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
56657 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
56658 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
56659 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
56660 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
56661 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
56662 seq_printf(m, "\nRenames: %d T2 Renames %d",
56663 - atomic_read(&tcon->stats.cifs_stats.num_renames),
56664 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
56665 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
56666 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
56667 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
56668 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
56669 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
56670 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
56671 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
56672 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
56673 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
56674 #endif
56675 }
56676
56677 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
56678 index 757da3e..07bf1ed 100644
56679 --- a/fs/cifs/smb2ops.c
56680 +++ b/fs/cifs/smb2ops.c
56681 @@ -370,8 +370,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
56682 #ifdef CONFIG_CIFS_STATS
56683 int i;
56684 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
56685 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56686 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56687 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56688 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56689 }
56690 #endif
56691 }
56692 @@ -411,65 +411,65 @@ static void
56693 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56694 {
56695 #ifdef CONFIG_CIFS_STATS
56696 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56697 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56698 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56699 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56700 seq_printf(m, "\nNegotiates: %d sent %d failed",
56701 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
56702 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
56703 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
56704 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
56705 seq_printf(m, "\nSessionSetups: %d sent %d failed",
56706 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
56707 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
56708 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
56709 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
56710 seq_printf(m, "\nLogoffs: %d sent %d failed",
56711 - atomic_read(&sent[SMB2_LOGOFF_HE]),
56712 - atomic_read(&failed[SMB2_LOGOFF_HE]));
56713 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
56714 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
56715 seq_printf(m, "\nTreeConnects: %d sent %d failed",
56716 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
56717 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
56718 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
56719 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
56720 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
56721 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
56722 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
56723 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
56724 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
56725 seq_printf(m, "\nCreates: %d sent %d failed",
56726 - atomic_read(&sent[SMB2_CREATE_HE]),
56727 - atomic_read(&failed[SMB2_CREATE_HE]));
56728 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
56729 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
56730 seq_printf(m, "\nCloses: %d sent %d failed",
56731 - atomic_read(&sent[SMB2_CLOSE_HE]),
56732 - atomic_read(&failed[SMB2_CLOSE_HE]));
56733 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
56734 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
56735 seq_printf(m, "\nFlushes: %d sent %d failed",
56736 - atomic_read(&sent[SMB2_FLUSH_HE]),
56737 - atomic_read(&failed[SMB2_FLUSH_HE]));
56738 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
56739 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
56740 seq_printf(m, "\nReads: %d sent %d failed",
56741 - atomic_read(&sent[SMB2_READ_HE]),
56742 - atomic_read(&failed[SMB2_READ_HE]));
56743 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
56744 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
56745 seq_printf(m, "\nWrites: %d sent %d failed",
56746 - atomic_read(&sent[SMB2_WRITE_HE]),
56747 - atomic_read(&failed[SMB2_WRITE_HE]));
56748 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
56749 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
56750 seq_printf(m, "\nLocks: %d sent %d failed",
56751 - atomic_read(&sent[SMB2_LOCK_HE]),
56752 - atomic_read(&failed[SMB2_LOCK_HE]));
56753 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
56754 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
56755 seq_printf(m, "\nIOCTLs: %d sent %d failed",
56756 - atomic_read(&sent[SMB2_IOCTL_HE]),
56757 - atomic_read(&failed[SMB2_IOCTL_HE]));
56758 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
56759 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
56760 seq_printf(m, "\nCancels: %d sent %d failed",
56761 - atomic_read(&sent[SMB2_CANCEL_HE]),
56762 - atomic_read(&failed[SMB2_CANCEL_HE]));
56763 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
56764 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
56765 seq_printf(m, "\nEchos: %d sent %d failed",
56766 - atomic_read(&sent[SMB2_ECHO_HE]),
56767 - atomic_read(&failed[SMB2_ECHO_HE]));
56768 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
56769 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
56770 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
56771 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
56772 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
56773 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
56774 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
56775 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
56776 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
56777 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
56778 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
56779 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
56780 seq_printf(m, "\nQueryInfos: %d sent %d failed",
56781 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
56782 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
56783 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
56784 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
56785 seq_printf(m, "\nSetInfos: %d sent %d failed",
56786 - atomic_read(&sent[SMB2_SET_INFO_HE]),
56787 - atomic_read(&failed[SMB2_SET_INFO_HE]));
56788 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
56789 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
56790 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
56791 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
56792 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
56793 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
56794 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
56795 #endif
56796 }
56797
56798 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
56799 index 2013234..a720734 100644
56800 --- a/fs/cifs/smb2pdu.c
56801 +++ b/fs/cifs/smb2pdu.c
56802 @@ -2091,8 +2091,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
56803 default:
56804 cifs_dbg(VFS, "info level %u isn't supported\n",
56805 srch_inf->info_level);
56806 - rc = -EINVAL;
56807 - goto qdir_exit;
56808 + return -EINVAL;
56809 }
56810
56811 req->FileIndex = cpu_to_le32(index);
56812 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
56813 index 1da168c..8bc7ff6 100644
56814 --- a/fs/coda/cache.c
56815 +++ b/fs/coda/cache.c
56816 @@ -24,7 +24,7 @@
56817 #include "coda_linux.h"
56818 #include "coda_cache.h"
56819
56820 -static atomic_t permission_epoch = ATOMIC_INIT(0);
56821 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
56822
56823 /* replace or extend an acl cache hit */
56824 void coda_cache_enter(struct inode *inode, int mask)
56825 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
56826 struct coda_inode_info *cii = ITOC(inode);
56827
56828 spin_lock(&cii->c_lock);
56829 - cii->c_cached_epoch = atomic_read(&permission_epoch);
56830 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
56831 if (!uid_eq(cii->c_uid, current_fsuid())) {
56832 cii->c_uid = current_fsuid();
56833 cii->c_cached_perm = mask;
56834 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
56835 {
56836 struct coda_inode_info *cii = ITOC(inode);
56837 spin_lock(&cii->c_lock);
56838 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
56839 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
56840 spin_unlock(&cii->c_lock);
56841 }
56842
56843 /* remove all acl caches */
56844 void coda_cache_clear_all(struct super_block *sb)
56845 {
56846 - atomic_inc(&permission_epoch);
56847 + atomic_inc_unchecked(&permission_epoch);
56848 }
56849
56850
56851 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
56852 spin_lock(&cii->c_lock);
56853 hit = (mask & cii->c_cached_perm) == mask &&
56854 uid_eq(cii->c_uid, current_fsuid()) &&
56855 - cii->c_cached_epoch == atomic_read(&permission_epoch);
56856 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
56857 spin_unlock(&cii->c_lock);
56858
56859 return hit;
56860 diff --git a/fs/compat.c b/fs/compat.c
56861 index 6af20de..fec3fbb 100644
56862 --- a/fs/compat.c
56863 +++ b/fs/compat.c
56864 @@ -54,7 +54,7 @@
56865 #include <asm/ioctls.h>
56866 #include "internal.h"
56867
56868 -int compat_log = 1;
56869 +int compat_log = 0;
56870
56871 int compat_printk(const char *fmt, ...)
56872 {
56873 @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
56874
56875 set_fs(KERNEL_DS);
56876 /* The __user pointer cast is valid because of the set_fs() */
56877 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
56878 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
56879 set_fs(oldfs);
56880 /* truncating is ok because it's a user address */
56881 if (!ret)
56882 @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
56883 goto out;
56884
56885 ret = -EINVAL;
56886 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
56887 + if (nr_segs > UIO_MAXIOV)
56888 goto out;
56889 if (nr_segs > fast_segs) {
56890 ret = -ENOMEM;
56891 @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
56892 struct compat_readdir_callback {
56893 struct dir_context ctx;
56894 struct compat_old_linux_dirent __user *dirent;
56895 + struct file * file;
56896 int result;
56897 };
56898
56899 @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
56900 buf->result = -EOVERFLOW;
56901 return -EOVERFLOW;
56902 }
56903 +
56904 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56905 + return 0;
56906 +
56907 buf->result++;
56908 dirent = buf->dirent;
56909 if (!access_ok(VERIFY_WRITE, dirent,
56910 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
56911 if (!f.file)
56912 return -EBADF;
56913
56914 + buf.file = f.file;
56915 error = iterate_dir(f.file, &buf.ctx);
56916 if (buf.result)
56917 error = buf.result;
56918 @@ -901,6 +907,7 @@ struct compat_getdents_callback {
56919 struct dir_context ctx;
56920 struct compat_linux_dirent __user *current_dir;
56921 struct compat_linux_dirent __user *previous;
56922 + struct file * file;
56923 int count;
56924 int error;
56925 };
56926 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
56927 buf->error = -EOVERFLOW;
56928 return -EOVERFLOW;
56929 }
56930 +
56931 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56932 + return 0;
56933 +
56934 dirent = buf->previous;
56935 if (dirent) {
56936 if (__put_user(offset, &dirent->d_off))
56937 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
56938 if (!f.file)
56939 return -EBADF;
56940
56941 + buf.file = f.file;
56942 error = iterate_dir(f.file, &buf.ctx);
56943 if (error >= 0)
56944 error = buf.error;
56945 @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
56946 struct dir_context ctx;
56947 struct linux_dirent64 __user *current_dir;
56948 struct linux_dirent64 __user *previous;
56949 + struct file * file;
56950 int count;
56951 int error;
56952 };
56953 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
56954 buf->error = -EINVAL; /* only used if we fail.. */
56955 if (reclen > buf->count)
56956 return -EINVAL;
56957 +
56958 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56959 + return 0;
56960 +
56961 dirent = buf->previous;
56962
56963 if (dirent) {
56964 @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
56965 if (!f.file)
56966 return -EBADF;
56967
56968 + buf.file = f.file;
56969 error = iterate_dir(f.file, &buf.ctx);
56970 if (error >= 0)
56971 error = buf.error;
56972 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
56973 index a81147e..20bf2b5 100644
56974 --- a/fs/compat_binfmt_elf.c
56975 +++ b/fs/compat_binfmt_elf.c
56976 @@ -30,11 +30,13 @@
56977 #undef elf_phdr
56978 #undef elf_shdr
56979 #undef elf_note
56980 +#undef elf_dyn
56981 #undef elf_addr_t
56982 #define elfhdr elf32_hdr
56983 #define elf_phdr elf32_phdr
56984 #define elf_shdr elf32_shdr
56985 #define elf_note elf32_note
56986 +#define elf_dyn Elf32_Dyn
56987 #define elf_addr_t Elf32_Addr
56988
56989 /*
56990 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
56991 index dc52e13..ec61057 100644
56992 --- a/fs/compat_ioctl.c
56993 +++ b/fs/compat_ioctl.c
56994 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
56995 return -EFAULT;
56996 if (__get_user(udata, &ss32->iomem_base))
56997 return -EFAULT;
56998 - ss.iomem_base = compat_ptr(udata);
56999 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
57000 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
57001 __get_user(ss.port_high, &ss32->port_high))
57002 return -EFAULT;
57003 @@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
57004 for (i = 0; i < nmsgs; i++) {
57005 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
57006 return -EFAULT;
57007 - if (get_user(datap, &umsgs[i].buf) ||
57008 - put_user(compat_ptr(datap), &tmsgs[i].buf))
57009 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
57010 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
57011 return -EFAULT;
57012 }
57013 return sys_ioctl(fd, cmd, (unsigned long)tdata);
57014 @@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
57015 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
57016 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
57017 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
57018 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
57019 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
57020 return -EFAULT;
57021
57022 return ioctl_preallocate(file, p);
57023 @@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
57024 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
57025 {
57026 unsigned int a, b;
57027 - a = *(unsigned int *)p;
57028 - b = *(unsigned int *)q;
57029 + a = *(const unsigned int *)p;
57030 + b = *(const unsigned int *)q;
57031 if (a > b)
57032 return 1;
57033 if (a < b)
57034 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
57035 index e081acb..911df21 100644
57036 --- a/fs/configfs/dir.c
57037 +++ b/fs/configfs/dir.c
57038 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57039 }
57040 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
57041 struct configfs_dirent *next;
57042 - const char *name;
57043 + const unsigned char * name;
57044 + char d_name[sizeof(next->s_dentry->d_iname)];
57045 int len;
57046 struct inode *inode = NULL;
57047
57048 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57049 continue;
57050
57051 name = configfs_get_name(next);
57052 - len = strlen(name);
57053 + if (next->s_dentry && name == next->s_dentry->d_iname) {
57054 + len = next->s_dentry->d_name.len;
57055 + memcpy(d_name, name, len);
57056 + name = d_name;
57057 + } else
57058 + len = strlen(name);
57059
57060 /*
57061 * We'll have a dentry and an inode for
57062 diff --git a/fs/coredump.c b/fs/coredump.c
57063 index bc3fbcd..6031650 100644
57064 --- a/fs/coredump.c
57065 +++ b/fs/coredump.c
57066 @@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
57067 struct pipe_inode_info *pipe = file->private_data;
57068
57069 pipe_lock(pipe);
57070 - pipe->readers++;
57071 - pipe->writers--;
57072 + atomic_inc(&pipe->readers);
57073 + atomic_dec(&pipe->writers);
57074 wake_up_interruptible_sync(&pipe->wait);
57075 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
57076 pipe_unlock(pipe);
57077 @@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
57078 * We actually want wait_event_freezable() but then we need
57079 * to clear TIF_SIGPENDING and improve dump_interrupted().
57080 */
57081 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
57082 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
57083
57084 pipe_lock(pipe);
57085 - pipe->readers--;
57086 - pipe->writers++;
57087 + atomic_dec(&pipe->readers);
57088 + atomic_inc(&pipe->writers);
57089 pipe_unlock(pipe);
57090 }
57091
57092 @@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
57093 struct files_struct *displaced;
57094 bool need_nonrelative = false;
57095 bool core_dumped = false;
57096 - static atomic_t core_dump_count = ATOMIC_INIT(0);
57097 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
57098 + long signr = siginfo->si_signo;
57099 + int dumpable;
57100 struct coredump_params cprm = {
57101 .siginfo = siginfo,
57102 .regs = signal_pt_regs(),
57103 @@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
57104 .mm_flags = mm->flags,
57105 };
57106
57107 - audit_core_dumps(siginfo->si_signo);
57108 + audit_core_dumps(signr);
57109 +
57110 + dumpable = __get_dumpable(cprm.mm_flags);
57111 +
57112 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
57113 + gr_handle_brute_attach(dumpable);
57114
57115 binfmt = mm->binfmt;
57116 if (!binfmt || !binfmt->core_dump)
57117 goto fail;
57118 - if (!__get_dumpable(cprm.mm_flags))
57119 + if (!dumpable)
57120 goto fail;
57121
57122 cred = prepare_creds();
57123 @@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
57124 need_nonrelative = true;
57125 }
57126
57127 - retval = coredump_wait(siginfo->si_signo, &core_state);
57128 + retval = coredump_wait(signr, &core_state);
57129 if (retval < 0)
57130 goto fail_creds;
57131
57132 @@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
57133 }
57134 cprm.limit = RLIM_INFINITY;
57135
57136 - dump_count = atomic_inc_return(&core_dump_count);
57137 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
57138 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
57139 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
57140 task_tgid_vnr(current), current->comm);
57141 @@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
57142 } else {
57143 struct inode *inode;
57144
57145 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
57146 +
57147 if (cprm.limit < binfmt->min_coredump)
57148 goto fail_unlock;
57149
57150 @@ -669,7 +678,7 @@ close_fail:
57151 filp_close(cprm.file, NULL);
57152 fail_dropcount:
57153 if (ispipe)
57154 - atomic_dec(&core_dump_count);
57155 + atomic_dec_unchecked(&core_dump_count);
57156 fail_unlock:
57157 kfree(cn.corename);
57158 coredump_finish(mm, core_dumped);
57159 @@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
57160 struct file *file = cprm->file;
57161 loff_t pos = file->f_pos;
57162 ssize_t n;
57163 +
57164 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
57165 if (cprm->written + nr > cprm->limit)
57166 return 0;
57167 while (nr) {
57168 diff --git a/fs/dcache.c b/fs/dcache.c
57169 index cb4a106..b75581f 100644
57170 --- a/fs/dcache.c
57171 +++ b/fs/dcache.c
57172 @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
57173 */
57174 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
57175 if (name->len > DNAME_INLINE_LEN-1) {
57176 - dname = kmalloc(name->len + 1, GFP_KERNEL);
57177 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
57178 if (!dname) {
57179 kmem_cache_free(dentry_cache, dentry);
57180 return NULL;
57181 @@ -3429,7 +3429,8 @@ void __init vfs_caches_init(unsigned long mempages)
57182 mempages -= reserve;
57183
57184 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
57185 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
57186 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
57187 + SLAB_NO_SANITIZE, NULL);
57188
57189 dcache_init();
57190 inode_init();
57191 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
57192 index 9c0444c..628490c 100644
57193 --- a/fs/debugfs/inode.c
57194 +++ b/fs/debugfs/inode.c
57195 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
57196 */
57197 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
57198 {
57199 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
57200 + return __create_file(name, S_IFDIR | S_IRWXU,
57201 +#else
57202 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
57203 +#endif
57204 parent, NULL, NULL);
57205 }
57206 EXPORT_SYMBOL_GPL(debugfs_create_dir);
57207 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
57208 index c36c448..fc96710 100644
57209 --- a/fs/ecryptfs/inode.c
57210 +++ b/fs/ecryptfs/inode.c
57211 @@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
57212 old_fs = get_fs();
57213 set_fs(get_ds());
57214 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
57215 - (char __user *)lower_buf,
57216 + (char __force_user *)lower_buf,
57217 PATH_MAX);
57218 set_fs(old_fs);
57219 if (rc < 0)
57220 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
57221 index e4141f2..d8263e8 100644
57222 --- a/fs/ecryptfs/miscdev.c
57223 +++ b/fs/ecryptfs/miscdev.c
57224 @@ -304,7 +304,7 @@ check_list:
57225 goto out_unlock_msg_ctx;
57226 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
57227 if (msg_ctx->msg) {
57228 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
57229 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
57230 goto out_unlock_msg_ctx;
57231 i += packet_length_size;
57232 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
57233 diff --git a/fs/exec.c b/fs/exec.c
57234 index 7ea097f..0158d8a 100644
57235 --- a/fs/exec.c
57236 +++ b/fs/exec.c
57237 @@ -55,8 +55,20 @@
57238 #include <linux/pipe_fs_i.h>
57239 #include <linux/oom.h>
57240 #include <linux/compat.h>
57241 +#include <linux/random.h>
57242 +#include <linux/seq_file.h>
57243 +#include <linux/coredump.h>
57244 +#include <linux/mman.h>
57245 +
57246 +#ifdef CONFIG_PAX_REFCOUNT
57247 +#include <linux/kallsyms.h>
57248 +#include <linux/kdebug.h>
57249 +#endif
57250 +
57251 +#include <trace/events/fs.h>
57252
57253 #include <asm/uaccess.h>
57254 +#include <asm/sections.h>
57255 #include <asm/mmu_context.h>
57256 #include <asm/tlb.h>
57257
57258 @@ -66,19 +78,34 @@
57259
57260 #include <trace/events/sched.h>
57261
57262 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57263 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
57264 +{
57265 + 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");
57266 +}
57267 +#endif
57268 +
57269 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
57270 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
57271 +EXPORT_SYMBOL(pax_set_initial_flags_func);
57272 +#endif
57273 +
57274 int suid_dumpable = 0;
57275
57276 static LIST_HEAD(formats);
57277 static DEFINE_RWLOCK(binfmt_lock);
57278
57279 +extern int gr_process_kernel_exec_ban(void);
57280 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
57281 +
57282 void __register_binfmt(struct linux_binfmt * fmt, int insert)
57283 {
57284 BUG_ON(!fmt);
57285 if (WARN_ON(!fmt->load_binary))
57286 return;
57287 write_lock(&binfmt_lock);
57288 - insert ? list_add(&fmt->lh, &formats) :
57289 - list_add_tail(&fmt->lh, &formats);
57290 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
57291 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
57292 write_unlock(&binfmt_lock);
57293 }
57294
57295 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
57296 void unregister_binfmt(struct linux_binfmt * fmt)
57297 {
57298 write_lock(&binfmt_lock);
57299 - list_del(&fmt->lh);
57300 + pax_list_del((struct list_head *)&fmt->lh);
57301 write_unlock(&binfmt_lock);
57302 }
57303
57304 @@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57305 int write)
57306 {
57307 struct page *page;
57308 - int ret;
57309
57310 -#ifdef CONFIG_STACK_GROWSUP
57311 - if (write) {
57312 - ret = expand_downwards(bprm->vma, pos);
57313 - if (ret < 0)
57314 - return NULL;
57315 - }
57316 -#endif
57317 - ret = get_user_pages(current, bprm->mm, pos,
57318 - 1, write, 1, &page, NULL);
57319 - if (ret <= 0)
57320 + if (0 > expand_downwards(bprm->vma, pos))
57321 + return NULL;
57322 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
57323 return NULL;
57324
57325 if (write) {
57326 @@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57327 if (size <= ARG_MAX)
57328 return page;
57329
57330 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57331 + // only allow 512KB for argv+env on suid/sgid binaries
57332 + // to prevent easy ASLR exhaustion
57333 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
57334 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
57335 + (size > (512 * 1024))) {
57336 + put_page(page);
57337 + return NULL;
57338 + }
57339 +#endif
57340 +
57341 /*
57342 * Limit to 1/4-th the stack size for the argv+env strings.
57343 * This ensures that:
57344 @@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57345 vma->vm_end = STACK_TOP_MAX;
57346 vma->vm_start = vma->vm_end - PAGE_SIZE;
57347 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
57348 +
57349 +#ifdef CONFIG_PAX_SEGMEXEC
57350 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
57351 +#endif
57352 +
57353 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
57354 INIT_LIST_HEAD(&vma->anon_vma_chain);
57355
57356 @@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57357 mm->stack_vm = mm->total_vm = 1;
57358 up_write(&mm->mmap_sem);
57359 bprm->p = vma->vm_end - sizeof(void *);
57360 +
57361 +#ifdef CONFIG_PAX_RANDUSTACK
57362 + if (randomize_va_space)
57363 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
57364 +#endif
57365 +
57366 return 0;
57367 err:
57368 up_write(&mm->mmap_sem);
57369 @@ -397,7 +438,7 @@ struct user_arg_ptr {
57370 } ptr;
57371 };
57372
57373 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57374 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57375 {
57376 const char __user *native;
57377
57378 @@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57379 compat_uptr_t compat;
57380
57381 if (get_user(compat, argv.ptr.compat + nr))
57382 - return ERR_PTR(-EFAULT);
57383 + return (const char __force_user *)ERR_PTR(-EFAULT);
57384
57385 return compat_ptr(compat);
57386 }
57387 #endif
57388
57389 if (get_user(native, argv.ptr.native + nr))
57390 - return ERR_PTR(-EFAULT);
57391 + return (const char __force_user *)ERR_PTR(-EFAULT);
57392
57393 return native;
57394 }
57395 @@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
57396 if (!p)
57397 break;
57398
57399 - if (IS_ERR(p))
57400 + if (IS_ERR((const char __force_kernel *)p))
57401 return -EFAULT;
57402
57403 if (i >= max)
57404 @@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
57405
57406 ret = -EFAULT;
57407 str = get_user_arg_ptr(argv, argc);
57408 - if (IS_ERR(str))
57409 + if (IS_ERR((const char __force_kernel *)str))
57410 goto out;
57411
57412 len = strnlen_user(str, MAX_ARG_STRLEN);
57413 @@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
57414 int r;
57415 mm_segment_t oldfs = get_fs();
57416 struct user_arg_ptr argv = {
57417 - .ptr.native = (const char __user *const __user *)__argv,
57418 + .ptr.native = (const char __user * const __force_user *)__argv,
57419 };
57420
57421 set_fs(KERNEL_DS);
57422 @@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57423 unsigned long new_end = old_end - shift;
57424 struct mmu_gather tlb;
57425
57426 - BUG_ON(new_start > new_end);
57427 + if (new_start >= new_end || new_start < mmap_min_addr)
57428 + return -ENOMEM;
57429
57430 /*
57431 * ensure there are no vmas between where we want to go
57432 @@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57433 if (vma != find_vma(mm, new_start))
57434 return -EFAULT;
57435
57436 +#ifdef CONFIG_PAX_SEGMEXEC
57437 + BUG_ON(pax_find_mirror_vma(vma));
57438 +#endif
57439 +
57440 /*
57441 * cover the whole range: [new_start, old_end)
57442 */
57443 @@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57444 stack_top = arch_align_stack(stack_top);
57445 stack_top = PAGE_ALIGN(stack_top);
57446
57447 - if (unlikely(stack_top < mmap_min_addr) ||
57448 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
57449 - return -ENOMEM;
57450 -
57451 stack_shift = vma->vm_end - stack_top;
57452
57453 bprm->p -= stack_shift;
57454 @@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
57455 bprm->exec -= stack_shift;
57456
57457 down_write(&mm->mmap_sem);
57458 +
57459 + /* Move stack pages down in memory. */
57460 + if (stack_shift) {
57461 + ret = shift_arg_pages(vma, stack_shift);
57462 + if (ret)
57463 + goto out_unlock;
57464 + }
57465 +
57466 vm_flags = VM_STACK_FLAGS;
57467
57468 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57469 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57470 + vm_flags &= ~VM_EXEC;
57471 +
57472 +#ifdef CONFIG_PAX_MPROTECT
57473 + if (mm->pax_flags & MF_PAX_MPROTECT)
57474 + vm_flags &= ~VM_MAYEXEC;
57475 +#endif
57476 +
57477 + }
57478 +#endif
57479 +
57480 /*
57481 * Adjust stack execute permissions; explicitly enable for
57482 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
57483 @@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57484 goto out_unlock;
57485 BUG_ON(prev != vma);
57486
57487 - /* Move stack pages down in memory. */
57488 - if (stack_shift) {
57489 - ret = shift_arg_pages(vma, stack_shift);
57490 - if (ret)
57491 - goto out_unlock;
57492 - }
57493 -
57494 /* mprotect_fixup is overkill to remove the temporary stack flags */
57495 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
57496
57497 @@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
57498 #endif
57499 current->mm->start_stack = bprm->p;
57500 ret = expand_stack(vma, stack_base);
57501 +
57502 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
57503 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
57504 + unsigned long size;
57505 + vm_flags_t vm_flags;
57506 +
57507 + size = STACK_TOP - vma->vm_end;
57508 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
57509 +
57510 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
57511 +
57512 +#ifdef CONFIG_X86
57513 + if (!ret) {
57514 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
57515 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
57516 + }
57517 +#endif
57518 +
57519 + }
57520 +#endif
57521 +
57522 if (ret)
57523 ret = -EFAULT;
57524
57525 @@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
57526
57527 fsnotify_open(file);
57528
57529 + trace_open_exec(name);
57530 +
57531 err = deny_write_access(file);
57532 if (err)
57533 goto exit;
57534 @@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
57535 old_fs = get_fs();
57536 set_fs(get_ds());
57537 /* The cast to a user pointer is valid due to the set_fs() */
57538 - result = vfs_read(file, (void __user *)addr, count, &pos);
57539 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
57540 set_fs(old_fs);
57541 return result;
57542 }
57543 @@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
57544 }
57545 rcu_read_unlock();
57546
57547 - if (p->fs->users > n_fs) {
57548 + if (atomic_read(&p->fs->users) > n_fs) {
57549 bprm->unsafe |= LSM_UNSAFE_SHARE;
57550 } else {
57551 res = -EAGAIN;
57552 @@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
57553 return ret;
57554 }
57555
57556 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57557 +static DEFINE_PER_CPU(u64, exec_counter);
57558 +static int __init init_exec_counters(void)
57559 +{
57560 + unsigned int cpu;
57561 +
57562 + for_each_possible_cpu(cpu) {
57563 + per_cpu(exec_counter, cpu) = (u64)cpu;
57564 + }
57565 +
57566 + return 0;
57567 +}
57568 +early_initcall(init_exec_counters);
57569 +static inline void increment_exec_counter(void)
57570 +{
57571 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
57572 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
57573 +}
57574 +#else
57575 +static inline void increment_exec_counter(void) {}
57576 +#endif
57577 +
57578 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
57579 + struct user_arg_ptr argv);
57580 +
57581 /*
57582 * sys_execve() executes a new program.
57583 */
57584 @@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
57585 struct user_arg_ptr argv,
57586 struct user_arg_ptr envp)
57587 {
57588 +#ifdef CONFIG_GRKERNSEC
57589 + struct file *old_exec_file;
57590 + struct acl_subject_label *old_acl;
57591 + struct rlimit old_rlim[RLIM_NLIMITS];
57592 +#endif
57593 struct linux_binprm *bprm;
57594 struct file *file;
57595 struct files_struct *displaced;
57596 bool clear_in_exec;
57597 int retval;
57598
57599 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
57600 +
57601 /*
57602 * We move the actual failure in case of RLIMIT_NPROC excess from
57603 * set*uid() to execve() because too many poorly written programs
57604 @@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
57605 if (IS_ERR(file))
57606 goto out_unmark;
57607
57608 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
57609 + retval = -EPERM;
57610 + goto out_file;
57611 + }
57612 +
57613 sched_exec();
57614
57615 bprm->file = file;
57616 bprm->filename = filename;
57617 bprm->interp = filename;
57618
57619 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
57620 + retval = -EACCES;
57621 + goto out_file;
57622 + }
57623 +
57624 retval = bprm_mm_init(bprm);
57625 if (retval)
57626 goto out_file;
57627 @@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
57628 if (retval < 0)
57629 goto out;
57630
57631 +#ifdef CONFIG_GRKERNSEC
57632 + old_acl = current->acl;
57633 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
57634 + old_exec_file = current->exec_file;
57635 + get_file(file);
57636 + current->exec_file = file;
57637 +#endif
57638 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57639 + /* limit suid stack to 8MB
57640 + * we saved the old limits above and will restore them if this exec fails
57641 + */
57642 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
57643 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
57644 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
57645 +#endif
57646 +
57647 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
57648 + retval = -EPERM;
57649 + goto out_fail;
57650 + }
57651 +
57652 + if (!gr_tpe_allow(file)) {
57653 + retval = -EACCES;
57654 + goto out_fail;
57655 + }
57656 +
57657 + if (gr_check_crash_exec(file)) {
57658 + retval = -EACCES;
57659 + goto out_fail;
57660 + }
57661 +
57662 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
57663 + bprm->unsafe);
57664 + if (retval < 0)
57665 + goto out_fail;
57666 +
57667 retval = copy_strings_kernel(1, &bprm->filename, bprm);
57668 if (retval < 0)
57669 - goto out;
57670 + goto out_fail;
57671
57672 bprm->exec = bprm->p;
57673 retval = copy_strings(bprm->envc, envp, bprm);
57674 if (retval < 0)
57675 - goto out;
57676 + goto out_fail;
57677
57678 retval = copy_strings(bprm->argc, argv, bprm);
57679 if (retval < 0)
57680 - goto out;
57681 + goto out_fail;
57682 +
57683 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
57684 +
57685 + gr_handle_exec_args(bprm, argv);
57686
57687 retval = exec_binprm(bprm);
57688 if (retval < 0)
57689 - goto out;
57690 + goto out_fail;
57691 +#ifdef CONFIG_GRKERNSEC
57692 + if (old_exec_file)
57693 + fput(old_exec_file);
57694 +#endif
57695
57696 /* execve succeeded */
57697 +
57698 + increment_exec_counter();
57699 current->fs->in_exec = 0;
57700 current->in_execve = 0;
57701 acct_update_integrals(current);
57702 @@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
57703 put_files_struct(displaced);
57704 return retval;
57705
57706 +out_fail:
57707 +#ifdef CONFIG_GRKERNSEC
57708 + current->acl = old_acl;
57709 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
57710 + fput(current->exec_file);
57711 + current->exec_file = old_exec_file;
57712 +#endif
57713 +
57714 out:
57715 if (bprm->mm) {
57716 acct_arg_size(bprm, 0);
57717 @@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
57718 return error;
57719 }
57720 #endif
57721 +
57722 +int pax_check_flags(unsigned long *flags)
57723 +{
57724 + int retval = 0;
57725 +
57726 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
57727 + if (*flags & MF_PAX_SEGMEXEC)
57728 + {
57729 + *flags &= ~MF_PAX_SEGMEXEC;
57730 + retval = -EINVAL;
57731 + }
57732 +#endif
57733 +
57734 + if ((*flags & MF_PAX_PAGEEXEC)
57735 +
57736 +#ifdef CONFIG_PAX_PAGEEXEC
57737 + && (*flags & MF_PAX_SEGMEXEC)
57738 +#endif
57739 +
57740 + )
57741 + {
57742 + *flags &= ~MF_PAX_PAGEEXEC;
57743 + retval = -EINVAL;
57744 + }
57745 +
57746 + if ((*flags & MF_PAX_MPROTECT)
57747 +
57748 +#ifdef CONFIG_PAX_MPROTECT
57749 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57750 +#endif
57751 +
57752 + )
57753 + {
57754 + *flags &= ~MF_PAX_MPROTECT;
57755 + retval = -EINVAL;
57756 + }
57757 +
57758 + if ((*flags & MF_PAX_EMUTRAMP)
57759 +
57760 +#ifdef CONFIG_PAX_EMUTRAMP
57761 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57762 +#endif
57763 +
57764 + )
57765 + {
57766 + *flags &= ~MF_PAX_EMUTRAMP;
57767 + retval = -EINVAL;
57768 + }
57769 +
57770 + return retval;
57771 +}
57772 +
57773 +EXPORT_SYMBOL(pax_check_flags);
57774 +
57775 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57776 +char *pax_get_path(const struct path *path, char *buf, int buflen)
57777 +{
57778 + char *pathname = d_path(path, buf, buflen);
57779 +
57780 + if (IS_ERR(pathname))
57781 + goto toolong;
57782 +
57783 + pathname = mangle_path(buf, pathname, "\t\n\\");
57784 + if (!pathname)
57785 + goto toolong;
57786 +
57787 + *pathname = 0;
57788 + return buf;
57789 +
57790 +toolong:
57791 + return "<path too long>";
57792 +}
57793 +EXPORT_SYMBOL(pax_get_path);
57794 +
57795 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
57796 +{
57797 + struct task_struct *tsk = current;
57798 + struct mm_struct *mm = current->mm;
57799 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
57800 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
57801 + char *path_exec = NULL;
57802 + char *path_fault = NULL;
57803 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
57804 + siginfo_t info = { };
57805 +
57806 + if (buffer_exec && buffer_fault) {
57807 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
57808 +
57809 + down_read(&mm->mmap_sem);
57810 + vma = mm->mmap;
57811 + while (vma && (!vma_exec || !vma_fault)) {
57812 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
57813 + vma_exec = vma;
57814 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
57815 + vma_fault = vma;
57816 + vma = vma->vm_next;
57817 + }
57818 + if (vma_exec)
57819 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
57820 + if (vma_fault) {
57821 + start = vma_fault->vm_start;
57822 + end = vma_fault->vm_end;
57823 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
57824 + if (vma_fault->vm_file)
57825 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
57826 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
57827 + path_fault = "<heap>";
57828 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
57829 + path_fault = "<stack>";
57830 + else
57831 + path_fault = "<anonymous mapping>";
57832 + }
57833 + up_read(&mm->mmap_sem);
57834 + }
57835 + if (tsk->signal->curr_ip)
57836 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
57837 + else
57838 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
57839 + 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),
57840 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
57841 + free_page((unsigned long)buffer_exec);
57842 + free_page((unsigned long)buffer_fault);
57843 + pax_report_insns(regs, pc, sp);
57844 + info.si_signo = SIGKILL;
57845 + info.si_errno = 0;
57846 + info.si_code = SI_KERNEL;
57847 + info.si_pid = 0;
57848 + info.si_uid = 0;
57849 + do_coredump(&info);
57850 +}
57851 +#endif
57852 +
57853 +#ifdef CONFIG_PAX_REFCOUNT
57854 +void pax_report_refcount_overflow(struct pt_regs *regs)
57855 +{
57856 + if (current->signal->curr_ip)
57857 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
57858 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
57859 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
57860 + else
57861 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
57862 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
57863 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
57864 + preempt_disable();
57865 + show_regs(regs);
57866 + preempt_enable();
57867 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
57868 +}
57869 +#endif
57870 +
57871 +#ifdef CONFIG_PAX_USERCOPY
57872 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
57873 +static noinline int check_stack_object(const void *obj, unsigned long len)
57874 +{
57875 + const void * const stack = task_stack_page(current);
57876 + const void * const stackend = stack + THREAD_SIZE;
57877 +
57878 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
57879 + const void *frame = NULL;
57880 + const void *oldframe;
57881 +#endif
57882 +
57883 + if (obj + len < obj)
57884 + return -1;
57885 +
57886 + if (obj + len <= stack || stackend <= obj)
57887 + return 0;
57888 +
57889 + if (obj < stack || stackend < obj + len)
57890 + return -1;
57891 +
57892 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
57893 + oldframe = __builtin_frame_address(1);
57894 + if (oldframe)
57895 + frame = __builtin_frame_address(2);
57896 + /*
57897 + low ----------------------------------------------> high
57898 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
57899 + ^----------------^
57900 + allow copies only within here
57901 + */
57902 + while (stack <= frame && frame < stackend) {
57903 + /* if obj + len extends past the last frame, this
57904 + check won't pass and the next frame will be 0,
57905 + causing us to bail out and correctly report
57906 + the copy as invalid
57907 + */
57908 + if (obj + len <= frame)
57909 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
57910 + oldframe = frame;
57911 + frame = *(const void * const *)frame;
57912 + }
57913 + return -1;
57914 +#else
57915 + return 1;
57916 +#endif
57917 +}
57918 +
57919 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
57920 +{
57921 + if (current->signal->curr_ip)
57922 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
57923 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
57924 + else
57925 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
57926 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
57927 + dump_stack();
57928 + gr_handle_kernel_exploit();
57929 + do_group_exit(SIGKILL);
57930 +}
57931 +#endif
57932 +
57933 +#ifdef CONFIG_PAX_USERCOPY
57934 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
57935 +{
57936 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
57937 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
57938 +#ifdef CONFIG_MODULES
57939 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
57940 +#else
57941 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
57942 +#endif
57943 +
57944 +#else
57945 + unsigned long textlow = (unsigned long)_stext;
57946 + unsigned long texthigh = (unsigned long)_etext;
57947 +
57948 +#ifdef CONFIG_X86_64
57949 + /* check against linear mapping as well */
57950 + if (high > (unsigned long)__va(__pa(textlow)) &&
57951 + low <= (unsigned long)__va(__pa(texthigh)))
57952 + return true;
57953 +#endif
57954 +
57955 +#endif
57956 +
57957 + if (high <= textlow || low > texthigh)
57958 + return false;
57959 + else
57960 + return true;
57961 +}
57962 +#endif
57963 +
57964 +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
57965 +{
57966 +
57967 +#ifdef CONFIG_PAX_USERCOPY
57968 + const char *type;
57969 +
57970 + if (!n)
57971 + return;
57972 +
57973 + type = check_heap_object(ptr, n);
57974 + if (!type) {
57975 + int ret = check_stack_object(ptr, n);
57976 + if (ret == 1 || ret == 2)
57977 + return;
57978 + if (ret == 0) {
57979 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
57980 + type = "<kernel text>";
57981 + else
57982 + return;
57983 + } else
57984 + type = "<process stack>";
57985 + }
57986 +
57987 + pax_report_usercopy(ptr, n, to_user, type);
57988 +#endif
57989 +
57990 +}
57991 +EXPORT_SYMBOL(__check_object_size);
57992 +
57993 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
57994 +void pax_track_stack(void)
57995 +{
57996 + unsigned long sp = (unsigned long)&sp;
57997 + if (sp < current_thread_info()->lowest_stack &&
57998 + sp > (unsigned long)task_stack_page(current))
57999 + current_thread_info()->lowest_stack = sp;
58000 +}
58001 +EXPORT_SYMBOL(pax_track_stack);
58002 +#endif
58003 +
58004 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
58005 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
58006 +{
58007 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
58008 + dump_stack();
58009 + do_group_exit(SIGKILL);
58010 +}
58011 +EXPORT_SYMBOL(report_size_overflow);
58012 +#endif
58013 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
58014 index 9f9992b..8b59411 100644
58015 --- a/fs/ext2/balloc.c
58016 +++ b/fs/ext2/balloc.c
58017 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
58018
58019 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58020 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58021 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58022 + if (free_blocks < root_blocks + 1 &&
58023 !uid_eq(sbi->s_resuid, current_fsuid()) &&
58024 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58025 - !in_group_p (sbi->s_resgid))) {
58026 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58027 return 0;
58028 }
58029 return 1;
58030 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
58031 index 2d7557d..14e38f94 100644
58032 --- a/fs/ext2/xattr.c
58033 +++ b/fs/ext2/xattr.c
58034 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
58035 struct buffer_head *bh = NULL;
58036 struct ext2_xattr_entry *entry;
58037 char *end;
58038 - size_t rest = buffer_size;
58039 + size_t rest = buffer_size, total_size = 0;
58040 int error;
58041
58042 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
58043 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
58044 buffer += size;
58045 }
58046 rest -= size;
58047 + total_size += size;
58048 }
58049 }
58050 - error = buffer_size - rest; /* total size */
58051 + error = total_size;
58052
58053 cleanup:
58054 brelse(bh);
58055 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
58056 index 22548f5..41521d8 100644
58057 --- a/fs/ext3/balloc.c
58058 +++ b/fs/ext3/balloc.c
58059 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
58060
58061 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58062 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58063 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58064 + if (free_blocks < root_blocks + 1 &&
58065 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
58066 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58067 - !in_group_p (sbi->s_resgid))) {
58068 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58069 return 0;
58070 }
58071 return 1;
58072 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
58073 index b1fc963..881228c 100644
58074 --- a/fs/ext3/xattr.c
58075 +++ b/fs/ext3/xattr.c
58076 @@ -330,7 +330,7 @@ static int
58077 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58078 char *buffer, size_t buffer_size)
58079 {
58080 - size_t rest = buffer_size;
58081 + size_t rest = buffer_size, total_size = 0;
58082
58083 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
58084 const struct xattr_handler *handler =
58085 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58086 buffer += size;
58087 }
58088 rest -= size;
58089 + total_size += size;
58090 }
58091 }
58092 - return buffer_size - rest;
58093 + return total_size;
58094 }
58095
58096 static int
58097 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
58098 index 6ea7b14..8fa16d9 100644
58099 --- a/fs/ext4/balloc.c
58100 +++ b/fs/ext4/balloc.c
58101 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
58102 /* Hm, nope. Are (enough) root reserved clusters available? */
58103 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
58104 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
58105 - capable(CAP_SYS_RESOURCE) ||
58106 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
58107 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
58108 + capable_nolog(CAP_SYS_RESOURCE)) {
58109
58110 if (free_clusters >= (nclusters + dirty_clusters +
58111 resv_clusters))
58112 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
58113 index ece5556..e39d3a8 100644
58114 --- a/fs/ext4/ext4.h
58115 +++ b/fs/ext4/ext4.h
58116 @@ -1267,19 +1267,19 @@ struct ext4_sb_info {
58117 unsigned long s_mb_last_start;
58118
58119 /* stats for buddy allocator */
58120 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
58121 - atomic_t s_bal_success; /* we found long enough chunks */
58122 - atomic_t s_bal_allocated; /* in blocks */
58123 - atomic_t s_bal_ex_scanned; /* total extents scanned */
58124 - atomic_t s_bal_goals; /* goal hits */
58125 - atomic_t s_bal_breaks; /* too long searches */
58126 - atomic_t s_bal_2orders; /* 2^order hits */
58127 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
58128 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
58129 + atomic_unchecked_t s_bal_allocated; /* in blocks */
58130 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
58131 + atomic_unchecked_t s_bal_goals; /* goal hits */
58132 + atomic_unchecked_t s_bal_breaks; /* too long searches */
58133 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
58134 spinlock_t s_bal_lock;
58135 unsigned long s_mb_buddies_generated;
58136 unsigned long long s_mb_generation_time;
58137 - atomic_t s_mb_lost_chunks;
58138 - atomic_t s_mb_preallocated;
58139 - atomic_t s_mb_discarded;
58140 + atomic_unchecked_t s_mb_lost_chunks;
58141 + atomic_unchecked_t s_mb_preallocated;
58142 + atomic_unchecked_t s_mb_discarded;
58143 atomic_t s_lock_busy;
58144
58145 /* locality groups */
58146 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
58147 index 04a5c75..09894fa 100644
58148 --- a/fs/ext4/mballoc.c
58149 +++ b/fs/ext4/mballoc.c
58150 @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
58151 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
58152
58153 if (EXT4_SB(sb)->s_mb_stats)
58154 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
58155 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
58156
58157 break;
58158 }
58159 @@ -2189,7 +2189,7 @@ repeat:
58160 ac->ac_status = AC_STATUS_CONTINUE;
58161 ac->ac_flags |= EXT4_MB_HINT_FIRST;
58162 cr = 3;
58163 - atomic_inc(&sbi->s_mb_lost_chunks);
58164 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
58165 goto repeat;
58166 }
58167 }
58168 @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
58169 if (sbi->s_mb_stats) {
58170 ext4_msg(sb, KERN_INFO,
58171 "mballoc: %u blocks %u reqs (%u success)",
58172 - atomic_read(&sbi->s_bal_allocated),
58173 - atomic_read(&sbi->s_bal_reqs),
58174 - atomic_read(&sbi->s_bal_success));
58175 + atomic_read_unchecked(&sbi->s_bal_allocated),
58176 + atomic_read_unchecked(&sbi->s_bal_reqs),
58177 + atomic_read_unchecked(&sbi->s_bal_success));
58178 ext4_msg(sb, KERN_INFO,
58179 "mballoc: %u extents scanned, %u goal hits, "
58180 "%u 2^N hits, %u breaks, %u lost",
58181 - atomic_read(&sbi->s_bal_ex_scanned),
58182 - atomic_read(&sbi->s_bal_goals),
58183 - atomic_read(&sbi->s_bal_2orders),
58184 - atomic_read(&sbi->s_bal_breaks),
58185 - atomic_read(&sbi->s_mb_lost_chunks));
58186 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
58187 + atomic_read_unchecked(&sbi->s_bal_goals),
58188 + atomic_read_unchecked(&sbi->s_bal_2orders),
58189 + atomic_read_unchecked(&sbi->s_bal_breaks),
58190 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
58191 ext4_msg(sb, KERN_INFO,
58192 "mballoc: %lu generated and it took %Lu",
58193 sbi->s_mb_buddies_generated,
58194 sbi->s_mb_generation_time);
58195 ext4_msg(sb, KERN_INFO,
58196 "mballoc: %u preallocated, %u discarded",
58197 - atomic_read(&sbi->s_mb_preallocated),
58198 - atomic_read(&sbi->s_mb_discarded));
58199 + atomic_read_unchecked(&sbi->s_mb_preallocated),
58200 + atomic_read_unchecked(&sbi->s_mb_discarded));
58201 }
58202
58203 free_percpu(sbi->s_locality_groups);
58204 @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
58205 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
58206
58207 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
58208 - atomic_inc(&sbi->s_bal_reqs);
58209 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
58210 + atomic_inc_unchecked(&sbi->s_bal_reqs);
58211 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
58212 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
58213 - atomic_inc(&sbi->s_bal_success);
58214 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
58215 + atomic_inc_unchecked(&sbi->s_bal_success);
58216 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
58217 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
58218 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
58219 - atomic_inc(&sbi->s_bal_goals);
58220 + atomic_inc_unchecked(&sbi->s_bal_goals);
58221 if (ac->ac_found > sbi->s_mb_max_to_scan)
58222 - atomic_inc(&sbi->s_bal_breaks);
58223 + atomic_inc_unchecked(&sbi->s_bal_breaks);
58224 }
58225
58226 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
58227 @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
58228 trace_ext4_mb_new_inode_pa(ac, pa);
58229
58230 ext4_mb_use_inode_pa(ac, pa);
58231 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
58232 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
58233
58234 ei = EXT4_I(ac->ac_inode);
58235 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
58236 @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
58237 trace_ext4_mb_new_group_pa(ac, pa);
58238
58239 ext4_mb_use_group_pa(ac, pa);
58240 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
58241 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
58242
58243 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
58244 lg = ac->ac_lg;
58245 @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
58246 * from the bitmap and continue.
58247 */
58248 }
58249 - atomic_add(free, &sbi->s_mb_discarded);
58250 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
58251
58252 return err;
58253 }
58254 @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
58255 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
58256 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
58257 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
58258 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58259 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58260 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
58261
58262 return 0;
58263 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
58264 index 04434ad..6404663 100644
58265 --- a/fs/ext4/mmp.c
58266 +++ b/fs/ext4/mmp.c
58267 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
58268 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
58269 const char *function, unsigned int line, const char *msg)
58270 {
58271 - __ext4_warning(sb, function, line, msg);
58272 + __ext4_warning(sb, function, line, "%s", msg);
58273 __ext4_warning(sb, function, line,
58274 "MMP failure info: last update time: %llu, last update "
58275 "node: %s, last update device: %s\n",
58276 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
58277 index 1f7784d..5d8bbad 100644
58278 --- a/fs/ext4/super.c
58279 +++ b/fs/ext4/super.c
58280 @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
58281 }
58282
58283 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
58284 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58285 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58286 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
58287
58288 #ifdef CONFIG_QUOTA
58289 @@ -2450,7 +2450,7 @@ struct ext4_attr {
58290 int offset;
58291 int deprecated_val;
58292 } u;
58293 -};
58294 +} __do_const;
58295
58296 static int parse_strtoull(const char *buf,
58297 unsigned long long max, unsigned long long *value)
58298 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
58299 index 1423c48..9c0c6dc 100644
58300 --- a/fs/ext4/xattr.c
58301 +++ b/fs/ext4/xattr.c
58302 @@ -381,7 +381,7 @@ static int
58303 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58304 char *buffer, size_t buffer_size)
58305 {
58306 - size_t rest = buffer_size;
58307 + size_t rest = buffer_size, total_size = 0;
58308
58309 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
58310 const struct xattr_handler *handler =
58311 @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58312 buffer += size;
58313 }
58314 rest -= size;
58315 + total_size += size;
58316 }
58317 }
58318 - return buffer_size - rest;
58319 + return total_size;
58320 }
58321
58322 static int
58323 diff --git a/fs/fcntl.c b/fs/fcntl.c
58324 index ef68665..5deacdc 100644
58325 --- a/fs/fcntl.c
58326 +++ b/fs/fcntl.c
58327 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
58328 if (err)
58329 return err;
58330
58331 + if (gr_handle_chroot_fowner(pid, type))
58332 + return -ENOENT;
58333 + if (gr_check_protected_task_fowner(pid, type))
58334 + return -EACCES;
58335 +
58336 f_modown(filp, pid, type, force);
58337 return 0;
58338 }
58339 diff --git a/fs/fhandle.c b/fs/fhandle.c
58340 index 999ff5c..41f4109 100644
58341 --- a/fs/fhandle.c
58342 +++ b/fs/fhandle.c
58343 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
58344 } else
58345 retval = 0;
58346 /* copy the mount id */
58347 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
58348 - sizeof(*mnt_id)) ||
58349 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
58350 copy_to_user(ufh, handle,
58351 sizeof(struct file_handle) + handle_bytes))
58352 retval = -EFAULT;
58353 diff --git a/fs/file.c b/fs/file.c
58354 index 4a78f98..f9a6d25 100644
58355 --- a/fs/file.c
58356 +++ b/fs/file.c
58357 @@ -16,6 +16,7 @@
58358 #include <linux/slab.h>
58359 #include <linux/vmalloc.h>
58360 #include <linux/file.h>
58361 +#include <linux/security.h>
58362 #include <linux/fdtable.h>
58363 #include <linux/bitops.h>
58364 #include <linux/interrupt.h>
58365 @@ -141,7 +142,7 @@ out:
58366 * Return <0 error code on error; 1 on successful completion.
58367 * The files->file_lock should be held on entry, and will be held on exit.
58368 */
58369 -static int expand_fdtable(struct files_struct *files, int nr)
58370 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
58371 __releases(files->file_lock)
58372 __acquires(files->file_lock)
58373 {
58374 @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
58375 * expanded and execution may have blocked.
58376 * The files->file_lock should be held on entry, and will be held on exit.
58377 */
58378 -static int expand_files(struct files_struct *files, int nr)
58379 +static int expand_files(struct files_struct *files, unsigned int nr)
58380 {
58381 struct fdtable *fdt;
58382
58383 @@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
58384 if (!file)
58385 return __close_fd(files, fd);
58386
58387 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
58388 if (fd >= rlimit(RLIMIT_NOFILE))
58389 return -EBADF;
58390
58391 @@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
58392 if (unlikely(oldfd == newfd))
58393 return -EINVAL;
58394
58395 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
58396 if (newfd >= rlimit(RLIMIT_NOFILE))
58397 return -EBADF;
58398
58399 @@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
58400 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
58401 {
58402 int err;
58403 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
58404 if (from >= rlimit(RLIMIT_NOFILE))
58405 return -EINVAL;
58406 err = alloc_fd(from, flags);
58407 diff --git a/fs/filesystems.c b/fs/filesystems.c
58408 index 92567d9..fcd8cbf 100644
58409 --- a/fs/filesystems.c
58410 +++ b/fs/filesystems.c
58411 @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
58412 int len = dot ? dot - name : strlen(name);
58413
58414 fs = __get_fs_type(name, len);
58415 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
58416 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
58417 +#else
58418 if (!fs && (request_module("fs-%.*s", len, name) == 0))
58419 +#endif
58420 fs = __get_fs_type(name, len);
58421
58422 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
58423 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
58424 index 7dca743..543d620 100644
58425 --- a/fs/fs_struct.c
58426 +++ b/fs/fs_struct.c
58427 @@ -4,6 +4,7 @@
58428 #include <linux/path.h>
58429 #include <linux/slab.h>
58430 #include <linux/fs_struct.h>
58431 +#include <linux/grsecurity.h>
58432 #include "internal.h"
58433
58434 /*
58435 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
58436 write_seqcount_begin(&fs->seq);
58437 old_root = fs->root;
58438 fs->root = *path;
58439 + gr_set_chroot_entries(current, path);
58440 write_seqcount_end(&fs->seq);
58441 spin_unlock(&fs->lock);
58442 if (old_root.dentry)
58443 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
58444 int hits = 0;
58445 spin_lock(&fs->lock);
58446 write_seqcount_begin(&fs->seq);
58447 + /* this root replacement is only done by pivot_root,
58448 + leave grsec's chroot tagging alone for this task
58449 + so that a pivoted root isn't treated as a chroot
58450 + */
58451 hits += replace_path(&fs->root, old_root, new_root);
58452 hits += replace_path(&fs->pwd, old_root, new_root);
58453 write_seqcount_end(&fs->seq);
58454 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
58455 task_lock(tsk);
58456 spin_lock(&fs->lock);
58457 tsk->fs = NULL;
58458 - kill = !--fs->users;
58459 + gr_clear_chroot_entries(tsk);
58460 + kill = !atomic_dec_return(&fs->users);
58461 spin_unlock(&fs->lock);
58462 task_unlock(tsk);
58463 if (kill)
58464 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58465 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
58466 /* We don't need to lock fs - think why ;-) */
58467 if (fs) {
58468 - fs->users = 1;
58469 + atomic_set(&fs->users, 1);
58470 fs->in_exec = 0;
58471 spin_lock_init(&fs->lock);
58472 seqcount_init(&fs->seq);
58473 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58474 spin_lock(&old->lock);
58475 fs->root = old->root;
58476 path_get(&fs->root);
58477 + /* instead of calling gr_set_chroot_entries here,
58478 + we call it from every caller of this function
58479 + */
58480 fs->pwd = old->pwd;
58481 path_get(&fs->pwd);
58482 spin_unlock(&old->lock);
58483 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
58484
58485 task_lock(current);
58486 spin_lock(&fs->lock);
58487 - kill = !--fs->users;
58488 + kill = !atomic_dec_return(&fs->users);
58489 current->fs = new_fs;
58490 + gr_set_chroot_entries(current, &new_fs->root);
58491 spin_unlock(&fs->lock);
58492 task_unlock(current);
58493
58494 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
58495
58496 int current_umask(void)
58497 {
58498 - return current->fs->umask;
58499 + return current->fs->umask | gr_acl_umask();
58500 }
58501 EXPORT_SYMBOL(current_umask);
58502
58503 /* to be mentioned only in INIT_TASK */
58504 struct fs_struct init_fs = {
58505 - .users = 1,
58506 + .users = ATOMIC_INIT(1),
58507 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
58508 .seq = SEQCNT_ZERO(init_fs.seq),
58509 .umask = 0022,
58510 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
58511 index 29d7feb..303644d 100644
58512 --- a/fs/fscache/cookie.c
58513 +++ b/fs/fscache/cookie.c
58514 @@ -19,7 +19,7 @@
58515
58516 struct kmem_cache *fscache_cookie_jar;
58517
58518 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
58519 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
58520
58521 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
58522 static int fscache_alloc_object(struct fscache_cache *cache,
58523 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
58524 parent ? (char *) parent->def->name : "<no-parent>",
58525 def->name, netfs_data, enable);
58526
58527 - fscache_stat(&fscache_n_acquires);
58528 + fscache_stat_unchecked(&fscache_n_acquires);
58529
58530 /* if there's no parent cookie, then we don't create one here either */
58531 if (!parent) {
58532 - fscache_stat(&fscache_n_acquires_null);
58533 + fscache_stat_unchecked(&fscache_n_acquires_null);
58534 _leave(" [no parent]");
58535 return NULL;
58536 }
58537 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58538 /* allocate and initialise a cookie */
58539 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
58540 if (!cookie) {
58541 - fscache_stat(&fscache_n_acquires_oom);
58542 + fscache_stat_unchecked(&fscache_n_acquires_oom);
58543 _leave(" [ENOMEM]");
58544 return NULL;
58545 }
58546 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
58547
58548 switch (cookie->def->type) {
58549 case FSCACHE_COOKIE_TYPE_INDEX:
58550 - fscache_stat(&fscache_n_cookie_index);
58551 + fscache_stat_unchecked(&fscache_n_cookie_index);
58552 break;
58553 case FSCACHE_COOKIE_TYPE_DATAFILE:
58554 - fscache_stat(&fscache_n_cookie_data);
58555 + fscache_stat_unchecked(&fscache_n_cookie_data);
58556 break;
58557 default:
58558 - fscache_stat(&fscache_n_cookie_special);
58559 + fscache_stat_unchecked(&fscache_n_cookie_special);
58560 break;
58561 }
58562
58563 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58564 } else {
58565 atomic_dec(&parent->n_children);
58566 __fscache_cookie_put(cookie);
58567 - fscache_stat(&fscache_n_acquires_nobufs);
58568 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
58569 _leave(" = NULL");
58570 return NULL;
58571 }
58572 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58573 }
58574 }
58575
58576 - fscache_stat(&fscache_n_acquires_ok);
58577 + fscache_stat_unchecked(&fscache_n_acquires_ok);
58578 _leave(" = %p", cookie);
58579 return cookie;
58580 }
58581 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
58582 cache = fscache_select_cache_for_object(cookie->parent);
58583 if (!cache) {
58584 up_read(&fscache_addremove_sem);
58585 - fscache_stat(&fscache_n_acquires_no_cache);
58586 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
58587 _leave(" = -ENOMEDIUM [no cache]");
58588 return -ENOMEDIUM;
58589 }
58590 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
58591 object = cache->ops->alloc_object(cache, cookie);
58592 fscache_stat_d(&fscache_n_cop_alloc_object);
58593 if (IS_ERR(object)) {
58594 - fscache_stat(&fscache_n_object_no_alloc);
58595 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
58596 ret = PTR_ERR(object);
58597 goto error;
58598 }
58599
58600 - fscache_stat(&fscache_n_object_alloc);
58601 + fscache_stat_unchecked(&fscache_n_object_alloc);
58602
58603 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
58604 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
58605
58606 _debug("ALLOC OBJ%x: %s {%lx}",
58607 object->debug_id, cookie->def->name, object->events);
58608 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
58609
58610 _enter("{%s}", cookie->def->name);
58611
58612 - fscache_stat(&fscache_n_invalidates);
58613 + fscache_stat_unchecked(&fscache_n_invalidates);
58614
58615 /* Only permit invalidation of data files. Invalidating an index will
58616 * require the caller to release all its attachments to the tree rooted
58617 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
58618 {
58619 struct fscache_object *object;
58620
58621 - fscache_stat(&fscache_n_updates);
58622 + fscache_stat_unchecked(&fscache_n_updates);
58623
58624 if (!cookie) {
58625 - fscache_stat(&fscache_n_updates_null);
58626 + fscache_stat_unchecked(&fscache_n_updates_null);
58627 _leave(" [no cookie]");
58628 return;
58629 }
58630 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
58631 */
58632 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
58633 {
58634 - fscache_stat(&fscache_n_relinquishes);
58635 + fscache_stat_unchecked(&fscache_n_relinquishes);
58636 if (retire)
58637 - fscache_stat(&fscache_n_relinquishes_retire);
58638 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
58639
58640 if (!cookie) {
58641 - fscache_stat(&fscache_n_relinquishes_null);
58642 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
58643 _leave(" [no cookie]");
58644 return;
58645 }
58646 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
58647 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
58648 goto inconsistent;
58649
58650 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58651 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58652
58653 __fscache_use_cookie(cookie);
58654 if (fscache_submit_op(object, op) < 0)
58655 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
58656 index 4226f66..0fb3f45 100644
58657 --- a/fs/fscache/internal.h
58658 +++ b/fs/fscache/internal.h
58659 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
58660 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
58661 extern int fscache_wait_for_operation_activation(struct fscache_object *,
58662 struct fscache_operation *,
58663 - atomic_t *,
58664 - atomic_t *,
58665 + atomic_unchecked_t *,
58666 + atomic_unchecked_t *,
58667 void (*)(struct fscache_operation *));
58668 extern void fscache_invalidate_writes(struct fscache_cookie *);
58669
58670 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
58671 * stats.c
58672 */
58673 #ifdef CONFIG_FSCACHE_STATS
58674 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58675 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58676 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58677 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58678
58679 -extern atomic_t fscache_n_op_pend;
58680 -extern atomic_t fscache_n_op_run;
58681 -extern atomic_t fscache_n_op_enqueue;
58682 -extern atomic_t fscache_n_op_deferred_release;
58683 -extern atomic_t fscache_n_op_release;
58684 -extern atomic_t fscache_n_op_gc;
58685 -extern atomic_t fscache_n_op_cancelled;
58686 -extern atomic_t fscache_n_op_rejected;
58687 +extern atomic_unchecked_t fscache_n_op_pend;
58688 +extern atomic_unchecked_t fscache_n_op_run;
58689 +extern atomic_unchecked_t fscache_n_op_enqueue;
58690 +extern atomic_unchecked_t fscache_n_op_deferred_release;
58691 +extern atomic_unchecked_t fscache_n_op_release;
58692 +extern atomic_unchecked_t fscache_n_op_gc;
58693 +extern atomic_unchecked_t fscache_n_op_cancelled;
58694 +extern atomic_unchecked_t fscache_n_op_rejected;
58695
58696 -extern atomic_t fscache_n_attr_changed;
58697 -extern atomic_t fscache_n_attr_changed_ok;
58698 -extern atomic_t fscache_n_attr_changed_nobufs;
58699 -extern atomic_t fscache_n_attr_changed_nomem;
58700 -extern atomic_t fscache_n_attr_changed_calls;
58701 +extern atomic_unchecked_t fscache_n_attr_changed;
58702 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
58703 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
58704 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
58705 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
58706
58707 -extern atomic_t fscache_n_allocs;
58708 -extern atomic_t fscache_n_allocs_ok;
58709 -extern atomic_t fscache_n_allocs_wait;
58710 -extern atomic_t fscache_n_allocs_nobufs;
58711 -extern atomic_t fscache_n_allocs_intr;
58712 -extern atomic_t fscache_n_allocs_object_dead;
58713 -extern atomic_t fscache_n_alloc_ops;
58714 -extern atomic_t fscache_n_alloc_op_waits;
58715 +extern atomic_unchecked_t fscache_n_allocs;
58716 +extern atomic_unchecked_t fscache_n_allocs_ok;
58717 +extern atomic_unchecked_t fscache_n_allocs_wait;
58718 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
58719 +extern atomic_unchecked_t fscache_n_allocs_intr;
58720 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
58721 +extern atomic_unchecked_t fscache_n_alloc_ops;
58722 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
58723
58724 -extern atomic_t fscache_n_retrievals;
58725 -extern atomic_t fscache_n_retrievals_ok;
58726 -extern atomic_t fscache_n_retrievals_wait;
58727 -extern atomic_t fscache_n_retrievals_nodata;
58728 -extern atomic_t fscache_n_retrievals_nobufs;
58729 -extern atomic_t fscache_n_retrievals_intr;
58730 -extern atomic_t fscache_n_retrievals_nomem;
58731 -extern atomic_t fscache_n_retrievals_object_dead;
58732 -extern atomic_t fscache_n_retrieval_ops;
58733 -extern atomic_t fscache_n_retrieval_op_waits;
58734 +extern atomic_unchecked_t fscache_n_retrievals;
58735 +extern atomic_unchecked_t fscache_n_retrievals_ok;
58736 +extern atomic_unchecked_t fscache_n_retrievals_wait;
58737 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
58738 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
58739 +extern atomic_unchecked_t fscache_n_retrievals_intr;
58740 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
58741 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
58742 +extern atomic_unchecked_t fscache_n_retrieval_ops;
58743 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
58744
58745 -extern atomic_t fscache_n_stores;
58746 -extern atomic_t fscache_n_stores_ok;
58747 -extern atomic_t fscache_n_stores_again;
58748 -extern atomic_t fscache_n_stores_nobufs;
58749 -extern atomic_t fscache_n_stores_oom;
58750 -extern atomic_t fscache_n_store_ops;
58751 -extern atomic_t fscache_n_store_calls;
58752 -extern atomic_t fscache_n_store_pages;
58753 -extern atomic_t fscache_n_store_radix_deletes;
58754 -extern atomic_t fscache_n_store_pages_over_limit;
58755 +extern atomic_unchecked_t fscache_n_stores;
58756 +extern atomic_unchecked_t fscache_n_stores_ok;
58757 +extern atomic_unchecked_t fscache_n_stores_again;
58758 +extern atomic_unchecked_t fscache_n_stores_nobufs;
58759 +extern atomic_unchecked_t fscache_n_stores_oom;
58760 +extern atomic_unchecked_t fscache_n_store_ops;
58761 +extern atomic_unchecked_t fscache_n_store_calls;
58762 +extern atomic_unchecked_t fscache_n_store_pages;
58763 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
58764 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
58765
58766 -extern atomic_t fscache_n_store_vmscan_not_storing;
58767 -extern atomic_t fscache_n_store_vmscan_gone;
58768 -extern atomic_t fscache_n_store_vmscan_busy;
58769 -extern atomic_t fscache_n_store_vmscan_cancelled;
58770 -extern atomic_t fscache_n_store_vmscan_wait;
58771 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
58772 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
58773 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
58774 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
58775 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
58776
58777 -extern atomic_t fscache_n_marks;
58778 -extern atomic_t fscache_n_uncaches;
58779 +extern atomic_unchecked_t fscache_n_marks;
58780 +extern atomic_unchecked_t fscache_n_uncaches;
58781
58782 -extern atomic_t fscache_n_acquires;
58783 -extern atomic_t fscache_n_acquires_null;
58784 -extern atomic_t fscache_n_acquires_no_cache;
58785 -extern atomic_t fscache_n_acquires_ok;
58786 -extern atomic_t fscache_n_acquires_nobufs;
58787 -extern atomic_t fscache_n_acquires_oom;
58788 +extern atomic_unchecked_t fscache_n_acquires;
58789 +extern atomic_unchecked_t fscache_n_acquires_null;
58790 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
58791 +extern atomic_unchecked_t fscache_n_acquires_ok;
58792 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
58793 +extern atomic_unchecked_t fscache_n_acquires_oom;
58794
58795 -extern atomic_t fscache_n_invalidates;
58796 -extern atomic_t fscache_n_invalidates_run;
58797 +extern atomic_unchecked_t fscache_n_invalidates;
58798 +extern atomic_unchecked_t fscache_n_invalidates_run;
58799
58800 -extern atomic_t fscache_n_updates;
58801 -extern atomic_t fscache_n_updates_null;
58802 -extern atomic_t fscache_n_updates_run;
58803 +extern atomic_unchecked_t fscache_n_updates;
58804 +extern atomic_unchecked_t fscache_n_updates_null;
58805 +extern atomic_unchecked_t fscache_n_updates_run;
58806
58807 -extern atomic_t fscache_n_relinquishes;
58808 -extern atomic_t fscache_n_relinquishes_null;
58809 -extern atomic_t fscache_n_relinquishes_waitcrt;
58810 -extern atomic_t fscache_n_relinquishes_retire;
58811 +extern atomic_unchecked_t fscache_n_relinquishes;
58812 +extern atomic_unchecked_t fscache_n_relinquishes_null;
58813 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
58814 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
58815
58816 -extern atomic_t fscache_n_cookie_index;
58817 -extern atomic_t fscache_n_cookie_data;
58818 -extern atomic_t fscache_n_cookie_special;
58819 +extern atomic_unchecked_t fscache_n_cookie_index;
58820 +extern atomic_unchecked_t fscache_n_cookie_data;
58821 +extern atomic_unchecked_t fscache_n_cookie_special;
58822
58823 -extern atomic_t fscache_n_object_alloc;
58824 -extern atomic_t fscache_n_object_no_alloc;
58825 -extern atomic_t fscache_n_object_lookups;
58826 -extern atomic_t fscache_n_object_lookups_negative;
58827 -extern atomic_t fscache_n_object_lookups_positive;
58828 -extern atomic_t fscache_n_object_lookups_timed_out;
58829 -extern atomic_t fscache_n_object_created;
58830 -extern atomic_t fscache_n_object_avail;
58831 -extern atomic_t fscache_n_object_dead;
58832 +extern atomic_unchecked_t fscache_n_object_alloc;
58833 +extern atomic_unchecked_t fscache_n_object_no_alloc;
58834 +extern atomic_unchecked_t fscache_n_object_lookups;
58835 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
58836 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
58837 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
58838 +extern atomic_unchecked_t fscache_n_object_created;
58839 +extern atomic_unchecked_t fscache_n_object_avail;
58840 +extern atomic_unchecked_t fscache_n_object_dead;
58841
58842 -extern atomic_t fscache_n_checkaux_none;
58843 -extern atomic_t fscache_n_checkaux_okay;
58844 -extern atomic_t fscache_n_checkaux_update;
58845 -extern atomic_t fscache_n_checkaux_obsolete;
58846 +extern atomic_unchecked_t fscache_n_checkaux_none;
58847 +extern atomic_unchecked_t fscache_n_checkaux_okay;
58848 +extern atomic_unchecked_t fscache_n_checkaux_update;
58849 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
58850
58851 extern atomic_t fscache_n_cop_alloc_object;
58852 extern atomic_t fscache_n_cop_lookup_object;
58853 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
58854 atomic_inc(stat);
58855 }
58856
58857 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
58858 +{
58859 + atomic_inc_unchecked(stat);
58860 +}
58861 +
58862 static inline void fscache_stat_d(atomic_t *stat)
58863 {
58864 atomic_dec(stat);
58865 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
58866
58867 #define __fscache_stat(stat) (NULL)
58868 #define fscache_stat(stat) do {} while (0)
58869 +#define fscache_stat_unchecked(stat) do {} while (0)
58870 #define fscache_stat_d(stat) do {} while (0)
58871 #endif
58872
58873 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
58874 index 53d35c5..5d68ed4 100644
58875 --- a/fs/fscache/object.c
58876 +++ b/fs/fscache/object.c
58877 @@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
58878 _debug("LOOKUP \"%s\" in \"%s\"",
58879 cookie->def->name, object->cache->tag->name);
58880
58881 - fscache_stat(&fscache_n_object_lookups);
58882 + fscache_stat_unchecked(&fscache_n_object_lookups);
58883 fscache_stat(&fscache_n_cop_lookup_object);
58884 ret = object->cache->ops->lookup_object(object);
58885 fscache_stat_d(&fscache_n_cop_lookup_object);
58886 @@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
58887 if (ret == -ETIMEDOUT) {
58888 /* probably stuck behind another object, so move this one to
58889 * the back of the queue */
58890 - fscache_stat(&fscache_n_object_lookups_timed_out);
58891 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
58892 _leave(" [timeout]");
58893 return NO_TRANSIT;
58894 }
58895 @@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
58896 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
58897
58898 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
58899 - fscache_stat(&fscache_n_object_lookups_negative);
58900 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
58901
58902 /* Allow write requests to begin stacking up and read requests to begin
58903 * returning ENODATA.
58904 @@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
58905 /* if we were still looking up, then we must have a positive lookup
58906 * result, in which case there may be data available */
58907 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
58908 - fscache_stat(&fscache_n_object_lookups_positive);
58909 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
58910
58911 /* We do (presumably) have data */
58912 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
58913 @@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
58914 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
58915 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
58916 } else {
58917 - fscache_stat(&fscache_n_object_created);
58918 + fscache_stat_unchecked(&fscache_n_object_created);
58919 }
58920
58921 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
58922 @@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
58923 fscache_stat_d(&fscache_n_cop_lookup_complete);
58924
58925 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
58926 - fscache_stat(&fscache_n_object_avail);
58927 + fscache_stat_unchecked(&fscache_n_object_avail);
58928
58929 _leave("");
58930 return transit_to(JUMPSTART_DEPS);
58931 @@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
58932
58933 /* this just shifts the object release to the work processor */
58934 fscache_put_object(object);
58935 - fscache_stat(&fscache_n_object_dead);
58936 + fscache_stat_unchecked(&fscache_n_object_dead);
58937
58938 _leave("");
58939 return transit_to(OBJECT_DEAD);
58940 @@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
58941 enum fscache_checkaux result;
58942
58943 if (!object->cookie->def->check_aux) {
58944 - fscache_stat(&fscache_n_checkaux_none);
58945 + fscache_stat_unchecked(&fscache_n_checkaux_none);
58946 return FSCACHE_CHECKAUX_OKAY;
58947 }
58948
58949 @@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
58950 switch (result) {
58951 /* entry okay as is */
58952 case FSCACHE_CHECKAUX_OKAY:
58953 - fscache_stat(&fscache_n_checkaux_okay);
58954 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
58955 break;
58956
58957 /* entry requires update */
58958 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
58959 - fscache_stat(&fscache_n_checkaux_update);
58960 + fscache_stat_unchecked(&fscache_n_checkaux_update);
58961 break;
58962
58963 /* entry requires deletion */
58964 case FSCACHE_CHECKAUX_OBSOLETE:
58965 - fscache_stat(&fscache_n_checkaux_obsolete);
58966 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
58967 break;
58968
58969 default:
58970 @@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
58971 {
58972 const struct fscache_state *s;
58973
58974 - fscache_stat(&fscache_n_invalidates_run);
58975 + fscache_stat_unchecked(&fscache_n_invalidates_run);
58976 fscache_stat(&fscache_n_cop_invalidate_object);
58977 s = _fscache_invalidate_object(object, event);
58978 fscache_stat_d(&fscache_n_cop_invalidate_object);
58979 @@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
58980 {
58981 _enter("{OBJ%x},%d", object->debug_id, event);
58982
58983 - fscache_stat(&fscache_n_updates_run);
58984 + fscache_stat_unchecked(&fscache_n_updates_run);
58985 fscache_stat(&fscache_n_cop_update_object);
58986 object->cache->ops->update_object(object);
58987 fscache_stat_d(&fscache_n_cop_update_object);
58988 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
58989 index 318071a..379938b 100644
58990 --- a/fs/fscache/operation.c
58991 +++ b/fs/fscache/operation.c
58992 @@ -17,7 +17,7 @@
58993 #include <linux/slab.h>
58994 #include "internal.h"
58995
58996 -atomic_t fscache_op_debug_id;
58997 +atomic_unchecked_t fscache_op_debug_id;
58998 EXPORT_SYMBOL(fscache_op_debug_id);
58999
59000 /**
59001 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
59002 ASSERTCMP(atomic_read(&op->usage), >, 0);
59003 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
59004
59005 - fscache_stat(&fscache_n_op_enqueue);
59006 + fscache_stat_unchecked(&fscache_n_op_enqueue);
59007 switch (op->flags & FSCACHE_OP_TYPE) {
59008 case FSCACHE_OP_ASYNC:
59009 _debug("queue async");
59010 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
59011 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
59012 if (op->processor)
59013 fscache_enqueue_operation(op);
59014 - fscache_stat(&fscache_n_op_run);
59015 + fscache_stat_unchecked(&fscache_n_op_run);
59016 }
59017
59018 /*
59019 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59020 if (object->n_in_progress > 0) {
59021 atomic_inc(&op->usage);
59022 list_add_tail(&op->pend_link, &object->pending_ops);
59023 - fscache_stat(&fscache_n_op_pend);
59024 + fscache_stat_unchecked(&fscache_n_op_pend);
59025 } else if (!list_empty(&object->pending_ops)) {
59026 atomic_inc(&op->usage);
59027 list_add_tail(&op->pend_link, &object->pending_ops);
59028 - fscache_stat(&fscache_n_op_pend);
59029 + fscache_stat_unchecked(&fscache_n_op_pend);
59030 fscache_start_operations(object);
59031 } else {
59032 ASSERTCMP(object->n_in_progress, ==, 0);
59033 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59034 object->n_exclusive++; /* reads and writes must wait */
59035 atomic_inc(&op->usage);
59036 list_add_tail(&op->pend_link, &object->pending_ops);
59037 - fscache_stat(&fscache_n_op_pend);
59038 + fscache_stat_unchecked(&fscache_n_op_pend);
59039 ret = 0;
59040 } else {
59041 /* If we're in any other state, there must have been an I/O
59042 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
59043 if (object->n_exclusive > 0) {
59044 atomic_inc(&op->usage);
59045 list_add_tail(&op->pend_link, &object->pending_ops);
59046 - fscache_stat(&fscache_n_op_pend);
59047 + fscache_stat_unchecked(&fscache_n_op_pend);
59048 } else if (!list_empty(&object->pending_ops)) {
59049 atomic_inc(&op->usage);
59050 list_add_tail(&op->pend_link, &object->pending_ops);
59051 - fscache_stat(&fscache_n_op_pend);
59052 + fscache_stat_unchecked(&fscache_n_op_pend);
59053 fscache_start_operations(object);
59054 } else {
59055 ASSERTCMP(object->n_exclusive, ==, 0);
59056 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
59057 object->n_ops++;
59058 atomic_inc(&op->usage);
59059 list_add_tail(&op->pend_link, &object->pending_ops);
59060 - fscache_stat(&fscache_n_op_pend);
59061 + fscache_stat_unchecked(&fscache_n_op_pend);
59062 ret = 0;
59063 } else if (fscache_object_is_dying(object)) {
59064 - fscache_stat(&fscache_n_op_rejected);
59065 + fscache_stat_unchecked(&fscache_n_op_rejected);
59066 op->state = FSCACHE_OP_ST_CANCELLED;
59067 ret = -ENOBUFS;
59068 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
59069 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
59070 ret = -EBUSY;
59071 if (op->state == FSCACHE_OP_ST_PENDING) {
59072 ASSERT(!list_empty(&op->pend_link));
59073 - fscache_stat(&fscache_n_op_cancelled);
59074 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59075 list_del_init(&op->pend_link);
59076 if (do_cancel)
59077 do_cancel(op);
59078 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
59079 while (!list_empty(&object->pending_ops)) {
59080 op = list_entry(object->pending_ops.next,
59081 struct fscache_operation, pend_link);
59082 - fscache_stat(&fscache_n_op_cancelled);
59083 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59084 list_del_init(&op->pend_link);
59085
59086 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
59087 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
59088 op->state, ==, FSCACHE_OP_ST_CANCELLED);
59089 op->state = FSCACHE_OP_ST_DEAD;
59090
59091 - fscache_stat(&fscache_n_op_release);
59092 + fscache_stat_unchecked(&fscache_n_op_release);
59093
59094 if (op->release) {
59095 op->release(op);
59096 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
59097 * lock, and defer it otherwise */
59098 if (!spin_trylock(&object->lock)) {
59099 _debug("defer put");
59100 - fscache_stat(&fscache_n_op_deferred_release);
59101 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
59102
59103 cache = object->cache;
59104 spin_lock(&cache->op_gc_list_lock);
59105 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
59106
59107 _debug("GC DEFERRED REL OBJ%x OP%x",
59108 object->debug_id, op->debug_id);
59109 - fscache_stat(&fscache_n_op_gc);
59110 + fscache_stat_unchecked(&fscache_n_op_gc);
59111
59112 ASSERTCMP(atomic_read(&op->usage), ==, 0);
59113 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
59114 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
59115 index 7f5c658..6c1e164 100644
59116 --- a/fs/fscache/page.c
59117 +++ b/fs/fscache/page.c
59118 @@ -61,7 +61,7 @@ try_again:
59119 val = radix_tree_lookup(&cookie->stores, page->index);
59120 if (!val) {
59121 rcu_read_unlock();
59122 - fscache_stat(&fscache_n_store_vmscan_not_storing);
59123 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
59124 __fscache_uncache_page(cookie, page);
59125 return true;
59126 }
59127 @@ -91,11 +91,11 @@ try_again:
59128 spin_unlock(&cookie->stores_lock);
59129
59130 if (xpage) {
59131 - fscache_stat(&fscache_n_store_vmscan_cancelled);
59132 - fscache_stat(&fscache_n_store_radix_deletes);
59133 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
59134 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59135 ASSERTCMP(xpage, ==, page);
59136 } else {
59137 - fscache_stat(&fscache_n_store_vmscan_gone);
59138 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
59139 }
59140
59141 wake_up_bit(&cookie->flags, 0);
59142 @@ -110,11 +110,11 @@ page_busy:
59143 * sleeping on memory allocation, so we may need to impose a timeout
59144 * too. */
59145 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
59146 - fscache_stat(&fscache_n_store_vmscan_busy);
59147 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
59148 return false;
59149 }
59150
59151 - fscache_stat(&fscache_n_store_vmscan_wait);
59152 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
59153 __fscache_wait_on_page_write(cookie, page);
59154 gfp &= ~__GFP_WAIT;
59155 goto try_again;
59156 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
59157 FSCACHE_COOKIE_STORING_TAG);
59158 if (!radix_tree_tag_get(&cookie->stores, page->index,
59159 FSCACHE_COOKIE_PENDING_TAG)) {
59160 - fscache_stat(&fscache_n_store_radix_deletes);
59161 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59162 xpage = radix_tree_delete(&cookie->stores, page->index);
59163 }
59164 spin_unlock(&cookie->stores_lock);
59165 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
59166
59167 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
59168
59169 - fscache_stat(&fscache_n_attr_changed_calls);
59170 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
59171
59172 if (fscache_object_is_active(object)) {
59173 fscache_stat(&fscache_n_cop_attr_changed);
59174 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59175
59176 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59177
59178 - fscache_stat(&fscache_n_attr_changed);
59179 + fscache_stat_unchecked(&fscache_n_attr_changed);
59180
59181 op = kzalloc(sizeof(*op), GFP_KERNEL);
59182 if (!op) {
59183 - fscache_stat(&fscache_n_attr_changed_nomem);
59184 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
59185 _leave(" = -ENOMEM");
59186 return -ENOMEM;
59187 }
59188 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59189 if (fscache_submit_exclusive_op(object, op) < 0)
59190 goto nobufs;
59191 spin_unlock(&cookie->lock);
59192 - fscache_stat(&fscache_n_attr_changed_ok);
59193 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
59194 fscache_put_operation(op);
59195 _leave(" = 0");
59196 return 0;
59197 @@ -225,7 +225,7 @@ nobufs:
59198 kfree(op);
59199 if (wake_cookie)
59200 __fscache_wake_unused_cookie(cookie);
59201 - fscache_stat(&fscache_n_attr_changed_nobufs);
59202 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
59203 _leave(" = %d", -ENOBUFS);
59204 return -ENOBUFS;
59205 }
59206 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
59207 /* allocate a retrieval operation and attempt to submit it */
59208 op = kzalloc(sizeof(*op), GFP_NOIO);
59209 if (!op) {
59210 - fscache_stat(&fscache_n_retrievals_nomem);
59211 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59212 return NULL;
59213 }
59214
59215 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
59216 return 0;
59217 }
59218
59219 - fscache_stat(&fscache_n_retrievals_wait);
59220 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
59221
59222 jif = jiffies;
59223 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
59224 fscache_wait_bit_interruptible,
59225 TASK_INTERRUPTIBLE) != 0) {
59226 - fscache_stat(&fscache_n_retrievals_intr);
59227 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
59228 _leave(" = -ERESTARTSYS");
59229 return -ERESTARTSYS;
59230 }
59231 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
59232 */
59233 int fscache_wait_for_operation_activation(struct fscache_object *object,
59234 struct fscache_operation *op,
59235 - atomic_t *stat_op_waits,
59236 - atomic_t *stat_object_dead,
59237 + atomic_unchecked_t *stat_op_waits,
59238 + atomic_unchecked_t *stat_object_dead,
59239 void (*do_cancel)(struct fscache_operation *))
59240 {
59241 int ret;
59242 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59243
59244 _debug(">>> WT");
59245 if (stat_op_waits)
59246 - fscache_stat(stat_op_waits);
59247 + fscache_stat_unchecked(stat_op_waits);
59248 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
59249 fscache_wait_bit_interruptible,
59250 TASK_INTERRUPTIBLE) != 0) {
59251 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59252 check_if_dead:
59253 if (op->state == FSCACHE_OP_ST_CANCELLED) {
59254 if (stat_object_dead)
59255 - fscache_stat(stat_object_dead);
59256 + fscache_stat_unchecked(stat_object_dead);
59257 _leave(" = -ENOBUFS [cancelled]");
59258 return -ENOBUFS;
59259 }
59260 @@ -366,7 +366,7 @@ check_if_dead:
59261 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
59262 fscache_cancel_op(op, do_cancel);
59263 if (stat_object_dead)
59264 - fscache_stat(stat_object_dead);
59265 + fscache_stat_unchecked(stat_object_dead);
59266 return -ENOBUFS;
59267 }
59268 return 0;
59269 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59270
59271 _enter("%p,%p,,,", cookie, page);
59272
59273 - fscache_stat(&fscache_n_retrievals);
59274 + fscache_stat_unchecked(&fscache_n_retrievals);
59275
59276 if (hlist_empty(&cookie->backing_objects))
59277 goto nobufs;
59278 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59279 goto nobufs_unlock_dec;
59280 spin_unlock(&cookie->lock);
59281
59282 - fscache_stat(&fscache_n_retrieval_ops);
59283 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
59284
59285 /* pin the netfs read context in case we need to do the actual netfs
59286 * read because we've encountered a cache read failure */
59287 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59288
59289 error:
59290 if (ret == -ENOMEM)
59291 - fscache_stat(&fscache_n_retrievals_nomem);
59292 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59293 else if (ret == -ERESTARTSYS)
59294 - fscache_stat(&fscache_n_retrievals_intr);
59295 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
59296 else if (ret == -ENODATA)
59297 - fscache_stat(&fscache_n_retrievals_nodata);
59298 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59299 else if (ret < 0)
59300 - fscache_stat(&fscache_n_retrievals_nobufs);
59301 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59302 else
59303 - fscache_stat(&fscache_n_retrievals_ok);
59304 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
59305
59306 fscache_put_retrieval(op);
59307 _leave(" = %d", ret);
59308 @@ -490,7 +490,7 @@ nobufs_unlock:
59309 __fscache_wake_unused_cookie(cookie);
59310 kfree(op);
59311 nobufs:
59312 - fscache_stat(&fscache_n_retrievals_nobufs);
59313 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59314 _leave(" = -ENOBUFS");
59315 return -ENOBUFS;
59316 }
59317 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59318
59319 _enter("%p,,%d,,,", cookie, *nr_pages);
59320
59321 - fscache_stat(&fscache_n_retrievals);
59322 + fscache_stat_unchecked(&fscache_n_retrievals);
59323
59324 if (hlist_empty(&cookie->backing_objects))
59325 goto nobufs;
59326 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59327 goto nobufs_unlock_dec;
59328 spin_unlock(&cookie->lock);
59329
59330 - fscache_stat(&fscache_n_retrieval_ops);
59331 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
59332
59333 /* pin the netfs read context in case we need to do the actual netfs
59334 * read because we've encountered a cache read failure */
59335 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59336
59337 error:
59338 if (ret == -ENOMEM)
59339 - fscache_stat(&fscache_n_retrievals_nomem);
59340 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59341 else if (ret == -ERESTARTSYS)
59342 - fscache_stat(&fscache_n_retrievals_intr);
59343 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
59344 else if (ret == -ENODATA)
59345 - fscache_stat(&fscache_n_retrievals_nodata);
59346 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59347 else if (ret < 0)
59348 - fscache_stat(&fscache_n_retrievals_nobufs);
59349 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59350 else
59351 - fscache_stat(&fscache_n_retrievals_ok);
59352 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
59353
59354 fscache_put_retrieval(op);
59355 _leave(" = %d", ret);
59356 @@ -621,7 +621,7 @@ nobufs_unlock:
59357 if (wake_cookie)
59358 __fscache_wake_unused_cookie(cookie);
59359 nobufs:
59360 - fscache_stat(&fscache_n_retrievals_nobufs);
59361 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59362 _leave(" = -ENOBUFS");
59363 return -ENOBUFS;
59364 }
59365 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59366
59367 _enter("%p,%p,,,", cookie, page);
59368
59369 - fscache_stat(&fscache_n_allocs);
59370 + fscache_stat_unchecked(&fscache_n_allocs);
59371
59372 if (hlist_empty(&cookie->backing_objects))
59373 goto nobufs;
59374 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59375 goto nobufs_unlock_dec;
59376 spin_unlock(&cookie->lock);
59377
59378 - fscache_stat(&fscache_n_alloc_ops);
59379 + fscache_stat_unchecked(&fscache_n_alloc_ops);
59380
59381 ret = fscache_wait_for_operation_activation(
59382 object, &op->op,
59383 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59384
59385 error:
59386 if (ret == -ERESTARTSYS)
59387 - fscache_stat(&fscache_n_allocs_intr);
59388 + fscache_stat_unchecked(&fscache_n_allocs_intr);
59389 else if (ret < 0)
59390 - fscache_stat(&fscache_n_allocs_nobufs);
59391 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59392 else
59393 - fscache_stat(&fscache_n_allocs_ok);
59394 + fscache_stat_unchecked(&fscache_n_allocs_ok);
59395
59396 fscache_put_retrieval(op);
59397 _leave(" = %d", ret);
59398 @@ -715,7 +715,7 @@ nobufs_unlock:
59399 if (wake_cookie)
59400 __fscache_wake_unused_cookie(cookie);
59401 nobufs:
59402 - fscache_stat(&fscache_n_allocs_nobufs);
59403 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59404 _leave(" = -ENOBUFS");
59405 return -ENOBUFS;
59406 }
59407 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59408
59409 spin_lock(&cookie->stores_lock);
59410
59411 - fscache_stat(&fscache_n_store_calls);
59412 + fscache_stat_unchecked(&fscache_n_store_calls);
59413
59414 /* find a page to store */
59415 page = NULL;
59416 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59417 page = results[0];
59418 _debug("gang %d [%lx]", n, page->index);
59419 if (page->index > op->store_limit) {
59420 - fscache_stat(&fscache_n_store_pages_over_limit);
59421 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
59422 goto superseded;
59423 }
59424
59425 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59426 spin_unlock(&cookie->stores_lock);
59427 spin_unlock(&object->lock);
59428
59429 - fscache_stat(&fscache_n_store_pages);
59430 + fscache_stat_unchecked(&fscache_n_store_pages);
59431 fscache_stat(&fscache_n_cop_write_page);
59432 ret = object->cache->ops->write_page(op, page);
59433 fscache_stat_d(&fscache_n_cop_write_page);
59434 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59435 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59436 ASSERT(PageFsCache(page));
59437
59438 - fscache_stat(&fscache_n_stores);
59439 + fscache_stat_unchecked(&fscache_n_stores);
59440
59441 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
59442 _leave(" = -ENOBUFS [invalidating]");
59443 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59444 spin_unlock(&cookie->stores_lock);
59445 spin_unlock(&object->lock);
59446
59447 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
59448 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59449 op->store_limit = object->store_limit;
59450
59451 __fscache_use_cookie(cookie);
59452 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59453
59454 spin_unlock(&cookie->lock);
59455 radix_tree_preload_end();
59456 - fscache_stat(&fscache_n_store_ops);
59457 - fscache_stat(&fscache_n_stores_ok);
59458 + fscache_stat_unchecked(&fscache_n_store_ops);
59459 + fscache_stat_unchecked(&fscache_n_stores_ok);
59460
59461 /* the work queue now carries its own ref on the object */
59462 fscache_put_operation(&op->op);
59463 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59464 return 0;
59465
59466 already_queued:
59467 - fscache_stat(&fscache_n_stores_again);
59468 + fscache_stat_unchecked(&fscache_n_stores_again);
59469 already_pending:
59470 spin_unlock(&cookie->stores_lock);
59471 spin_unlock(&object->lock);
59472 spin_unlock(&cookie->lock);
59473 radix_tree_preload_end();
59474 kfree(op);
59475 - fscache_stat(&fscache_n_stores_ok);
59476 + fscache_stat_unchecked(&fscache_n_stores_ok);
59477 _leave(" = 0");
59478 return 0;
59479
59480 @@ -1024,14 +1024,14 @@ nobufs:
59481 kfree(op);
59482 if (wake_cookie)
59483 __fscache_wake_unused_cookie(cookie);
59484 - fscache_stat(&fscache_n_stores_nobufs);
59485 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
59486 _leave(" = -ENOBUFS");
59487 return -ENOBUFS;
59488
59489 nomem_free:
59490 kfree(op);
59491 nomem:
59492 - fscache_stat(&fscache_n_stores_oom);
59493 + fscache_stat_unchecked(&fscache_n_stores_oom);
59494 _leave(" = -ENOMEM");
59495 return -ENOMEM;
59496 }
59497 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
59498 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59499 ASSERTCMP(page, !=, NULL);
59500
59501 - fscache_stat(&fscache_n_uncaches);
59502 + fscache_stat_unchecked(&fscache_n_uncaches);
59503
59504 /* cache withdrawal may beat us to it */
59505 if (!PageFsCache(page))
59506 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
59507 struct fscache_cookie *cookie = op->op.object->cookie;
59508
59509 #ifdef CONFIG_FSCACHE_STATS
59510 - atomic_inc(&fscache_n_marks);
59511 + atomic_inc_unchecked(&fscache_n_marks);
59512 #endif
59513
59514 _debug("- mark %p{%lx}", page, page->index);
59515 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
59516 index 40d13c7..ddf52b9 100644
59517 --- a/fs/fscache/stats.c
59518 +++ b/fs/fscache/stats.c
59519 @@ -18,99 +18,99 @@
59520 /*
59521 * operation counters
59522 */
59523 -atomic_t fscache_n_op_pend;
59524 -atomic_t fscache_n_op_run;
59525 -atomic_t fscache_n_op_enqueue;
59526 -atomic_t fscache_n_op_requeue;
59527 -atomic_t fscache_n_op_deferred_release;
59528 -atomic_t fscache_n_op_release;
59529 -atomic_t fscache_n_op_gc;
59530 -atomic_t fscache_n_op_cancelled;
59531 -atomic_t fscache_n_op_rejected;
59532 +atomic_unchecked_t fscache_n_op_pend;
59533 +atomic_unchecked_t fscache_n_op_run;
59534 +atomic_unchecked_t fscache_n_op_enqueue;
59535 +atomic_unchecked_t fscache_n_op_requeue;
59536 +atomic_unchecked_t fscache_n_op_deferred_release;
59537 +atomic_unchecked_t fscache_n_op_release;
59538 +atomic_unchecked_t fscache_n_op_gc;
59539 +atomic_unchecked_t fscache_n_op_cancelled;
59540 +atomic_unchecked_t fscache_n_op_rejected;
59541
59542 -atomic_t fscache_n_attr_changed;
59543 -atomic_t fscache_n_attr_changed_ok;
59544 -atomic_t fscache_n_attr_changed_nobufs;
59545 -atomic_t fscache_n_attr_changed_nomem;
59546 -atomic_t fscache_n_attr_changed_calls;
59547 +atomic_unchecked_t fscache_n_attr_changed;
59548 +atomic_unchecked_t fscache_n_attr_changed_ok;
59549 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
59550 +atomic_unchecked_t fscache_n_attr_changed_nomem;
59551 +atomic_unchecked_t fscache_n_attr_changed_calls;
59552
59553 -atomic_t fscache_n_allocs;
59554 -atomic_t fscache_n_allocs_ok;
59555 -atomic_t fscache_n_allocs_wait;
59556 -atomic_t fscache_n_allocs_nobufs;
59557 -atomic_t fscache_n_allocs_intr;
59558 -atomic_t fscache_n_allocs_object_dead;
59559 -atomic_t fscache_n_alloc_ops;
59560 -atomic_t fscache_n_alloc_op_waits;
59561 +atomic_unchecked_t fscache_n_allocs;
59562 +atomic_unchecked_t fscache_n_allocs_ok;
59563 +atomic_unchecked_t fscache_n_allocs_wait;
59564 +atomic_unchecked_t fscache_n_allocs_nobufs;
59565 +atomic_unchecked_t fscache_n_allocs_intr;
59566 +atomic_unchecked_t fscache_n_allocs_object_dead;
59567 +atomic_unchecked_t fscache_n_alloc_ops;
59568 +atomic_unchecked_t fscache_n_alloc_op_waits;
59569
59570 -atomic_t fscache_n_retrievals;
59571 -atomic_t fscache_n_retrievals_ok;
59572 -atomic_t fscache_n_retrievals_wait;
59573 -atomic_t fscache_n_retrievals_nodata;
59574 -atomic_t fscache_n_retrievals_nobufs;
59575 -atomic_t fscache_n_retrievals_intr;
59576 -atomic_t fscache_n_retrievals_nomem;
59577 -atomic_t fscache_n_retrievals_object_dead;
59578 -atomic_t fscache_n_retrieval_ops;
59579 -atomic_t fscache_n_retrieval_op_waits;
59580 +atomic_unchecked_t fscache_n_retrievals;
59581 +atomic_unchecked_t fscache_n_retrievals_ok;
59582 +atomic_unchecked_t fscache_n_retrievals_wait;
59583 +atomic_unchecked_t fscache_n_retrievals_nodata;
59584 +atomic_unchecked_t fscache_n_retrievals_nobufs;
59585 +atomic_unchecked_t fscache_n_retrievals_intr;
59586 +atomic_unchecked_t fscache_n_retrievals_nomem;
59587 +atomic_unchecked_t fscache_n_retrievals_object_dead;
59588 +atomic_unchecked_t fscache_n_retrieval_ops;
59589 +atomic_unchecked_t fscache_n_retrieval_op_waits;
59590
59591 -atomic_t fscache_n_stores;
59592 -atomic_t fscache_n_stores_ok;
59593 -atomic_t fscache_n_stores_again;
59594 -atomic_t fscache_n_stores_nobufs;
59595 -atomic_t fscache_n_stores_oom;
59596 -atomic_t fscache_n_store_ops;
59597 -atomic_t fscache_n_store_calls;
59598 -atomic_t fscache_n_store_pages;
59599 -atomic_t fscache_n_store_radix_deletes;
59600 -atomic_t fscache_n_store_pages_over_limit;
59601 +atomic_unchecked_t fscache_n_stores;
59602 +atomic_unchecked_t fscache_n_stores_ok;
59603 +atomic_unchecked_t fscache_n_stores_again;
59604 +atomic_unchecked_t fscache_n_stores_nobufs;
59605 +atomic_unchecked_t fscache_n_stores_oom;
59606 +atomic_unchecked_t fscache_n_store_ops;
59607 +atomic_unchecked_t fscache_n_store_calls;
59608 +atomic_unchecked_t fscache_n_store_pages;
59609 +atomic_unchecked_t fscache_n_store_radix_deletes;
59610 +atomic_unchecked_t fscache_n_store_pages_over_limit;
59611
59612 -atomic_t fscache_n_store_vmscan_not_storing;
59613 -atomic_t fscache_n_store_vmscan_gone;
59614 -atomic_t fscache_n_store_vmscan_busy;
59615 -atomic_t fscache_n_store_vmscan_cancelled;
59616 -atomic_t fscache_n_store_vmscan_wait;
59617 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59618 +atomic_unchecked_t fscache_n_store_vmscan_gone;
59619 +atomic_unchecked_t fscache_n_store_vmscan_busy;
59620 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59621 +atomic_unchecked_t fscache_n_store_vmscan_wait;
59622
59623 -atomic_t fscache_n_marks;
59624 -atomic_t fscache_n_uncaches;
59625 +atomic_unchecked_t fscache_n_marks;
59626 +atomic_unchecked_t fscache_n_uncaches;
59627
59628 -atomic_t fscache_n_acquires;
59629 -atomic_t fscache_n_acquires_null;
59630 -atomic_t fscache_n_acquires_no_cache;
59631 -atomic_t fscache_n_acquires_ok;
59632 -atomic_t fscache_n_acquires_nobufs;
59633 -atomic_t fscache_n_acquires_oom;
59634 +atomic_unchecked_t fscache_n_acquires;
59635 +atomic_unchecked_t fscache_n_acquires_null;
59636 +atomic_unchecked_t fscache_n_acquires_no_cache;
59637 +atomic_unchecked_t fscache_n_acquires_ok;
59638 +atomic_unchecked_t fscache_n_acquires_nobufs;
59639 +atomic_unchecked_t fscache_n_acquires_oom;
59640
59641 -atomic_t fscache_n_invalidates;
59642 -atomic_t fscache_n_invalidates_run;
59643 +atomic_unchecked_t fscache_n_invalidates;
59644 +atomic_unchecked_t fscache_n_invalidates_run;
59645
59646 -atomic_t fscache_n_updates;
59647 -atomic_t fscache_n_updates_null;
59648 -atomic_t fscache_n_updates_run;
59649 +atomic_unchecked_t fscache_n_updates;
59650 +atomic_unchecked_t fscache_n_updates_null;
59651 +atomic_unchecked_t fscache_n_updates_run;
59652
59653 -atomic_t fscache_n_relinquishes;
59654 -atomic_t fscache_n_relinquishes_null;
59655 -atomic_t fscache_n_relinquishes_waitcrt;
59656 -atomic_t fscache_n_relinquishes_retire;
59657 +atomic_unchecked_t fscache_n_relinquishes;
59658 +atomic_unchecked_t fscache_n_relinquishes_null;
59659 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59660 +atomic_unchecked_t fscache_n_relinquishes_retire;
59661
59662 -atomic_t fscache_n_cookie_index;
59663 -atomic_t fscache_n_cookie_data;
59664 -atomic_t fscache_n_cookie_special;
59665 +atomic_unchecked_t fscache_n_cookie_index;
59666 +atomic_unchecked_t fscache_n_cookie_data;
59667 +atomic_unchecked_t fscache_n_cookie_special;
59668
59669 -atomic_t fscache_n_object_alloc;
59670 -atomic_t fscache_n_object_no_alloc;
59671 -atomic_t fscache_n_object_lookups;
59672 -atomic_t fscache_n_object_lookups_negative;
59673 -atomic_t fscache_n_object_lookups_positive;
59674 -atomic_t fscache_n_object_lookups_timed_out;
59675 -atomic_t fscache_n_object_created;
59676 -atomic_t fscache_n_object_avail;
59677 -atomic_t fscache_n_object_dead;
59678 +atomic_unchecked_t fscache_n_object_alloc;
59679 +atomic_unchecked_t fscache_n_object_no_alloc;
59680 +atomic_unchecked_t fscache_n_object_lookups;
59681 +atomic_unchecked_t fscache_n_object_lookups_negative;
59682 +atomic_unchecked_t fscache_n_object_lookups_positive;
59683 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
59684 +atomic_unchecked_t fscache_n_object_created;
59685 +atomic_unchecked_t fscache_n_object_avail;
59686 +atomic_unchecked_t fscache_n_object_dead;
59687
59688 -atomic_t fscache_n_checkaux_none;
59689 -atomic_t fscache_n_checkaux_okay;
59690 -atomic_t fscache_n_checkaux_update;
59691 -atomic_t fscache_n_checkaux_obsolete;
59692 +atomic_unchecked_t fscache_n_checkaux_none;
59693 +atomic_unchecked_t fscache_n_checkaux_okay;
59694 +atomic_unchecked_t fscache_n_checkaux_update;
59695 +atomic_unchecked_t fscache_n_checkaux_obsolete;
59696
59697 atomic_t fscache_n_cop_alloc_object;
59698 atomic_t fscache_n_cop_lookup_object;
59699 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
59700 seq_puts(m, "FS-Cache statistics\n");
59701
59702 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
59703 - atomic_read(&fscache_n_cookie_index),
59704 - atomic_read(&fscache_n_cookie_data),
59705 - atomic_read(&fscache_n_cookie_special));
59706 + atomic_read_unchecked(&fscache_n_cookie_index),
59707 + atomic_read_unchecked(&fscache_n_cookie_data),
59708 + atomic_read_unchecked(&fscache_n_cookie_special));
59709
59710 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
59711 - atomic_read(&fscache_n_object_alloc),
59712 - atomic_read(&fscache_n_object_no_alloc),
59713 - atomic_read(&fscache_n_object_avail),
59714 - atomic_read(&fscache_n_object_dead));
59715 + atomic_read_unchecked(&fscache_n_object_alloc),
59716 + atomic_read_unchecked(&fscache_n_object_no_alloc),
59717 + atomic_read_unchecked(&fscache_n_object_avail),
59718 + atomic_read_unchecked(&fscache_n_object_dead));
59719 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
59720 - atomic_read(&fscache_n_checkaux_none),
59721 - atomic_read(&fscache_n_checkaux_okay),
59722 - atomic_read(&fscache_n_checkaux_update),
59723 - atomic_read(&fscache_n_checkaux_obsolete));
59724 + atomic_read_unchecked(&fscache_n_checkaux_none),
59725 + atomic_read_unchecked(&fscache_n_checkaux_okay),
59726 + atomic_read_unchecked(&fscache_n_checkaux_update),
59727 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
59728
59729 seq_printf(m, "Pages : mrk=%u unc=%u\n",
59730 - atomic_read(&fscache_n_marks),
59731 - atomic_read(&fscache_n_uncaches));
59732 + atomic_read_unchecked(&fscache_n_marks),
59733 + atomic_read_unchecked(&fscache_n_uncaches));
59734
59735 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
59736 " oom=%u\n",
59737 - atomic_read(&fscache_n_acquires),
59738 - atomic_read(&fscache_n_acquires_null),
59739 - atomic_read(&fscache_n_acquires_no_cache),
59740 - atomic_read(&fscache_n_acquires_ok),
59741 - atomic_read(&fscache_n_acquires_nobufs),
59742 - atomic_read(&fscache_n_acquires_oom));
59743 + atomic_read_unchecked(&fscache_n_acquires),
59744 + atomic_read_unchecked(&fscache_n_acquires_null),
59745 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
59746 + atomic_read_unchecked(&fscache_n_acquires_ok),
59747 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
59748 + atomic_read_unchecked(&fscache_n_acquires_oom));
59749
59750 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
59751 - atomic_read(&fscache_n_object_lookups),
59752 - atomic_read(&fscache_n_object_lookups_negative),
59753 - atomic_read(&fscache_n_object_lookups_positive),
59754 - atomic_read(&fscache_n_object_created),
59755 - atomic_read(&fscache_n_object_lookups_timed_out));
59756 + atomic_read_unchecked(&fscache_n_object_lookups),
59757 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
59758 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
59759 + atomic_read_unchecked(&fscache_n_object_created),
59760 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
59761
59762 seq_printf(m, "Invals : n=%u run=%u\n",
59763 - atomic_read(&fscache_n_invalidates),
59764 - atomic_read(&fscache_n_invalidates_run));
59765 + atomic_read_unchecked(&fscache_n_invalidates),
59766 + atomic_read_unchecked(&fscache_n_invalidates_run));
59767
59768 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
59769 - atomic_read(&fscache_n_updates),
59770 - atomic_read(&fscache_n_updates_null),
59771 - atomic_read(&fscache_n_updates_run));
59772 + atomic_read_unchecked(&fscache_n_updates),
59773 + atomic_read_unchecked(&fscache_n_updates_null),
59774 + atomic_read_unchecked(&fscache_n_updates_run));
59775
59776 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
59777 - atomic_read(&fscache_n_relinquishes),
59778 - atomic_read(&fscache_n_relinquishes_null),
59779 - atomic_read(&fscache_n_relinquishes_waitcrt),
59780 - atomic_read(&fscache_n_relinquishes_retire));
59781 + atomic_read_unchecked(&fscache_n_relinquishes),
59782 + atomic_read_unchecked(&fscache_n_relinquishes_null),
59783 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
59784 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
59785
59786 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
59787 - atomic_read(&fscache_n_attr_changed),
59788 - atomic_read(&fscache_n_attr_changed_ok),
59789 - atomic_read(&fscache_n_attr_changed_nobufs),
59790 - atomic_read(&fscache_n_attr_changed_nomem),
59791 - atomic_read(&fscache_n_attr_changed_calls));
59792 + atomic_read_unchecked(&fscache_n_attr_changed),
59793 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
59794 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
59795 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
59796 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
59797
59798 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
59799 - atomic_read(&fscache_n_allocs),
59800 - atomic_read(&fscache_n_allocs_ok),
59801 - atomic_read(&fscache_n_allocs_wait),
59802 - atomic_read(&fscache_n_allocs_nobufs),
59803 - atomic_read(&fscache_n_allocs_intr));
59804 + atomic_read_unchecked(&fscache_n_allocs),
59805 + atomic_read_unchecked(&fscache_n_allocs_ok),
59806 + atomic_read_unchecked(&fscache_n_allocs_wait),
59807 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
59808 + atomic_read_unchecked(&fscache_n_allocs_intr));
59809 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
59810 - atomic_read(&fscache_n_alloc_ops),
59811 - atomic_read(&fscache_n_alloc_op_waits),
59812 - atomic_read(&fscache_n_allocs_object_dead));
59813 + atomic_read_unchecked(&fscache_n_alloc_ops),
59814 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
59815 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
59816
59817 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
59818 " int=%u oom=%u\n",
59819 - atomic_read(&fscache_n_retrievals),
59820 - atomic_read(&fscache_n_retrievals_ok),
59821 - atomic_read(&fscache_n_retrievals_wait),
59822 - atomic_read(&fscache_n_retrievals_nodata),
59823 - atomic_read(&fscache_n_retrievals_nobufs),
59824 - atomic_read(&fscache_n_retrievals_intr),
59825 - atomic_read(&fscache_n_retrievals_nomem));
59826 + atomic_read_unchecked(&fscache_n_retrievals),
59827 + atomic_read_unchecked(&fscache_n_retrievals_ok),
59828 + atomic_read_unchecked(&fscache_n_retrievals_wait),
59829 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
59830 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
59831 + atomic_read_unchecked(&fscache_n_retrievals_intr),
59832 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
59833 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
59834 - atomic_read(&fscache_n_retrieval_ops),
59835 - atomic_read(&fscache_n_retrieval_op_waits),
59836 - atomic_read(&fscache_n_retrievals_object_dead));
59837 + atomic_read_unchecked(&fscache_n_retrieval_ops),
59838 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
59839 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
59840
59841 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
59842 - atomic_read(&fscache_n_stores),
59843 - atomic_read(&fscache_n_stores_ok),
59844 - atomic_read(&fscache_n_stores_again),
59845 - atomic_read(&fscache_n_stores_nobufs),
59846 - atomic_read(&fscache_n_stores_oom));
59847 + atomic_read_unchecked(&fscache_n_stores),
59848 + atomic_read_unchecked(&fscache_n_stores_ok),
59849 + atomic_read_unchecked(&fscache_n_stores_again),
59850 + atomic_read_unchecked(&fscache_n_stores_nobufs),
59851 + atomic_read_unchecked(&fscache_n_stores_oom));
59852 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
59853 - atomic_read(&fscache_n_store_ops),
59854 - atomic_read(&fscache_n_store_calls),
59855 - atomic_read(&fscache_n_store_pages),
59856 - atomic_read(&fscache_n_store_radix_deletes),
59857 - atomic_read(&fscache_n_store_pages_over_limit));
59858 + atomic_read_unchecked(&fscache_n_store_ops),
59859 + atomic_read_unchecked(&fscache_n_store_calls),
59860 + atomic_read_unchecked(&fscache_n_store_pages),
59861 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
59862 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
59863
59864 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
59865 - atomic_read(&fscache_n_store_vmscan_not_storing),
59866 - atomic_read(&fscache_n_store_vmscan_gone),
59867 - atomic_read(&fscache_n_store_vmscan_busy),
59868 - atomic_read(&fscache_n_store_vmscan_cancelled),
59869 - atomic_read(&fscache_n_store_vmscan_wait));
59870 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
59871 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
59872 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
59873 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
59874 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
59875
59876 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
59877 - atomic_read(&fscache_n_op_pend),
59878 - atomic_read(&fscache_n_op_run),
59879 - atomic_read(&fscache_n_op_enqueue),
59880 - atomic_read(&fscache_n_op_cancelled),
59881 - atomic_read(&fscache_n_op_rejected));
59882 + atomic_read_unchecked(&fscache_n_op_pend),
59883 + atomic_read_unchecked(&fscache_n_op_run),
59884 + atomic_read_unchecked(&fscache_n_op_enqueue),
59885 + atomic_read_unchecked(&fscache_n_op_cancelled),
59886 + atomic_read_unchecked(&fscache_n_op_rejected));
59887 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
59888 - atomic_read(&fscache_n_op_deferred_release),
59889 - atomic_read(&fscache_n_op_release),
59890 - atomic_read(&fscache_n_op_gc));
59891 + atomic_read_unchecked(&fscache_n_op_deferred_release),
59892 + atomic_read_unchecked(&fscache_n_op_release),
59893 + atomic_read_unchecked(&fscache_n_op_gc));
59894
59895 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
59896 atomic_read(&fscache_n_cop_alloc_object),
59897 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
59898 index b96a49b..9bfdc47 100644
59899 --- a/fs/fuse/cuse.c
59900 +++ b/fs/fuse/cuse.c
59901 @@ -606,10 +606,12 @@ static int __init cuse_init(void)
59902 INIT_LIST_HEAD(&cuse_conntbl[i]);
59903
59904 /* inherit and extend fuse_dev_operations */
59905 - cuse_channel_fops = fuse_dev_operations;
59906 - cuse_channel_fops.owner = THIS_MODULE;
59907 - cuse_channel_fops.open = cuse_channel_open;
59908 - cuse_channel_fops.release = cuse_channel_release;
59909 + pax_open_kernel();
59910 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
59911 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
59912 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
59913 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
59914 + pax_close_kernel();
59915
59916 cuse_class = class_create(THIS_MODULE, "cuse");
59917 if (IS_ERR(cuse_class))
59918 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
59919 index ef74ad5..c9ac759e 100644
59920 --- a/fs/fuse/dev.c
59921 +++ b/fs/fuse/dev.c
59922 @@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
59923 ret = 0;
59924 pipe_lock(pipe);
59925
59926 - if (!pipe->readers) {
59927 + if (!atomic_read(&pipe->readers)) {
59928 send_sig(SIGPIPE, current, 0);
59929 if (!ret)
59930 ret = -EPIPE;
59931 @@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
59932 page_nr++;
59933 ret += buf->len;
59934
59935 - if (pipe->files)
59936 + if (atomic_read(&pipe->files))
59937 do_wakeup = 1;
59938 }
59939
59940 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
59941 index c3eb2c4..98007d4 100644
59942 --- a/fs/fuse/dir.c
59943 +++ b/fs/fuse/dir.c
59944 @@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
59945 return link;
59946 }
59947
59948 -static void free_link(char *link)
59949 +static void free_link(const char *link)
59950 {
59951 if (!IS_ERR(link))
59952 free_page((unsigned long) link);
59953 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
59954 index db23ce1..9e6cd9d 100644
59955 --- a/fs/hostfs/hostfs_kern.c
59956 +++ b/fs/hostfs/hostfs_kern.c
59957 @@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
59958
59959 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
59960 {
59961 - char *s = nd_get_link(nd);
59962 + const char *s = nd_get_link(nd);
59963 if (!IS_ERR(s))
59964 __putname(s);
59965 }
59966 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
59967 index d19b30a..ef89c36 100644
59968 --- a/fs/hugetlbfs/inode.c
59969 +++ b/fs/hugetlbfs/inode.c
59970 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
59971 struct mm_struct *mm = current->mm;
59972 struct vm_area_struct *vma;
59973 struct hstate *h = hstate_file(file);
59974 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
59975 struct vm_unmapped_area_info info;
59976
59977 if (len & ~huge_page_mask(h))
59978 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
59979 return addr;
59980 }
59981
59982 +#ifdef CONFIG_PAX_RANDMMAP
59983 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
59984 +#endif
59985 +
59986 if (addr) {
59987 addr = ALIGN(addr, huge_page_size(h));
59988 vma = find_vma(mm, addr);
59989 - if (TASK_SIZE - len >= addr &&
59990 - (!vma || addr + len <= vma->vm_start))
59991 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
59992 return addr;
59993 }
59994
59995 info.flags = 0;
59996 info.length = len;
59997 info.low_limit = TASK_UNMAPPED_BASE;
59998 +
59999 +#ifdef CONFIG_PAX_RANDMMAP
60000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
60001 + info.low_limit += mm->delta_mmap;
60002 +#endif
60003 +
60004 info.high_limit = TASK_SIZE;
60005 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
60006 info.align_offset = 0;
60007 @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
60008 };
60009 MODULE_ALIAS_FS("hugetlbfs");
60010
60011 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60012 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60013
60014 static int can_do_hugetlb_shm(void)
60015 {
60016 diff --git a/fs/inode.c b/fs/inode.c
60017 index 4bcdad3..1883822 100644
60018 --- a/fs/inode.c
60019 +++ b/fs/inode.c
60020 @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
60021
60022 #ifdef CONFIG_SMP
60023 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
60024 - static atomic_t shared_last_ino;
60025 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
60026 + static atomic_unchecked_t shared_last_ino;
60027 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
60028
60029 res = next - LAST_INO_BATCH;
60030 }
60031 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
60032 index 4a6cf28..d3a29d3 100644
60033 --- a/fs/jffs2/erase.c
60034 +++ b/fs/jffs2/erase.c
60035 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
60036 struct jffs2_unknown_node marker = {
60037 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
60038 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60039 - .totlen = cpu_to_je32(c->cleanmarker_size)
60040 + .totlen = cpu_to_je32(c->cleanmarker_size),
60041 + .hdr_crc = cpu_to_je32(0)
60042 };
60043
60044 jffs2_prealloc_raw_node_refs(c, jeb, 1);
60045 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
60046 index a6597d6..41b30ec 100644
60047 --- a/fs/jffs2/wbuf.c
60048 +++ b/fs/jffs2/wbuf.c
60049 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
60050 {
60051 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
60052 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60053 - .totlen = constant_cpu_to_je32(8)
60054 + .totlen = constant_cpu_to_je32(8),
60055 + .hdr_crc = constant_cpu_to_je32(0)
60056 };
60057
60058 /*
60059 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
60060 index 6669aa2..36b033d 100644
60061 --- a/fs/jfs/super.c
60062 +++ b/fs/jfs/super.c
60063 @@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
60064
60065 jfs_inode_cachep =
60066 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
60067 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
60068 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
60069 init_once);
60070 if (jfs_inode_cachep == NULL)
60071 return -ENOMEM;
60072 diff --git a/fs/libfs.c b/fs/libfs.c
60073 index a184424..944ddce 100644
60074 --- a/fs/libfs.c
60075 +++ b/fs/libfs.c
60076 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60077
60078 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
60079 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
60080 + char d_name[sizeof(next->d_iname)];
60081 + const unsigned char *name;
60082 +
60083 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
60084 if (!simple_positive(next)) {
60085 spin_unlock(&next->d_lock);
60086 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60087
60088 spin_unlock(&next->d_lock);
60089 spin_unlock(&dentry->d_lock);
60090 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
60091 + name = next->d_name.name;
60092 + if (name == next->d_iname) {
60093 + memcpy(d_name, name, next->d_name.len);
60094 + name = d_name;
60095 + }
60096 + if (!dir_emit(ctx, name, next->d_name.len,
60097 next->d_inode->i_ino, dt_type(next->d_inode)))
60098 return 0;
60099 spin_lock(&dentry->d_lock);
60100 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
60101 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
60102 void *cookie)
60103 {
60104 - char *s = nd_get_link(nd);
60105 + const char *s = nd_get_link(nd);
60106 if (!IS_ERR(s))
60107 kfree(s);
60108 }
60109 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
60110 index acd3947..1f896e2 100644
60111 --- a/fs/lockd/clntproc.c
60112 +++ b/fs/lockd/clntproc.c
60113 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
60114 /*
60115 * Cookie counter for NLM requests
60116 */
60117 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
60118 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
60119
60120 void nlmclnt_next_cookie(struct nlm_cookie *c)
60121 {
60122 - u32 cookie = atomic_inc_return(&nlm_cookie);
60123 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
60124
60125 memcpy(c->data, &cookie, 4);
60126 c->len=4;
60127 diff --git a/fs/locks.c b/fs/locks.c
60128 index 92a0f0a..45a48f0 100644
60129 --- a/fs/locks.c
60130 +++ b/fs/locks.c
60131 @@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
60132 return;
60133
60134 if (filp->f_op->flock) {
60135 - struct file_lock fl = {
60136 + struct file_lock flock = {
60137 .fl_pid = current->tgid,
60138 .fl_file = filp,
60139 .fl_flags = FL_FLOCK,
60140 .fl_type = F_UNLCK,
60141 .fl_end = OFFSET_MAX,
60142 };
60143 - filp->f_op->flock(filp, F_SETLKW, &fl);
60144 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
60145 - fl.fl_ops->fl_release_private(&fl);
60146 + filp->f_op->flock(filp, F_SETLKW, &flock);
60147 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
60148 + flock.fl_ops->fl_release_private(&flock);
60149 }
60150
60151 spin_lock(&inode->i_lock);
60152 diff --git a/fs/mount.h b/fs/mount.h
60153 index d64c594..6c283db 100644
60154 --- a/fs/mount.h
60155 +++ b/fs/mount.h
60156 @@ -11,7 +11,7 @@ struct mnt_namespace {
60157 u64 seq; /* Sequence number to prevent loops */
60158 wait_queue_head_t poll;
60159 int event;
60160 -};
60161 +} __randomize_layout;
60162
60163 struct mnt_pcp {
60164 int mnt_count;
60165 @@ -57,7 +57,7 @@ struct mount {
60166 int mnt_expiry_mark; /* true if marked for expiry */
60167 int mnt_pinned;
60168 struct path mnt_ex_mountpoint;
60169 -};
60170 +} __randomize_layout;
60171
60172 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
60173
60174 diff --git a/fs/namei.c b/fs/namei.c
60175 index 3531dee..3177227 100644
60176 --- a/fs/namei.c
60177 +++ b/fs/namei.c
60178 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
60179 if (ret != -EACCES)
60180 return ret;
60181
60182 +#ifdef CONFIG_GRKERNSEC
60183 + /* we'll block if we have to log due to a denied capability use */
60184 + if (mask & MAY_NOT_BLOCK)
60185 + return -ECHILD;
60186 +#endif
60187 +
60188 if (S_ISDIR(inode->i_mode)) {
60189 /* DACs are overridable for directories */
60190 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
60191 - return 0;
60192 if (!(mask & MAY_WRITE))
60193 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
60194 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
60195 + inode_capable(inode, CAP_DAC_READ_SEARCH))
60196 return 0;
60197 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
60198 + return 0;
60199 return -EACCES;
60200 }
60201 /*
60202 + * Searching includes executable on directories, else just read.
60203 + */
60204 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
60205 + if (mask == MAY_READ)
60206 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
60207 + inode_capable(inode, CAP_DAC_READ_SEARCH))
60208 + return 0;
60209 +
60210 + /*
60211 * Read/write DACs are always overridable.
60212 * Executable DACs are overridable when there is
60213 * at least one exec bit set.
60214 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
60215 if (inode_capable(inode, CAP_DAC_OVERRIDE))
60216 return 0;
60217
60218 - /*
60219 - * Searching includes executable on directories, else just read.
60220 - */
60221 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
60222 - if (mask == MAY_READ)
60223 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
60224 - return 0;
60225 -
60226 return -EACCES;
60227 }
60228
60229 @@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
60230 {
60231 struct dentry *dentry = link->dentry;
60232 int error;
60233 - char *s;
60234 + const char *s;
60235
60236 BUG_ON(nd->flags & LOOKUP_RCU);
60237
60238 @@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
60239 if (error)
60240 goto out_put_nd_path;
60241
60242 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
60243 + dentry->d_inode, dentry, nd->path.mnt)) {
60244 + error = -EACCES;
60245 + goto out_put_nd_path;
60246 + }
60247 +
60248 nd->last_type = LAST_BIND;
60249 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
60250 error = PTR_ERR(*p);
60251 @@ -1582,6 +1596,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
60252 if (res)
60253 break;
60254 res = walk_component(nd, path, LOOKUP_FOLLOW);
60255 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
60256 + res = -EACCES;
60257 put_link(nd, &link, cookie);
60258 } while (res > 0);
60259
60260 @@ -1655,7 +1671,7 @@ EXPORT_SYMBOL(full_name_hash);
60261 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
60262 {
60263 unsigned long a, b, adata, bdata, mask, hash, len;
60264 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60265 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60266
60267 hash = a = 0;
60268 len = -sizeof(unsigned long);
60269 @@ -1939,6 +1955,8 @@ static int path_lookupat(int dfd, const char *name,
60270 if (err)
60271 break;
60272 err = lookup_last(nd, &path);
60273 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
60274 + err = -EACCES;
60275 put_link(nd, &link, cookie);
60276 }
60277 }
60278 @@ -1946,6 +1964,13 @@ static int path_lookupat(int dfd, const char *name,
60279 if (!err)
60280 err = complete_walk(nd);
60281
60282 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
60283 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60284 + path_put(&nd->path);
60285 + err = -ENOENT;
60286 + }
60287 + }
60288 +
60289 if (!err && nd->flags & LOOKUP_DIRECTORY) {
60290 if (!d_is_directory(nd->path.dentry)) {
60291 path_put(&nd->path);
60292 @@ -1973,8 +1998,15 @@ static int filename_lookup(int dfd, struct filename *name,
60293 retval = path_lookupat(dfd, name->name,
60294 flags | LOOKUP_REVAL, nd);
60295
60296 - if (likely(!retval))
60297 + if (likely(!retval)) {
60298 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
60299 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
60300 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
60301 + path_put(&nd->path);
60302 + return -ENOENT;
60303 + }
60304 + }
60305 + }
60306 return retval;
60307 }
60308
60309 @@ -2548,6 +2580,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
60310 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
60311 return -EPERM;
60312
60313 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
60314 + return -EPERM;
60315 + if (gr_handle_rawio(inode))
60316 + return -EPERM;
60317 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
60318 + return -EACCES;
60319 +
60320 return 0;
60321 }
60322
60323 @@ -2779,7 +2818,7 @@ looked_up:
60324 * cleared otherwise prior to returning.
60325 */
60326 static int lookup_open(struct nameidata *nd, struct path *path,
60327 - struct file *file,
60328 + struct path *link, struct file *file,
60329 const struct open_flags *op,
60330 bool got_write, int *opened)
60331 {
60332 @@ -2814,6 +2853,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60333 /* Negative dentry, just create the file */
60334 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
60335 umode_t mode = op->mode;
60336 +
60337 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
60338 + error = -EACCES;
60339 + goto out_dput;
60340 + }
60341 +
60342 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
60343 + error = -EACCES;
60344 + goto out_dput;
60345 + }
60346 +
60347 if (!IS_POSIXACL(dir->d_inode))
60348 mode &= ~current_umask();
60349 /*
60350 @@ -2835,6 +2885,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60351 nd->flags & LOOKUP_EXCL);
60352 if (error)
60353 goto out_dput;
60354 + else
60355 + gr_handle_create(dentry, nd->path.mnt);
60356 }
60357 out_no_open:
60358 path->dentry = dentry;
60359 @@ -2849,7 +2901,7 @@ out_dput:
60360 /*
60361 * Handle the last step of open()
60362 */
60363 -static int do_last(struct nameidata *nd, struct path *path,
60364 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
60365 struct file *file, const struct open_flags *op,
60366 int *opened, struct filename *name)
60367 {
60368 @@ -2899,6 +2951,15 @@ static int do_last(struct nameidata *nd, struct path *path,
60369 if (error)
60370 return error;
60371
60372 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
60373 + error = -ENOENT;
60374 + goto out;
60375 + }
60376 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
60377 + error = -EACCES;
60378 + goto out;
60379 + }
60380 +
60381 audit_inode(name, dir, LOOKUP_PARENT);
60382 error = -EISDIR;
60383 /* trailing slashes? */
60384 @@ -2918,7 +2979,7 @@ retry_lookup:
60385 */
60386 }
60387 mutex_lock(&dir->d_inode->i_mutex);
60388 - error = lookup_open(nd, path, file, op, got_write, opened);
60389 + error = lookup_open(nd, path, link, file, op, got_write, opened);
60390 mutex_unlock(&dir->d_inode->i_mutex);
60391
60392 if (error <= 0) {
60393 @@ -2942,11 +3003,28 @@ retry_lookup:
60394 goto finish_open_created;
60395 }
60396
60397 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
60398 + error = -ENOENT;
60399 + goto exit_dput;
60400 + }
60401 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
60402 + error = -EACCES;
60403 + goto exit_dput;
60404 + }
60405 +
60406 /*
60407 * create/update audit record if it already exists.
60408 */
60409 - if (d_is_positive(path->dentry))
60410 + if (d_is_positive(path->dentry)) {
60411 + /* only check if O_CREAT is specified, all other checks need to go
60412 + into may_open */
60413 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
60414 + error = -EACCES;
60415 + goto exit_dput;
60416 + }
60417 +
60418 audit_inode(name, path->dentry, 0);
60419 + }
60420
60421 /*
60422 * If atomic_open() acquired write access it is dropped now due to
60423 @@ -2987,6 +3065,11 @@ finish_lookup:
60424 }
60425 }
60426 BUG_ON(inode != path->dentry->d_inode);
60427 + /* if we're resolving a symlink to another symlink */
60428 + if (link && gr_handle_symlink_owner(link, inode)) {
60429 + error = -EACCES;
60430 + goto out;
60431 + }
60432 return 1;
60433 }
60434
60435 @@ -2996,7 +3079,6 @@ finish_lookup:
60436 save_parent.dentry = nd->path.dentry;
60437 save_parent.mnt = mntget(path->mnt);
60438 nd->path.dentry = path->dentry;
60439 -
60440 }
60441 nd->inode = inode;
60442 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
60443 @@ -3006,7 +3088,18 @@ finish_open:
60444 path_put(&save_parent);
60445 return error;
60446 }
60447 +
60448 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60449 + error = -ENOENT;
60450 + goto out;
60451 + }
60452 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
60453 + error = -EACCES;
60454 + goto out;
60455 + }
60456 +
60457 audit_inode(name, nd->path.dentry, 0);
60458 +
60459 error = -EISDIR;
60460 if ((open_flag & O_CREAT) &&
60461 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
60462 @@ -3170,7 +3263,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60463 if (unlikely(error))
60464 goto out;
60465
60466 - error = do_last(nd, &path, file, op, &opened, pathname);
60467 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
60468 while (unlikely(error > 0)) { /* trailing symlink */
60469 struct path link = path;
60470 void *cookie;
60471 @@ -3188,7 +3281,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60472 error = follow_link(&link, nd, &cookie);
60473 if (unlikely(error))
60474 break;
60475 - error = do_last(nd, &path, file, op, &opened, pathname);
60476 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
60477 put_link(nd, &link, cookie);
60478 }
60479 out:
60480 @@ -3288,9 +3381,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
60481 goto unlock;
60482
60483 error = -EEXIST;
60484 - if (d_is_positive(dentry))
60485 + if (d_is_positive(dentry)) {
60486 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
60487 + error = -ENOENT;
60488 goto fail;
60489 -
60490 + }
60491 /*
60492 * Special case - lookup gave negative, but... we had foo/bar/
60493 * From the vfs_mknod() POV we just have a negative dentry -
60494 @@ -3342,6 +3437,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
60495 }
60496 EXPORT_SYMBOL(user_path_create);
60497
60498 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
60499 +{
60500 + struct filename *tmp = getname(pathname);
60501 + struct dentry *res;
60502 + if (IS_ERR(tmp))
60503 + return ERR_CAST(tmp);
60504 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
60505 + if (IS_ERR(res))
60506 + putname(tmp);
60507 + else
60508 + *to = tmp;
60509 + return res;
60510 +}
60511 +
60512 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
60513 {
60514 int error = may_create(dir, dentry);
60515 @@ -3404,6 +3513,17 @@ retry:
60516
60517 if (!IS_POSIXACL(path.dentry->d_inode))
60518 mode &= ~current_umask();
60519 +
60520 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
60521 + error = -EPERM;
60522 + goto out;
60523 + }
60524 +
60525 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
60526 + error = -EACCES;
60527 + goto out;
60528 + }
60529 +
60530 error = security_path_mknod(&path, dentry, mode, dev);
60531 if (error)
60532 goto out;
60533 @@ -3420,6 +3540,8 @@ retry:
60534 break;
60535 }
60536 out:
60537 + if (!error)
60538 + gr_handle_create(dentry, path.mnt);
60539 done_path_create(&path, dentry);
60540 if (retry_estale(error, lookup_flags)) {
60541 lookup_flags |= LOOKUP_REVAL;
60542 @@ -3472,9 +3594,16 @@ retry:
60543
60544 if (!IS_POSIXACL(path.dentry->d_inode))
60545 mode &= ~current_umask();
60546 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
60547 + error = -EACCES;
60548 + goto out;
60549 + }
60550 error = security_path_mkdir(&path, dentry, mode);
60551 if (!error)
60552 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
60553 + if (!error)
60554 + gr_handle_create(dentry, path.mnt);
60555 +out:
60556 done_path_create(&path, dentry);
60557 if (retry_estale(error, lookup_flags)) {
60558 lookup_flags |= LOOKUP_REVAL;
60559 @@ -3555,6 +3684,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
60560 struct filename *name;
60561 struct dentry *dentry;
60562 struct nameidata nd;
60563 + ino_t saved_ino = 0;
60564 + dev_t saved_dev = 0;
60565 unsigned int lookup_flags = 0;
60566 retry:
60567 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60568 @@ -3587,10 +3718,21 @@ retry:
60569 error = -ENOENT;
60570 goto exit3;
60571 }
60572 +
60573 + saved_ino = dentry->d_inode->i_ino;
60574 + saved_dev = gr_get_dev_from_dentry(dentry);
60575 +
60576 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
60577 + error = -EACCES;
60578 + goto exit3;
60579 + }
60580 +
60581 error = security_path_rmdir(&nd.path, dentry);
60582 if (error)
60583 goto exit3;
60584 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
60585 + if (!error && (saved_dev || saved_ino))
60586 + gr_handle_delete(saved_ino, saved_dev);
60587 exit3:
60588 dput(dentry);
60589 exit2:
60590 @@ -3680,6 +3822,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
60591 struct nameidata nd;
60592 struct inode *inode = NULL;
60593 struct inode *delegated_inode = NULL;
60594 + ino_t saved_ino = 0;
60595 + dev_t saved_dev = 0;
60596 unsigned int lookup_flags = 0;
60597 retry:
60598 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60599 @@ -3706,10 +3850,22 @@ retry_deleg:
60600 if (d_is_negative(dentry))
60601 goto slashes;
60602 ihold(inode);
60603 +
60604 + if (inode->i_nlink <= 1) {
60605 + saved_ino = inode->i_ino;
60606 + saved_dev = gr_get_dev_from_dentry(dentry);
60607 + }
60608 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
60609 + error = -EACCES;
60610 + goto exit2;
60611 + }
60612 +
60613 error = security_path_unlink(&nd.path, dentry);
60614 if (error)
60615 goto exit2;
60616 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
60617 + if (!error && (saved_ino || saved_dev))
60618 + gr_handle_delete(saved_ino, saved_dev);
60619 exit2:
60620 dput(dentry);
60621 }
60622 @@ -3797,9 +3953,17 @@ retry:
60623 if (IS_ERR(dentry))
60624 goto out_putname;
60625
60626 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
60627 + error = -EACCES;
60628 + goto out;
60629 + }
60630 +
60631 error = security_path_symlink(&path, dentry, from->name);
60632 if (!error)
60633 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
60634 + if (!error)
60635 + gr_handle_create(dentry, path.mnt);
60636 +out:
60637 done_path_create(&path, dentry);
60638 if (retry_estale(error, lookup_flags)) {
60639 lookup_flags |= LOOKUP_REVAL;
60640 @@ -3902,6 +4066,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
60641 struct dentry *new_dentry;
60642 struct path old_path, new_path;
60643 struct inode *delegated_inode = NULL;
60644 + struct filename *to = NULL;
60645 int how = 0;
60646 int error;
60647
60648 @@ -3925,7 +4090,7 @@ retry:
60649 if (error)
60650 return error;
60651
60652 - new_dentry = user_path_create(newdfd, newname, &new_path,
60653 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
60654 (how & LOOKUP_REVAL));
60655 error = PTR_ERR(new_dentry);
60656 if (IS_ERR(new_dentry))
60657 @@ -3937,11 +4102,28 @@ retry:
60658 error = may_linkat(&old_path);
60659 if (unlikely(error))
60660 goto out_dput;
60661 +
60662 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
60663 + old_path.dentry->d_inode,
60664 + old_path.dentry->d_inode->i_mode, to)) {
60665 + error = -EACCES;
60666 + goto out_dput;
60667 + }
60668 +
60669 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
60670 + old_path.dentry, old_path.mnt, to)) {
60671 + error = -EACCES;
60672 + goto out_dput;
60673 + }
60674 +
60675 error = security_path_link(old_path.dentry, &new_path, new_dentry);
60676 if (error)
60677 goto out_dput;
60678 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
60679 + if (!error)
60680 + gr_handle_create(new_dentry, new_path.mnt);
60681 out_dput:
60682 + putname(to);
60683 done_path_create(&new_path, new_dentry);
60684 if (delegated_inode) {
60685 error = break_deleg_wait(&delegated_inode);
60686 @@ -4225,6 +4407,12 @@ retry_deleg:
60687 if (new_dentry == trap)
60688 goto exit5;
60689
60690 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
60691 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
60692 + to);
60693 + if (error)
60694 + goto exit5;
60695 +
60696 error = security_path_rename(&oldnd.path, old_dentry,
60697 &newnd.path, new_dentry);
60698 if (error)
60699 @@ -4232,6 +4420,9 @@ retry_deleg:
60700 error = vfs_rename(old_dir->d_inode, old_dentry,
60701 new_dir->d_inode, new_dentry,
60702 &delegated_inode);
60703 + if (!error)
60704 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
60705 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
60706 exit5:
60707 dput(new_dentry);
60708 exit4:
60709 @@ -4268,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
60710
60711 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
60712 {
60713 + char tmpbuf[64];
60714 + const char *newlink;
60715 int len;
60716
60717 len = PTR_ERR(link);
60718 @@ -4277,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
60719 len = strlen(link);
60720 if (len > (unsigned) buflen)
60721 len = buflen;
60722 - if (copy_to_user(buffer, link, len))
60723 +
60724 + if (len < sizeof(tmpbuf)) {
60725 + memcpy(tmpbuf, link, len);
60726 + newlink = tmpbuf;
60727 + } else
60728 + newlink = link;
60729 +
60730 + if (copy_to_user(buffer, newlink, len))
60731 len = -EFAULT;
60732 out:
60733 return len;
60734 diff --git a/fs/namespace.c b/fs/namespace.c
60735 index be32ebc..c595734 100644
60736 --- a/fs/namespace.c
60737 +++ b/fs/namespace.c
60738 @@ -1293,6 +1293,9 @@ static int do_umount(struct mount *mnt, int flags)
60739 if (!(sb->s_flags & MS_RDONLY))
60740 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
60741 up_write(&sb->s_umount);
60742 +
60743 + gr_log_remount(mnt->mnt_devname, retval);
60744 +
60745 return retval;
60746 }
60747
60748 @@ -1315,6 +1318,9 @@ static int do_umount(struct mount *mnt, int flags)
60749 }
60750 unlock_mount_hash();
60751 namespace_unlock();
60752 +
60753 + gr_log_unmount(mnt->mnt_devname, retval);
60754 +
60755 return retval;
60756 }
60757
60758 @@ -1334,7 +1340,7 @@ static inline bool may_mount(void)
60759 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
60760 */
60761
60762 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
60763 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
60764 {
60765 struct path path;
60766 struct mount *mnt;
60767 @@ -1376,7 +1382,7 @@ out:
60768 /*
60769 * The 2.0 compatible umount. No flags.
60770 */
60771 -SYSCALL_DEFINE1(oldumount, char __user *, name)
60772 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
60773 {
60774 return sys_umount(name, 0);
60775 }
60776 @@ -2379,6 +2385,16 @@ long do_mount(const char *dev_name, const char *dir_name,
60777 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
60778 MS_STRICTATIME);
60779
60780 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
60781 + retval = -EPERM;
60782 + goto dput_out;
60783 + }
60784 +
60785 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
60786 + retval = -EPERM;
60787 + goto dput_out;
60788 + }
60789 +
60790 if (flags & MS_REMOUNT)
60791 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
60792 data_page);
60793 @@ -2393,6 +2409,9 @@ long do_mount(const char *dev_name, const char *dir_name,
60794 dev_name, data_page);
60795 dput_out:
60796 path_put(&path);
60797 +
60798 + gr_log_mount(dev_name, dir_name, retval);
60799 +
60800 return retval;
60801 }
60802
60803 @@ -2410,7 +2429,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
60804 * number incrementing at 10Ghz will take 12,427 years to wrap which
60805 * is effectively never, so we can ignore the possibility.
60806 */
60807 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
60808 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
60809
60810 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60811 {
60812 @@ -2425,7 +2444,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60813 kfree(new_ns);
60814 return ERR_PTR(ret);
60815 }
60816 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
60817 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
60818 atomic_set(&new_ns->count, 1);
60819 new_ns->root = NULL;
60820 INIT_LIST_HEAD(&new_ns->list);
60821 @@ -2435,7 +2454,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60822 return new_ns;
60823 }
60824
60825 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
60826 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
60827 struct user_namespace *user_ns, struct fs_struct *new_fs)
60828 {
60829 struct mnt_namespace *new_ns;
60830 @@ -2556,8 +2575,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
60831 }
60832 EXPORT_SYMBOL(mount_subtree);
60833
60834 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
60835 - char __user *, type, unsigned long, flags, void __user *, data)
60836 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
60837 + const char __user *, type, unsigned long, flags, void __user *, data)
60838 {
60839 int ret;
60840 char *kernel_type;
60841 @@ -2670,6 +2689,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
60842 if (error)
60843 goto out2;
60844
60845 + if (gr_handle_chroot_pivot()) {
60846 + error = -EPERM;
60847 + goto out2;
60848 + }
60849 +
60850 get_fs_root(current->fs, &root);
60851 old_mp = lock_mount(&old);
60852 error = PTR_ERR(old_mp);
60853 @@ -2930,7 +2954,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
60854 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
60855 return -EPERM;
60856
60857 - if (fs->users != 1)
60858 + if (atomic_read(&fs->users) != 1)
60859 return -EINVAL;
60860
60861 get_mnt_ns(mnt_ns);
60862 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
60863 index f4ccfe6..a5cf064 100644
60864 --- a/fs/nfs/callback_xdr.c
60865 +++ b/fs/nfs/callback_xdr.c
60866 @@ -51,7 +51,7 @@ struct callback_op {
60867 callback_decode_arg_t decode_args;
60868 callback_encode_res_t encode_res;
60869 long res_maxsize;
60870 -};
60871 +} __do_const;
60872
60873 static struct callback_op callback_ops[];
60874
60875 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
60876 index 00ad1c2..2fde15e 100644
60877 --- a/fs/nfs/inode.c
60878 +++ b/fs/nfs/inode.c
60879 @@ -1146,16 +1146,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
60880 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
60881 }
60882
60883 -static atomic_long_t nfs_attr_generation_counter;
60884 +static atomic_long_unchecked_t nfs_attr_generation_counter;
60885
60886 static unsigned long nfs_read_attr_generation_counter(void)
60887 {
60888 - return atomic_long_read(&nfs_attr_generation_counter);
60889 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
60890 }
60891
60892 unsigned long nfs_inc_attr_generation_counter(void)
60893 {
60894 - return atomic_long_inc_return(&nfs_attr_generation_counter);
60895 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
60896 }
60897
60898 void nfs_fattr_init(struct nfs_fattr *fattr)
60899 diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c
60900 index b4a160a..2b9bfba 100644
60901 --- a/fs/nfs/nfs4client.c
60902 +++ b/fs/nfs/nfs4client.c
60903 @@ -409,13 +409,11 @@ struct nfs_client *nfs4_init_client(struct nfs_client *clp,
60904 error = nfs4_discover_server_trunking(clp, &old);
60905 if (error < 0)
60906 goto error;
60907 - nfs_put_client(clp);
60908 - if (clp != old) {
60909 +
60910 + if (clp != old)
60911 clp->cl_preserve_clid = true;
60912 - clp = old;
60913 - }
60914 -
60915 - return clp;
60916 + nfs_put_client(clp);
60917 + return old;
60918
60919 error:
60920 nfs_mark_client_ready(clp, error);
60921 @@ -493,9 +491,10 @@ int nfs40_walk_client_list(struct nfs_client *new,
60922 prev = pos;
60923
60924 status = nfs_wait_client_init_complete(pos);
60925 - spin_lock(&nn->nfs_client_lock);
60926 if (status < 0)
60927 - continue;
60928 + goto out;
60929 + status = -NFS4ERR_STALE_CLIENTID;
60930 + spin_lock(&nn->nfs_client_lock);
60931 }
60932 if (pos->cl_cons_state != NFS_CS_READY)
60933 continue;
60934 @@ -633,7 +632,8 @@ int nfs41_walk_client_list(struct nfs_client *new,
60935 }
60936 spin_lock(&nn->nfs_client_lock);
60937 if (status < 0)
60938 - continue;
60939 + break;
60940 + status = -NFS4ERR_STALE_CLIENTID;
60941 }
60942 if (pos->cl_cons_state != NFS_CS_READY)
60943 continue;
60944 diff --git a/fs/nfs/write.c b/fs/nfs/write.c
60945 index c1d5482..6a85038 100644
60946 --- a/fs/nfs/write.c
60947 +++ b/fs/nfs/write.c
60948 @@ -922,19 +922,20 @@ out:
60949 * extend the write to cover the entire page in order to avoid fragmentation
60950 * inefficiencies.
60951 *
60952 - * If the file is opened for synchronous writes or if we have a write delegation
60953 - * from the server then we can just skip the rest of the checks.
60954 + * If the file is opened for synchronous writes then we can just skip the rest
60955 + * of the checks.
60956 */
60957 static int nfs_can_extend_write(struct file *file, struct page *page, struct inode *inode)
60958 {
60959 if (file->f_flags & O_DSYNC)
60960 return 0;
60961 + if (!nfs_write_pageuptodate(page, inode))
60962 + return 0;
60963 if (NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE))
60964 return 1;
60965 - if (nfs_write_pageuptodate(page, inode) && (inode->i_flock == NULL ||
60966 - (inode->i_flock->fl_start == 0 &&
60967 + if (inode->i_flock == NULL || (inode->i_flock->fl_start == 0 &&
60968 inode->i_flock->fl_end == OFFSET_MAX &&
60969 - inode->i_flock->fl_type != F_RDLCK)))
60970 + inode->i_flock->fl_type != F_RDLCK))
60971 return 1;
60972 return 0;
60973 }
60974 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
60975 index 419572f..5414a23 100644
60976 --- a/fs/nfsd/nfs4proc.c
60977 +++ b/fs/nfsd/nfs4proc.c
60978 @@ -1168,7 +1168,7 @@ struct nfsd4_operation {
60979 nfsd4op_rsize op_rsize_bop;
60980 stateid_getter op_get_currentstateid;
60981 stateid_setter op_set_currentstateid;
60982 -};
60983 +} __do_const;
60984
60985 static struct nfsd4_operation nfsd4_ops[];
60986
60987 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
60988 index ee7237f..e3ae60a 100644
60989 --- a/fs/nfsd/nfs4xdr.c
60990 +++ b/fs/nfsd/nfs4xdr.c
60991 @@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
60992
60993 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
60994
60995 -static nfsd4_dec nfsd4_dec_ops[] = {
60996 +static const nfsd4_dec nfsd4_dec_ops[] = {
60997 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
60998 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
60999 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61000 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61001 index b6af150..f6ec5e3 100644
61002 --- a/fs/nfsd/nfscache.c
61003 +++ b/fs/nfsd/nfscache.c
61004 @@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61005 {
61006 struct svc_cacherep *rp = rqstp->rq_cacherep;
61007 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61008 - int len;
61009 + long len;
61010 size_t bufsize = 0;
61011
61012 if (!rp)
61013 return;
61014
61015 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
61016 - len >>= 2;
61017 + if (statp) {
61018 + len = (char*)statp - (char*)resv->iov_base;
61019 + len = resv->iov_len - len;
61020 + len >>= 2;
61021 + }
61022
61023 /* Don't cache excessive amounts of data and XDR failures */
61024 if (!statp || len > (256 >> 2)) {
61025 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
61026 index 7eea63c..a35f4fb 100644
61027 --- a/fs/nfsd/vfs.c
61028 +++ b/fs/nfsd/vfs.c
61029 @@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61030 } else {
61031 oldfs = get_fs();
61032 set_fs(KERNEL_DS);
61033 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
61034 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
61035 set_fs(oldfs);
61036 }
61037
61038 @@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61039
61040 /* Write the data. */
61041 oldfs = get_fs(); set_fs(KERNEL_DS);
61042 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
61043 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
61044 set_fs(oldfs);
61045 if (host_err < 0)
61046 goto out_nfserr;
61047 @@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
61048 */
61049
61050 oldfs = get_fs(); set_fs(KERNEL_DS);
61051 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
61052 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
61053 set_fs(oldfs);
61054
61055 if (host_err < 0)
61056 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
61057 index fea6bd5..8ee9d81 100644
61058 --- a/fs/nls/nls_base.c
61059 +++ b/fs/nls/nls_base.c
61060 @@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
61061
61062 int register_nls(struct nls_table * nls)
61063 {
61064 - struct nls_table ** tmp = &tables;
61065 + struct nls_table *tmp = tables;
61066
61067 if (nls->next)
61068 return -EBUSY;
61069
61070 spin_lock(&nls_lock);
61071 - while (*tmp) {
61072 - if (nls == *tmp) {
61073 + while (tmp) {
61074 + if (nls == tmp) {
61075 spin_unlock(&nls_lock);
61076 return -EBUSY;
61077 }
61078 - tmp = &(*tmp)->next;
61079 + tmp = tmp->next;
61080 }
61081 - nls->next = tables;
61082 + pax_open_kernel();
61083 + *(struct nls_table **)&nls->next = tables;
61084 + pax_close_kernel();
61085 tables = nls;
61086 spin_unlock(&nls_lock);
61087 return 0;
61088 @@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
61089
61090 int unregister_nls(struct nls_table * nls)
61091 {
61092 - struct nls_table ** tmp = &tables;
61093 + struct nls_table * const * tmp = &tables;
61094
61095 spin_lock(&nls_lock);
61096 while (*tmp) {
61097 if (nls == *tmp) {
61098 - *tmp = nls->next;
61099 + pax_open_kernel();
61100 + *(struct nls_table **)tmp = nls->next;
61101 + pax_close_kernel();
61102 spin_unlock(&nls_lock);
61103 return 0;
61104 }
61105 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
61106 index 7424929..35f6be5 100644
61107 --- a/fs/nls/nls_euc-jp.c
61108 +++ b/fs/nls/nls_euc-jp.c
61109 @@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
61110 p_nls = load_nls("cp932");
61111
61112 if (p_nls) {
61113 - table.charset2upper = p_nls->charset2upper;
61114 - table.charset2lower = p_nls->charset2lower;
61115 + pax_open_kernel();
61116 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61117 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61118 + pax_close_kernel();
61119 return register_nls(&table);
61120 }
61121
61122 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
61123 index e7bc1d7..06bd4bb 100644
61124 --- a/fs/nls/nls_koi8-ru.c
61125 +++ b/fs/nls/nls_koi8-ru.c
61126 @@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
61127 p_nls = load_nls("koi8-u");
61128
61129 if (p_nls) {
61130 - table.charset2upper = p_nls->charset2upper;
61131 - table.charset2lower = p_nls->charset2lower;
61132 + pax_open_kernel();
61133 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61134 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61135 + pax_close_kernel();
61136 return register_nls(&table);
61137 }
61138
61139 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
61140 index e44cb64..7668ca4 100644
61141 --- a/fs/notify/fanotify/fanotify_user.c
61142 +++ b/fs/notify/fanotify/fanotify_user.c
61143 @@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
61144
61145 fd = fanotify_event_metadata.fd;
61146 ret = -EFAULT;
61147 - if (copy_to_user(buf, &fanotify_event_metadata,
61148 - fanotify_event_metadata.event_len))
61149 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
61150 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
61151 goto out_close_fd;
61152
61153 ret = prepare_for_access_response(group, event, fd);
61154 @@ -888,9 +888,9 @@ COMPAT_SYSCALL_DEFINE6(fanotify_mark,
61155 {
61156 return sys_fanotify_mark(fanotify_fd, flags,
61157 #ifdef __BIG_ENDIAN
61158 - ((__u64)mask1 << 32) | mask0,
61159 -#else
61160 ((__u64)mask0 << 32) | mask1,
61161 +#else
61162 + ((__u64)mask1 << 32) | mask0,
61163 #endif
61164 dfd, pathname);
61165 }
61166 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
61167 index 7b51b05..5ea5ef6 100644
61168 --- a/fs/notify/notification.c
61169 +++ b/fs/notify/notification.c
61170 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
61171 * get set to 0 so it will never get 'freed'
61172 */
61173 static struct fsnotify_event *q_overflow_event;
61174 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61175 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61176
61177 /**
61178 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
61179 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61180 */
61181 u32 fsnotify_get_cookie(void)
61182 {
61183 - return atomic_inc_return(&fsnotify_sync_cookie);
61184 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
61185 }
61186 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
61187
61188 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
61189 index 9e38daf..5727cae 100644
61190 --- a/fs/ntfs/dir.c
61191 +++ b/fs/ntfs/dir.c
61192 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
61193 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
61194 ~(s64)(ndir->itype.index.block_size - 1)));
61195 /* Bounds checks. */
61196 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61197 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61198 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
61199 "inode 0x%lx or driver bug.", vdir->i_ino);
61200 goto err_out;
61201 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
61202 index ea4ba9d..1e13d34 100644
61203 --- a/fs/ntfs/file.c
61204 +++ b/fs/ntfs/file.c
61205 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
61206 char *addr;
61207 size_t total = 0;
61208 unsigned len;
61209 - int left;
61210 + unsigned left;
61211
61212 do {
61213 len = PAGE_CACHE_SIZE - ofs;
61214 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
61215 index 82650d5..db37dcf 100644
61216 --- a/fs/ntfs/super.c
61217 +++ b/fs/ntfs/super.c
61218 @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61219 if (!silent)
61220 ntfs_error(sb, "Primary boot sector is invalid.");
61221 } else if (!silent)
61222 - ntfs_error(sb, read_err_str, "primary");
61223 + ntfs_error(sb, read_err_str, "%s", "primary");
61224 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
61225 if (bh_primary)
61226 brelse(bh_primary);
61227 @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61228 goto hotfix_primary_boot_sector;
61229 brelse(bh_backup);
61230 } else if (!silent)
61231 - ntfs_error(sb, read_err_str, "backup");
61232 + ntfs_error(sb, read_err_str, "%s", "backup");
61233 /* Try to read NT3.51- backup boot sector. */
61234 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
61235 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
61236 @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61237 "sector.");
61238 brelse(bh_backup);
61239 } else if (!silent)
61240 - ntfs_error(sb, read_err_str, "backup");
61241 + ntfs_error(sb, read_err_str, "%s", "backup");
61242 /* We failed. Cleanup and return. */
61243 if (bh_primary)
61244 brelse(bh_primary);
61245 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
61246 index cd5496b..26a1055 100644
61247 --- a/fs/ocfs2/localalloc.c
61248 +++ b/fs/ocfs2/localalloc.c
61249 @@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
61250 goto bail;
61251 }
61252
61253 - atomic_inc(&osb->alloc_stats.moves);
61254 + atomic_inc_unchecked(&osb->alloc_stats.moves);
61255
61256 bail:
61257 if (handle)
61258 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
61259 index 3a90347..c40bef8 100644
61260 --- a/fs/ocfs2/ocfs2.h
61261 +++ b/fs/ocfs2/ocfs2.h
61262 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
61263
61264 struct ocfs2_alloc_stats
61265 {
61266 - atomic_t moves;
61267 - atomic_t local_data;
61268 - atomic_t bitmap_data;
61269 - atomic_t bg_allocs;
61270 - atomic_t bg_extends;
61271 + atomic_unchecked_t moves;
61272 + atomic_unchecked_t local_data;
61273 + atomic_unchecked_t bitmap_data;
61274 + atomic_unchecked_t bg_allocs;
61275 + atomic_unchecked_t bg_extends;
61276 };
61277
61278 enum ocfs2_local_alloc_state
61279 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
61280 index 2c91452..77a3cd2 100644
61281 --- a/fs/ocfs2/suballoc.c
61282 +++ b/fs/ocfs2/suballoc.c
61283 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
61284 mlog_errno(status);
61285 goto bail;
61286 }
61287 - atomic_inc(&osb->alloc_stats.bg_extends);
61288 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
61289
61290 /* You should never ask for this much metadata */
61291 BUG_ON(bits_wanted >
61292 @@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
61293 mlog_errno(status);
61294 goto bail;
61295 }
61296 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61297 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61298
61299 *suballoc_loc = res.sr_bg_blkno;
61300 *suballoc_bit_start = res.sr_bit_offset;
61301 @@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
61302 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
61303 res->sr_bits);
61304
61305 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61306 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61307
61308 BUG_ON(res->sr_bits != 1);
61309
61310 @@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
61311 mlog_errno(status);
61312 goto bail;
61313 }
61314 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61315 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61316
61317 BUG_ON(res.sr_bits != 1);
61318
61319 @@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61320 cluster_start,
61321 num_clusters);
61322 if (!status)
61323 - atomic_inc(&osb->alloc_stats.local_data);
61324 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
61325 } else {
61326 if (min_clusters > (osb->bitmap_cpg - 1)) {
61327 /* The only paths asking for contiguousness
61328 @@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61329 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
61330 res.sr_bg_blkno,
61331 res.sr_bit_offset);
61332 - atomic_inc(&osb->alloc_stats.bitmap_data);
61333 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
61334 *num_clusters = res.sr_bits;
61335 }
61336 }
61337 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
61338 index c414929..5c9ee542 100644
61339 --- a/fs/ocfs2/super.c
61340 +++ b/fs/ocfs2/super.c
61341 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
61342 "%10s => GlobalAllocs: %d LocalAllocs: %d "
61343 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
61344 "Stats",
61345 - atomic_read(&osb->alloc_stats.bitmap_data),
61346 - atomic_read(&osb->alloc_stats.local_data),
61347 - atomic_read(&osb->alloc_stats.bg_allocs),
61348 - atomic_read(&osb->alloc_stats.moves),
61349 - atomic_read(&osb->alloc_stats.bg_extends));
61350 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
61351 + atomic_read_unchecked(&osb->alloc_stats.local_data),
61352 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
61353 + atomic_read_unchecked(&osb->alloc_stats.moves),
61354 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
61355
61356 out += snprintf(buf + out, len - out,
61357 "%10s => State: %u Descriptor: %llu Size: %u bits "
61358 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
61359 spin_lock_init(&osb->osb_xattr_lock);
61360 ocfs2_init_steal_slots(osb);
61361
61362 - atomic_set(&osb->alloc_stats.moves, 0);
61363 - atomic_set(&osb->alloc_stats.local_data, 0);
61364 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
61365 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
61366 - atomic_set(&osb->alloc_stats.bg_extends, 0);
61367 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
61368 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
61369 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
61370 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
61371 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
61372
61373 /* Copy the blockcheck stats from the superblock probe */
61374 osb->osb_ecc_stats = *stats;
61375 diff --git a/fs/open.c b/fs/open.c
61376 index 4b3e1ed..1c84599 100644
61377 --- a/fs/open.c
61378 +++ b/fs/open.c
61379 @@ -32,6 +32,8 @@
61380 #include <linux/dnotify.h>
61381 #include <linux/compat.h>
61382
61383 +#define CREATE_TRACE_POINTS
61384 +#include <trace/events/fs.h>
61385 #include "internal.h"
61386
61387 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
61388 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
61389 error = locks_verify_truncate(inode, NULL, length);
61390 if (!error)
61391 error = security_path_truncate(path);
61392 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
61393 + error = -EACCES;
61394 if (!error)
61395 error = do_truncate(path->dentry, length, 0, NULL);
61396
61397 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
61398 error = locks_verify_truncate(inode, f.file, length);
61399 if (!error)
61400 error = security_path_truncate(&f.file->f_path);
61401 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
61402 + error = -EACCES;
61403 if (!error)
61404 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
61405 sb_end_write(inode->i_sb);
61406 @@ -361,6 +367,9 @@ retry:
61407 if (__mnt_is_readonly(path.mnt))
61408 res = -EROFS;
61409
61410 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
61411 + res = -EACCES;
61412 +
61413 out_path_release:
61414 path_put(&path);
61415 if (retry_estale(res, lookup_flags)) {
61416 @@ -392,6 +401,8 @@ retry:
61417 if (error)
61418 goto dput_and_out;
61419
61420 + gr_log_chdir(path.dentry, path.mnt);
61421 +
61422 set_fs_pwd(current->fs, &path);
61423
61424 dput_and_out:
61425 @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
61426 goto out_putf;
61427
61428 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
61429 +
61430 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
61431 + error = -EPERM;
61432 +
61433 + if (!error)
61434 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
61435 +
61436 if (!error)
61437 set_fs_pwd(current->fs, &f.file->f_path);
61438 out_putf:
61439 @@ -450,7 +468,13 @@ retry:
61440 if (error)
61441 goto dput_and_out;
61442
61443 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
61444 + goto dput_and_out;
61445 +
61446 set_fs_root(current->fs, &path);
61447 +
61448 + gr_handle_chroot_chdir(&path);
61449 +
61450 error = 0;
61451 dput_and_out:
61452 path_put(&path);
61453 @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
61454 return error;
61455 retry_deleg:
61456 mutex_lock(&inode->i_mutex);
61457 +
61458 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
61459 + error = -EACCES;
61460 + goto out_unlock;
61461 + }
61462 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
61463 + error = -EACCES;
61464 + goto out_unlock;
61465 + }
61466 +
61467 error = security_path_chmod(path, mode);
61468 if (error)
61469 goto out_unlock;
61470 @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
61471 uid = make_kuid(current_user_ns(), user);
61472 gid = make_kgid(current_user_ns(), group);
61473
61474 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
61475 + return -EACCES;
61476 +
61477 newattrs.ia_valid = ATTR_CTIME;
61478 if (user != (uid_t) -1) {
61479 if (!uid_valid(uid))
61480 @@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
61481 } else {
61482 fsnotify_open(f);
61483 fd_install(fd, f);
61484 + trace_do_sys_open(tmp->name, flags, mode);
61485 }
61486 }
61487 putname(tmp);
61488 diff --git a/fs/pipe.c b/fs/pipe.c
61489 index 0e0752e..7cfdd50 100644
61490 --- a/fs/pipe.c
61491 +++ b/fs/pipe.c
61492 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
61493
61494 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
61495 {
61496 - if (pipe->files)
61497 + if (atomic_read(&pipe->files))
61498 mutex_lock_nested(&pipe->mutex, subclass);
61499 }
61500
61501 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
61502
61503 void pipe_unlock(struct pipe_inode_info *pipe)
61504 {
61505 - if (pipe->files)
61506 + if (atomic_read(&pipe->files))
61507 mutex_unlock(&pipe->mutex);
61508 }
61509 EXPORT_SYMBOL(pipe_unlock);
61510 @@ -449,9 +449,9 @@ redo:
61511 }
61512 if (bufs) /* More to do? */
61513 continue;
61514 - if (!pipe->writers)
61515 + if (!atomic_read(&pipe->writers))
61516 break;
61517 - if (!pipe->waiting_writers) {
61518 + if (!atomic_read(&pipe->waiting_writers)) {
61519 /* syscall merging: Usually we must not sleep
61520 * if O_NONBLOCK is set, or if we got some data.
61521 * But if a writer sleeps in kernel space, then
61522 @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
61523 ret = 0;
61524 __pipe_lock(pipe);
61525
61526 - if (!pipe->readers) {
61527 + if (!atomic_read(&pipe->readers)) {
61528 send_sig(SIGPIPE, current, 0);
61529 ret = -EPIPE;
61530 goto out;
61531 @@ -562,7 +562,7 @@ redo1:
61532 for (;;) {
61533 int bufs;
61534
61535 - if (!pipe->readers) {
61536 + if (!atomic_read(&pipe->readers)) {
61537 send_sig(SIGPIPE, current, 0);
61538 if (!ret)
61539 ret = -EPIPE;
61540 @@ -653,9 +653,9 @@ redo2:
61541 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61542 do_wakeup = 0;
61543 }
61544 - pipe->waiting_writers++;
61545 + atomic_inc(&pipe->waiting_writers);
61546 pipe_wait(pipe);
61547 - pipe->waiting_writers--;
61548 + atomic_dec(&pipe->waiting_writers);
61549 }
61550 out:
61551 __pipe_unlock(pipe);
61552 @@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61553 mask = 0;
61554 if (filp->f_mode & FMODE_READ) {
61555 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
61556 - if (!pipe->writers && filp->f_version != pipe->w_counter)
61557 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
61558 mask |= POLLHUP;
61559 }
61560
61561 @@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61562 * Most Unices do not set POLLERR for FIFOs but on Linux they
61563 * behave exactly like pipes for poll().
61564 */
61565 - if (!pipe->readers)
61566 + if (!atomic_read(&pipe->readers))
61567 mask |= POLLERR;
61568 }
61569
61570 @@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
61571 int kill = 0;
61572
61573 spin_lock(&inode->i_lock);
61574 - if (!--pipe->files) {
61575 + if (atomic_dec_and_test(&pipe->files)) {
61576 inode->i_pipe = NULL;
61577 kill = 1;
61578 }
61579 @@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
61580
61581 __pipe_lock(pipe);
61582 if (file->f_mode & FMODE_READ)
61583 - pipe->readers--;
61584 + atomic_dec(&pipe->readers);
61585 if (file->f_mode & FMODE_WRITE)
61586 - pipe->writers--;
61587 + atomic_dec(&pipe->writers);
61588
61589 - if (pipe->readers || pipe->writers) {
61590 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
61591 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
61592 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61593 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
61594 @@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
61595 kfree(pipe);
61596 }
61597
61598 -static struct vfsmount *pipe_mnt __read_mostly;
61599 +struct vfsmount *pipe_mnt __read_mostly;
61600
61601 /*
61602 * pipefs_dname() is called from d_path().
61603 @@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
61604 goto fail_iput;
61605
61606 inode->i_pipe = pipe;
61607 - pipe->files = 2;
61608 - pipe->readers = pipe->writers = 1;
61609 + atomic_set(&pipe->files, 2);
61610 + atomic_set(&pipe->readers, 1);
61611 + atomic_set(&pipe->writers, 1);
61612 inode->i_fop = &pipefifo_fops;
61613
61614 /*
61615 @@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
61616 spin_lock(&inode->i_lock);
61617 if (inode->i_pipe) {
61618 pipe = inode->i_pipe;
61619 - pipe->files++;
61620 + atomic_inc(&pipe->files);
61621 spin_unlock(&inode->i_lock);
61622 } else {
61623 spin_unlock(&inode->i_lock);
61624 pipe = alloc_pipe_info();
61625 if (!pipe)
61626 return -ENOMEM;
61627 - pipe->files = 1;
61628 + atomic_set(&pipe->files, 1);
61629 spin_lock(&inode->i_lock);
61630 if (unlikely(inode->i_pipe)) {
61631 - inode->i_pipe->files++;
61632 + atomic_inc(&inode->i_pipe->files);
61633 spin_unlock(&inode->i_lock);
61634 free_pipe_info(pipe);
61635 pipe = inode->i_pipe;
61636 @@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
61637 * opened, even when there is no process writing the FIFO.
61638 */
61639 pipe->r_counter++;
61640 - if (pipe->readers++ == 0)
61641 + if (atomic_inc_return(&pipe->readers) == 1)
61642 wake_up_partner(pipe);
61643
61644 - if (!is_pipe && !pipe->writers) {
61645 + if (!is_pipe && !atomic_read(&pipe->writers)) {
61646 if ((filp->f_flags & O_NONBLOCK)) {
61647 /* suppress POLLHUP until we have
61648 * seen a writer */
61649 @@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
61650 * errno=ENXIO when there is no process reading the FIFO.
61651 */
61652 ret = -ENXIO;
61653 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
61654 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
61655 goto err;
61656
61657 pipe->w_counter++;
61658 - if (!pipe->writers++)
61659 + if (atomic_inc_return(&pipe->writers) == 1)
61660 wake_up_partner(pipe);
61661
61662 - if (!is_pipe && !pipe->readers) {
61663 + if (!is_pipe && !atomic_read(&pipe->readers)) {
61664 if (wait_for_partner(pipe, &pipe->r_counter))
61665 goto err_wr;
61666 }
61667 @@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
61668 * the process can at least talk to itself.
61669 */
61670
61671 - pipe->readers++;
61672 - pipe->writers++;
61673 + atomic_inc(&pipe->readers);
61674 + atomic_inc(&pipe->writers);
61675 pipe->r_counter++;
61676 pipe->w_counter++;
61677 - if (pipe->readers == 1 || pipe->writers == 1)
61678 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
61679 wake_up_partner(pipe);
61680 break;
61681
61682 @@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
61683 return 0;
61684
61685 err_rd:
61686 - if (!--pipe->readers)
61687 + if (atomic_dec_and_test(&pipe->readers))
61688 wake_up_interruptible(&pipe->wait);
61689 ret = -ERESTARTSYS;
61690 goto err;
61691
61692 err_wr:
61693 - if (!--pipe->writers)
61694 + if (atomic_dec_and_test(&pipe->writers))
61695 wake_up_interruptible(&pipe->wait);
61696 ret = -ERESTARTSYS;
61697 goto err;
61698 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
61699 index 2183fcf..3c32a98 100644
61700 --- a/fs/proc/Kconfig
61701 +++ b/fs/proc/Kconfig
61702 @@ -30,7 +30,7 @@ config PROC_FS
61703
61704 config PROC_KCORE
61705 bool "/proc/kcore support" if !ARM
61706 - depends on PROC_FS && MMU
61707 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
61708 help
61709 Provides a virtual ELF core file of the live kernel. This can
61710 be read with gdb and other ELF tools. No modifications can be
61711 @@ -38,8 +38,8 @@ config PROC_KCORE
61712
61713 config PROC_VMCORE
61714 bool "/proc/vmcore support"
61715 - depends on PROC_FS && CRASH_DUMP
61716 - default y
61717 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
61718 + default n
61719 help
61720 Exports the dump image of crashed kernel in ELF format.
61721
61722 @@ -63,8 +63,8 @@ config PROC_SYSCTL
61723 limited in memory.
61724
61725 config PROC_PAGE_MONITOR
61726 - default y
61727 - depends on PROC_FS && MMU
61728 + default n
61729 + depends on PROC_FS && MMU && !GRKERNSEC
61730 bool "Enable /proc page monitoring" if EXPERT
61731 help
61732 Various /proc files exist to monitor process memory utilization:
61733 diff --git a/fs/proc/array.c b/fs/proc/array.c
61734 index 1bd2077..2f7cfd5 100644
61735 --- a/fs/proc/array.c
61736 +++ b/fs/proc/array.c
61737 @@ -60,6 +60,7 @@
61738 #include <linux/tty.h>
61739 #include <linux/string.h>
61740 #include <linux/mman.h>
61741 +#include <linux/grsecurity.h>
61742 #include <linux/proc_fs.h>
61743 #include <linux/ioport.h>
61744 #include <linux/uaccess.h>
61745 @@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
61746 seq_putc(m, '\n');
61747 }
61748
61749 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61750 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
61751 +{
61752 + if (p->mm)
61753 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
61754 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
61755 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
61756 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
61757 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
61758 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
61759 + else
61760 + seq_printf(m, "PaX:\t-----\n");
61761 +}
61762 +#endif
61763 +
61764 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61765 struct pid *pid, struct task_struct *task)
61766 {
61767 @@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61768 task_cpus_allowed(m, task);
61769 cpuset_task_status_allowed(m, task);
61770 task_context_switch_counts(m, task);
61771 +
61772 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61773 + task_pax(m, task);
61774 +#endif
61775 +
61776 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
61777 + task_grsec_rbac(m, task);
61778 +#endif
61779 +
61780 return 0;
61781 }
61782
61783 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61784 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61785 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
61786 + _mm->pax_flags & MF_PAX_SEGMEXEC))
61787 +#endif
61788 +
61789 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61790 struct pid *pid, struct task_struct *task, int whole)
61791 {
61792 @@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61793 char tcomm[sizeof(task->comm)];
61794 unsigned long flags;
61795
61796 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61797 + if (current->exec_id != m->exec_id) {
61798 + gr_log_badprocpid("stat");
61799 + return 0;
61800 + }
61801 +#endif
61802 +
61803 state = *get_task_state(task);
61804 vsize = eip = esp = 0;
61805 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
61806 @@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61807 gtime = task_gtime(task);
61808 }
61809
61810 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61811 + if (PAX_RAND_FLAGS(mm)) {
61812 + eip = 0;
61813 + esp = 0;
61814 + wchan = 0;
61815 + }
61816 +#endif
61817 +#ifdef CONFIG_GRKERNSEC_HIDESYM
61818 + wchan = 0;
61819 + eip =0;
61820 + esp =0;
61821 +#endif
61822 +
61823 /* scale priority and nice values from timeslices to -20..20 */
61824 /* to make it look like a "normal" Unix priority/nice value */
61825 priority = task_prio(task);
61826 @@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61827 seq_put_decimal_ull(m, ' ', vsize);
61828 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
61829 seq_put_decimal_ull(m, ' ', rsslim);
61830 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61831 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
61832 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
61833 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
61834 +#else
61835 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
61836 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
61837 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
61838 +#endif
61839 seq_put_decimal_ull(m, ' ', esp);
61840 seq_put_decimal_ull(m, ' ', eip);
61841 /* The signal information here is obsolete.
61842 @@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61843 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
61844 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
61845
61846 - if (mm && permitted) {
61847 + if (mm && permitted
61848 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61849 + && !PAX_RAND_FLAGS(mm)
61850 +#endif
61851 + ) {
61852 seq_put_decimal_ull(m, ' ', mm->start_data);
61853 seq_put_decimal_ull(m, ' ', mm->end_data);
61854 seq_put_decimal_ull(m, ' ', mm->start_brk);
61855 @@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61856 struct pid *pid, struct task_struct *task)
61857 {
61858 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
61859 - struct mm_struct *mm = get_task_mm(task);
61860 + struct mm_struct *mm;
61861
61862 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61863 + if (current->exec_id != m->exec_id) {
61864 + gr_log_badprocpid("statm");
61865 + return 0;
61866 + }
61867 +#endif
61868 + mm = get_task_mm(task);
61869 if (mm) {
61870 size = task_statm(mm, &shared, &text, &data, &resident);
61871 mmput(mm);
61872 @@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61873 return 0;
61874 }
61875
61876 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
61877 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
61878 +{
61879 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
61880 +}
61881 +#endif
61882 +
61883 #ifdef CONFIG_CHECKPOINT_RESTORE
61884 static struct pid *
61885 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
61886 diff --git a/fs/proc/base.c b/fs/proc/base.c
61887 index 03c8d74..4efb575 100644
61888 --- a/fs/proc/base.c
61889 +++ b/fs/proc/base.c
61890 @@ -113,6 +113,14 @@ struct pid_entry {
61891 union proc_op op;
61892 };
61893
61894 +struct getdents_callback {
61895 + struct linux_dirent __user * current_dir;
61896 + struct linux_dirent __user * previous;
61897 + struct file * file;
61898 + int count;
61899 + int error;
61900 +};
61901 +
61902 #define NOD(NAME, MODE, IOP, FOP, OP) { \
61903 .name = (NAME), \
61904 .len = sizeof(NAME) - 1, \
61905 @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
61906 if (!mm->arg_end)
61907 goto out_mm; /* Shh! No looking before we're done */
61908
61909 + if (gr_acl_handle_procpidmem(task))
61910 + goto out_mm;
61911 +
61912 len = mm->arg_end - mm->arg_start;
61913
61914 if (len > PAGE_SIZE)
61915 @@ -237,12 +248,28 @@ out:
61916 return res;
61917 }
61918
61919 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61920 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61921 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
61922 + _mm->pax_flags & MF_PAX_SEGMEXEC))
61923 +#endif
61924 +
61925 static int proc_pid_auxv(struct task_struct *task, char *buffer)
61926 {
61927 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
61928 int res = PTR_ERR(mm);
61929 if (mm && !IS_ERR(mm)) {
61930 unsigned int nwords = 0;
61931 +
61932 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61933 + /* allow if we're currently ptracing this task */
61934 + if (PAX_RAND_FLAGS(mm) &&
61935 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
61936 + mmput(mm);
61937 + return 0;
61938 + }
61939 +#endif
61940 +
61941 do {
61942 nwords += 2;
61943 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
61944 @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
61945 }
61946
61947
61948 -#ifdef CONFIG_KALLSYMS
61949 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61950 /*
61951 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
61952 * Returns the resolved symbol. If that fails, simply return the address.
61953 @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
61954 mutex_unlock(&task->signal->cred_guard_mutex);
61955 }
61956
61957 -#ifdef CONFIG_STACKTRACE
61958 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61959
61960 #define MAX_STACK_TRACE_DEPTH 64
61961
61962 @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
61963 return count;
61964 }
61965
61966 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
61967 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
61968 static int proc_pid_syscall(struct task_struct *task, char *buffer)
61969 {
61970 long nr;
61971 @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
61972 /************************************************************************/
61973
61974 /* permission checks */
61975 -static int proc_fd_access_allowed(struct inode *inode)
61976 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
61977 {
61978 struct task_struct *task;
61979 int allowed = 0;
61980 @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
61981 */
61982 task = get_proc_task(inode);
61983 if (task) {
61984 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
61985 + if (log)
61986 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
61987 + else
61988 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
61989 put_task_struct(task);
61990 }
61991 return allowed;
61992 @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
61993 struct task_struct *task,
61994 int hide_pid_min)
61995 {
61996 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
61997 + return false;
61998 +
61999 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62000 + rcu_read_lock();
62001 + {
62002 + const struct cred *tmpcred = current_cred();
62003 + const struct cred *cred = __task_cred(task);
62004 +
62005 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
62006 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62007 + || in_group_p(grsec_proc_gid)
62008 +#endif
62009 + ) {
62010 + rcu_read_unlock();
62011 + return true;
62012 + }
62013 + }
62014 + rcu_read_unlock();
62015 +
62016 + if (!pid->hide_pid)
62017 + return false;
62018 +#endif
62019 +
62020 if (pid->hide_pid < hide_pid_min)
62021 return true;
62022 if (in_group_p(pid->pid_gid))
62023 return true;
62024 +
62025 return ptrace_may_access(task, PTRACE_MODE_READ);
62026 }
62027
62028 @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
62029 put_task_struct(task);
62030
62031 if (!has_perms) {
62032 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62033 + {
62034 +#else
62035 if (pid->hide_pid == 2) {
62036 +#endif
62037 /*
62038 * Let's make getdents(), stat(), and open()
62039 * consistent with each other. If a process
62040 @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62041 if (!task)
62042 return -ESRCH;
62043
62044 + if (gr_acl_handle_procpidmem(task)) {
62045 + put_task_struct(task);
62046 + return -EPERM;
62047 + }
62048 +
62049 mm = mm_access(task, mode);
62050 put_task_struct(task);
62051
62052 @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62053
62054 file->private_data = mm;
62055
62056 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62057 + file->f_version = current->exec_id;
62058 +#endif
62059 +
62060 return 0;
62061 }
62062
62063 @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62064 ssize_t copied;
62065 char *page;
62066
62067 +#ifdef CONFIG_GRKERNSEC
62068 + if (write)
62069 + return -EPERM;
62070 +#endif
62071 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62072 + if (file->f_version != current->exec_id) {
62073 + gr_log_badprocpid("mem");
62074 + return 0;
62075 + }
62076 +#endif
62077 +
62078 if (!mm)
62079 return 0;
62080
62081 @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62082 goto free;
62083
62084 while (count > 0) {
62085 - int this_len = min_t(int, count, PAGE_SIZE);
62086 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
62087
62088 if (write && copy_from_user(page, buf, this_len)) {
62089 copied = -EFAULT;
62090 @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62091 if (!mm)
62092 return 0;
62093
62094 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62095 + if (file->f_version != current->exec_id) {
62096 + gr_log_badprocpid("environ");
62097 + return 0;
62098 + }
62099 +#endif
62100 +
62101 page = (char *)__get_free_page(GFP_TEMPORARY);
62102 if (!page)
62103 return -ENOMEM;
62104 @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62105 goto free;
62106 while (count > 0) {
62107 size_t this_len, max_len;
62108 - int retval;
62109 + ssize_t retval;
62110
62111 if (src >= (mm->env_end - mm->env_start))
62112 break;
62113 @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
62114 int error = -EACCES;
62115
62116 /* Are we allowed to snoop on the tasks file descriptors? */
62117 - if (!proc_fd_access_allowed(inode))
62118 + if (!proc_fd_access_allowed(inode, 0))
62119 goto out;
62120
62121 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62122 @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
62123 struct path path;
62124
62125 /* Are we allowed to snoop on the tasks file descriptors? */
62126 - if (!proc_fd_access_allowed(inode))
62127 - goto out;
62128 + /* logging this is needed for learning on chromium to work properly,
62129 + but we don't want to flood the logs from 'ps' which does a readlink
62130 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
62131 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
62132 + */
62133 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
62134 + if (!proc_fd_access_allowed(inode,0))
62135 + goto out;
62136 + } else {
62137 + if (!proc_fd_access_allowed(inode,1))
62138 + goto out;
62139 + }
62140
62141 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62142 if (error)
62143 @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
62144 rcu_read_lock();
62145 cred = __task_cred(task);
62146 inode->i_uid = cred->euid;
62147 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62148 + inode->i_gid = grsec_proc_gid;
62149 +#else
62150 inode->i_gid = cred->egid;
62151 +#endif
62152 rcu_read_unlock();
62153 }
62154 security_task_to_inode(task, inode);
62155 @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
62156 return -ENOENT;
62157 }
62158 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62159 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62160 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62161 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62162 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62163 +#endif
62164 task_dumpable(task)) {
62165 cred = __task_cred(task);
62166 stat->uid = cred->euid;
62167 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62168 + stat->gid = grsec_proc_gid;
62169 +#else
62170 stat->gid = cred->egid;
62171 +#endif
62172 }
62173 }
62174 rcu_read_unlock();
62175 @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
62176
62177 if (task) {
62178 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62179 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62180 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62181 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62182 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62183 +#endif
62184 task_dumpable(task)) {
62185 rcu_read_lock();
62186 cred = __task_cred(task);
62187 inode->i_uid = cred->euid;
62188 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62189 + inode->i_gid = grsec_proc_gid;
62190 +#else
62191 inode->i_gid = cred->egid;
62192 +#endif
62193 rcu_read_unlock();
62194 } else {
62195 inode->i_uid = GLOBAL_ROOT_UID;
62196 @@ -2172,6 +2290,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
62197 if (!task)
62198 goto out_no_task;
62199
62200 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62201 + goto out;
62202 +
62203 /*
62204 * Yes, it does not scale. And it should not. Don't add
62205 * new entries into /proc/<tgid>/ without very good reasons.
62206 @@ -2202,6 +2323,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
62207 if (!task)
62208 return -ENOENT;
62209
62210 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62211 + goto out;
62212 +
62213 if (!dir_emit_dots(file, ctx))
62214 goto out;
62215
62216 @@ -2591,7 +2715,7 @@ static const struct pid_entry tgid_base_stuff[] = {
62217 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
62218 #endif
62219 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
62220 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62221 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62222 INF("syscall", S_IRUGO, proc_pid_syscall),
62223 #endif
62224 INF("cmdline", S_IRUGO, proc_pid_cmdline),
62225 @@ -2616,10 +2740,10 @@ static const struct pid_entry tgid_base_stuff[] = {
62226 #ifdef CONFIG_SECURITY
62227 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
62228 #endif
62229 -#ifdef CONFIG_KALLSYMS
62230 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62231 INF("wchan", S_IRUGO, proc_pid_wchan),
62232 #endif
62233 -#ifdef CONFIG_STACKTRACE
62234 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62235 ONE("stack", S_IRUGO, proc_pid_stack),
62236 #endif
62237 #ifdef CONFIG_SCHEDSTATS
62238 @@ -2653,6 +2777,9 @@ static const struct pid_entry tgid_base_stuff[] = {
62239 #ifdef CONFIG_HARDWALL
62240 INF("hardwall", S_IRUGO, proc_pid_hardwall),
62241 #endif
62242 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62243 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
62244 +#endif
62245 #ifdef CONFIG_USER_NS
62246 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
62247 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
62248 @@ -2783,7 +2910,14 @@ static int proc_pid_instantiate(struct inode *dir,
62249 if (!inode)
62250 goto out;
62251
62252 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62253 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
62254 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62255 + inode->i_gid = grsec_proc_gid;
62256 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
62257 +#else
62258 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
62259 +#endif
62260 inode->i_op = &proc_tgid_base_inode_operations;
62261 inode->i_fop = &proc_tgid_base_operations;
62262 inode->i_flags|=S_IMMUTABLE;
62263 @@ -2821,7 +2955,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
62264 if (!task)
62265 goto out;
62266
62267 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62268 + goto out_put_task;
62269 +
62270 result = proc_pid_instantiate(dir, dentry, task, NULL);
62271 +out_put_task:
62272 put_task_struct(task);
62273 out:
62274 return ERR_PTR(result);
62275 @@ -2927,7 +3065,7 @@ static const struct pid_entry tid_base_stuff[] = {
62276 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
62277 #endif
62278 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
62279 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62280 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62281 INF("syscall", S_IRUGO, proc_pid_syscall),
62282 #endif
62283 INF("cmdline", S_IRUGO, proc_pid_cmdline),
62284 @@ -2954,10 +3092,10 @@ static const struct pid_entry tid_base_stuff[] = {
62285 #ifdef CONFIG_SECURITY
62286 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
62287 #endif
62288 -#ifdef CONFIG_KALLSYMS
62289 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62290 INF("wchan", S_IRUGO, proc_pid_wchan),
62291 #endif
62292 -#ifdef CONFIG_STACKTRACE
62293 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62294 ONE("stack", S_IRUGO, proc_pid_stack),
62295 #endif
62296 #ifdef CONFIG_SCHEDSTATS
62297 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
62298 index 82676e3..5f8518a 100644
62299 --- a/fs/proc/cmdline.c
62300 +++ b/fs/proc/cmdline.c
62301 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
62302
62303 static int __init proc_cmdline_init(void)
62304 {
62305 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62306 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
62307 +#else
62308 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
62309 +#endif
62310 return 0;
62311 }
62312 module_init(proc_cmdline_init);
62313 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
62314 index b143471..bb105e5 100644
62315 --- a/fs/proc/devices.c
62316 +++ b/fs/proc/devices.c
62317 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
62318
62319 static int __init proc_devices_init(void)
62320 {
62321 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62322 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
62323 +#else
62324 proc_create("devices", 0, NULL, &proc_devinfo_operations);
62325 +#endif
62326 return 0;
62327 }
62328 module_init(proc_devices_init);
62329 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
62330 index 985ea88..d118a0a 100644
62331 --- a/fs/proc/fd.c
62332 +++ b/fs/proc/fd.c
62333 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
62334 if (!task)
62335 return -ENOENT;
62336
62337 - files = get_files_struct(task);
62338 + if (!gr_acl_handle_procpidmem(task))
62339 + files = get_files_struct(task);
62340 put_task_struct(task);
62341
62342 if (files) {
62343 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
62344 */
62345 int proc_fd_permission(struct inode *inode, int mask)
62346 {
62347 + struct task_struct *task;
62348 int rv = generic_permission(inode, mask);
62349 - if (rv == 0)
62350 - return 0;
62351 +
62352 if (task_tgid(current) == proc_pid(inode))
62353 rv = 0;
62354 +
62355 + task = get_proc_task(inode);
62356 + if (task == NULL)
62357 + return rv;
62358 +
62359 + if (gr_acl_handle_procpidmem(task))
62360 + rv = -EACCES;
62361 +
62362 + put_task_struct(task);
62363 +
62364 return rv;
62365 }
62366
62367 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
62368 index 124fc43..8afbb02 100644
62369 --- a/fs/proc/inode.c
62370 +++ b/fs/proc/inode.c
62371 @@ -23,11 +23,17 @@
62372 #include <linux/slab.h>
62373 #include <linux/mount.h>
62374 #include <linux/magic.h>
62375 +#include <linux/grsecurity.h>
62376
62377 #include <asm/uaccess.h>
62378
62379 #include "internal.h"
62380
62381 +#ifdef CONFIG_PROC_SYSCTL
62382 +extern const struct inode_operations proc_sys_inode_operations;
62383 +extern const struct inode_operations proc_sys_dir_operations;
62384 +#endif
62385 +
62386 static void proc_evict_inode(struct inode *inode)
62387 {
62388 struct proc_dir_entry *de;
62389 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
62390 ns = PROC_I(inode)->ns.ns;
62391 if (ns_ops && ns)
62392 ns_ops->put(ns);
62393 +
62394 +#ifdef CONFIG_PROC_SYSCTL
62395 + if (inode->i_op == &proc_sys_inode_operations ||
62396 + inode->i_op == &proc_sys_dir_operations)
62397 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
62398 +#endif
62399 +
62400 }
62401
62402 static struct kmem_cache * proc_inode_cachep;
62403 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
62404 if (de->mode) {
62405 inode->i_mode = de->mode;
62406 inode->i_uid = de->uid;
62407 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62408 + inode->i_gid = grsec_proc_gid;
62409 +#else
62410 inode->i_gid = de->gid;
62411 +#endif
62412 }
62413 if (de->size)
62414 inode->i_size = de->size;
62415 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
62416 index 651d09a..3d7f0bf 100644
62417 --- a/fs/proc/internal.h
62418 +++ b/fs/proc/internal.h
62419 @@ -48,7 +48,7 @@ struct proc_dir_entry {
62420 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
62421 u8 namelen;
62422 char name[];
62423 -};
62424 +} __randomize_layout;
62425
62426 union proc_op {
62427 int (*proc_get_link)(struct dentry *, struct path *);
62428 @@ -67,7 +67,7 @@ struct proc_inode {
62429 struct ctl_table *sysctl_entry;
62430 struct proc_ns ns;
62431 struct inode vfs_inode;
62432 -};
62433 +} __randomize_layout;
62434
62435 /*
62436 * General functions
62437 @@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
62438 struct pid *, struct task_struct *);
62439 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
62440 struct pid *, struct task_struct *);
62441 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62442 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
62443 +#endif
62444
62445 /*
62446 * base.c
62447 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
62448 index 05029c0..7ea1987 100644
62449 --- a/fs/proc/interrupts.c
62450 +++ b/fs/proc/interrupts.c
62451 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
62452
62453 static int __init proc_interrupts_init(void)
62454 {
62455 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62456 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
62457 +#else
62458 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
62459 +#endif
62460 return 0;
62461 }
62462 module_init(proc_interrupts_init);
62463 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
62464 index 5ed0e52..a1c1f2e 100644
62465 --- a/fs/proc/kcore.c
62466 +++ b/fs/proc/kcore.c
62467 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62468 * the addresses in the elf_phdr on our list.
62469 */
62470 start = kc_offset_to_vaddr(*fpos - elf_buflen);
62471 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
62472 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
62473 + if (tsz > buflen)
62474 tsz = buflen;
62475 -
62476 +
62477 while (buflen) {
62478 struct kcore_list *m;
62479
62480 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62481 kfree(elf_buf);
62482 } else {
62483 if (kern_addr_valid(start)) {
62484 - unsigned long n;
62485 + char *elf_buf;
62486 + mm_segment_t oldfs;
62487
62488 - n = copy_to_user(buffer, (char *)start, tsz);
62489 - /*
62490 - * We cannot distinguish between fault on source
62491 - * and fault on destination. When this happens
62492 - * we clear too and hope it will trigger the
62493 - * EFAULT again.
62494 - */
62495 - if (n) {
62496 - if (clear_user(buffer + tsz - n,
62497 - n))
62498 + elf_buf = kmalloc(tsz, GFP_KERNEL);
62499 + if (!elf_buf)
62500 + return -ENOMEM;
62501 + oldfs = get_fs();
62502 + set_fs(KERNEL_DS);
62503 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
62504 + set_fs(oldfs);
62505 + if (copy_to_user(buffer, elf_buf, tsz)) {
62506 + kfree(elf_buf);
62507 return -EFAULT;
62508 + }
62509 }
62510 + set_fs(oldfs);
62511 + kfree(elf_buf);
62512 } else {
62513 if (clear_user(buffer, tsz))
62514 return -EFAULT;
62515 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62516
62517 static int open_kcore(struct inode *inode, struct file *filp)
62518 {
62519 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
62520 + return -EPERM;
62521 +#endif
62522 if (!capable(CAP_SYS_RAWIO))
62523 return -EPERM;
62524 if (kcore_need_update)
62525 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
62526 index a77d2b2..a9153f0 100644
62527 --- a/fs/proc/meminfo.c
62528 +++ b/fs/proc/meminfo.c
62529 @@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
62530 vmi.used >> 10,
62531 vmi.largest_chunk >> 10
62532 #ifdef CONFIG_MEMORY_FAILURE
62533 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62534 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62535 #endif
62536 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
62537 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
62538 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
62539 index 5f9bc8a..5c35f08 100644
62540 --- a/fs/proc/nommu.c
62541 +++ b/fs/proc/nommu.c
62542 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
62543
62544 if (file) {
62545 seq_pad(m, ' ');
62546 - seq_path(m, &file->f_path, "");
62547 + seq_path(m, &file->f_path, "\n\\");
62548 }
62549
62550 seq_putc(m, '\n');
62551 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
62552 index 4677bb7..408e936 100644
62553 --- a/fs/proc/proc_net.c
62554 +++ b/fs/proc/proc_net.c
62555 @@ -23,6 +23,7 @@
62556 #include <linux/nsproxy.h>
62557 #include <net/net_namespace.h>
62558 #include <linux/seq_file.h>
62559 +#include <linux/grsecurity.h>
62560
62561 #include "internal.h"
62562
62563 @@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
62564 struct task_struct *task;
62565 struct nsproxy *ns;
62566 struct net *net = NULL;
62567 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62568 + const struct cred *cred = current_cred();
62569 +#endif
62570 +
62571 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62572 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
62573 + return net;
62574 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62575 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
62576 + return net;
62577 +#endif
62578
62579 rcu_read_lock();
62580 task = pid_task(proc_pid(dir), PIDTYPE_PID);
62581 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
62582 index 7129046..6914844 100644
62583 --- a/fs/proc/proc_sysctl.c
62584 +++ b/fs/proc/proc_sysctl.c
62585 @@ -11,13 +11,21 @@
62586 #include <linux/namei.h>
62587 #include <linux/mm.h>
62588 #include <linux/module.h>
62589 +#include <linux/nsproxy.h>
62590 +#ifdef CONFIG_GRKERNSEC
62591 +#include <net/net_namespace.h>
62592 +#endif
62593 #include "internal.h"
62594
62595 +extern int gr_handle_chroot_sysctl(const int op);
62596 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
62597 + const int op);
62598 +
62599 static const struct dentry_operations proc_sys_dentry_operations;
62600 static const struct file_operations proc_sys_file_operations;
62601 -static const struct inode_operations proc_sys_inode_operations;
62602 +const struct inode_operations proc_sys_inode_operations;
62603 static const struct file_operations proc_sys_dir_file_operations;
62604 -static const struct inode_operations proc_sys_dir_operations;
62605 +const struct inode_operations proc_sys_dir_operations;
62606
62607 void proc_sys_poll_notify(struct ctl_table_poll *poll)
62608 {
62609 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
62610
62611 err = NULL;
62612 d_set_d_op(dentry, &proc_sys_dentry_operations);
62613 +
62614 + gr_handle_proc_create(dentry, inode);
62615 +
62616 d_add(dentry, inode);
62617
62618 out:
62619 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62620 struct inode *inode = file_inode(filp);
62621 struct ctl_table_header *head = grab_header(inode);
62622 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
62623 + int op = write ? MAY_WRITE : MAY_READ;
62624 ssize_t error;
62625 size_t res;
62626
62627 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62628 * and won't be until we finish.
62629 */
62630 error = -EPERM;
62631 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
62632 + if (sysctl_perm(head, table, op))
62633 goto out;
62634
62635 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
62636 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62637 if (!table->proc_handler)
62638 goto out;
62639
62640 +#ifdef CONFIG_GRKERNSEC
62641 + error = -EPERM;
62642 + if (gr_handle_chroot_sysctl(op))
62643 + goto out;
62644 + dget(filp->f_path.dentry);
62645 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
62646 + dput(filp->f_path.dentry);
62647 + goto out;
62648 + }
62649 + dput(filp->f_path.dentry);
62650 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
62651 + goto out;
62652 + if (write) {
62653 + if (current->nsproxy->net_ns != table->extra2) {
62654 + if (!capable(CAP_SYS_ADMIN))
62655 + goto out;
62656 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
62657 + goto out;
62658 + }
62659 +#endif
62660 +
62661 /* careful: calling conventions are nasty here */
62662 res = count;
62663 error = table->proc_handler(table, write, buf, &res, ppos);
62664 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
62665 return false;
62666 } else {
62667 d_set_d_op(child, &proc_sys_dentry_operations);
62668 +
62669 + gr_handle_proc_create(child, inode);
62670 +
62671 d_add(child, inode);
62672 }
62673 } else {
62674 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
62675 if ((*pos)++ < ctx->pos)
62676 return true;
62677
62678 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
62679 + return 0;
62680 +
62681 if (unlikely(S_ISLNK(table->mode)))
62682 res = proc_sys_link_fill_cache(file, ctx, head, table);
62683 else
62684 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
62685 if (IS_ERR(head))
62686 return PTR_ERR(head);
62687
62688 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
62689 + return -ENOENT;
62690 +
62691 generic_fillattr(inode, stat);
62692 if (table)
62693 stat->mode = (stat->mode & S_IFMT) | table->mode;
62694 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
62695 .llseek = generic_file_llseek,
62696 };
62697
62698 -static const struct inode_operations proc_sys_inode_operations = {
62699 +const struct inode_operations proc_sys_inode_operations = {
62700 .permission = proc_sys_permission,
62701 .setattr = proc_sys_setattr,
62702 .getattr = proc_sys_getattr,
62703 };
62704
62705 -static const struct inode_operations proc_sys_dir_operations = {
62706 +const struct inode_operations proc_sys_dir_operations = {
62707 .lookup = proc_sys_lookup,
62708 .permission = proc_sys_permission,
62709 .setattr = proc_sys_setattr,
62710 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
62711 static struct ctl_dir *new_dir(struct ctl_table_set *set,
62712 const char *name, int namelen)
62713 {
62714 - struct ctl_table *table;
62715 + ctl_table_no_const *table;
62716 struct ctl_dir *new;
62717 struct ctl_node *node;
62718 char *new_name;
62719 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
62720 return NULL;
62721
62722 node = (struct ctl_node *)(new + 1);
62723 - table = (struct ctl_table *)(node + 1);
62724 + table = (ctl_table_no_const *)(node + 1);
62725 new_name = (char *)(table + 2);
62726 memcpy(new_name, name, namelen);
62727 new_name[namelen] = '\0';
62728 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
62729 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
62730 struct ctl_table_root *link_root)
62731 {
62732 - struct ctl_table *link_table, *entry, *link;
62733 + ctl_table_no_const *link_table, *link;
62734 + struct ctl_table *entry;
62735 struct ctl_table_header *links;
62736 struct ctl_node *node;
62737 char *link_name;
62738 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
62739 return NULL;
62740
62741 node = (struct ctl_node *)(links + 1);
62742 - link_table = (struct ctl_table *)(node + nr_entries);
62743 + link_table = (ctl_table_no_const *)(node + nr_entries);
62744 link_name = (char *)&link_table[nr_entries + 1];
62745
62746 for (link = link_table, entry = table; entry->procname; link++, entry++) {
62747 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62748 struct ctl_table_header ***subheader, struct ctl_table_set *set,
62749 struct ctl_table *table)
62750 {
62751 - struct ctl_table *ctl_table_arg = NULL;
62752 - struct ctl_table *entry, *files;
62753 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
62754 + struct ctl_table *entry;
62755 int nr_files = 0;
62756 int nr_dirs = 0;
62757 int err = -ENOMEM;
62758 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62759 nr_files++;
62760 }
62761
62762 - files = table;
62763 /* If there are mixed files and directories we need a new table */
62764 if (nr_dirs && nr_files) {
62765 - struct ctl_table *new;
62766 + ctl_table_no_const *new;
62767 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
62768 GFP_KERNEL);
62769 if (!files)
62770 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62771 /* Register everything except a directory full of subdirectories */
62772 if (nr_files || !nr_dirs) {
62773 struct ctl_table_header *header;
62774 - header = __register_sysctl_table(set, path, files);
62775 + header = __register_sysctl_table(set, path, files ? files : table);
62776 if (!header) {
62777 kfree(ctl_table_arg);
62778 goto out;
62779 diff --git a/fs/proc/root.c b/fs/proc/root.c
62780 index 87dbcbe..55e1b4d 100644
62781 --- a/fs/proc/root.c
62782 +++ b/fs/proc/root.c
62783 @@ -186,7 +186,15 @@ void __init proc_root_init(void)
62784 #ifdef CONFIG_PROC_DEVICETREE
62785 proc_device_tree_init();
62786 #endif
62787 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62788 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62789 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
62790 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62791 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
62792 +#endif
62793 +#else
62794 proc_mkdir("bus", NULL);
62795 +#endif
62796 proc_sys_init();
62797 }
62798
62799 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
62800 index 1cf86c0..0ee1ca5 100644
62801 --- a/fs/proc/stat.c
62802 +++ b/fs/proc/stat.c
62803 @@ -11,6 +11,7 @@
62804 #include <linux/irqnr.h>
62805 #include <asm/cputime.h>
62806 #include <linux/tick.h>
62807 +#include <linux/grsecurity.h>
62808
62809 #ifndef arch_irq_stat_cpu
62810 #define arch_irq_stat_cpu(cpu) 0
62811 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
62812 u64 sum_softirq = 0;
62813 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
62814 struct timespec boottime;
62815 + int unrestricted = 1;
62816 +
62817 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62818 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62819 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
62820 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62821 + && !in_group_p(grsec_proc_gid)
62822 +#endif
62823 + )
62824 + unrestricted = 0;
62825 +#endif
62826 +#endif
62827
62828 user = nice = system = idle = iowait =
62829 irq = softirq = steal = 0;
62830 @@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
62831 getboottime(&boottime);
62832 jif = boottime.tv_sec;
62833
62834 + if (unrestricted) {
62835 for_each_possible_cpu(i) {
62836 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
62837 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62838 @@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
62839 }
62840 }
62841 sum += arch_irq_stat();
62842 + }
62843
62844 seq_puts(p, "cpu ");
62845 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62846 @@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
62847 seq_putc(p, '\n');
62848
62849 for_each_online_cpu(i) {
62850 + if (unrestricted) {
62851 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
62852 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
62853 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62854 @@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
62855 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
62856 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
62857 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
62858 + }
62859 seq_printf(p, "cpu%d", i);
62860 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62861 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
62862 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
62863
62864 /* sum again ? it could be updated? */
62865 for_each_irq_nr(j)
62866 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
62867 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
62868
62869 seq_printf(p,
62870 "\nctxt %llu\n"
62871 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
62872 "processes %lu\n"
62873 "procs_running %lu\n"
62874 "procs_blocked %lu\n",
62875 - nr_context_switches(),
62876 + unrestricted ? nr_context_switches() : 0ULL,
62877 (unsigned long)jif,
62878 - total_forks,
62879 - nr_running(),
62880 - nr_iowait());
62881 + unrestricted ? total_forks : 0UL,
62882 + unrestricted ? nr_running() : 0UL,
62883 + unrestricted ? nr_iowait() : 0UL);
62884
62885 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
62886
62887 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
62888 index fb52b54..5fc7c14 100644
62889 --- a/fs/proc/task_mmu.c
62890 +++ b/fs/proc/task_mmu.c
62891 @@ -12,12 +12,19 @@
62892 #include <linux/swap.h>
62893 #include <linux/swapops.h>
62894 #include <linux/mmu_notifier.h>
62895 +#include <linux/grsecurity.h>
62896
62897 #include <asm/elf.h>
62898 #include <asm/uaccess.h>
62899 #include <asm/tlbflush.h>
62900 #include "internal.h"
62901
62902 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62903 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62904 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62905 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62906 +#endif
62907 +
62908 void task_mem(struct seq_file *m, struct mm_struct *mm)
62909 {
62910 unsigned long data, text, lib, swap;
62911 @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
62912 "VmExe:\t%8lu kB\n"
62913 "VmLib:\t%8lu kB\n"
62914 "VmPTE:\t%8lu kB\n"
62915 - "VmSwap:\t%8lu kB\n",
62916 - hiwater_vm << (PAGE_SHIFT-10),
62917 + "VmSwap:\t%8lu kB\n"
62918 +
62919 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62920 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
62921 +#endif
62922 +
62923 + ,hiwater_vm << (PAGE_SHIFT-10),
62924 total_vm << (PAGE_SHIFT-10),
62925 mm->locked_vm << (PAGE_SHIFT-10),
62926 mm->pinned_vm << (PAGE_SHIFT-10),
62927 @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
62928 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
62929 (PTRS_PER_PTE * sizeof(pte_t) *
62930 atomic_long_read(&mm->nr_ptes)) >> 10,
62931 - swap << (PAGE_SHIFT-10));
62932 + swap << (PAGE_SHIFT-10)
62933 +
62934 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62935 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62936 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
62937 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
62938 +#else
62939 + , mm->context.user_cs_base
62940 + , mm->context.user_cs_limit
62941 +#endif
62942 +#endif
62943 +
62944 + );
62945 }
62946
62947 unsigned long task_vsize(struct mm_struct *mm)
62948 @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62949 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
62950 }
62951
62952 - /* We don't show the stack guard page in /proc/maps */
62953 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62954 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
62955 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
62956 +#else
62957 start = vma->vm_start;
62958 - if (stack_guard_page_start(vma, start))
62959 - start += PAGE_SIZE;
62960 end = vma->vm_end;
62961 - if (stack_guard_page_end(vma, end))
62962 - end -= PAGE_SIZE;
62963 +#endif
62964
62965 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
62966 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
62967 @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62968 flags & VM_WRITE ? 'w' : '-',
62969 flags & VM_EXEC ? 'x' : '-',
62970 flags & VM_MAYSHARE ? 's' : 'p',
62971 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62972 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
62973 +#else
62974 pgoff,
62975 +#endif
62976 MAJOR(dev), MINOR(dev), ino);
62977
62978 /*
62979 @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62980 */
62981 if (file) {
62982 seq_pad(m, ' ');
62983 - seq_path(m, &file->f_path, "\n");
62984 + seq_path(m, &file->f_path, "\n\\");
62985 goto done;
62986 }
62987
62988 @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
62989 * Thread stack in /proc/PID/task/TID/maps or
62990 * the main process stack.
62991 */
62992 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
62993 - vma->vm_end >= mm->start_stack)) {
62994 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
62995 + (vma->vm_start <= mm->start_stack &&
62996 + vma->vm_end >= mm->start_stack)) {
62997 name = "[stack]";
62998 } else {
62999 /* Thread stack in /proc/PID/maps */
63000 @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
63001 struct proc_maps_private *priv = m->private;
63002 struct task_struct *task = priv->task;
63003
63004 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63005 + if (current->exec_id != m->exec_id) {
63006 + gr_log_badprocpid("maps");
63007 + return 0;
63008 + }
63009 +#endif
63010 +
63011 show_map_vma(m, vma, is_pid);
63012
63013 if (m->count < m->size) /* vma is copied successfully */
63014 @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63015 .private = &mss,
63016 };
63017
63018 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63019 + if (current->exec_id != m->exec_id) {
63020 + gr_log_badprocpid("smaps");
63021 + return 0;
63022 + }
63023 +#endif
63024 memset(&mss, 0, sizeof mss);
63025 - mss.vma = vma;
63026 - /* mmap_sem is held in m_start */
63027 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63028 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63029 -
63030 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63031 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
63032 +#endif
63033 + mss.vma = vma;
63034 + /* mmap_sem is held in m_start */
63035 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63036 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63037 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63038 + }
63039 +#endif
63040 show_map_vma(m, vma, is_pid);
63041
63042 seq_printf(m,
63043 @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63044 "KernelPageSize: %8lu kB\n"
63045 "MMUPageSize: %8lu kB\n"
63046 "Locked: %8lu kB\n",
63047 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63048 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
63049 +#else
63050 (vma->vm_end - vma->vm_start) >> 10,
63051 +#endif
63052 mss.resident >> 10,
63053 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
63054 mss.shared_clean >> 10,
63055 @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63056 char buffer[64];
63057 int nid;
63058
63059 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63060 + if (current->exec_id != m->exec_id) {
63061 + gr_log_badprocpid("numa_maps");
63062 + return 0;
63063 + }
63064 +#endif
63065 +
63066 if (!mm)
63067 return 0;
63068
63069 @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63070 mpol_to_str(buffer, sizeof(buffer), pol);
63071 mpol_cond_put(pol);
63072
63073 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63074 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
63075 +#else
63076 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
63077 +#endif
63078
63079 if (file) {
63080 seq_printf(m, " file=");
63081 - seq_path(m, &file->f_path, "\n\t= ");
63082 + seq_path(m, &file->f_path, "\n\t\\= ");
63083 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
63084 seq_printf(m, " heap");
63085 } else {
63086 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
63087 index 678455d..ebd3245 100644
63088 --- a/fs/proc/task_nommu.c
63089 +++ b/fs/proc/task_nommu.c
63090 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63091 else
63092 bytes += kobjsize(mm);
63093
63094 - if (current->fs && current->fs->users > 1)
63095 + if (current->fs && atomic_read(&current->fs->users) > 1)
63096 sbytes += kobjsize(current->fs);
63097 else
63098 bytes += kobjsize(current->fs);
63099 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
63100
63101 if (file) {
63102 seq_pad(m, ' ');
63103 - seq_path(m, &file->f_path, "");
63104 + seq_path(m, &file->f_path, "\n\\");
63105 } else if (mm) {
63106 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
63107
63108 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
63109 index 9100d69..51cd925 100644
63110 --- a/fs/proc/vmcore.c
63111 +++ b/fs/proc/vmcore.c
63112 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
63113 nr_bytes = count;
63114
63115 /* If pfn is not ram, return zeros for sparse dump files */
63116 - if (pfn_is_ram(pfn) == 0)
63117 - memset(buf, 0, nr_bytes);
63118 - else {
63119 + if (pfn_is_ram(pfn) == 0) {
63120 + if (userbuf) {
63121 + if (clear_user((char __force_user *)buf, nr_bytes))
63122 + return -EFAULT;
63123 + } else
63124 + memset(buf, 0, nr_bytes);
63125 + } else {
63126 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
63127 offset, userbuf);
63128 if (tmp < 0)
63129 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
63130 static int copy_to(void *target, void *src, size_t size, int userbuf)
63131 {
63132 if (userbuf) {
63133 - if (copy_to_user((char __user *) target, src, size))
63134 + if (copy_to_user((char __force_user *) target, src, size))
63135 return -EFAULT;
63136 } else {
63137 memcpy(target, src, size);
63138 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63139 if (*fpos < m->offset + m->size) {
63140 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
63141 start = m->paddr + *fpos - m->offset;
63142 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
63143 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
63144 if (tmp < 0)
63145 return tmp;
63146 buflen -= tsz;
63147 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63148 static ssize_t read_vmcore(struct file *file, char __user *buffer,
63149 size_t buflen, loff_t *fpos)
63150 {
63151 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
63152 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
63153 }
63154
63155 /*
63156 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
63157 index b00fcc9..e0c6381 100644
63158 --- a/fs/qnx6/qnx6.h
63159 +++ b/fs/qnx6/qnx6.h
63160 @@ -74,7 +74,7 @@ enum {
63161 BYTESEX_BE,
63162 };
63163
63164 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63165 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63166 {
63167 if (sbi->s_bytesex == BYTESEX_LE)
63168 return le64_to_cpu((__force __le64)n);
63169 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
63170 return (__force __fs64)cpu_to_be64(n);
63171 }
63172
63173 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63174 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63175 {
63176 if (sbi->s_bytesex == BYTESEX_LE)
63177 return le32_to_cpu((__force __le32)n);
63178 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
63179 index 72d2917..c917c12 100644
63180 --- a/fs/quota/netlink.c
63181 +++ b/fs/quota/netlink.c
63182 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
63183 void quota_send_warning(struct kqid qid, dev_t dev,
63184 const char warntype)
63185 {
63186 - static atomic_t seq;
63187 + static atomic_unchecked_t seq;
63188 struct sk_buff *skb;
63189 void *msg_head;
63190 int ret;
63191 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
63192 "VFS: Not enough memory to send quota warning.\n");
63193 return;
63194 }
63195 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
63196 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
63197 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
63198 if (!msg_head) {
63199 printk(KERN_ERR
63200 diff --git a/fs/read_write.c b/fs/read_write.c
63201 index 58e440d..8ec2838 100644
63202 --- a/fs/read_write.c
63203 +++ b/fs/read_write.c
63204 @@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
63205
63206 old_fs = get_fs();
63207 set_fs(get_ds());
63208 - p = (__force const char __user *)buf;
63209 + p = (const char __force_user *)buf;
63210 if (count > MAX_RW_COUNT)
63211 count = MAX_RW_COUNT;
63212 if (file->f_op->write)
63213 diff --git a/fs/readdir.c b/fs/readdir.c
63214 index 5b53d99..a6c3049 100644
63215 --- a/fs/readdir.c
63216 +++ b/fs/readdir.c
63217 @@ -17,6 +17,7 @@
63218 #include <linux/security.h>
63219 #include <linux/syscalls.h>
63220 #include <linux/unistd.h>
63221 +#include <linux/namei.h>
63222
63223 #include <asm/uaccess.h>
63224
63225 @@ -69,6 +70,7 @@ struct old_linux_dirent {
63226 struct readdir_callback {
63227 struct dir_context ctx;
63228 struct old_linux_dirent __user * dirent;
63229 + struct file * file;
63230 int result;
63231 };
63232
63233 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
63234 buf->result = -EOVERFLOW;
63235 return -EOVERFLOW;
63236 }
63237 +
63238 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63239 + return 0;
63240 +
63241 buf->result++;
63242 dirent = buf->dirent;
63243 if (!access_ok(VERIFY_WRITE, dirent,
63244 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
63245 if (!f.file)
63246 return -EBADF;
63247
63248 + buf.file = f.file;
63249 error = iterate_dir(f.file, &buf.ctx);
63250 if (buf.result)
63251 error = buf.result;
63252 @@ -142,6 +149,7 @@ struct getdents_callback {
63253 struct dir_context ctx;
63254 struct linux_dirent __user * current_dir;
63255 struct linux_dirent __user * previous;
63256 + struct file * file;
63257 int count;
63258 int error;
63259 };
63260 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
63261 buf->error = -EOVERFLOW;
63262 return -EOVERFLOW;
63263 }
63264 +
63265 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63266 + return 0;
63267 +
63268 dirent = buf->previous;
63269 if (dirent) {
63270 if (__put_user(offset, &dirent->d_off))
63271 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
63272 if (!f.file)
63273 return -EBADF;
63274
63275 + buf.file = f.file;
63276 error = iterate_dir(f.file, &buf.ctx);
63277 if (error >= 0)
63278 error = buf.error;
63279 @@ -226,6 +239,7 @@ struct getdents_callback64 {
63280 struct dir_context ctx;
63281 struct linux_dirent64 __user * current_dir;
63282 struct linux_dirent64 __user * previous;
63283 + struct file *file;
63284 int count;
63285 int error;
63286 };
63287 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
63288 buf->error = -EINVAL; /* only used if we fail.. */
63289 if (reclen > buf->count)
63290 return -EINVAL;
63291 +
63292 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63293 + return 0;
63294 +
63295 dirent = buf->previous;
63296 if (dirent) {
63297 if (__put_user(offset, &dirent->d_off))
63298 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
63299 if (!f.file)
63300 return -EBADF;
63301
63302 + buf.file = f.file;
63303 error = iterate_dir(f.file, &buf.ctx);
63304 if (error >= 0)
63305 error = buf.error;
63306 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
63307 index 2b7882b..1c5ef48 100644
63308 --- a/fs/reiserfs/do_balan.c
63309 +++ b/fs/reiserfs/do_balan.c
63310 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
63311 return;
63312 }
63313
63314 - atomic_inc(&(fs_generation(tb->tb_sb)));
63315 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
63316 do_balance_starts(tb);
63317
63318 /* balance leaf returns 0 except if combining L R and S into
63319 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
63320 index ee382ef..f4eb6eb5 100644
63321 --- a/fs/reiserfs/item_ops.c
63322 +++ b/fs/reiserfs/item_ops.c
63323 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
63324 }
63325
63326 static struct item_operations errcatch_ops = {
63327 - errcatch_bytes_number,
63328 - errcatch_decrement_key,
63329 - errcatch_is_left_mergeable,
63330 - errcatch_print_item,
63331 - errcatch_check_item,
63332 + .bytes_number = errcatch_bytes_number,
63333 + .decrement_key = errcatch_decrement_key,
63334 + .is_left_mergeable = errcatch_is_left_mergeable,
63335 + .print_item = errcatch_print_item,
63336 + .check_item = errcatch_check_item,
63337
63338 - errcatch_create_vi,
63339 - errcatch_check_left,
63340 - errcatch_check_right,
63341 - errcatch_part_size,
63342 - errcatch_unit_num,
63343 - errcatch_print_vi
63344 + .create_vi = errcatch_create_vi,
63345 + .check_left = errcatch_check_left,
63346 + .check_right = errcatch_check_right,
63347 + .part_size = errcatch_part_size,
63348 + .unit_num = errcatch_unit_num,
63349 + .print_vi = errcatch_print_vi
63350 };
63351
63352 //////////////////////////////////////////////////////////////////////////////
63353 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
63354 index a958444..42b2323 100644
63355 --- a/fs/reiserfs/procfs.c
63356 +++ b/fs/reiserfs/procfs.c
63357 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
63358 "SMALL_TAILS " : "NO_TAILS ",
63359 replay_only(sb) ? "REPLAY_ONLY " : "",
63360 convert_reiserfs(sb) ? "CONV " : "",
63361 - atomic_read(&r->s_generation_counter),
63362 + atomic_read_unchecked(&r->s_generation_counter),
63363 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
63364 SF(s_do_balance), SF(s_unneeded_left_neighbor),
63365 SF(s_good_search_by_key_reada), SF(s_bmaps),
63366 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
63367 index f8adaee..0eeeeca 100644
63368 --- a/fs/reiserfs/reiserfs.h
63369 +++ b/fs/reiserfs/reiserfs.h
63370 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
63371 /* Comment? -Hans */
63372 wait_queue_head_t s_wait;
63373 /* To be obsoleted soon by per buffer seals.. -Hans */
63374 - atomic_t s_generation_counter; // increased by one every time the
63375 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63376 // tree gets re-balanced
63377 unsigned long s_properties; /* File system properties. Currently holds
63378 on-disk FS format */
63379 @@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63380 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63381
63382 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63383 -#define get_generation(s) atomic_read (&fs_generation(s))
63384 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63385 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63386 #define __fs_changed(gen,s) (gen != get_generation (s))
63387 #define fs_changed(gen,s) \
63388 diff --git a/fs/select.c b/fs/select.c
63389 index 467bb1c..cf9d65a 100644
63390 --- a/fs/select.c
63391 +++ b/fs/select.c
63392 @@ -20,6 +20,7 @@
63393 #include <linux/export.h>
63394 #include <linux/slab.h>
63395 #include <linux/poll.h>
63396 +#include <linux/security.h>
63397 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
63398 #include <linux/file.h>
63399 #include <linux/fdtable.h>
63400 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
63401 struct poll_list *walk = head;
63402 unsigned long todo = nfds;
63403
63404 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
63405 if (nfds > rlimit(RLIMIT_NOFILE))
63406 return -EINVAL;
63407
63408 diff --git a/fs/seq_file.c b/fs/seq_file.c
63409 index 1d641bb..e600623 100644
63410 --- a/fs/seq_file.c
63411 +++ b/fs/seq_file.c
63412 @@ -10,6 +10,7 @@
63413 #include <linux/seq_file.h>
63414 #include <linux/slab.h>
63415 #include <linux/cred.h>
63416 +#include <linux/sched.h>
63417
63418 #include <asm/uaccess.h>
63419 #include <asm/page.h>
63420 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
63421 #ifdef CONFIG_USER_NS
63422 p->user_ns = file->f_cred->user_ns;
63423 #endif
63424 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63425 + p->exec_id = current->exec_id;
63426 +#endif
63427
63428 /*
63429 * Wrappers around seq_open(e.g. swaps_open) need to be
63430 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
63431 return 0;
63432 }
63433 if (!m->buf) {
63434 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63435 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63436 if (!m->buf)
63437 return -ENOMEM;
63438 }
63439 @@ -137,7 +141,7 @@ Eoverflow:
63440 m->op->stop(m, p);
63441 kfree(m->buf);
63442 m->count = 0;
63443 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63444 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63445 return !m->buf ? -ENOMEM : -EAGAIN;
63446 }
63447
63448 @@ -153,7 +157,7 @@ Eoverflow:
63449 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63450 {
63451 struct seq_file *m = file->private_data;
63452 - size_t copied = 0;
63453 + ssize_t copied = 0;
63454 loff_t pos;
63455 size_t n;
63456 void *p;
63457 @@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63458
63459 /* grab buffer if we didn't have one */
63460 if (!m->buf) {
63461 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63462 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63463 if (!m->buf)
63464 goto Enomem;
63465 }
63466 @@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63467 m->op->stop(m, p);
63468 kfree(m->buf);
63469 m->count = 0;
63470 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63471 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63472 if (!m->buf)
63473 goto Enomem;
63474 m->version = 0;
63475 @@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
63476 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
63477 void *data)
63478 {
63479 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
63480 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
63481 int res = -ENOMEM;
63482
63483 if (op) {
63484 diff --git a/fs/splice.c b/fs/splice.c
63485 index 46a08f7..bb163cc 100644
63486 --- a/fs/splice.c
63487 +++ b/fs/splice.c
63488 @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63489 pipe_lock(pipe);
63490
63491 for (;;) {
63492 - if (!pipe->readers) {
63493 + if (!atomic_read(&pipe->readers)) {
63494 send_sig(SIGPIPE, current, 0);
63495 if (!ret)
63496 ret = -EPIPE;
63497 @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63498 page_nr++;
63499 ret += buf->len;
63500
63501 - if (pipe->files)
63502 + if (atomic_read(&pipe->files))
63503 do_wakeup = 1;
63504
63505 if (!--spd->nr_pages)
63506 @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63507 do_wakeup = 0;
63508 }
63509
63510 - pipe->waiting_writers++;
63511 + atomic_inc(&pipe->waiting_writers);
63512 pipe_wait(pipe);
63513 - pipe->waiting_writers--;
63514 + atomic_dec(&pipe->waiting_writers);
63515 }
63516
63517 pipe_unlock(pipe);
63518 @@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
63519 old_fs = get_fs();
63520 set_fs(get_ds());
63521 /* The cast to a user pointer is valid due to the set_fs() */
63522 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
63523 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
63524 set_fs(old_fs);
63525
63526 return res;
63527 @@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
63528 old_fs = get_fs();
63529 set_fs(get_ds());
63530 /* The cast to a user pointer is valid due to the set_fs() */
63531 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
63532 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
63533 set_fs(old_fs);
63534
63535 return res;
63536 @@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
63537 goto err;
63538
63539 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
63540 - vec[i].iov_base = (void __user *) page_address(page);
63541 + vec[i].iov_base = (void __force_user *) page_address(page);
63542 vec[i].iov_len = this_len;
63543 spd.pages[i] = page;
63544 spd.nr_pages++;
63545 @@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
63546 ops->release(pipe, buf);
63547 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
63548 pipe->nrbufs--;
63549 - if (pipe->files)
63550 + if (atomic_read(&pipe->files))
63551 sd->need_wakeup = true;
63552 }
63553
63554 @@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
63555 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
63556 {
63557 while (!pipe->nrbufs) {
63558 - if (!pipe->writers)
63559 + if (!atomic_read(&pipe->writers))
63560 return 0;
63561
63562 - if (!pipe->waiting_writers && sd->num_spliced)
63563 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
63564 return 0;
63565
63566 if (sd->flags & SPLICE_F_NONBLOCK)
63567 @@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
63568 * out of the pipe right after the splice_to_pipe(). So set
63569 * PIPE_READERS appropriately.
63570 */
63571 - pipe->readers = 1;
63572 + atomic_set(&pipe->readers, 1);
63573
63574 current->splice_pipe = pipe;
63575 }
63576 @@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
63577
63578 partial[buffers].offset = off;
63579 partial[buffers].len = plen;
63580 + partial[buffers].private = 0;
63581
63582 off = 0;
63583 len -= plen;
63584 @@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63585 ret = -ERESTARTSYS;
63586 break;
63587 }
63588 - if (!pipe->writers)
63589 + if (!atomic_read(&pipe->writers))
63590 break;
63591 - if (!pipe->waiting_writers) {
63592 + if (!atomic_read(&pipe->waiting_writers)) {
63593 if (flags & SPLICE_F_NONBLOCK) {
63594 ret = -EAGAIN;
63595 break;
63596 @@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63597 pipe_lock(pipe);
63598
63599 while (pipe->nrbufs >= pipe->buffers) {
63600 - if (!pipe->readers) {
63601 + if (!atomic_read(&pipe->readers)) {
63602 send_sig(SIGPIPE, current, 0);
63603 ret = -EPIPE;
63604 break;
63605 @@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63606 ret = -ERESTARTSYS;
63607 break;
63608 }
63609 - pipe->waiting_writers++;
63610 + atomic_inc(&pipe->waiting_writers);
63611 pipe_wait(pipe);
63612 - pipe->waiting_writers--;
63613 + atomic_dec(&pipe->waiting_writers);
63614 }
63615
63616 pipe_unlock(pipe);
63617 @@ -1862,14 +1863,14 @@ retry:
63618 pipe_double_lock(ipipe, opipe);
63619
63620 do {
63621 - if (!opipe->readers) {
63622 + if (!atomic_read(&opipe->readers)) {
63623 send_sig(SIGPIPE, current, 0);
63624 if (!ret)
63625 ret = -EPIPE;
63626 break;
63627 }
63628
63629 - if (!ipipe->nrbufs && !ipipe->writers)
63630 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
63631 break;
63632
63633 /*
63634 @@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63635 pipe_double_lock(ipipe, opipe);
63636
63637 do {
63638 - if (!opipe->readers) {
63639 + if (!atomic_read(&opipe->readers)) {
63640 send_sig(SIGPIPE, current, 0);
63641 if (!ret)
63642 ret = -EPIPE;
63643 @@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63644 * return EAGAIN if we have the potential of some data in the
63645 * future, otherwise just return 0
63646 */
63647 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
63648 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
63649 ret = -EAGAIN;
63650
63651 pipe_unlock(ipipe);
63652 diff --git a/fs/stat.c b/fs/stat.c
63653 index ae0c3ce..9ee641c 100644
63654 --- a/fs/stat.c
63655 +++ b/fs/stat.c
63656 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
63657 stat->gid = inode->i_gid;
63658 stat->rdev = inode->i_rdev;
63659 stat->size = i_size_read(inode);
63660 - stat->atime = inode->i_atime;
63661 - stat->mtime = inode->i_mtime;
63662 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63663 + stat->atime = inode->i_ctime;
63664 + stat->mtime = inode->i_ctime;
63665 + } else {
63666 + stat->atime = inode->i_atime;
63667 + stat->mtime = inode->i_mtime;
63668 + }
63669 stat->ctime = inode->i_ctime;
63670 stat->blksize = (1 << inode->i_blkbits);
63671 stat->blocks = inode->i_blocks;
63672 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
63673 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
63674 {
63675 struct inode *inode = path->dentry->d_inode;
63676 + int retval;
63677
63678 - if (inode->i_op->getattr)
63679 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
63680 + if (inode->i_op->getattr) {
63681 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
63682 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63683 + stat->atime = stat->ctime;
63684 + stat->mtime = stat->ctime;
63685 + }
63686 + return retval;
63687 + }
63688
63689 generic_fillattr(inode, stat);
63690 return 0;
63691 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
63692 index 5e73d66..4f165fd 100644
63693 --- a/fs/sysfs/dir.c
63694 +++ b/fs/sysfs/dir.c
63695 @@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
63696 *
63697 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63698 */
63699 -static unsigned int sysfs_name_hash(const char *name, const void *ns)
63700 +static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
63701 {
63702 unsigned long hash = init_name_hash();
63703 unsigned int len = strlen(name);
63704 @@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
63705 struct sysfs_dirent *sd;
63706 int rc;
63707
63708 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
63709 + const char *parent_name = parent_sd->s_name;
63710 +
63711 + mode = S_IFDIR | S_IRWXU;
63712 +
63713 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
63714 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
63715 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
63716 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
63717 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
63718 +#endif
63719 +
63720 /* allocate */
63721 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
63722 if (!sd)
63723 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
63724 index 35e7d08..4d6e676 100644
63725 --- a/fs/sysfs/file.c
63726 +++ b/fs/sysfs/file.c
63727 @@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
63728
63729 struct sysfs_open_dirent {
63730 atomic_t refcnt;
63731 - atomic_t event;
63732 + atomic_unchecked_t event;
63733 wait_queue_head_t poll;
63734 struct list_head files; /* goes through sysfs_open_file.list */
63735 };
63736 @@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
63737 return -ENODEV;
63738 }
63739
63740 - of->event = atomic_read(&of->sd->s_attr.open->event);
63741 + of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
63742
63743 /*
63744 * Lookup @ops and invoke show(). Control may reach here via seq
63745 @@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
63746 return ret;
63747 }
63748
63749 -static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
63750 - void *buf, int len, int write)
63751 +static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
63752 + void *buf, size_t len, int write)
63753 {
63754 struct file *file = vma->vm_file;
63755 struct sysfs_open_file *of = sysfs_of(file);
63756 - int ret;
63757 + ssize_t ret;
63758
63759 if (!of->vm_ops)
63760 return -EINVAL;
63761 @@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
63762 return -ENOMEM;
63763
63764 atomic_set(&new_od->refcnt, 0);
63765 - atomic_set(&new_od->event, 1);
63766 + atomic_set_unchecked(&new_od->event, 1);
63767 init_waitqueue_head(&new_od->poll);
63768 INIT_LIST_HEAD(&new_od->files);
63769 goto retry;
63770 @@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
63771
63772 sysfs_put_active(attr_sd);
63773
63774 - if (of->event != atomic_read(&od->event))
63775 + if (of->event != atomic_read_unchecked(&od->event))
63776 goto trigger;
63777
63778 return DEFAULT_POLLMASK;
63779 @@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
63780 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
63781 od = sd->s_attr.open;
63782 if (od) {
63783 - atomic_inc(&od->event);
63784 + atomic_inc_unchecked(&od->event);
63785 wake_up_interruptible(&od->poll);
63786 }
63787 }
63788 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
63789 index 3ae3f1b..081a26c 100644
63790 --- a/fs/sysfs/symlink.c
63791 +++ b/fs/sysfs/symlink.c
63792 @@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63793 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
63794 void *cookie)
63795 {
63796 - char *page = nd_get_link(nd);
63797 + const char *page = nd_get_link(nd);
63798 if (!IS_ERR(page))
63799 free_page((unsigned long)page);
63800 }
63801 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
63802 index 69d4889..a810bd4 100644
63803 --- a/fs/sysv/sysv.h
63804 +++ b/fs/sysv/sysv.h
63805 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
63806 #endif
63807 }
63808
63809 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63810 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63811 {
63812 if (sbi->s_bytesex == BYTESEX_PDP)
63813 return PDP_swab((__force __u32)n);
63814 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
63815 index e18b988..f1d4ad0f 100644
63816 --- a/fs/ubifs/io.c
63817 +++ b/fs/ubifs/io.c
63818 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
63819 return err;
63820 }
63821
63822 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63823 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63824 {
63825 int err;
63826
63827 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
63828 index c175b4d..8f36a16 100644
63829 --- a/fs/udf/misc.c
63830 +++ b/fs/udf/misc.c
63831 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
63832
63833 u8 udf_tag_checksum(const struct tag *t)
63834 {
63835 - u8 *data = (u8 *)t;
63836 + const u8 *data = (const u8 *)t;
63837 u8 checksum = 0;
63838 int i;
63839 for (i = 0; i < sizeof(struct tag); ++i)
63840 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
63841 index 8d974c4..b82f6ec 100644
63842 --- a/fs/ufs/swab.h
63843 +++ b/fs/ufs/swab.h
63844 @@ -22,7 +22,7 @@ enum {
63845 BYTESEX_BE
63846 };
63847
63848 -static inline u64
63849 +static inline u64 __intentional_overflow(-1)
63850 fs64_to_cpu(struct super_block *sbp, __fs64 n)
63851 {
63852 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63853 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
63854 return (__force __fs64)cpu_to_be64(n);
63855 }
63856
63857 -static inline u32
63858 +static inline u32 __intentional_overflow(-1)
63859 fs32_to_cpu(struct super_block *sbp, __fs32 n)
63860 {
63861 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63862 diff --git a/fs/utimes.c b/fs/utimes.c
63863 index aa138d6..5f3a811 100644
63864 --- a/fs/utimes.c
63865 +++ b/fs/utimes.c
63866 @@ -1,6 +1,7 @@
63867 #include <linux/compiler.h>
63868 #include <linux/file.h>
63869 #include <linux/fs.h>
63870 +#include <linux/security.h>
63871 #include <linux/linkage.h>
63872 #include <linux/mount.h>
63873 #include <linux/namei.h>
63874 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
63875 }
63876 }
63877 retry_deleg:
63878 +
63879 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
63880 + error = -EACCES;
63881 + goto mnt_drop_write_and_out;
63882 + }
63883 +
63884 mutex_lock(&inode->i_mutex);
63885 error = notify_change(path->dentry, &newattrs, &delegated_inode);
63886 mutex_unlock(&inode->i_mutex);
63887 diff --git a/fs/xattr.c b/fs/xattr.c
63888 index 3377dff..f394815 100644
63889 --- a/fs/xattr.c
63890 +++ b/fs/xattr.c
63891 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
63892 return rc;
63893 }
63894
63895 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
63896 +ssize_t
63897 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
63898 +{
63899 + struct inode *inode = dentry->d_inode;
63900 + ssize_t error;
63901 +
63902 + error = inode_permission(inode, MAY_EXEC);
63903 + if (error)
63904 + return error;
63905 +
63906 + if (inode->i_op->getxattr)
63907 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
63908 + else
63909 + error = -EOPNOTSUPP;
63910 +
63911 + return error;
63912 +}
63913 +EXPORT_SYMBOL(pax_getxattr);
63914 +#endif
63915 +
63916 ssize_t
63917 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
63918 {
63919 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
63920 * Extended attribute SET operations
63921 */
63922 static long
63923 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
63924 +setxattr(struct path *path, const char __user *name, const void __user *value,
63925 size_t size, int flags)
63926 {
63927 int error;
63928 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
63929 posix_acl_fix_xattr_from_user(kvalue, size);
63930 }
63931
63932 - error = vfs_setxattr(d, kname, kvalue, size, flags);
63933 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
63934 + error = -EACCES;
63935 + goto out;
63936 + }
63937 +
63938 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
63939 out:
63940 if (vvalue)
63941 vfree(vvalue);
63942 @@ -377,7 +403,7 @@ retry:
63943 return error;
63944 error = mnt_want_write(path.mnt);
63945 if (!error) {
63946 - error = setxattr(path.dentry, name, value, size, flags);
63947 + error = setxattr(&path, name, value, size, flags);
63948 mnt_drop_write(path.mnt);
63949 }
63950 path_put(&path);
63951 @@ -401,7 +427,7 @@ retry:
63952 return error;
63953 error = mnt_want_write(path.mnt);
63954 if (!error) {
63955 - error = setxattr(path.dentry, name, value, size, flags);
63956 + error = setxattr(&path, name, value, size, flags);
63957 mnt_drop_write(path.mnt);
63958 }
63959 path_put(&path);
63960 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
63961 const void __user *,value, size_t, size, int, flags)
63962 {
63963 struct fd f = fdget(fd);
63964 - struct dentry *dentry;
63965 int error = -EBADF;
63966
63967 if (!f.file)
63968 return error;
63969 - dentry = f.file->f_path.dentry;
63970 - audit_inode(NULL, dentry, 0);
63971 + audit_inode(NULL, f.file->f_path.dentry, 0);
63972 error = mnt_want_write_file(f.file);
63973 if (!error) {
63974 - error = setxattr(dentry, name, value, size, flags);
63975 + error = setxattr(&f.file->f_path, name, value, size, flags);
63976 mnt_drop_write_file(f.file);
63977 }
63978 fdput(f);
63979 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
63980 * Extended attribute REMOVE operations
63981 */
63982 static long
63983 -removexattr(struct dentry *d, const char __user *name)
63984 +removexattr(struct path *path, const char __user *name)
63985 {
63986 int error;
63987 char kname[XATTR_NAME_MAX + 1];
63988 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
63989 if (error < 0)
63990 return error;
63991
63992 - return vfs_removexattr(d, kname);
63993 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
63994 + return -EACCES;
63995 +
63996 + return vfs_removexattr(path->dentry, kname);
63997 }
63998
63999 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
64000 @@ -652,7 +679,7 @@ retry:
64001 return error;
64002 error = mnt_want_write(path.mnt);
64003 if (!error) {
64004 - error = removexattr(path.dentry, name);
64005 + error = removexattr(&path, name);
64006 mnt_drop_write(path.mnt);
64007 }
64008 path_put(&path);
64009 @@ -675,7 +702,7 @@ retry:
64010 return error;
64011 error = mnt_want_write(path.mnt);
64012 if (!error) {
64013 - error = removexattr(path.dentry, name);
64014 + error = removexattr(&path, name);
64015 mnt_drop_write(path.mnt);
64016 }
64017 path_put(&path);
64018 @@ -689,16 +716,16 @@ retry:
64019 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
64020 {
64021 struct fd f = fdget(fd);
64022 - struct dentry *dentry;
64023 + struct path *path;
64024 int error = -EBADF;
64025
64026 if (!f.file)
64027 return error;
64028 - dentry = f.file->f_path.dentry;
64029 - audit_inode(NULL, dentry, 0);
64030 + path = &f.file->f_path;
64031 + audit_inode(NULL, path->dentry, 0);
64032 error = mnt_want_write_file(f.file);
64033 if (!error) {
64034 - error = removexattr(dentry, name);
64035 + error = removexattr(path, name);
64036 mnt_drop_write_file(f.file);
64037 }
64038 fdput(f);
64039 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
64040 index 9fbea87..6b19972 100644
64041 --- a/fs/xattr_acl.c
64042 +++ b/fs/xattr_acl.c
64043 @@ -76,8 +76,8 @@ struct posix_acl *
64044 posix_acl_from_xattr(struct user_namespace *user_ns,
64045 const void *value, size_t size)
64046 {
64047 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
64048 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
64049 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
64050 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
64051 int count;
64052 struct posix_acl *acl;
64053 struct posix_acl_entry *acl_e;
64054 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
64055 index 3b2c14b..de031fe 100644
64056 --- a/fs/xfs/xfs_bmap.c
64057 +++ b/fs/xfs/xfs_bmap.c
64058 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
64059
64060 #else
64061 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
64062 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
64063 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
64064 #endif /* DEBUG */
64065
64066 /*
64067 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
64068 index c4e50c6..8ba93e3 100644
64069 --- a/fs/xfs/xfs_dir2_readdir.c
64070 +++ b/fs/xfs/xfs_dir2_readdir.c
64071 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
64072 ino = dp->d_ops->sf_get_ino(sfp, sfep);
64073 filetype = dp->d_ops->sf_get_ftype(sfep);
64074 ctx->pos = off & 0x7fffffff;
64075 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64076 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
64077 + char name[sfep->namelen];
64078 + memcpy(name, sfep->name, sfep->namelen);
64079 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
64080 + return 0;
64081 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64082 xfs_dir3_get_dtype(mp, filetype)))
64083 return 0;
64084 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
64085 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
64086 index 33ad9a7..82c18ba 100644
64087 --- a/fs/xfs/xfs_ioctl.c
64088 +++ b/fs/xfs/xfs_ioctl.c
64089 @@ -126,7 +126,7 @@ xfs_find_handle(
64090 }
64091
64092 error = -EFAULT;
64093 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
64094 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
64095 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
64096 goto out_put;
64097
64098 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
64099 index 104455b..764c512 100644
64100 --- a/fs/xfs/xfs_iops.c
64101 +++ b/fs/xfs/xfs_iops.c
64102 @@ -397,7 +397,7 @@ xfs_vn_put_link(
64103 struct nameidata *nd,
64104 void *p)
64105 {
64106 - char *s = nd_get_link(nd);
64107 + const char *s = nd_get_link(nd);
64108
64109 if (!IS_ERR(s))
64110 kfree(s);
64111 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
64112 new file mode 100644
64113 index 0000000..01d5523
64114 --- /dev/null
64115 +++ b/grsecurity/Kconfig
64116 @@ -0,0 +1,1147 @@
64117 +#
64118 +# grecurity configuration
64119 +#
64120 +menu "Memory Protections"
64121 +depends on GRKERNSEC
64122 +
64123 +config GRKERNSEC_KMEM
64124 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
64125 + default y if GRKERNSEC_CONFIG_AUTO
64126 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
64127 + help
64128 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
64129 + be written to or read from to modify or leak the contents of the running
64130 + kernel. /dev/port will also not be allowed to be opened, and support
64131 + for /dev/cpu/*/msr and kexec will be removed. If you have module
64132 + support disabled, enabling this will close up six ways that are
64133 + currently used to insert malicious code into the running kernel.
64134 +
64135 + Even with this feature enabled, we still highly recommend that
64136 + you use the RBAC system, as it is still possible for an attacker to
64137 + modify the running kernel through other more obscure methods.
64138 +
64139 + Enabling this feature will prevent the "cpupower" and "powertop" tools
64140 + from working.
64141 +
64142 + It is highly recommended that you say Y here if you meet all the
64143 + conditions above.
64144 +
64145 +config GRKERNSEC_VM86
64146 + bool "Restrict VM86 mode"
64147 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64148 + depends on X86_32
64149 +
64150 + help
64151 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
64152 + make use of a special execution mode on 32bit x86 processors called
64153 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
64154 + video cards and will still work with this option enabled. The purpose
64155 + of the option is to prevent exploitation of emulation errors in
64156 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
64157 + Nearly all users should be able to enable this option.
64158 +
64159 +config GRKERNSEC_IO
64160 + bool "Disable privileged I/O"
64161 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64162 + depends on X86
64163 + select RTC_CLASS
64164 + select RTC_INTF_DEV
64165 + select RTC_DRV_CMOS
64166 +
64167 + help
64168 + If you say Y here, all ioperm and iopl calls will return an error.
64169 + Ioperm and iopl can be used to modify the running kernel.
64170 + Unfortunately, some programs need this access to operate properly,
64171 + the most notable of which are XFree86 and hwclock. hwclock can be
64172 + remedied by having RTC support in the kernel, so real-time
64173 + clock support is enabled if this option is enabled, to ensure
64174 + that hwclock operates correctly.
64175 +
64176 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
64177 + you may not be able to boot into a graphical environment with this
64178 + option enabled. In this case, you should use the RBAC system instead.
64179 +
64180 +config GRKERNSEC_JIT_HARDEN
64181 + bool "Harden BPF JIT against spray attacks"
64182 + default y if GRKERNSEC_CONFIG_AUTO
64183 + depends on BPF_JIT && X86
64184 + help
64185 + If you say Y here, the native code generated by the kernel's Berkeley
64186 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
64187 + attacks that attempt to fit attacker-beneficial instructions in
64188 + 32bit immediate fields of JIT-generated native instructions. The
64189 + attacker will generally aim to cause an unintended instruction sequence
64190 + of JIT-generated native code to execute by jumping into the middle of
64191 + a generated instruction. This feature effectively randomizes the 32bit
64192 + immediate constants present in the generated code to thwart such attacks.
64193 +
64194 + If you're using KERNEXEC, it's recommended that you enable this option
64195 + to supplement the hardening of the kernel.
64196 +
64197 +config GRKERNSEC_PERF_HARDEN
64198 + bool "Disable unprivileged PERF_EVENTS usage by default"
64199 + default y if GRKERNSEC_CONFIG_AUTO
64200 + depends on PERF_EVENTS
64201 + help
64202 + If you say Y here, the range of acceptable values for the
64203 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
64204 + default to a new value: 3. When the sysctl is set to this value, no
64205 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
64206 +
64207 + Though PERF_EVENTS can be used legitimately for performance monitoring
64208 + and low-level application profiling, it is forced on regardless of
64209 + configuration, has been at fault for several vulnerabilities, and
64210 + creates new opportunities for side channels and other information leaks.
64211 +
64212 + This feature puts PERF_EVENTS into a secure default state and permits
64213 + the administrator to change out of it temporarily if unprivileged
64214 + application profiling is needed.
64215 +
64216 +config GRKERNSEC_RAND_THREADSTACK
64217 + bool "Insert random gaps between thread stacks"
64218 + default y if GRKERNSEC_CONFIG_AUTO
64219 + depends on PAX_RANDMMAP && !PPC
64220 + help
64221 + If you say Y here, a random-sized gap will be enforced between allocated
64222 + thread stacks. Glibc's NPTL and other threading libraries that
64223 + pass MAP_STACK to the kernel for thread stack allocation are supported.
64224 + The implementation currently provides 8 bits of entropy for the gap.
64225 +
64226 + Many distributions do not compile threaded remote services with the
64227 + -fstack-check argument to GCC, causing the variable-sized stack-based
64228 + allocator, alloca(), to not probe the stack on allocation. This
64229 + permits an unbounded alloca() to skip over any guard page and potentially
64230 + modify another thread's stack reliably. An enforced random gap
64231 + reduces the reliability of such an attack and increases the chance
64232 + that such a read/write to another thread's stack instead lands in
64233 + an unmapped area, causing a crash and triggering grsecurity's
64234 + anti-bruteforcing logic.
64235 +
64236 +config GRKERNSEC_PROC_MEMMAP
64237 + bool "Harden ASLR against information leaks and entropy reduction"
64238 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
64239 + depends on PAX_NOEXEC || PAX_ASLR
64240 + help
64241 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
64242 + give no information about the addresses of its mappings if
64243 + PaX features that rely on random addresses are enabled on the task.
64244 + In addition to sanitizing this information and disabling other
64245 + dangerous sources of information, this option causes reads of sensitive
64246 + /proc/<pid> entries where the file descriptor was opened in a different
64247 + task than the one performing the read. Such attempts are logged.
64248 + This option also limits argv/env strings for suid/sgid binaries
64249 + to 512KB to prevent a complete exhaustion of the stack entropy provided
64250 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
64251 + binaries to prevent alternative mmap layouts from being abused.
64252 +
64253 + If you use PaX it is essential that you say Y here as it closes up
64254 + several holes that make full ASLR useless locally.
64255 +
64256 +config GRKERNSEC_BRUTE
64257 + bool "Deter exploit bruteforcing"
64258 + default y if GRKERNSEC_CONFIG_AUTO
64259 + help
64260 + If you say Y here, attempts to bruteforce exploits against forking
64261 + daemons such as apache or sshd, as well as against suid/sgid binaries
64262 + will be deterred. When a child of a forking daemon is killed by PaX
64263 + or crashes due to an illegal instruction or other suspicious signal,
64264 + the parent process will be delayed 30 seconds upon every subsequent
64265 + fork until the administrator is able to assess the situation and
64266 + restart the daemon.
64267 + In the suid/sgid case, the attempt is logged, the user has all their
64268 + existing instances of the suid/sgid binary terminated and will
64269 + be unable to execute any suid/sgid binaries for 15 minutes.
64270 +
64271 + It is recommended that you also enable signal logging in the auditing
64272 + section so that logs are generated when a process triggers a suspicious
64273 + signal.
64274 + If the sysctl option is enabled, a sysctl option with name
64275 + "deter_bruteforce" is created.
64276 +
64277 +config GRKERNSEC_MODHARDEN
64278 + bool "Harden module auto-loading"
64279 + default y if GRKERNSEC_CONFIG_AUTO
64280 + depends on MODULES
64281 + help
64282 + If you say Y here, module auto-loading in response to use of some
64283 + feature implemented by an unloaded module will be restricted to
64284 + root users. Enabling this option helps defend against attacks
64285 + by unprivileged users who abuse the auto-loading behavior to
64286 + cause a vulnerable module to load that is then exploited.
64287 +
64288 + If this option prevents a legitimate use of auto-loading for a
64289 + non-root user, the administrator can execute modprobe manually
64290 + with the exact name of the module mentioned in the alert log.
64291 + Alternatively, the administrator can add the module to the list
64292 + of modules loaded at boot by modifying init scripts.
64293 +
64294 + Modification of init scripts will most likely be needed on
64295 + Ubuntu servers with encrypted home directory support enabled,
64296 + as the first non-root user logging in will cause the ecb(aes),
64297 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
64298 +
64299 +config GRKERNSEC_HIDESYM
64300 + bool "Hide kernel symbols"
64301 + default y if GRKERNSEC_CONFIG_AUTO
64302 + select PAX_USERCOPY_SLABS
64303 + help
64304 + If you say Y here, getting information on loaded modules, and
64305 + displaying all kernel symbols through a syscall will be restricted
64306 + to users with CAP_SYS_MODULE. For software compatibility reasons,
64307 + /proc/kallsyms will be restricted to the root user. The RBAC
64308 + system can hide that entry even from root.
64309 +
64310 + This option also prevents leaking of kernel addresses through
64311 + several /proc entries.
64312 +
64313 + Note that this option is only effective provided the following
64314 + conditions are met:
64315 + 1) The kernel using grsecurity is not precompiled by some distribution
64316 + 2) You have also enabled GRKERNSEC_DMESG
64317 + 3) You are using the RBAC system and hiding other files such as your
64318 + kernel image and System.map. Alternatively, enabling this option
64319 + causes the permissions on /boot, /lib/modules, and the kernel
64320 + source directory to change at compile time to prevent
64321 + reading by non-root users.
64322 + If the above conditions are met, this option will aid in providing a
64323 + useful protection against local kernel exploitation of overflows
64324 + and arbitrary read/write vulnerabilities.
64325 +
64326 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
64327 + in addition to this feature.
64328 +
64329 +config GRKERNSEC_RANDSTRUCT
64330 + bool "Randomize layout of sensitive kernel structures"
64331 + default y if GRKERNSEC_CONFIG_AUTO
64332 + select GRKERNSEC_HIDESYM
64333 + select MODVERSIONS if MODULES
64334 + help
64335 + If you say Y here, the layouts of a number of sensitive kernel
64336 + structures (task, fs, cred, etc) and all structures composed entirely
64337 + of function pointers (aka "ops" structs) will be randomized at compile-time.
64338 + This can introduce the requirement of an additional infoleak
64339 + vulnerability for exploits targeting these structure types.
64340 +
64341 + Enabling this feature will introduce some performance impact, slightly
64342 + increase memory usage, and prevent the use of forensic tools like
64343 + Volatility against the system (unless the kernel source tree isn't
64344 + cleaned after kernel installation).
64345 +
64346 + The seed used for compilation is located at tools/gcc/randstruct.seed.
64347 + It remains after a make clean to allow for external modules to be compiled
64348 + with the existing seed and will be removed by a make mrproper or
64349 + make distclean.
64350 +
64351 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
64352 + bool "Use cacheline-aware structure randomization"
64353 + depends on GRKERNSEC_RANDSTRUCT
64354 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
64355 + help
64356 + If you say Y here, the RANDSTRUCT randomization will make a best effort
64357 + at restricting randomization to cacheline-sized groups of elements. It
64358 + will further not randomize bitfields in structures. This reduces the
64359 + performance hit of RANDSTRUCT at the cost of weakened randomization.
64360 +
64361 +config GRKERNSEC_KERN_LOCKOUT
64362 + bool "Active kernel exploit response"
64363 + default y if GRKERNSEC_CONFIG_AUTO
64364 + depends on X86 || ARM || PPC || SPARC
64365 + help
64366 + If you say Y here, when a PaX alert is triggered due to suspicious
64367 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
64368 + or an OOPS occurs due to bad memory accesses, instead of just
64369 + terminating the offending process (and potentially allowing
64370 + a subsequent exploit from the same user), we will take one of two
64371 + actions:
64372 + If the user was root, we will panic the system
64373 + If the user was non-root, we will log the attempt, terminate
64374 + all processes owned by the user, then prevent them from creating
64375 + any new processes until the system is restarted
64376 + This deters repeated kernel exploitation/bruteforcing attempts
64377 + and is useful for later forensics.
64378 +
64379 +config GRKERNSEC_OLD_ARM_USERLAND
64380 + bool "Old ARM userland compatibility"
64381 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
64382 + help
64383 + If you say Y here, stubs of executable code to perform such operations
64384 + as "compare-exchange" will be placed at fixed locations in the ARM vector
64385 + table. This is unfortunately needed for old ARM userland meant to run
64386 + across a wide range of processors. Without this option enabled,
64387 + the get_tls and data memory barrier stubs will be emulated by the kernel,
64388 + which is enough for Linaro userlands or other userlands designed for v6
64389 + and newer ARM CPUs. It's recommended that you try without this option enabled
64390 + first, and only enable it if your userland does not boot (it will likely fail
64391 + at init time).
64392 +
64393 +endmenu
64394 +menu "Role Based Access Control Options"
64395 +depends on GRKERNSEC
64396 +
64397 +config GRKERNSEC_RBAC_DEBUG
64398 + bool
64399 +
64400 +config GRKERNSEC_NO_RBAC
64401 + bool "Disable RBAC system"
64402 + help
64403 + If you say Y here, the /dev/grsec device will be removed from the kernel,
64404 + preventing the RBAC system from being enabled. You should only say Y
64405 + here if you have no intention of using the RBAC system, so as to prevent
64406 + an attacker with root access from misusing the RBAC system to hide files
64407 + and processes when loadable module support and /dev/[k]mem have been
64408 + locked down.
64409 +
64410 +config GRKERNSEC_ACL_HIDEKERN
64411 + bool "Hide kernel processes"
64412 + help
64413 + If you say Y here, all kernel threads will be hidden to all
64414 + processes but those whose subject has the "view hidden processes"
64415 + flag.
64416 +
64417 +config GRKERNSEC_ACL_MAXTRIES
64418 + int "Maximum tries before password lockout"
64419 + default 3
64420 + help
64421 + This option enforces the maximum number of times a user can attempt
64422 + to authorize themselves with the grsecurity RBAC system before being
64423 + denied the ability to attempt authorization again for a specified time.
64424 + The lower the number, the harder it will be to brute-force a password.
64425 +
64426 +config GRKERNSEC_ACL_TIMEOUT
64427 + int "Time to wait after max password tries, in seconds"
64428 + default 30
64429 + help
64430 + This option specifies the time the user must wait after attempting to
64431 + authorize to the RBAC system with the maximum number of invalid
64432 + passwords. The higher the number, the harder it will be to brute-force
64433 + a password.
64434 +
64435 +endmenu
64436 +menu "Filesystem Protections"
64437 +depends on GRKERNSEC
64438 +
64439 +config GRKERNSEC_PROC
64440 + bool "Proc restrictions"
64441 + default y if GRKERNSEC_CONFIG_AUTO
64442 + help
64443 + If you say Y here, the permissions of the /proc filesystem
64444 + will be altered to enhance system security and privacy. You MUST
64445 + choose either a user only restriction or a user and group restriction.
64446 + Depending upon the option you choose, you can either restrict users to
64447 + see only the processes they themselves run, or choose a group that can
64448 + view all processes and files normally restricted to root if you choose
64449 + the "restrict to user only" option. NOTE: If you're running identd or
64450 + ntpd as a non-root user, you will have to run it as the group you
64451 + specify here.
64452 +
64453 +config GRKERNSEC_PROC_USER
64454 + bool "Restrict /proc to user only"
64455 + depends on GRKERNSEC_PROC
64456 + help
64457 + If you say Y here, non-root users will only be able to view their own
64458 + processes, and restricts them from viewing network-related information,
64459 + and viewing kernel symbol and module information.
64460 +
64461 +config GRKERNSEC_PROC_USERGROUP
64462 + bool "Allow special group"
64463 + default y if GRKERNSEC_CONFIG_AUTO
64464 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
64465 + help
64466 + If you say Y here, you will be able to select a group that will be
64467 + able to view all processes and network-related information. If you've
64468 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
64469 + remain hidden. This option is useful if you want to run identd as
64470 + a non-root user. The group you select may also be chosen at boot time
64471 + via "grsec_proc_gid=" on the kernel commandline.
64472 +
64473 +config GRKERNSEC_PROC_GID
64474 + int "GID for special group"
64475 + depends on GRKERNSEC_PROC_USERGROUP
64476 + default 1001
64477 +
64478 +config GRKERNSEC_PROC_ADD
64479 + bool "Additional restrictions"
64480 + default y if GRKERNSEC_CONFIG_AUTO
64481 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
64482 + help
64483 + If you say Y here, additional restrictions will be placed on
64484 + /proc that keep normal users from viewing device information and
64485 + slabinfo information that could be useful for exploits.
64486 +
64487 +config GRKERNSEC_LINK
64488 + bool "Linking restrictions"
64489 + default y if GRKERNSEC_CONFIG_AUTO
64490 + help
64491 + If you say Y here, /tmp race exploits will be prevented, since users
64492 + will no longer be able to follow symlinks owned by other users in
64493 + world-writable +t directories (e.g. /tmp), unless the owner of the
64494 + symlink is the owner of the directory. users will also not be
64495 + able to hardlink to files they do not own. If the sysctl option is
64496 + enabled, a sysctl option with name "linking_restrictions" is created.
64497 +
64498 +config GRKERNSEC_SYMLINKOWN
64499 + bool "Kernel-enforced SymlinksIfOwnerMatch"
64500 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64501 + help
64502 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
64503 + that prevents it from being used as a security feature. As Apache
64504 + verifies the symlink by performing a stat() against the target of
64505 + the symlink before it is followed, an attacker can setup a symlink
64506 + to point to a same-owned file, then replace the symlink with one
64507 + that targets another user's file just after Apache "validates" the
64508 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
64509 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
64510 + will be in place for the group you specify. If the sysctl option
64511 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
64512 + created.
64513 +
64514 +config GRKERNSEC_SYMLINKOWN_GID
64515 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
64516 + depends on GRKERNSEC_SYMLINKOWN
64517 + default 1006
64518 + help
64519 + Setting this GID determines what group kernel-enforced
64520 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
64521 + is enabled, a sysctl option with name "symlinkown_gid" is created.
64522 +
64523 +config GRKERNSEC_FIFO
64524 + bool "FIFO restrictions"
64525 + default y if GRKERNSEC_CONFIG_AUTO
64526 + help
64527 + If you say Y here, users will not be able to write to FIFOs they don't
64528 + own in world-writable +t directories (e.g. /tmp), unless the owner of
64529 + the FIFO is the same owner of the directory it's held in. If the sysctl
64530 + option is enabled, a sysctl option with name "fifo_restrictions" is
64531 + created.
64532 +
64533 +config GRKERNSEC_SYSFS_RESTRICT
64534 + bool "Sysfs/debugfs restriction"
64535 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64536 + depends on SYSFS
64537 + help
64538 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
64539 + any filesystem normally mounted under it (e.g. debugfs) will be
64540 + mostly accessible only by root. These filesystems generally provide access
64541 + to hardware and debug information that isn't appropriate for unprivileged
64542 + users of the system. Sysfs and debugfs have also become a large source
64543 + of new vulnerabilities, ranging from infoleaks to local compromise.
64544 + There has been very little oversight with an eye toward security involved
64545 + in adding new exporters of information to these filesystems, so their
64546 + use is discouraged.
64547 + For reasons of compatibility, a few directories have been whitelisted
64548 + for access by non-root users:
64549 + /sys/fs/selinux
64550 + /sys/fs/fuse
64551 + /sys/devices/system/cpu
64552 +
64553 +config GRKERNSEC_ROFS
64554 + bool "Runtime read-only mount protection"
64555 + depends on SYSCTL
64556 + help
64557 + If you say Y here, a sysctl option with name "romount_protect" will
64558 + be created. By setting this option to 1 at runtime, filesystems
64559 + will be protected in the following ways:
64560 + * No new writable mounts will be allowed
64561 + * Existing read-only mounts won't be able to be remounted read/write
64562 + * Write operations will be denied on all block devices
64563 + This option acts independently of grsec_lock: once it is set to 1,
64564 + it cannot be turned off. Therefore, please be mindful of the resulting
64565 + behavior if this option is enabled in an init script on a read-only
64566 + filesystem.
64567 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
64568 + and GRKERNSEC_IO should be enabled and module loading disabled via
64569 + config or at runtime.
64570 + This feature is mainly intended for secure embedded systems.
64571 +
64572 +
64573 +config GRKERNSEC_DEVICE_SIDECHANNEL
64574 + bool "Eliminate stat/notify-based device sidechannels"
64575 + default y if GRKERNSEC_CONFIG_AUTO
64576 + help
64577 + If you say Y here, timing analyses on block or character
64578 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
64579 + will be thwarted for unprivileged users. If a process without
64580 + CAP_MKNOD stats such a device, the last access and last modify times
64581 + will match the device's create time. No access or modify events
64582 + will be triggered through inotify/dnotify/fanotify for such devices.
64583 + This feature will prevent attacks that may at a minimum
64584 + allow an attacker to determine the administrator's password length.
64585 +
64586 +config GRKERNSEC_CHROOT
64587 + bool "Chroot jail restrictions"
64588 + default y if GRKERNSEC_CONFIG_AUTO
64589 + help
64590 + If you say Y here, you will be able to choose several options that will
64591 + make breaking out of a chrooted jail much more difficult. If you
64592 + encounter no software incompatibilities with the following options, it
64593 + is recommended that you enable each one.
64594 +
64595 +config GRKERNSEC_CHROOT_MOUNT
64596 + bool "Deny mounts"
64597 + default y if GRKERNSEC_CONFIG_AUTO
64598 + depends on GRKERNSEC_CHROOT
64599 + help
64600 + If you say Y here, processes inside a chroot will not be able to
64601 + mount or remount filesystems. If the sysctl option is enabled, a
64602 + sysctl option with name "chroot_deny_mount" is created.
64603 +
64604 +config GRKERNSEC_CHROOT_DOUBLE
64605 + bool "Deny double-chroots"
64606 + default y if GRKERNSEC_CONFIG_AUTO
64607 + depends on GRKERNSEC_CHROOT
64608 + help
64609 + If you say Y here, processes inside a chroot will not be able to chroot
64610 + again outside the chroot. This is a widely used method of breaking
64611 + out of a chroot jail and should not be allowed. If the sysctl
64612 + option is enabled, a sysctl option with name
64613 + "chroot_deny_chroot" is created.
64614 +
64615 +config GRKERNSEC_CHROOT_PIVOT
64616 + bool "Deny pivot_root in chroot"
64617 + default y if GRKERNSEC_CONFIG_AUTO
64618 + depends on GRKERNSEC_CHROOT
64619 + help
64620 + If you say Y here, processes inside a chroot will not be able to use
64621 + a function called pivot_root() that was introduced in Linux 2.3.41. It
64622 + works similar to chroot in that it changes the root filesystem. This
64623 + function could be misused in a chrooted process to attempt to break out
64624 + of the chroot, and therefore should not be allowed. If the sysctl
64625 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
64626 + created.
64627 +
64628 +config GRKERNSEC_CHROOT_CHDIR
64629 + bool "Enforce chdir(\"/\") on all chroots"
64630 + default y if GRKERNSEC_CONFIG_AUTO
64631 + depends on GRKERNSEC_CHROOT
64632 + help
64633 + If you say Y here, the current working directory of all newly-chrooted
64634 + applications will be set to the the root directory of the chroot.
64635 + The man page on chroot(2) states:
64636 + Note that this call does not change the current working
64637 + directory, so that `.' can be outside the tree rooted at
64638 + `/'. In particular, the super-user can escape from a
64639 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
64640 +
64641 + It is recommended that you say Y here, since it's not known to break
64642 + any software. If the sysctl option is enabled, a sysctl option with
64643 + name "chroot_enforce_chdir" is created.
64644 +
64645 +config GRKERNSEC_CHROOT_CHMOD
64646 + bool "Deny (f)chmod +s"
64647 + default y if GRKERNSEC_CONFIG_AUTO
64648 + depends on GRKERNSEC_CHROOT
64649 + help
64650 + If you say Y here, processes inside a chroot will not be able to chmod
64651 + or fchmod files to make them have suid or sgid bits. This protects
64652 + against another published method of breaking a chroot. If the sysctl
64653 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
64654 + created.
64655 +
64656 +config GRKERNSEC_CHROOT_FCHDIR
64657 + bool "Deny fchdir out of chroot"
64658 + default y if GRKERNSEC_CONFIG_AUTO
64659 + depends on GRKERNSEC_CHROOT
64660 + help
64661 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
64662 + to a file descriptor of the chrooting process that points to a directory
64663 + outside the filesystem will be stopped. If the sysctl option
64664 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
64665 +
64666 +config GRKERNSEC_CHROOT_MKNOD
64667 + bool "Deny mknod"
64668 + default y if GRKERNSEC_CONFIG_AUTO
64669 + depends on GRKERNSEC_CHROOT
64670 + help
64671 + If you say Y here, processes inside a chroot will not be allowed to
64672 + mknod. The problem with using mknod inside a chroot is that it
64673 + would allow an attacker to create a device entry that is the same
64674 + as one on the physical root of your system, which could range from
64675 + anything from the console device to a device for your harddrive (which
64676 + they could then use to wipe the drive or steal data). It is recommended
64677 + that you say Y here, unless you run into software incompatibilities.
64678 + If the sysctl option is enabled, a sysctl option with name
64679 + "chroot_deny_mknod" is created.
64680 +
64681 +config GRKERNSEC_CHROOT_SHMAT
64682 + bool "Deny shmat() out of chroot"
64683 + default y if GRKERNSEC_CONFIG_AUTO
64684 + depends on GRKERNSEC_CHROOT
64685 + help
64686 + If you say Y here, processes inside a chroot will not be able to attach
64687 + to shared memory segments that were created outside of the chroot jail.
64688 + It is recommended that you say Y here. If the sysctl option is enabled,
64689 + a sysctl option with name "chroot_deny_shmat" is created.
64690 +
64691 +config GRKERNSEC_CHROOT_UNIX
64692 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
64693 + default y if GRKERNSEC_CONFIG_AUTO
64694 + depends on GRKERNSEC_CHROOT
64695 + help
64696 + If you say Y here, processes inside a chroot will not be able to
64697 + connect to abstract (meaning not belonging to a filesystem) Unix
64698 + domain sockets that were bound outside of a chroot. It is recommended
64699 + that you say Y here. If the sysctl option is enabled, a sysctl option
64700 + with name "chroot_deny_unix" is created.
64701 +
64702 +config GRKERNSEC_CHROOT_FINDTASK
64703 + bool "Protect outside processes"
64704 + default y if GRKERNSEC_CONFIG_AUTO
64705 + depends on GRKERNSEC_CHROOT
64706 + help
64707 + If you say Y here, processes inside a chroot will not be able to
64708 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
64709 + getsid, or view any process outside of the chroot. If the sysctl
64710 + option is enabled, a sysctl option with name "chroot_findtask" is
64711 + created.
64712 +
64713 +config GRKERNSEC_CHROOT_NICE
64714 + bool "Restrict priority changes"
64715 + default y if GRKERNSEC_CONFIG_AUTO
64716 + depends on GRKERNSEC_CHROOT
64717 + help
64718 + If you say Y here, processes inside a chroot will not be able to raise
64719 + the priority of processes in the chroot, or alter the priority of
64720 + processes outside the chroot. This provides more security than simply
64721 + removing CAP_SYS_NICE from the process' capability set. If the
64722 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
64723 + is created.
64724 +
64725 +config GRKERNSEC_CHROOT_SYSCTL
64726 + bool "Deny sysctl writes"
64727 + default y if GRKERNSEC_CONFIG_AUTO
64728 + depends on GRKERNSEC_CHROOT
64729 + help
64730 + If you say Y here, an attacker in a chroot will not be able to
64731 + write to sysctl entries, either by sysctl(2) or through a /proc
64732 + interface. It is strongly recommended that you say Y here. If the
64733 + sysctl option is enabled, a sysctl option with name
64734 + "chroot_deny_sysctl" is created.
64735 +
64736 +config GRKERNSEC_CHROOT_CAPS
64737 + bool "Capability restrictions"
64738 + default y if GRKERNSEC_CONFIG_AUTO
64739 + depends on GRKERNSEC_CHROOT
64740 + help
64741 + If you say Y here, the capabilities on all processes within a
64742 + chroot jail will be lowered to stop module insertion, raw i/o,
64743 + system and net admin tasks, rebooting the system, modifying immutable
64744 + files, modifying IPC owned by another, and changing the system time.
64745 + This is left an option because it can break some apps. Disable this
64746 + if your chrooted apps are having problems performing those kinds of
64747 + tasks. If the sysctl option is enabled, a sysctl option with
64748 + name "chroot_caps" is created.
64749 +
64750 +config GRKERNSEC_CHROOT_INITRD
64751 + bool "Exempt initrd tasks from restrictions"
64752 + default y if GRKERNSEC_CONFIG_AUTO
64753 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
64754 + help
64755 + If you say Y here, tasks started prior to init will be exempted from
64756 + grsecurity's chroot restrictions. This option is mainly meant to
64757 + resolve Plymouth's performing privileged operations unnecessarily
64758 + in a chroot.
64759 +
64760 +endmenu
64761 +menu "Kernel Auditing"
64762 +depends on GRKERNSEC
64763 +
64764 +config GRKERNSEC_AUDIT_GROUP
64765 + bool "Single group for auditing"
64766 + help
64767 + If you say Y here, the exec and chdir logging features will only operate
64768 + on a group you specify. This option is recommended if you only want to
64769 + watch certain users instead of having a large amount of logs from the
64770 + entire system. If the sysctl option is enabled, a sysctl option with
64771 + name "audit_group" is created.
64772 +
64773 +config GRKERNSEC_AUDIT_GID
64774 + int "GID for auditing"
64775 + depends on GRKERNSEC_AUDIT_GROUP
64776 + default 1007
64777 +
64778 +config GRKERNSEC_EXECLOG
64779 + bool "Exec logging"
64780 + help
64781 + If you say Y here, all execve() calls will be logged (since the
64782 + other exec*() calls are frontends to execve(), all execution
64783 + will be logged). Useful for shell-servers that like to keep track
64784 + of their users. If the sysctl option is enabled, a sysctl option with
64785 + name "exec_logging" is created.
64786 + WARNING: This option when enabled will produce a LOT of logs, especially
64787 + on an active system.
64788 +
64789 +config GRKERNSEC_RESLOG
64790 + bool "Resource logging"
64791 + default y if GRKERNSEC_CONFIG_AUTO
64792 + help
64793 + If you say Y here, all attempts to overstep resource limits will
64794 + be logged with the resource name, the requested size, and the current
64795 + limit. It is highly recommended that you say Y here. If the sysctl
64796 + option is enabled, a sysctl option with name "resource_logging" is
64797 + created. If the RBAC system is enabled, the sysctl value is ignored.
64798 +
64799 +config GRKERNSEC_CHROOT_EXECLOG
64800 + bool "Log execs within chroot"
64801 + help
64802 + If you say Y here, all executions inside a chroot jail will be logged
64803 + to syslog. This can cause a large amount of logs if certain
64804 + applications (eg. djb's daemontools) are installed on the system, and
64805 + is therefore left as an option. If the sysctl option is enabled, a
64806 + sysctl option with name "chroot_execlog" is created.
64807 +
64808 +config GRKERNSEC_AUDIT_PTRACE
64809 + bool "Ptrace logging"
64810 + help
64811 + If you say Y here, all attempts to attach to a process via ptrace
64812 + will be logged. If the sysctl option is enabled, a sysctl option
64813 + with name "audit_ptrace" is created.
64814 +
64815 +config GRKERNSEC_AUDIT_CHDIR
64816 + bool "Chdir logging"
64817 + help
64818 + If you say Y here, all chdir() calls will be logged. If the sysctl
64819 + option is enabled, a sysctl option with name "audit_chdir" is created.
64820 +
64821 +config GRKERNSEC_AUDIT_MOUNT
64822 + bool "(Un)Mount logging"
64823 + help
64824 + If you say Y here, all mounts and unmounts will be logged. If the
64825 + sysctl option is enabled, a sysctl option with name "audit_mount" is
64826 + created.
64827 +
64828 +config GRKERNSEC_SIGNAL
64829 + bool "Signal logging"
64830 + default y if GRKERNSEC_CONFIG_AUTO
64831 + help
64832 + If you say Y here, certain important signals will be logged, such as
64833 + SIGSEGV, which will as a result inform you of when a error in a program
64834 + occurred, which in some cases could mean a possible exploit attempt.
64835 + If the sysctl option is enabled, a sysctl option with name
64836 + "signal_logging" is created.
64837 +
64838 +config GRKERNSEC_FORKFAIL
64839 + bool "Fork failure logging"
64840 + help
64841 + If you say Y here, all failed fork() attempts will be logged.
64842 + This could suggest a fork bomb, or someone attempting to overstep
64843 + their process limit. If the sysctl option is enabled, a sysctl option
64844 + with name "forkfail_logging" is created.
64845 +
64846 +config GRKERNSEC_TIME
64847 + bool "Time change logging"
64848 + default y if GRKERNSEC_CONFIG_AUTO
64849 + help
64850 + If you say Y here, any changes of the system clock will be logged.
64851 + If the sysctl option is enabled, a sysctl option with name
64852 + "timechange_logging" is created.
64853 +
64854 +config GRKERNSEC_PROC_IPADDR
64855 + bool "/proc/<pid>/ipaddr support"
64856 + default y if GRKERNSEC_CONFIG_AUTO
64857 + help
64858 + If you say Y here, a new entry will be added to each /proc/<pid>
64859 + directory that contains the IP address of the person using the task.
64860 + The IP is carried across local TCP and AF_UNIX stream sockets.
64861 + This information can be useful for IDS/IPSes to perform remote response
64862 + to a local attack. The entry is readable by only the owner of the
64863 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
64864 + the RBAC system), and thus does not create privacy concerns.
64865 +
64866 +config GRKERNSEC_RWXMAP_LOG
64867 + bool 'Denied RWX mmap/mprotect logging'
64868 + default y if GRKERNSEC_CONFIG_AUTO
64869 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
64870 + help
64871 + If you say Y here, calls to mmap() and mprotect() with explicit
64872 + usage of PROT_WRITE and PROT_EXEC together will be logged when
64873 + denied by the PAX_MPROTECT feature. This feature will also
64874 + log other problematic scenarios that can occur when PAX_MPROTECT
64875 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
64876 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
64877 + is created.
64878 +
64879 +endmenu
64880 +
64881 +menu "Executable Protections"
64882 +depends on GRKERNSEC
64883 +
64884 +config GRKERNSEC_DMESG
64885 + bool "Dmesg(8) restriction"
64886 + default y if GRKERNSEC_CONFIG_AUTO
64887 + help
64888 + If you say Y here, non-root users will not be able to use dmesg(8)
64889 + to view the contents of the kernel's circular log buffer.
64890 + The kernel's log buffer often contains kernel addresses and other
64891 + identifying information useful to an attacker in fingerprinting a
64892 + system for a targeted exploit.
64893 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
64894 + created.
64895 +
64896 +config GRKERNSEC_HARDEN_PTRACE
64897 + bool "Deter ptrace-based process snooping"
64898 + default y if GRKERNSEC_CONFIG_AUTO
64899 + help
64900 + If you say Y here, TTY sniffers and other malicious monitoring
64901 + programs implemented through ptrace will be defeated. If you
64902 + have been using the RBAC system, this option has already been
64903 + enabled for several years for all users, with the ability to make
64904 + fine-grained exceptions.
64905 +
64906 + This option only affects the ability of non-root users to ptrace
64907 + processes that are not a descendent of the ptracing process.
64908 + This means that strace ./binary and gdb ./binary will still work,
64909 + but attaching to arbitrary processes will not. If the sysctl
64910 + option is enabled, a sysctl option with name "harden_ptrace" is
64911 + created.
64912 +
64913 +config GRKERNSEC_PTRACE_READEXEC
64914 + bool "Require read access to ptrace sensitive binaries"
64915 + default y if GRKERNSEC_CONFIG_AUTO
64916 + help
64917 + If you say Y here, unprivileged users will not be able to ptrace unreadable
64918 + binaries. This option is useful in environments that
64919 + remove the read bits (e.g. file mode 4711) from suid binaries to
64920 + prevent infoleaking of their contents. This option adds
64921 + consistency to the use of that file mode, as the binary could normally
64922 + be read out when run without privileges while ptracing.
64923 +
64924 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
64925 + is created.
64926 +
64927 +config GRKERNSEC_SETXID
64928 + bool "Enforce consistent multithreaded privileges"
64929 + default y if GRKERNSEC_CONFIG_AUTO
64930 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
64931 + help
64932 + If you say Y here, a change from a root uid to a non-root uid
64933 + in a multithreaded application will cause the resulting uids,
64934 + gids, supplementary groups, and capabilities in that thread
64935 + to be propagated to the other threads of the process. In most
64936 + cases this is unnecessary, as glibc will emulate this behavior
64937 + on behalf of the application. Other libcs do not act in the
64938 + same way, allowing the other threads of the process to continue
64939 + running with root privileges. If the sysctl option is enabled,
64940 + a sysctl option with name "consistent_setxid" is created.
64941 +
64942 +config GRKERNSEC_HARDEN_IPC
64943 + bool "Disallow access to overly-permissive IPC objects"
64944 + default y if GRKERNSEC_CONFIG_AUTO
64945 + depends on SYSVIPC
64946 + help
64947 + If you say Y here, access to overly-permissive IPC objects (shared
64948 + memory, message queues, and semaphores) will be denied for processes
64949 + given the following criteria beyond normal permission checks:
64950 + 1) If the IPC object is world-accessible and the euid doesn't match
64951 + that of the creator or current uid for the IPC object
64952 + 2) If the IPC object is group-accessible and the egid doesn't
64953 + match that of the creator or current gid for the IPC object
64954 + It's a common error to grant too much permission to these objects,
64955 + with impact ranging from denial of service and information leaking to
64956 + privilege escalation. This feature was developed in response to
64957 + research by Tim Brown:
64958 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
64959 + who found hundreds of such insecure usages. Processes with
64960 + CAP_IPC_OWNER are still permitted to access these IPC objects.
64961 + If the sysctl option is enabled, a sysctl option with name
64962 + "harden_ipc" is created.
64963 +
64964 +config GRKERNSEC_TPE
64965 + bool "Trusted Path Execution (TPE)"
64966 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64967 + help
64968 + If you say Y here, you will be able to choose a gid to add to the
64969 + supplementary groups of users you want to mark as "untrusted."
64970 + These users will not be able to execute any files that are not in
64971 + root-owned directories writable only by root. If the sysctl option
64972 + is enabled, a sysctl option with name "tpe" is created.
64973 +
64974 +config GRKERNSEC_TPE_ALL
64975 + bool "Partially restrict all non-root users"
64976 + depends on GRKERNSEC_TPE
64977 + help
64978 + If you say Y here, all non-root users will be covered under
64979 + a weaker TPE restriction. This is separate from, and in addition to,
64980 + the main TPE options that you have selected elsewhere. Thus, if a
64981 + "trusted" GID is chosen, this restriction applies to even that GID.
64982 + Under this restriction, all non-root users will only be allowed to
64983 + execute files in directories they own that are not group or
64984 + world-writable, or in directories owned by root and writable only by
64985 + root. If the sysctl option is enabled, a sysctl option with name
64986 + "tpe_restrict_all" is created.
64987 +
64988 +config GRKERNSEC_TPE_INVERT
64989 + bool "Invert GID option"
64990 + depends on GRKERNSEC_TPE
64991 + help
64992 + If you say Y here, the group you specify in the TPE configuration will
64993 + decide what group TPE restrictions will be *disabled* for. This
64994 + option is useful if you want TPE restrictions to be applied to most
64995 + users on the system. If the sysctl option is enabled, a sysctl option
64996 + with name "tpe_invert" is created. Unlike other sysctl options, this
64997 + entry will default to on for backward-compatibility.
64998 +
64999 +config GRKERNSEC_TPE_GID
65000 + int
65001 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
65002 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
65003 +
65004 +config GRKERNSEC_TPE_UNTRUSTED_GID
65005 + int "GID for TPE-untrusted users"
65006 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
65007 + default 1005
65008 + help
65009 + Setting this GID determines what group TPE restrictions will be
65010 + *enabled* for. If the sysctl option is enabled, a sysctl option
65011 + with name "tpe_gid" is created.
65012 +
65013 +config GRKERNSEC_TPE_TRUSTED_GID
65014 + int "GID for TPE-trusted users"
65015 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
65016 + default 1005
65017 + help
65018 + Setting this GID determines what group TPE restrictions will be
65019 + *disabled* for. If the sysctl option is enabled, a sysctl option
65020 + with name "tpe_gid" is created.
65021 +
65022 +endmenu
65023 +menu "Network Protections"
65024 +depends on GRKERNSEC
65025 +
65026 +config GRKERNSEC_RANDNET
65027 + bool "Larger entropy pools"
65028 + default y if GRKERNSEC_CONFIG_AUTO
65029 + help
65030 + If you say Y here, the entropy pools used for many features of Linux
65031 + and grsecurity will be doubled in size. Since several grsecurity
65032 + features use additional randomness, it is recommended that you say Y
65033 + here. Saying Y here has a similar effect as modifying
65034 + /proc/sys/kernel/random/poolsize.
65035 +
65036 +config GRKERNSEC_BLACKHOLE
65037 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
65038 + default y if GRKERNSEC_CONFIG_AUTO
65039 + depends on NET
65040 + help
65041 + If you say Y here, neither TCP resets nor ICMP
65042 + destination-unreachable packets will be sent in response to packets
65043 + sent to ports for which no associated listening process exists.
65044 + This feature supports both IPV4 and IPV6 and exempts the
65045 + loopback interface from blackholing. Enabling this feature
65046 + makes a host more resilient to DoS attacks and reduces network
65047 + visibility against scanners.
65048 +
65049 + The blackhole feature as-implemented is equivalent to the FreeBSD
65050 + blackhole feature, as it prevents RST responses to all packets, not
65051 + just SYNs. Under most application behavior this causes no
65052 + problems, but applications (like haproxy) may not close certain
65053 + connections in a way that cleanly terminates them on the remote
65054 + end, leaving the remote host in LAST_ACK state. Because of this
65055 + side-effect and to prevent intentional LAST_ACK DoSes, this
65056 + feature also adds automatic mitigation against such attacks.
65057 + The mitigation drastically reduces the amount of time a socket
65058 + can spend in LAST_ACK state. If you're using haproxy and not
65059 + all servers it connects to have this option enabled, consider
65060 + disabling this feature on the haproxy host.
65061 +
65062 + If the sysctl option is enabled, two sysctl options with names
65063 + "ip_blackhole" and "lastack_retries" will be created.
65064 + While "ip_blackhole" takes the standard zero/non-zero on/off
65065 + toggle, "lastack_retries" uses the same kinds of values as
65066 + "tcp_retries1" and "tcp_retries2". The default value of 4
65067 + prevents a socket from lasting more than 45 seconds in LAST_ACK
65068 + state.
65069 +
65070 +config GRKERNSEC_NO_SIMULT_CONNECT
65071 + bool "Disable TCP Simultaneous Connect"
65072 + default y if GRKERNSEC_CONFIG_AUTO
65073 + depends on NET
65074 + help
65075 + If you say Y here, a feature by Willy Tarreau will be enabled that
65076 + removes a weakness in Linux's strict implementation of TCP that
65077 + allows two clients to connect to each other without either entering
65078 + a listening state. The weakness allows an attacker to easily prevent
65079 + a client from connecting to a known server provided the source port
65080 + for the connection is guessed correctly.
65081 +
65082 + As the weakness could be used to prevent an antivirus or IPS from
65083 + fetching updates, or prevent an SSL gateway from fetching a CRL,
65084 + it should be eliminated by enabling this option. Though Linux is
65085 + one of few operating systems supporting simultaneous connect, it
65086 + has no legitimate use in practice and is rarely supported by firewalls.
65087 +
65088 +config GRKERNSEC_SOCKET
65089 + bool "Socket restrictions"
65090 + depends on NET
65091 + help
65092 + If you say Y here, you will be able to choose from several options.
65093 + If you assign a GID on your system and add it to the supplementary
65094 + groups of users you want to restrict socket access to, this patch
65095 + will perform up to three things, based on the option(s) you choose.
65096 +
65097 +config GRKERNSEC_SOCKET_ALL
65098 + bool "Deny any sockets to group"
65099 + depends on GRKERNSEC_SOCKET
65100 + help
65101 + If you say Y here, you will be able to choose a GID of whose users will
65102 + be unable to connect to other hosts from your machine or run server
65103 + applications from your machine. If the sysctl option is enabled, a
65104 + sysctl option with name "socket_all" is created.
65105 +
65106 +config GRKERNSEC_SOCKET_ALL_GID
65107 + int "GID to deny all sockets for"
65108 + depends on GRKERNSEC_SOCKET_ALL
65109 + default 1004
65110 + help
65111 + Here you can choose the GID to disable socket access for. Remember to
65112 + add the users you want socket access disabled for to the GID
65113 + specified here. If the sysctl option is enabled, a sysctl option
65114 + with name "socket_all_gid" is created.
65115 +
65116 +config GRKERNSEC_SOCKET_CLIENT
65117 + bool "Deny client sockets to group"
65118 + depends on GRKERNSEC_SOCKET
65119 + help
65120 + If you say Y here, you will be able to choose a GID of whose users will
65121 + be unable to connect to other hosts from your machine, but will be
65122 + able to run servers. If this option is enabled, all users in the group
65123 + you specify will have to use passive mode when initiating ftp transfers
65124 + from the shell on your machine. If the sysctl option is enabled, a
65125 + sysctl option with name "socket_client" is created.
65126 +
65127 +config GRKERNSEC_SOCKET_CLIENT_GID
65128 + int "GID to deny client sockets for"
65129 + depends on GRKERNSEC_SOCKET_CLIENT
65130 + default 1003
65131 + help
65132 + Here you can choose the GID to disable client socket access for.
65133 + Remember to add the users you want client socket access disabled for to
65134 + the GID specified here. If the sysctl option is enabled, a sysctl
65135 + option with name "socket_client_gid" is created.
65136 +
65137 +config GRKERNSEC_SOCKET_SERVER
65138 + bool "Deny server sockets to group"
65139 + depends on GRKERNSEC_SOCKET
65140 + help
65141 + If you say Y here, you will be able to choose a GID of whose users will
65142 + be unable to run server applications from your machine. If the sysctl
65143 + option is enabled, a sysctl option with name "socket_server" is created.
65144 +
65145 +config GRKERNSEC_SOCKET_SERVER_GID
65146 + int "GID to deny server sockets for"
65147 + depends on GRKERNSEC_SOCKET_SERVER
65148 + default 1002
65149 + help
65150 + Here you can choose the GID to disable server socket access for.
65151 + Remember to add the users you want server socket access disabled for to
65152 + the GID specified here. If the sysctl option is enabled, a sysctl
65153 + option with name "socket_server_gid" is created.
65154 +
65155 +endmenu
65156 +
65157 +menu "Physical Protections"
65158 +depends on GRKERNSEC
65159 +
65160 +config GRKERNSEC_DENYUSB
65161 + bool "Deny new USB connections after toggle"
65162 + default y if GRKERNSEC_CONFIG_AUTO
65163 + depends on SYSCTL && USB_SUPPORT
65164 + help
65165 + If you say Y here, a new sysctl option with name "deny_new_usb"
65166 + will be created. Setting its value to 1 will prevent any new
65167 + USB devices from being recognized by the OS. Any attempted USB
65168 + device insertion will be logged. This option is intended to be
65169 + used against custom USB devices designed to exploit vulnerabilities
65170 + in various USB device drivers.
65171 +
65172 + For greatest effectiveness, this sysctl should be set after any
65173 + relevant init scripts. This option is safe to enable in distros
65174 + as each user can choose whether or not to toggle the sysctl.
65175 +
65176 +config GRKERNSEC_DENYUSB_FORCE
65177 + bool "Reject all USB devices not connected at boot"
65178 + select USB
65179 + depends on GRKERNSEC_DENYUSB
65180 + help
65181 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
65182 + that doesn't involve a sysctl entry. This option should only be
65183 + enabled if you're sure you want to deny all new USB connections
65184 + at runtime and don't want to modify init scripts. This should not
65185 + be enabled by distros. It forces the core USB code to be built
65186 + into the kernel image so that all devices connected at boot time
65187 + can be recognized and new USB device connections can be prevented
65188 + prior to init running.
65189 +
65190 +endmenu
65191 +
65192 +menu "Sysctl Support"
65193 +depends on GRKERNSEC && SYSCTL
65194 +
65195 +config GRKERNSEC_SYSCTL
65196 + bool "Sysctl support"
65197 + default y if GRKERNSEC_CONFIG_AUTO
65198 + help
65199 + If you say Y here, you will be able to change the options that
65200 + grsecurity runs with at bootup, without having to recompile your
65201 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
65202 + to enable (1) or disable (0) various features. All the sysctl entries
65203 + are mutable until the "grsec_lock" entry is set to a non-zero value.
65204 + All features enabled in the kernel configuration are disabled at boot
65205 + if you do not say Y to the "Turn on features by default" option.
65206 + All options should be set at startup, and the grsec_lock entry should
65207 + be set to a non-zero value after all the options are set.
65208 + *THIS IS EXTREMELY IMPORTANT*
65209 +
65210 +config GRKERNSEC_SYSCTL_DISTRO
65211 + bool "Extra sysctl support for distro makers (READ HELP)"
65212 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
65213 + help
65214 + If you say Y here, additional sysctl options will be created
65215 + for features that affect processes running as root. Therefore,
65216 + it is critical when using this option that the grsec_lock entry be
65217 + enabled after boot. Only distros with prebuilt kernel packages
65218 + with this option enabled that can ensure grsec_lock is enabled
65219 + after boot should use this option.
65220 + *Failure to set grsec_lock after boot makes all grsec features
65221 + this option covers useless*
65222 +
65223 + Currently this option creates the following sysctl entries:
65224 + "Disable Privileged I/O": "disable_priv_io"
65225 +
65226 +config GRKERNSEC_SYSCTL_ON
65227 + bool "Turn on features by default"
65228 + default y if GRKERNSEC_CONFIG_AUTO
65229 + depends on GRKERNSEC_SYSCTL
65230 + help
65231 + If you say Y here, instead of having all features enabled in the
65232 + kernel configuration disabled at boot time, the features will be
65233 + enabled at boot time. It is recommended you say Y here unless
65234 + there is some reason you would want all sysctl-tunable features to
65235 + be disabled by default. As mentioned elsewhere, it is important
65236 + to enable the grsec_lock entry once you have finished modifying
65237 + the sysctl entries.
65238 +
65239 +endmenu
65240 +menu "Logging Options"
65241 +depends on GRKERNSEC
65242 +
65243 +config GRKERNSEC_FLOODTIME
65244 + int "Seconds in between log messages (minimum)"
65245 + default 10
65246 + help
65247 + This option allows you to enforce the number of seconds between
65248 + grsecurity log messages. The default should be suitable for most
65249 + people, however, if you choose to change it, choose a value small enough
65250 + to allow informative logs to be produced, but large enough to
65251 + prevent flooding.
65252 +
65253 +config GRKERNSEC_FLOODBURST
65254 + int "Number of messages in a burst (maximum)"
65255 + default 6
65256 + help
65257 + This option allows you to choose the maximum number of messages allowed
65258 + within the flood time interval you chose in a separate option. The
65259 + default should be suitable for most people, however if you find that
65260 + many of your logs are being interpreted as flooding, you may want to
65261 + raise this value.
65262 +
65263 +endmenu
65264 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
65265 new file mode 100644
65266 index 0000000..d1344d2
65267 --- /dev/null
65268 +++ b/grsecurity/Makefile
65269 @@ -0,0 +1,43 @@
65270 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
65271 +# during 2001-2009 it has been completely redesigned by Brad Spengler
65272 +# into an RBAC system
65273 +#
65274 +# All code in this directory and various hooks inserted throughout the kernel
65275 +# are copyright Brad Spengler - Open Source Security, Inc., and released
65276 +# under the GPL v2
65277 +
65278 +KBUILD_CFLAGS += -Werror
65279 +
65280 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
65281 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
65282 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
65283 + grsec_usb.o grsec_ipc.o
65284 +
65285 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
65286 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
65287 + gracl_learn.o grsec_log.o gracl_policy.o
65288 +ifdef CONFIG_COMPAT
65289 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
65290 +endif
65291 +
65292 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
65293 +
65294 +ifdef CONFIG_NET
65295 +obj-y += grsec_sock.o
65296 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
65297 +endif
65298 +
65299 +ifndef CONFIG_GRKERNSEC
65300 +obj-y += grsec_disabled.o
65301 +endif
65302 +
65303 +ifdef CONFIG_GRKERNSEC_HIDESYM
65304 +extra-y := grsec_hidesym.o
65305 +$(obj)/grsec_hidesym.o:
65306 + @-chmod -f 500 /boot
65307 + @-chmod -f 500 /lib/modules
65308 + @-chmod -f 500 /lib64/modules
65309 + @-chmod -f 500 /lib32/modules
65310 + @-chmod -f 700 .
65311 + @echo ' grsec: protected kernel image paths'
65312 +endif
65313 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
65314 new file mode 100644
65315 index 0000000..7232a45
65316 --- /dev/null
65317 +++ b/grsecurity/gracl.c
65318 @@ -0,0 +1,2677 @@
65319 +#include <linux/kernel.h>
65320 +#include <linux/module.h>
65321 +#include <linux/sched.h>
65322 +#include <linux/mm.h>
65323 +#include <linux/file.h>
65324 +#include <linux/fs.h>
65325 +#include <linux/namei.h>
65326 +#include <linux/mount.h>
65327 +#include <linux/tty.h>
65328 +#include <linux/proc_fs.h>
65329 +#include <linux/lglock.h>
65330 +#include <linux/slab.h>
65331 +#include <linux/vmalloc.h>
65332 +#include <linux/types.h>
65333 +#include <linux/sysctl.h>
65334 +#include <linux/netdevice.h>
65335 +#include <linux/ptrace.h>
65336 +#include <linux/gracl.h>
65337 +#include <linux/gralloc.h>
65338 +#include <linux/security.h>
65339 +#include <linux/grinternal.h>
65340 +#include <linux/pid_namespace.h>
65341 +#include <linux/stop_machine.h>
65342 +#include <linux/fdtable.h>
65343 +#include <linux/percpu.h>
65344 +#include <linux/lglock.h>
65345 +#include <linux/hugetlb.h>
65346 +#include <linux/posix-timers.h>
65347 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65348 +#include <linux/magic.h>
65349 +#include <linux/pagemap.h>
65350 +#include "../fs/btrfs/async-thread.h"
65351 +#include "../fs/btrfs/ctree.h"
65352 +#include "../fs/btrfs/btrfs_inode.h"
65353 +#endif
65354 +#include "../fs/mount.h"
65355 +
65356 +#include <asm/uaccess.h>
65357 +#include <asm/errno.h>
65358 +#include <asm/mman.h>
65359 +
65360 +#define FOR_EACH_ROLE_START(role) \
65361 + role = running_polstate.role_list; \
65362 + while (role) {
65363 +
65364 +#define FOR_EACH_ROLE_END(role) \
65365 + role = role->prev; \
65366 + }
65367 +
65368 +extern struct path gr_real_root;
65369 +
65370 +static struct gr_policy_state running_polstate;
65371 +struct gr_policy_state *polstate = &running_polstate;
65372 +extern struct gr_alloc_state *current_alloc_state;
65373 +
65374 +extern char *gr_shared_page[4];
65375 +DEFINE_RWLOCK(gr_inode_lock);
65376 +
65377 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
65378 +
65379 +#ifdef CONFIG_NET
65380 +extern struct vfsmount *sock_mnt;
65381 +#endif
65382 +
65383 +extern struct vfsmount *pipe_mnt;
65384 +extern struct vfsmount *shm_mnt;
65385 +
65386 +#ifdef CONFIG_HUGETLBFS
65387 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
65388 +#endif
65389 +
65390 +extern u16 acl_sp_role_value;
65391 +extern struct acl_object_label *fakefs_obj_rw;
65392 +extern struct acl_object_label *fakefs_obj_rwx;
65393 +
65394 +int gr_acl_is_enabled(void)
65395 +{
65396 + return (gr_status & GR_READY);
65397 +}
65398 +
65399 +void gr_enable_rbac_system(void)
65400 +{
65401 + pax_open_kernel();
65402 + gr_status |= GR_READY;
65403 + pax_close_kernel();
65404 +}
65405 +
65406 +int gr_rbac_disable(void *unused)
65407 +{
65408 + pax_open_kernel();
65409 + gr_status &= ~GR_READY;
65410 + pax_close_kernel();
65411 +
65412 + return 0;
65413 +}
65414 +
65415 +static inline dev_t __get_dev(const struct dentry *dentry)
65416 +{
65417 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65418 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
65419 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
65420 + else
65421 +#endif
65422 + return dentry->d_sb->s_dev;
65423 +}
65424 +
65425 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
65426 +{
65427 + return __get_dev(dentry);
65428 +}
65429 +
65430 +static char gr_task_roletype_to_char(struct task_struct *task)
65431 +{
65432 + switch (task->role->roletype &
65433 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
65434 + GR_ROLE_SPECIAL)) {
65435 + case GR_ROLE_DEFAULT:
65436 + return 'D';
65437 + case GR_ROLE_USER:
65438 + return 'U';
65439 + case GR_ROLE_GROUP:
65440 + return 'G';
65441 + case GR_ROLE_SPECIAL:
65442 + return 'S';
65443 + }
65444 +
65445 + return 'X';
65446 +}
65447 +
65448 +char gr_roletype_to_char(void)
65449 +{
65450 + return gr_task_roletype_to_char(current);
65451 +}
65452 +
65453 +__inline__ int
65454 +gr_acl_tpe_check(void)
65455 +{
65456 + if (unlikely(!(gr_status & GR_READY)))
65457 + return 0;
65458 + if (current->role->roletype & GR_ROLE_TPE)
65459 + return 1;
65460 + else
65461 + return 0;
65462 +}
65463 +
65464 +int
65465 +gr_handle_rawio(const struct inode *inode)
65466 +{
65467 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65468 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
65469 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
65470 + !capable(CAP_SYS_RAWIO))
65471 + return 1;
65472 +#endif
65473 + return 0;
65474 +}
65475 +
65476 +int
65477 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
65478 +{
65479 + if (likely(lena != lenb))
65480 + return 0;
65481 +
65482 + return !memcmp(a, b, lena);
65483 +}
65484 +
65485 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
65486 +{
65487 + *buflen -= namelen;
65488 + if (*buflen < 0)
65489 + return -ENAMETOOLONG;
65490 + *buffer -= namelen;
65491 + memcpy(*buffer, str, namelen);
65492 + return 0;
65493 +}
65494 +
65495 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
65496 +{
65497 + return prepend(buffer, buflen, name->name, name->len);
65498 +}
65499 +
65500 +static int prepend_path(const struct path *path, struct path *root,
65501 + char **buffer, int *buflen)
65502 +{
65503 + struct dentry *dentry = path->dentry;
65504 + struct vfsmount *vfsmnt = path->mnt;
65505 + struct mount *mnt = real_mount(vfsmnt);
65506 + bool slash = false;
65507 + int error = 0;
65508 +
65509 + while (dentry != root->dentry || vfsmnt != root->mnt) {
65510 + struct dentry * parent;
65511 +
65512 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
65513 + /* Global root? */
65514 + if (!mnt_has_parent(mnt)) {
65515 + goto out;
65516 + }
65517 + dentry = mnt->mnt_mountpoint;
65518 + mnt = mnt->mnt_parent;
65519 + vfsmnt = &mnt->mnt;
65520 + continue;
65521 + }
65522 + parent = dentry->d_parent;
65523 + prefetch(parent);
65524 + spin_lock(&dentry->d_lock);
65525 + error = prepend_name(buffer, buflen, &dentry->d_name);
65526 + spin_unlock(&dentry->d_lock);
65527 + if (!error)
65528 + error = prepend(buffer, buflen, "/", 1);
65529 + if (error)
65530 + break;
65531 +
65532 + slash = true;
65533 + dentry = parent;
65534 + }
65535 +
65536 +out:
65537 + if (!error && !slash)
65538 + error = prepend(buffer, buflen, "/", 1);
65539 +
65540 + return error;
65541 +}
65542 +
65543 +/* this must be called with mount_lock and rename_lock held */
65544 +
65545 +static char *__our_d_path(const struct path *path, struct path *root,
65546 + char *buf, int buflen)
65547 +{
65548 + char *res = buf + buflen;
65549 + int error;
65550 +
65551 + prepend(&res, &buflen, "\0", 1);
65552 + error = prepend_path(path, root, &res, &buflen);
65553 + if (error)
65554 + return ERR_PTR(error);
65555 +
65556 + return res;
65557 +}
65558 +
65559 +static char *
65560 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
65561 +{
65562 + char *retval;
65563 +
65564 + retval = __our_d_path(path, root, buf, buflen);
65565 + if (unlikely(IS_ERR(retval)))
65566 + retval = strcpy(buf, "<path too long>");
65567 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
65568 + retval[1] = '\0';
65569 +
65570 + return retval;
65571 +}
65572 +
65573 +static char *
65574 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65575 + char *buf, int buflen)
65576 +{
65577 + struct path path;
65578 + char *res;
65579 +
65580 + path.dentry = (struct dentry *)dentry;
65581 + path.mnt = (struct vfsmount *)vfsmnt;
65582 +
65583 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
65584 + by the RBAC system */
65585 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
65586 +
65587 + return res;
65588 +}
65589 +
65590 +static char *
65591 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65592 + char *buf, int buflen)
65593 +{
65594 + char *res;
65595 + struct path path;
65596 + struct path root;
65597 + struct task_struct *reaper = init_pid_ns.child_reaper;
65598 +
65599 + path.dentry = (struct dentry *)dentry;
65600 + path.mnt = (struct vfsmount *)vfsmnt;
65601 +
65602 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
65603 + get_fs_root(reaper->fs, &root);
65604 +
65605 + read_seqlock_excl(&mount_lock);
65606 + write_seqlock(&rename_lock);
65607 + res = gen_full_path(&path, &root, buf, buflen);
65608 + write_sequnlock(&rename_lock);
65609 + read_sequnlock_excl(&mount_lock);
65610 +
65611 + path_put(&root);
65612 + return res;
65613 +}
65614 +
65615 +char *
65616 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65617 +{
65618 + char *ret;
65619 + read_seqlock_excl(&mount_lock);
65620 + write_seqlock(&rename_lock);
65621 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65622 + PAGE_SIZE);
65623 + write_sequnlock(&rename_lock);
65624 + read_sequnlock_excl(&mount_lock);
65625 + return ret;
65626 +}
65627 +
65628 +static char *
65629 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65630 +{
65631 + char *ret;
65632 + char *buf;
65633 + int buflen;
65634 +
65635 + read_seqlock_excl(&mount_lock);
65636 + write_seqlock(&rename_lock);
65637 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
65638 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
65639 + buflen = (int)(ret - buf);
65640 + if (buflen >= 5)
65641 + prepend(&ret, &buflen, "/proc", 5);
65642 + else
65643 + ret = strcpy(buf, "<path too long>");
65644 + write_sequnlock(&rename_lock);
65645 + read_sequnlock_excl(&mount_lock);
65646 + return ret;
65647 +}
65648 +
65649 +char *
65650 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
65651 +{
65652 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65653 + PAGE_SIZE);
65654 +}
65655 +
65656 +char *
65657 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
65658 +{
65659 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
65660 + PAGE_SIZE);
65661 +}
65662 +
65663 +char *
65664 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
65665 +{
65666 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
65667 + PAGE_SIZE);
65668 +}
65669 +
65670 +char *
65671 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
65672 +{
65673 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
65674 + PAGE_SIZE);
65675 +}
65676 +
65677 +char *
65678 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
65679 +{
65680 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
65681 + PAGE_SIZE);
65682 +}
65683 +
65684 +__inline__ __u32
65685 +to_gr_audit(const __u32 reqmode)
65686 +{
65687 + /* masks off auditable permission flags, then shifts them to create
65688 + auditing flags, and adds the special case of append auditing if
65689 + we're requesting write */
65690 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
65691 +}
65692 +
65693 +struct acl_role_label *
65694 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
65695 + const gid_t gid)
65696 +{
65697 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
65698 + struct acl_role_label *match;
65699 + struct role_allowed_ip *ipp;
65700 + unsigned int x;
65701 + u32 curr_ip = task->signal->saved_ip;
65702 +
65703 + match = state->acl_role_set.r_hash[index];
65704 +
65705 + while (match) {
65706 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
65707 + for (x = 0; x < match->domain_child_num; x++) {
65708 + if (match->domain_children[x] == uid)
65709 + goto found;
65710 + }
65711 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
65712 + break;
65713 + match = match->next;
65714 + }
65715 +found:
65716 + if (match == NULL) {
65717 + try_group:
65718 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
65719 + match = state->acl_role_set.r_hash[index];
65720 +
65721 + while (match) {
65722 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
65723 + for (x = 0; x < match->domain_child_num; x++) {
65724 + if (match->domain_children[x] == gid)
65725 + goto found2;
65726 + }
65727 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
65728 + break;
65729 + match = match->next;
65730 + }
65731 +found2:
65732 + if (match == NULL)
65733 + match = state->default_role;
65734 + if (match->allowed_ips == NULL)
65735 + return match;
65736 + else {
65737 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65738 + if (likely
65739 + ((ntohl(curr_ip) & ipp->netmask) ==
65740 + (ntohl(ipp->addr) & ipp->netmask)))
65741 + return match;
65742 + }
65743 + match = state->default_role;
65744 + }
65745 + } else if (match->allowed_ips == NULL) {
65746 + return match;
65747 + } else {
65748 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65749 + if (likely
65750 + ((ntohl(curr_ip) & ipp->netmask) ==
65751 + (ntohl(ipp->addr) & ipp->netmask)))
65752 + return match;
65753 + }
65754 + goto try_group;
65755 + }
65756 +
65757 + return match;
65758 +}
65759 +
65760 +static struct acl_role_label *
65761 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
65762 + const gid_t gid)
65763 +{
65764 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
65765 +}
65766 +
65767 +struct acl_subject_label *
65768 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
65769 + const struct acl_role_label *role)
65770 +{
65771 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65772 + struct acl_subject_label *match;
65773 +
65774 + match = role->subj_hash[index];
65775 +
65776 + while (match && (match->inode != ino || match->device != dev ||
65777 + (match->mode & GR_DELETED))) {
65778 + match = match->next;
65779 + }
65780 +
65781 + if (match && !(match->mode & GR_DELETED))
65782 + return match;
65783 + else
65784 + return NULL;
65785 +}
65786 +
65787 +struct acl_subject_label *
65788 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
65789 + const struct acl_role_label *role)
65790 +{
65791 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65792 + struct acl_subject_label *match;
65793 +
65794 + match = role->subj_hash[index];
65795 +
65796 + while (match && (match->inode != ino || match->device != dev ||
65797 + !(match->mode & GR_DELETED))) {
65798 + match = match->next;
65799 + }
65800 +
65801 + if (match && (match->mode & GR_DELETED))
65802 + return match;
65803 + else
65804 + return NULL;
65805 +}
65806 +
65807 +static struct acl_object_label *
65808 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
65809 + const struct acl_subject_label *subj)
65810 +{
65811 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65812 + struct acl_object_label *match;
65813 +
65814 + match = subj->obj_hash[index];
65815 +
65816 + while (match && (match->inode != ino || match->device != dev ||
65817 + (match->mode & GR_DELETED))) {
65818 + match = match->next;
65819 + }
65820 +
65821 + if (match && !(match->mode & GR_DELETED))
65822 + return match;
65823 + else
65824 + return NULL;
65825 +}
65826 +
65827 +static struct acl_object_label *
65828 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
65829 + const struct acl_subject_label *subj)
65830 +{
65831 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65832 + struct acl_object_label *match;
65833 +
65834 + match = subj->obj_hash[index];
65835 +
65836 + while (match && (match->inode != ino || match->device != dev ||
65837 + !(match->mode & GR_DELETED))) {
65838 + match = match->next;
65839 + }
65840 +
65841 + if (match && (match->mode & GR_DELETED))
65842 + return match;
65843 +
65844 + match = subj->obj_hash[index];
65845 +
65846 + while (match && (match->inode != ino || match->device != dev ||
65847 + (match->mode & GR_DELETED))) {
65848 + match = match->next;
65849 + }
65850 +
65851 + if (match && !(match->mode & GR_DELETED))
65852 + return match;
65853 + else
65854 + return NULL;
65855 +}
65856 +
65857 +struct name_entry *
65858 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
65859 +{
65860 + unsigned int len = strlen(name);
65861 + unsigned int key = full_name_hash(name, len);
65862 + unsigned int index = key % state->name_set.n_size;
65863 + struct name_entry *match;
65864 +
65865 + match = state->name_set.n_hash[index];
65866 +
65867 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
65868 + match = match->next;
65869 +
65870 + return match;
65871 +}
65872 +
65873 +static struct name_entry *
65874 +lookup_name_entry(const char *name)
65875 +{
65876 + return __lookup_name_entry(&running_polstate, name);
65877 +}
65878 +
65879 +static struct name_entry *
65880 +lookup_name_entry_create(const char *name)
65881 +{
65882 + unsigned int len = strlen(name);
65883 + unsigned int key = full_name_hash(name, len);
65884 + unsigned int index = key % running_polstate.name_set.n_size;
65885 + struct name_entry *match;
65886 +
65887 + match = running_polstate.name_set.n_hash[index];
65888 +
65889 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
65890 + !match->deleted))
65891 + match = match->next;
65892 +
65893 + if (match && match->deleted)
65894 + return match;
65895 +
65896 + match = running_polstate.name_set.n_hash[index];
65897 +
65898 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
65899 + match->deleted))
65900 + match = match->next;
65901 +
65902 + if (match && !match->deleted)
65903 + return match;
65904 + else
65905 + return NULL;
65906 +}
65907 +
65908 +static struct inodev_entry *
65909 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
65910 +{
65911 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
65912 + struct inodev_entry *match;
65913 +
65914 + match = running_polstate.inodev_set.i_hash[index];
65915 +
65916 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
65917 + match = match->next;
65918 +
65919 + return match;
65920 +}
65921 +
65922 +void
65923 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
65924 +{
65925 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
65926 + state->inodev_set.i_size);
65927 + struct inodev_entry **curr;
65928 +
65929 + entry->prev = NULL;
65930 +
65931 + curr = &state->inodev_set.i_hash[index];
65932 + if (*curr != NULL)
65933 + (*curr)->prev = entry;
65934 +
65935 + entry->next = *curr;
65936 + *curr = entry;
65937 +
65938 + return;
65939 +}
65940 +
65941 +static void
65942 +insert_inodev_entry(struct inodev_entry *entry)
65943 +{
65944 + __insert_inodev_entry(&running_polstate, entry);
65945 +}
65946 +
65947 +void
65948 +insert_acl_obj_label(struct acl_object_label *obj,
65949 + struct acl_subject_label *subj)
65950 +{
65951 + unsigned int index =
65952 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
65953 + struct acl_object_label **curr;
65954 +
65955 + obj->prev = NULL;
65956 +
65957 + curr = &subj->obj_hash[index];
65958 + if (*curr != NULL)
65959 + (*curr)->prev = obj;
65960 +
65961 + obj->next = *curr;
65962 + *curr = obj;
65963 +
65964 + return;
65965 +}
65966 +
65967 +void
65968 +insert_acl_subj_label(struct acl_subject_label *obj,
65969 + struct acl_role_label *role)
65970 +{
65971 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
65972 + struct acl_subject_label **curr;
65973 +
65974 + obj->prev = NULL;
65975 +
65976 + curr = &role->subj_hash[index];
65977 + if (*curr != NULL)
65978 + (*curr)->prev = obj;
65979 +
65980 + obj->next = *curr;
65981 + *curr = obj;
65982 +
65983 + return;
65984 +}
65985 +
65986 +/* derived from glibc fnmatch() 0: match, 1: no match*/
65987 +
65988 +static int
65989 +glob_match(const char *p, const char *n)
65990 +{
65991 + char c;
65992 +
65993 + while ((c = *p++) != '\0') {
65994 + switch (c) {
65995 + case '?':
65996 + if (*n == '\0')
65997 + return 1;
65998 + else if (*n == '/')
65999 + return 1;
66000 + break;
66001 + case '\\':
66002 + if (*n != c)
66003 + return 1;
66004 + break;
66005 + case '*':
66006 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
66007 + if (*n == '/')
66008 + return 1;
66009 + else if (c == '?') {
66010 + if (*n == '\0')
66011 + return 1;
66012 + else
66013 + ++n;
66014 + }
66015 + }
66016 + if (c == '\0') {
66017 + return 0;
66018 + } else {
66019 + const char *endp;
66020 +
66021 + if ((endp = strchr(n, '/')) == NULL)
66022 + endp = n + strlen(n);
66023 +
66024 + if (c == '[') {
66025 + for (--p; n < endp; ++n)
66026 + if (!glob_match(p, n))
66027 + return 0;
66028 + } else if (c == '/') {
66029 + while (*n != '\0' && *n != '/')
66030 + ++n;
66031 + if (*n == '/' && !glob_match(p, n + 1))
66032 + return 0;
66033 + } else {
66034 + for (--p; n < endp; ++n)
66035 + if (*n == c && !glob_match(p, n))
66036 + return 0;
66037 + }
66038 +
66039 + return 1;
66040 + }
66041 + case '[':
66042 + {
66043 + int not;
66044 + char cold;
66045 +
66046 + if (*n == '\0' || *n == '/')
66047 + return 1;
66048 +
66049 + not = (*p == '!' || *p == '^');
66050 + if (not)
66051 + ++p;
66052 +
66053 + c = *p++;
66054 + for (;;) {
66055 + unsigned char fn = (unsigned char)*n;
66056 +
66057 + if (c == '\0')
66058 + return 1;
66059 + else {
66060 + if (c == fn)
66061 + goto matched;
66062 + cold = c;
66063 + c = *p++;
66064 +
66065 + if (c == '-' && *p != ']') {
66066 + unsigned char cend = *p++;
66067 +
66068 + if (cend == '\0')
66069 + return 1;
66070 +
66071 + if (cold <= fn && fn <= cend)
66072 + goto matched;
66073 +
66074 + c = *p++;
66075 + }
66076 + }
66077 +
66078 + if (c == ']')
66079 + break;
66080 + }
66081 + if (!not)
66082 + return 1;
66083 + break;
66084 + matched:
66085 + while (c != ']') {
66086 + if (c == '\0')
66087 + return 1;
66088 +
66089 + c = *p++;
66090 + }
66091 + if (not)
66092 + return 1;
66093 + }
66094 + break;
66095 + default:
66096 + if (c != *n)
66097 + return 1;
66098 + }
66099 +
66100 + ++n;
66101 + }
66102 +
66103 + if (*n == '\0')
66104 + return 0;
66105 +
66106 + if (*n == '/')
66107 + return 0;
66108 +
66109 + return 1;
66110 +}
66111 +
66112 +static struct acl_object_label *
66113 +chk_glob_label(struct acl_object_label *globbed,
66114 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
66115 +{
66116 + struct acl_object_label *tmp;
66117 +
66118 + if (*path == NULL)
66119 + *path = gr_to_filename_nolock(dentry, mnt);
66120 +
66121 + tmp = globbed;
66122 +
66123 + while (tmp) {
66124 + if (!glob_match(tmp->filename, *path))
66125 + return tmp;
66126 + tmp = tmp->next;
66127 + }
66128 +
66129 + return NULL;
66130 +}
66131 +
66132 +static struct acl_object_label *
66133 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66134 + const ino_t curr_ino, const dev_t curr_dev,
66135 + const struct acl_subject_label *subj, char **path, const int checkglob)
66136 +{
66137 + struct acl_subject_label *tmpsubj;
66138 + struct acl_object_label *retval;
66139 + struct acl_object_label *retval2;
66140 +
66141 + tmpsubj = (struct acl_subject_label *) subj;
66142 + read_lock(&gr_inode_lock);
66143 + do {
66144 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
66145 + if (retval) {
66146 + if (checkglob && retval->globbed) {
66147 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
66148 + if (retval2)
66149 + retval = retval2;
66150 + }
66151 + break;
66152 + }
66153 + } while ((tmpsubj = tmpsubj->parent_subject));
66154 + read_unlock(&gr_inode_lock);
66155 +
66156 + return retval;
66157 +}
66158 +
66159 +static __inline__ struct acl_object_label *
66160 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66161 + struct dentry *curr_dentry,
66162 + const struct acl_subject_label *subj, char **path, const int checkglob)
66163 +{
66164 + int newglob = checkglob;
66165 + ino_t inode;
66166 + dev_t device;
66167 +
66168 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
66169 + as we don't want a / * rule to match instead of the / object
66170 + don't do this for create lookups that call this function though, since they're looking up
66171 + on the parent and thus need globbing checks on all paths
66172 + */
66173 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
66174 + newglob = GR_NO_GLOB;
66175 +
66176 + spin_lock(&curr_dentry->d_lock);
66177 + inode = curr_dentry->d_inode->i_ino;
66178 + device = __get_dev(curr_dentry);
66179 + spin_unlock(&curr_dentry->d_lock);
66180 +
66181 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
66182 +}
66183 +
66184 +#ifdef CONFIG_HUGETLBFS
66185 +static inline bool
66186 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
66187 +{
66188 + int i;
66189 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
66190 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
66191 + return true;
66192 + }
66193 +
66194 + return false;
66195 +}
66196 +#endif
66197 +
66198 +static struct acl_object_label *
66199 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66200 + const struct acl_subject_label *subj, char *path, const int checkglob)
66201 +{
66202 + struct dentry *dentry = (struct dentry *) l_dentry;
66203 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66204 + struct mount *real_mnt = real_mount(mnt);
66205 + struct acl_object_label *retval;
66206 + struct dentry *parent;
66207 +
66208 + read_seqlock_excl(&mount_lock);
66209 + write_seqlock(&rename_lock);
66210 +
66211 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
66212 +#ifdef CONFIG_NET
66213 + mnt == sock_mnt ||
66214 +#endif
66215 +#ifdef CONFIG_HUGETLBFS
66216 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
66217 +#endif
66218 + /* ignore Eric Biederman */
66219 + IS_PRIVATE(l_dentry->d_inode))) {
66220 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
66221 + goto out;
66222 + }
66223 +
66224 + for (;;) {
66225 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66226 + break;
66227 +
66228 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66229 + if (!mnt_has_parent(real_mnt))
66230 + break;
66231 +
66232 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66233 + if (retval != NULL)
66234 + goto out;
66235 +
66236 + dentry = real_mnt->mnt_mountpoint;
66237 + real_mnt = real_mnt->mnt_parent;
66238 + mnt = &real_mnt->mnt;
66239 + continue;
66240 + }
66241 +
66242 + parent = dentry->d_parent;
66243 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66244 + if (retval != NULL)
66245 + goto out;
66246 +
66247 + dentry = parent;
66248 + }
66249 +
66250 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66251 +
66252 + /* gr_real_root is pinned so we don't have to hold a reference */
66253 + if (retval == NULL)
66254 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
66255 +out:
66256 + write_sequnlock(&rename_lock);
66257 + read_sequnlock_excl(&mount_lock);
66258 +
66259 + BUG_ON(retval == NULL);
66260 +
66261 + return retval;
66262 +}
66263 +
66264 +static __inline__ struct acl_object_label *
66265 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66266 + const struct acl_subject_label *subj)
66267 +{
66268 + char *path = NULL;
66269 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
66270 +}
66271 +
66272 +static __inline__ struct acl_object_label *
66273 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66274 + const struct acl_subject_label *subj)
66275 +{
66276 + char *path = NULL;
66277 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
66278 +}
66279 +
66280 +static __inline__ struct acl_object_label *
66281 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66282 + const struct acl_subject_label *subj, char *path)
66283 +{
66284 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
66285 +}
66286 +
66287 +struct acl_subject_label *
66288 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66289 + const struct acl_role_label *role)
66290 +{
66291 + struct dentry *dentry = (struct dentry *) l_dentry;
66292 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66293 + struct mount *real_mnt = real_mount(mnt);
66294 + struct acl_subject_label *retval;
66295 + struct dentry *parent;
66296 +
66297 + read_seqlock_excl(&mount_lock);
66298 + write_seqlock(&rename_lock);
66299 +
66300 + for (;;) {
66301 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66302 + break;
66303 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66304 + if (!mnt_has_parent(real_mnt))
66305 + break;
66306 +
66307 + spin_lock(&dentry->d_lock);
66308 + read_lock(&gr_inode_lock);
66309 + retval =
66310 + lookup_acl_subj_label(dentry->d_inode->i_ino,
66311 + __get_dev(dentry), role);
66312 + read_unlock(&gr_inode_lock);
66313 + spin_unlock(&dentry->d_lock);
66314 + if (retval != NULL)
66315 + goto out;
66316 +
66317 + dentry = real_mnt->mnt_mountpoint;
66318 + real_mnt = real_mnt->mnt_parent;
66319 + mnt = &real_mnt->mnt;
66320 + continue;
66321 + }
66322 +
66323 + spin_lock(&dentry->d_lock);
66324 + read_lock(&gr_inode_lock);
66325 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66326 + __get_dev(dentry), role);
66327 + read_unlock(&gr_inode_lock);
66328 + parent = dentry->d_parent;
66329 + spin_unlock(&dentry->d_lock);
66330 +
66331 + if (retval != NULL)
66332 + goto out;
66333 +
66334 + dentry = parent;
66335 + }
66336 +
66337 + spin_lock(&dentry->d_lock);
66338 + read_lock(&gr_inode_lock);
66339 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66340 + __get_dev(dentry), role);
66341 + read_unlock(&gr_inode_lock);
66342 + spin_unlock(&dentry->d_lock);
66343 +
66344 + if (unlikely(retval == NULL)) {
66345 + /* gr_real_root is pinned, we don't need to hold a reference */
66346 + read_lock(&gr_inode_lock);
66347 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
66348 + __get_dev(gr_real_root.dentry), role);
66349 + read_unlock(&gr_inode_lock);
66350 + }
66351 +out:
66352 + write_sequnlock(&rename_lock);
66353 + read_sequnlock_excl(&mount_lock);
66354 +
66355 + BUG_ON(retval == NULL);
66356 +
66357 + return retval;
66358 +}
66359 +
66360 +void
66361 +assign_special_role(const char *rolename)
66362 +{
66363 + struct acl_object_label *obj;
66364 + struct acl_role_label *r;
66365 + struct acl_role_label *assigned = NULL;
66366 + struct task_struct *tsk;
66367 + struct file *filp;
66368 +
66369 + FOR_EACH_ROLE_START(r)
66370 + if (!strcmp(rolename, r->rolename) &&
66371 + (r->roletype & GR_ROLE_SPECIAL)) {
66372 + assigned = r;
66373 + break;
66374 + }
66375 + FOR_EACH_ROLE_END(r)
66376 +
66377 + if (!assigned)
66378 + return;
66379 +
66380 + read_lock(&tasklist_lock);
66381 + read_lock(&grsec_exec_file_lock);
66382 +
66383 + tsk = current->real_parent;
66384 + if (tsk == NULL)
66385 + goto out_unlock;
66386 +
66387 + filp = tsk->exec_file;
66388 + if (filp == NULL)
66389 + goto out_unlock;
66390 +
66391 + tsk->is_writable = 0;
66392 + tsk->inherited = 0;
66393 +
66394 + tsk->acl_sp_role = 1;
66395 + tsk->acl_role_id = ++acl_sp_role_value;
66396 + tsk->role = assigned;
66397 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
66398 +
66399 + /* ignore additional mmap checks for processes that are writable
66400 + by the default ACL */
66401 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66402 + if (unlikely(obj->mode & GR_WRITE))
66403 + tsk->is_writable = 1;
66404 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
66405 + if (unlikely(obj->mode & GR_WRITE))
66406 + tsk->is_writable = 1;
66407 +
66408 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66409 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
66410 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
66411 +#endif
66412 +
66413 +out_unlock:
66414 + read_unlock(&grsec_exec_file_lock);
66415 + read_unlock(&tasklist_lock);
66416 + return;
66417 +}
66418 +
66419 +
66420 +static void
66421 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
66422 +{
66423 + struct task_struct *task = current;
66424 + const struct cred *cred = current_cred();
66425 +
66426 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
66427 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66428 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66429 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
66430 +
66431 + return;
66432 +}
66433 +
66434 +static void
66435 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
66436 +{
66437 + struct task_struct *task = current;
66438 + const struct cred *cred = current_cred();
66439 +
66440 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66441 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66442 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66443 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
66444 +
66445 + return;
66446 +}
66447 +
66448 +static void
66449 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
66450 +{
66451 + struct task_struct *task = current;
66452 + const struct cred *cred = current_cred();
66453 +
66454 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66455 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66456 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66457 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
66458 +
66459 + return;
66460 +}
66461 +
66462 +static void
66463 +gr_set_proc_res(struct task_struct *task)
66464 +{
66465 + struct acl_subject_label *proc;
66466 + unsigned short i;
66467 +
66468 + proc = task->acl;
66469 +
66470 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
66471 + return;
66472 +
66473 + for (i = 0; i < RLIM_NLIMITS; i++) {
66474 + if (!(proc->resmask & (1U << i)))
66475 + continue;
66476 +
66477 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
66478 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
66479 +
66480 + if (i == RLIMIT_CPU)
66481 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
66482 + }
66483 +
66484 + return;
66485 +}
66486 +
66487 +/* both of the below must be called with
66488 + rcu_read_lock();
66489 + read_lock(&tasklist_lock);
66490 + read_lock(&grsec_exec_file_lock);
66491 +*/
66492 +
66493 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
66494 +{
66495 + char *tmpname;
66496 + struct acl_subject_label *tmpsubj;
66497 + struct file *filp;
66498 + struct name_entry *nmatch;
66499 +
66500 + filp = task->exec_file;
66501 + if (filp == NULL)
66502 + return NULL;
66503 +
66504 + /* the following is to apply the correct subject
66505 + on binaries running when the RBAC system
66506 + is enabled, when the binaries have been
66507 + replaced or deleted since their execution
66508 + -----
66509 + when the RBAC system starts, the inode/dev
66510 + from exec_file will be one the RBAC system
66511 + is unaware of. It only knows the inode/dev
66512 + of the present file on disk, or the absence
66513 + of it.
66514 + */
66515 +
66516 + if (filename)
66517 + nmatch = __lookup_name_entry(state, filename);
66518 + else {
66519 + preempt_disable();
66520 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
66521 +
66522 + nmatch = __lookup_name_entry(state, tmpname);
66523 + preempt_enable();
66524 + }
66525 + tmpsubj = NULL;
66526 + if (nmatch) {
66527 + if (nmatch->deleted)
66528 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
66529 + else
66530 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
66531 + }
66532 + /* this also works for the reload case -- if we don't match a potentially inherited subject
66533 + then we fall back to a normal lookup based on the binary's ino/dev
66534 + */
66535 + if (tmpsubj == NULL)
66536 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
66537 +
66538 + return tmpsubj;
66539 +}
66540 +
66541 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
66542 +{
66543 + return __gr_get_subject_for_task(&running_polstate, task, filename);
66544 +}
66545 +
66546 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
66547 +{
66548 + struct acl_object_label *obj;
66549 + struct file *filp;
66550 +
66551 + filp = task->exec_file;
66552 +
66553 + task->acl = subj;
66554 + task->is_writable = 0;
66555 + /* ignore additional mmap checks for processes that are writable
66556 + by the default ACL */
66557 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
66558 + if (unlikely(obj->mode & GR_WRITE))
66559 + task->is_writable = 1;
66560 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66561 + if (unlikely(obj->mode & GR_WRITE))
66562 + task->is_writable = 1;
66563 +
66564 + gr_set_proc_res(task);
66565 +
66566 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66567 + 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);
66568 +#endif
66569 +}
66570 +
66571 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
66572 +{
66573 + __gr_apply_subject_to_task(&running_polstate, task, subj);
66574 +}
66575 +
66576 +__u32
66577 +gr_search_file(const struct dentry * dentry, const __u32 mode,
66578 + const struct vfsmount * mnt)
66579 +{
66580 + __u32 retval = mode;
66581 + struct acl_subject_label *curracl;
66582 + struct acl_object_label *currobj;
66583 +
66584 + if (unlikely(!(gr_status & GR_READY)))
66585 + return (mode & ~GR_AUDITS);
66586 +
66587 + curracl = current->acl;
66588 +
66589 + currobj = chk_obj_label(dentry, mnt, curracl);
66590 + retval = currobj->mode & mode;
66591 +
66592 + /* if we're opening a specified transfer file for writing
66593 + (e.g. /dev/initctl), then transfer our role to init
66594 + */
66595 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
66596 + current->role->roletype & GR_ROLE_PERSIST)) {
66597 + struct task_struct *task = init_pid_ns.child_reaper;
66598 +
66599 + if (task->role != current->role) {
66600 + struct acl_subject_label *subj;
66601 +
66602 + task->acl_sp_role = 0;
66603 + task->acl_role_id = current->acl_role_id;
66604 + task->role = current->role;
66605 + rcu_read_lock();
66606 + read_lock(&grsec_exec_file_lock);
66607 + subj = gr_get_subject_for_task(task, NULL);
66608 + gr_apply_subject_to_task(task, subj);
66609 + read_unlock(&grsec_exec_file_lock);
66610 + rcu_read_unlock();
66611 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
66612 + }
66613 + }
66614 +
66615 + if (unlikely
66616 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
66617 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
66618 + __u32 new_mode = mode;
66619 +
66620 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66621 +
66622 + retval = new_mode;
66623 +
66624 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
66625 + new_mode |= GR_INHERIT;
66626 +
66627 + if (!(mode & GR_NOLEARN))
66628 + gr_log_learn(dentry, mnt, new_mode);
66629 + }
66630 +
66631 + return retval;
66632 +}
66633 +
66634 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
66635 + const struct dentry *parent,
66636 + const struct vfsmount *mnt)
66637 +{
66638 + struct name_entry *match;
66639 + struct acl_object_label *matchpo;
66640 + struct acl_subject_label *curracl;
66641 + char *path;
66642 +
66643 + if (unlikely(!(gr_status & GR_READY)))
66644 + return NULL;
66645 +
66646 + preempt_disable();
66647 + path = gr_to_filename_rbac(new_dentry, mnt);
66648 + match = lookup_name_entry_create(path);
66649 +
66650 + curracl = current->acl;
66651 +
66652 + if (match) {
66653 + read_lock(&gr_inode_lock);
66654 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
66655 + read_unlock(&gr_inode_lock);
66656 +
66657 + if (matchpo) {
66658 + preempt_enable();
66659 + return matchpo;
66660 + }
66661 + }
66662 +
66663 + // lookup parent
66664 +
66665 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
66666 +
66667 + preempt_enable();
66668 + return matchpo;
66669 +}
66670 +
66671 +__u32
66672 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
66673 + const struct vfsmount * mnt, const __u32 mode)
66674 +{
66675 + struct acl_object_label *matchpo;
66676 + __u32 retval;
66677 +
66678 + if (unlikely(!(gr_status & GR_READY)))
66679 + return (mode & ~GR_AUDITS);
66680 +
66681 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
66682 +
66683 + retval = matchpo->mode & mode;
66684 +
66685 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
66686 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
66687 + __u32 new_mode = mode;
66688 +
66689 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66690 +
66691 + gr_log_learn(new_dentry, mnt, new_mode);
66692 + return new_mode;
66693 + }
66694 +
66695 + return retval;
66696 +}
66697 +
66698 +__u32
66699 +gr_check_link(const struct dentry * new_dentry,
66700 + const struct dentry * parent_dentry,
66701 + const struct vfsmount * parent_mnt,
66702 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
66703 +{
66704 + struct acl_object_label *obj;
66705 + __u32 oldmode, newmode;
66706 + __u32 needmode;
66707 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
66708 + GR_DELETE | GR_INHERIT;
66709 +
66710 + if (unlikely(!(gr_status & GR_READY)))
66711 + return (GR_CREATE | GR_LINK);
66712 +
66713 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
66714 + oldmode = obj->mode;
66715 +
66716 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
66717 + newmode = obj->mode;
66718 +
66719 + needmode = newmode & checkmodes;
66720 +
66721 + // old name for hardlink must have at least the permissions of the new name
66722 + if ((oldmode & needmode) != needmode)
66723 + goto bad;
66724 +
66725 + // if old name had restrictions/auditing, make sure the new name does as well
66726 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
66727 +
66728 + // don't allow hardlinking of suid/sgid/fcapped files without permission
66729 + if (is_privileged_binary(old_dentry))
66730 + needmode |= GR_SETID;
66731 +
66732 + if ((newmode & needmode) != needmode)
66733 + goto bad;
66734 +
66735 + // enforce minimum permissions
66736 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
66737 + return newmode;
66738 +bad:
66739 + needmode = oldmode;
66740 + if (is_privileged_binary(old_dentry))
66741 + needmode |= GR_SETID;
66742 +
66743 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
66744 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
66745 + return (GR_CREATE | GR_LINK);
66746 + } else if (newmode & GR_SUPPRESS)
66747 + return GR_SUPPRESS;
66748 + else
66749 + return 0;
66750 +}
66751 +
66752 +int
66753 +gr_check_hidden_task(const struct task_struct *task)
66754 +{
66755 + if (unlikely(!(gr_status & GR_READY)))
66756 + return 0;
66757 +
66758 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
66759 + return 1;
66760 +
66761 + return 0;
66762 +}
66763 +
66764 +int
66765 +gr_check_protected_task(const struct task_struct *task)
66766 +{
66767 + if (unlikely(!(gr_status & GR_READY) || !task))
66768 + return 0;
66769 +
66770 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66771 + task->acl != current->acl)
66772 + return 1;
66773 +
66774 + return 0;
66775 +}
66776 +
66777 +int
66778 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
66779 +{
66780 + struct task_struct *p;
66781 + int ret = 0;
66782 +
66783 + if (unlikely(!(gr_status & GR_READY) || !pid))
66784 + return ret;
66785 +
66786 + read_lock(&tasklist_lock);
66787 + do_each_pid_task(pid, type, p) {
66788 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66789 + p->acl != current->acl) {
66790 + ret = 1;
66791 + goto out;
66792 + }
66793 + } while_each_pid_task(pid, type, p);
66794 +out:
66795 + read_unlock(&tasklist_lock);
66796 +
66797 + return ret;
66798 +}
66799 +
66800 +void
66801 +gr_copy_label(struct task_struct *tsk)
66802 +{
66803 + struct task_struct *p = current;
66804 +
66805 + tsk->inherited = p->inherited;
66806 + tsk->acl_sp_role = 0;
66807 + tsk->acl_role_id = p->acl_role_id;
66808 + tsk->acl = p->acl;
66809 + tsk->role = p->role;
66810 + tsk->signal->used_accept = 0;
66811 + tsk->signal->curr_ip = p->signal->curr_ip;
66812 + tsk->signal->saved_ip = p->signal->saved_ip;
66813 + if (p->exec_file)
66814 + get_file(p->exec_file);
66815 + tsk->exec_file = p->exec_file;
66816 + tsk->is_writable = p->is_writable;
66817 + if (unlikely(p->signal->used_accept)) {
66818 + p->signal->curr_ip = 0;
66819 + p->signal->saved_ip = 0;
66820 + }
66821 +
66822 + return;
66823 +}
66824 +
66825 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
66826 +
66827 +int
66828 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
66829 +{
66830 + unsigned int i;
66831 + __u16 num;
66832 + uid_t *uidlist;
66833 + uid_t curuid;
66834 + int realok = 0;
66835 + int effectiveok = 0;
66836 + int fsok = 0;
66837 + uid_t globalreal, globaleffective, globalfs;
66838 +
66839 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
66840 + struct user_struct *user;
66841 +
66842 + if (!uid_valid(real))
66843 + goto skipit;
66844 +
66845 + /* find user based on global namespace */
66846 +
66847 + globalreal = GR_GLOBAL_UID(real);
66848 +
66849 + user = find_user(make_kuid(&init_user_ns, globalreal));
66850 + if (user == NULL)
66851 + goto skipit;
66852 +
66853 + if (gr_process_kernel_setuid_ban(user)) {
66854 + /* for find_user */
66855 + free_uid(user);
66856 + return 1;
66857 + }
66858 +
66859 + /* for find_user */
66860 + free_uid(user);
66861 +
66862 +skipit:
66863 +#endif
66864 +
66865 + if (unlikely(!(gr_status & GR_READY)))
66866 + return 0;
66867 +
66868 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66869 + gr_log_learn_uid_change(real, effective, fs);
66870 +
66871 + num = current->acl->user_trans_num;
66872 + uidlist = current->acl->user_transitions;
66873 +
66874 + if (uidlist == NULL)
66875 + return 0;
66876 +
66877 + if (!uid_valid(real)) {
66878 + realok = 1;
66879 + globalreal = (uid_t)-1;
66880 + } else {
66881 + globalreal = GR_GLOBAL_UID(real);
66882 + }
66883 + if (!uid_valid(effective)) {
66884 + effectiveok = 1;
66885 + globaleffective = (uid_t)-1;
66886 + } else {
66887 + globaleffective = GR_GLOBAL_UID(effective);
66888 + }
66889 + if (!uid_valid(fs)) {
66890 + fsok = 1;
66891 + globalfs = (uid_t)-1;
66892 + } else {
66893 + globalfs = GR_GLOBAL_UID(fs);
66894 + }
66895 +
66896 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
66897 + for (i = 0; i < num; i++) {
66898 + curuid = uidlist[i];
66899 + if (globalreal == curuid)
66900 + realok = 1;
66901 + if (globaleffective == curuid)
66902 + effectiveok = 1;
66903 + if (globalfs == curuid)
66904 + fsok = 1;
66905 + }
66906 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
66907 + for (i = 0; i < num; i++) {
66908 + curuid = uidlist[i];
66909 + if (globalreal == curuid)
66910 + break;
66911 + if (globaleffective == curuid)
66912 + break;
66913 + if (globalfs == curuid)
66914 + break;
66915 + }
66916 + /* not in deny list */
66917 + if (i == num) {
66918 + realok = 1;
66919 + effectiveok = 1;
66920 + fsok = 1;
66921 + }
66922 + }
66923 +
66924 + if (realok && effectiveok && fsok)
66925 + return 0;
66926 + else {
66927 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
66928 + return 1;
66929 + }
66930 +}
66931 +
66932 +int
66933 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
66934 +{
66935 + unsigned int i;
66936 + __u16 num;
66937 + gid_t *gidlist;
66938 + gid_t curgid;
66939 + int realok = 0;
66940 + int effectiveok = 0;
66941 + int fsok = 0;
66942 + gid_t globalreal, globaleffective, globalfs;
66943 +
66944 + if (unlikely(!(gr_status & GR_READY)))
66945 + return 0;
66946 +
66947 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66948 + gr_log_learn_gid_change(real, effective, fs);
66949 +
66950 + num = current->acl->group_trans_num;
66951 + gidlist = current->acl->group_transitions;
66952 +
66953 + if (gidlist == NULL)
66954 + return 0;
66955 +
66956 + if (!gid_valid(real)) {
66957 + realok = 1;
66958 + globalreal = (gid_t)-1;
66959 + } else {
66960 + globalreal = GR_GLOBAL_GID(real);
66961 + }
66962 + if (!gid_valid(effective)) {
66963 + effectiveok = 1;
66964 + globaleffective = (gid_t)-1;
66965 + } else {
66966 + globaleffective = GR_GLOBAL_GID(effective);
66967 + }
66968 + if (!gid_valid(fs)) {
66969 + fsok = 1;
66970 + globalfs = (gid_t)-1;
66971 + } else {
66972 + globalfs = GR_GLOBAL_GID(fs);
66973 + }
66974 +
66975 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
66976 + for (i = 0; i < num; i++) {
66977 + curgid = gidlist[i];
66978 + if (globalreal == curgid)
66979 + realok = 1;
66980 + if (globaleffective == curgid)
66981 + effectiveok = 1;
66982 + if (globalfs == curgid)
66983 + fsok = 1;
66984 + }
66985 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
66986 + for (i = 0; i < num; i++) {
66987 + curgid = gidlist[i];
66988 + if (globalreal == curgid)
66989 + break;
66990 + if (globaleffective == curgid)
66991 + break;
66992 + if (globalfs == curgid)
66993 + break;
66994 + }
66995 + /* not in deny list */
66996 + if (i == num) {
66997 + realok = 1;
66998 + effectiveok = 1;
66999 + fsok = 1;
67000 + }
67001 + }
67002 +
67003 + if (realok && effectiveok && fsok)
67004 + return 0;
67005 + else {
67006 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67007 + return 1;
67008 + }
67009 +}
67010 +
67011 +extern int gr_acl_is_capable(const int cap);
67012 +
67013 +void
67014 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
67015 +{
67016 + struct acl_role_label *role = task->role;
67017 + struct acl_subject_label *subj = NULL;
67018 + struct acl_object_label *obj;
67019 + struct file *filp;
67020 + uid_t uid;
67021 + gid_t gid;
67022 +
67023 + if (unlikely(!(gr_status & GR_READY)))
67024 + return;
67025 +
67026 + uid = GR_GLOBAL_UID(kuid);
67027 + gid = GR_GLOBAL_GID(kgid);
67028 +
67029 + filp = task->exec_file;
67030 +
67031 + /* kernel process, we'll give them the kernel role */
67032 + if (unlikely(!filp)) {
67033 + task->role = running_polstate.kernel_role;
67034 + task->acl = running_polstate.kernel_role->root_label;
67035 + return;
67036 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
67037 + /* save the current ip at time of role lookup so that the proper
67038 + IP will be learned for role_allowed_ip */
67039 + task->signal->saved_ip = task->signal->curr_ip;
67040 + role = lookup_acl_role_label(task, uid, gid);
67041 + }
67042 +
67043 + /* don't change the role if we're not a privileged process */
67044 + if (role && task->role != role &&
67045 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
67046 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
67047 + return;
67048 +
67049 + /* perform subject lookup in possibly new role
67050 + we can use this result below in the case where role == task->role
67051 + */
67052 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
67053 +
67054 + /* if we changed uid/gid, but result in the same role
67055 + and are using inheritance, don't lose the inherited subject
67056 + if current subject is other than what normal lookup
67057 + would result in, we arrived via inheritance, don't
67058 + lose subject
67059 + */
67060 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
67061 + (subj == task->acl)))
67062 + task->acl = subj;
67063 +
67064 + /* leave task->inherited unaffected */
67065 +
67066 + task->role = role;
67067 +
67068 + task->is_writable = 0;
67069 +
67070 + /* ignore additional mmap checks for processes that are writable
67071 + by the default ACL */
67072 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67073 + if (unlikely(obj->mode & GR_WRITE))
67074 + task->is_writable = 1;
67075 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67076 + if (unlikely(obj->mode & GR_WRITE))
67077 + task->is_writable = 1;
67078 +
67079 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67080 + 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);
67081 +#endif
67082 +
67083 + gr_set_proc_res(task);
67084 +
67085 + return;
67086 +}
67087 +
67088 +int
67089 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
67090 + const int unsafe_flags)
67091 +{
67092 + struct task_struct *task = current;
67093 + struct acl_subject_label *newacl;
67094 + struct acl_object_label *obj;
67095 + __u32 retmode;
67096 +
67097 + if (unlikely(!(gr_status & GR_READY)))
67098 + return 0;
67099 +
67100 + newacl = chk_subj_label(dentry, mnt, task->role);
67101 +
67102 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
67103 + did an exec
67104 + */
67105 + rcu_read_lock();
67106 + read_lock(&tasklist_lock);
67107 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
67108 + (task->parent->acl->mode & GR_POVERRIDE))) {
67109 + read_unlock(&tasklist_lock);
67110 + rcu_read_unlock();
67111 + goto skip_check;
67112 + }
67113 + read_unlock(&tasklist_lock);
67114 + rcu_read_unlock();
67115 +
67116 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
67117 + !(task->role->roletype & GR_ROLE_GOD) &&
67118 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
67119 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67120 + if (unsafe_flags & LSM_UNSAFE_SHARE)
67121 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
67122 + else
67123 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
67124 + return -EACCES;
67125 + }
67126 +
67127 +skip_check:
67128 +
67129 + obj = chk_obj_label(dentry, mnt, task->acl);
67130 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
67131 +
67132 + if (!(task->acl->mode & GR_INHERITLEARN) &&
67133 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
67134 + if (obj->nested)
67135 + task->acl = obj->nested;
67136 + else
67137 + task->acl = newacl;
67138 + task->inherited = 0;
67139 + } else {
67140 + task->inherited = 1;
67141 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
67142 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
67143 + }
67144 +
67145 + task->is_writable = 0;
67146 +
67147 + /* ignore additional mmap checks for processes that are writable
67148 + by the default ACL */
67149 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
67150 + if (unlikely(obj->mode & GR_WRITE))
67151 + task->is_writable = 1;
67152 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
67153 + if (unlikely(obj->mode & GR_WRITE))
67154 + task->is_writable = 1;
67155 +
67156 + gr_set_proc_res(task);
67157 +
67158 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67159 + 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);
67160 +#endif
67161 + return 0;
67162 +}
67163 +
67164 +/* always called with valid inodev ptr */
67165 +static void
67166 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
67167 +{
67168 + struct acl_object_label *matchpo;
67169 + struct acl_subject_label *matchps;
67170 + struct acl_subject_label *subj;
67171 + struct acl_role_label *role;
67172 + unsigned int x;
67173 +
67174 + FOR_EACH_ROLE_START(role)
67175 + FOR_EACH_SUBJECT_START(role, subj, x)
67176 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67177 + matchpo->mode |= GR_DELETED;
67178 + FOR_EACH_SUBJECT_END(subj,x)
67179 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
67180 + /* nested subjects aren't in the role's subj_hash table */
67181 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67182 + matchpo->mode |= GR_DELETED;
67183 + FOR_EACH_NESTED_SUBJECT_END(subj)
67184 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
67185 + matchps->mode |= GR_DELETED;
67186 + FOR_EACH_ROLE_END(role)
67187 +
67188 + inodev->nentry->deleted = 1;
67189 +
67190 + return;
67191 +}
67192 +
67193 +void
67194 +gr_handle_delete(const ino_t ino, const dev_t dev)
67195 +{
67196 + struct inodev_entry *inodev;
67197 +
67198 + if (unlikely(!(gr_status & GR_READY)))
67199 + return;
67200 +
67201 + write_lock(&gr_inode_lock);
67202 + inodev = lookup_inodev_entry(ino, dev);
67203 + if (inodev != NULL)
67204 + do_handle_delete(inodev, ino, dev);
67205 + write_unlock(&gr_inode_lock);
67206 +
67207 + return;
67208 +}
67209 +
67210 +static void
67211 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
67212 + const ino_t newinode, const dev_t newdevice,
67213 + struct acl_subject_label *subj)
67214 +{
67215 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
67216 + struct acl_object_label *match;
67217 +
67218 + match = subj->obj_hash[index];
67219 +
67220 + while (match && (match->inode != oldinode ||
67221 + match->device != olddevice ||
67222 + !(match->mode & GR_DELETED)))
67223 + match = match->next;
67224 +
67225 + if (match && (match->inode == oldinode)
67226 + && (match->device == olddevice)
67227 + && (match->mode & GR_DELETED)) {
67228 + if (match->prev == NULL) {
67229 + subj->obj_hash[index] = match->next;
67230 + if (match->next != NULL)
67231 + match->next->prev = NULL;
67232 + } else {
67233 + match->prev->next = match->next;
67234 + if (match->next != NULL)
67235 + match->next->prev = match->prev;
67236 + }
67237 + match->prev = NULL;
67238 + match->next = NULL;
67239 + match->inode = newinode;
67240 + match->device = newdevice;
67241 + match->mode &= ~GR_DELETED;
67242 +
67243 + insert_acl_obj_label(match, subj);
67244 + }
67245 +
67246 + return;
67247 +}
67248 +
67249 +static void
67250 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
67251 + const ino_t newinode, const dev_t newdevice,
67252 + struct acl_role_label *role)
67253 +{
67254 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
67255 + struct acl_subject_label *match;
67256 +
67257 + match = role->subj_hash[index];
67258 +
67259 + while (match && (match->inode != oldinode ||
67260 + match->device != olddevice ||
67261 + !(match->mode & GR_DELETED)))
67262 + match = match->next;
67263 +
67264 + if (match && (match->inode == oldinode)
67265 + && (match->device == olddevice)
67266 + && (match->mode & GR_DELETED)) {
67267 + if (match->prev == NULL) {
67268 + role->subj_hash[index] = match->next;
67269 + if (match->next != NULL)
67270 + match->next->prev = NULL;
67271 + } else {
67272 + match->prev->next = match->next;
67273 + if (match->next != NULL)
67274 + match->next->prev = match->prev;
67275 + }
67276 + match->prev = NULL;
67277 + match->next = NULL;
67278 + match->inode = newinode;
67279 + match->device = newdevice;
67280 + match->mode &= ~GR_DELETED;
67281 +
67282 + insert_acl_subj_label(match, role);
67283 + }
67284 +
67285 + return;
67286 +}
67287 +
67288 +static void
67289 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
67290 + const ino_t newinode, const dev_t newdevice)
67291 +{
67292 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
67293 + struct inodev_entry *match;
67294 +
67295 + match = running_polstate.inodev_set.i_hash[index];
67296 +
67297 + while (match && (match->nentry->inode != oldinode ||
67298 + match->nentry->device != olddevice || !match->nentry->deleted))
67299 + match = match->next;
67300 +
67301 + if (match && (match->nentry->inode == oldinode)
67302 + && (match->nentry->device == olddevice) &&
67303 + match->nentry->deleted) {
67304 + if (match->prev == NULL) {
67305 + running_polstate.inodev_set.i_hash[index] = match->next;
67306 + if (match->next != NULL)
67307 + match->next->prev = NULL;
67308 + } else {
67309 + match->prev->next = match->next;
67310 + if (match->next != NULL)
67311 + match->next->prev = match->prev;
67312 + }
67313 + match->prev = NULL;
67314 + match->next = NULL;
67315 + match->nentry->inode = newinode;
67316 + match->nentry->device = newdevice;
67317 + match->nentry->deleted = 0;
67318 +
67319 + insert_inodev_entry(match);
67320 + }
67321 +
67322 + return;
67323 +}
67324 +
67325 +static void
67326 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
67327 +{
67328 + struct acl_subject_label *subj;
67329 + struct acl_role_label *role;
67330 + unsigned int x;
67331 +
67332 + FOR_EACH_ROLE_START(role)
67333 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
67334 +
67335 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
67336 + if ((subj->inode == ino) && (subj->device == dev)) {
67337 + subj->inode = ino;
67338 + subj->device = dev;
67339 + }
67340 + /* nested subjects aren't in the role's subj_hash table */
67341 + update_acl_obj_label(matchn->inode, matchn->device,
67342 + ino, dev, subj);
67343 + FOR_EACH_NESTED_SUBJECT_END(subj)
67344 + FOR_EACH_SUBJECT_START(role, subj, x)
67345 + update_acl_obj_label(matchn->inode, matchn->device,
67346 + ino, dev, subj);
67347 + FOR_EACH_SUBJECT_END(subj,x)
67348 + FOR_EACH_ROLE_END(role)
67349 +
67350 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
67351 +
67352 + return;
67353 +}
67354 +
67355 +static void
67356 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
67357 + const struct vfsmount *mnt)
67358 +{
67359 + ino_t ino = dentry->d_inode->i_ino;
67360 + dev_t dev = __get_dev(dentry);
67361 +
67362 + __do_handle_create(matchn, ino, dev);
67363 +
67364 + return;
67365 +}
67366 +
67367 +void
67368 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
67369 +{
67370 + struct name_entry *matchn;
67371 +
67372 + if (unlikely(!(gr_status & GR_READY)))
67373 + return;
67374 +
67375 + preempt_disable();
67376 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
67377 +
67378 + if (unlikely((unsigned long)matchn)) {
67379 + write_lock(&gr_inode_lock);
67380 + do_handle_create(matchn, dentry, mnt);
67381 + write_unlock(&gr_inode_lock);
67382 + }
67383 + preempt_enable();
67384 +
67385 + return;
67386 +}
67387 +
67388 +void
67389 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
67390 +{
67391 + struct name_entry *matchn;
67392 +
67393 + if (unlikely(!(gr_status & GR_READY)))
67394 + return;
67395 +
67396 + preempt_disable();
67397 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
67398 +
67399 + if (unlikely((unsigned long)matchn)) {
67400 + write_lock(&gr_inode_lock);
67401 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
67402 + write_unlock(&gr_inode_lock);
67403 + }
67404 + preempt_enable();
67405 +
67406 + return;
67407 +}
67408 +
67409 +void
67410 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67411 + struct dentry *old_dentry,
67412 + struct dentry *new_dentry,
67413 + struct vfsmount *mnt, const __u8 replace)
67414 +{
67415 + struct name_entry *matchn;
67416 + struct inodev_entry *inodev;
67417 + struct inode *inode = new_dentry->d_inode;
67418 + ino_t old_ino = old_dentry->d_inode->i_ino;
67419 + dev_t old_dev = __get_dev(old_dentry);
67420 +
67421 + /* vfs_rename swaps the name and parent link for old_dentry and
67422 + new_dentry
67423 + at this point, old_dentry has the new name, parent link, and inode
67424 + for the renamed file
67425 + if a file is being replaced by a rename, new_dentry has the inode
67426 + and name for the replaced file
67427 + */
67428 +
67429 + if (unlikely(!(gr_status & GR_READY)))
67430 + return;
67431 +
67432 + preempt_disable();
67433 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
67434 +
67435 + /* we wouldn't have to check d_inode if it weren't for
67436 + NFS silly-renaming
67437 + */
67438 +
67439 + write_lock(&gr_inode_lock);
67440 + if (unlikely(replace && inode)) {
67441 + ino_t new_ino = inode->i_ino;
67442 + dev_t new_dev = __get_dev(new_dentry);
67443 +
67444 + inodev = lookup_inodev_entry(new_ino, new_dev);
67445 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
67446 + do_handle_delete(inodev, new_ino, new_dev);
67447 + }
67448 +
67449 + inodev = lookup_inodev_entry(old_ino, old_dev);
67450 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
67451 + do_handle_delete(inodev, old_ino, old_dev);
67452 +
67453 + if (unlikely((unsigned long)matchn))
67454 + do_handle_create(matchn, old_dentry, mnt);
67455 +
67456 + write_unlock(&gr_inode_lock);
67457 + preempt_enable();
67458 +
67459 + return;
67460 +}
67461 +
67462 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
67463 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
67464 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
67465 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
67466 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
67467 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
67468 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
67469 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
67470 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
67471 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
67472 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
67473 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
67474 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
67475 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
67476 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
67477 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
67478 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
67479 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
67480 +};
67481 +
67482 +void
67483 +gr_learn_resource(const struct task_struct *task,
67484 + const int res, const unsigned long wanted, const int gt)
67485 +{
67486 + struct acl_subject_label *acl;
67487 + const struct cred *cred;
67488 +
67489 + if (unlikely((gr_status & GR_READY) &&
67490 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
67491 + goto skip_reslog;
67492 +
67493 + gr_log_resource(task, res, wanted, gt);
67494 +skip_reslog:
67495 +
67496 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
67497 + return;
67498 +
67499 + acl = task->acl;
67500 +
67501 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
67502 + !(acl->resmask & (1U << (unsigned short) res))))
67503 + return;
67504 +
67505 + if (wanted >= acl->res[res].rlim_cur) {
67506 + unsigned long res_add;
67507 +
67508 + res_add = wanted + res_learn_bumps[res];
67509 +
67510 + acl->res[res].rlim_cur = res_add;
67511 +
67512 + if (wanted > acl->res[res].rlim_max)
67513 + acl->res[res].rlim_max = res_add;
67514 +
67515 + /* only log the subject filename, since resource logging is supported for
67516 + single-subject learning only */
67517 + rcu_read_lock();
67518 + cred = __task_cred(task);
67519 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67520 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
67521 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
67522 + "", (unsigned long) res, &task->signal->saved_ip);
67523 + rcu_read_unlock();
67524 + }
67525 +
67526 + return;
67527 +}
67528 +EXPORT_SYMBOL(gr_learn_resource);
67529 +#endif
67530 +
67531 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
67532 +void
67533 +pax_set_initial_flags(struct linux_binprm *bprm)
67534 +{
67535 + struct task_struct *task = current;
67536 + struct acl_subject_label *proc;
67537 + unsigned long flags;
67538 +
67539 + if (unlikely(!(gr_status & GR_READY)))
67540 + return;
67541 +
67542 + flags = pax_get_flags(task);
67543 +
67544 + proc = task->acl;
67545 +
67546 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
67547 + flags &= ~MF_PAX_PAGEEXEC;
67548 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
67549 + flags &= ~MF_PAX_SEGMEXEC;
67550 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
67551 + flags &= ~MF_PAX_RANDMMAP;
67552 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
67553 + flags &= ~MF_PAX_EMUTRAMP;
67554 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
67555 + flags &= ~MF_PAX_MPROTECT;
67556 +
67557 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
67558 + flags |= MF_PAX_PAGEEXEC;
67559 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
67560 + flags |= MF_PAX_SEGMEXEC;
67561 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
67562 + flags |= MF_PAX_RANDMMAP;
67563 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
67564 + flags |= MF_PAX_EMUTRAMP;
67565 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
67566 + flags |= MF_PAX_MPROTECT;
67567 +
67568 + pax_set_flags(task, flags);
67569 +
67570 + return;
67571 +}
67572 +#endif
67573 +
67574 +int
67575 +gr_handle_proc_ptrace(struct task_struct *task)
67576 +{
67577 + struct file *filp;
67578 + struct task_struct *tmp = task;
67579 + struct task_struct *curtemp = current;
67580 + __u32 retmode;
67581 +
67582 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67583 + if (unlikely(!(gr_status & GR_READY)))
67584 + return 0;
67585 +#endif
67586 +
67587 + read_lock(&tasklist_lock);
67588 + read_lock(&grsec_exec_file_lock);
67589 + filp = task->exec_file;
67590 +
67591 + while (task_pid_nr(tmp) > 0) {
67592 + if (tmp == curtemp)
67593 + break;
67594 + tmp = tmp->real_parent;
67595 + }
67596 +
67597 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67598 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
67599 + read_unlock(&grsec_exec_file_lock);
67600 + read_unlock(&tasklist_lock);
67601 + return 1;
67602 + }
67603 +
67604 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67605 + if (!(gr_status & GR_READY)) {
67606 + read_unlock(&grsec_exec_file_lock);
67607 + read_unlock(&tasklist_lock);
67608 + return 0;
67609 + }
67610 +#endif
67611 +
67612 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
67613 + read_unlock(&grsec_exec_file_lock);
67614 + read_unlock(&tasklist_lock);
67615 +
67616 + if (retmode & GR_NOPTRACE)
67617 + return 1;
67618 +
67619 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
67620 + && (current->acl != task->acl || (current->acl != current->role->root_label
67621 + && task_pid_nr(current) != task_pid_nr(task))))
67622 + return 1;
67623 +
67624 + return 0;
67625 +}
67626 +
67627 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
67628 +{
67629 + if (unlikely(!(gr_status & GR_READY)))
67630 + return;
67631 +
67632 + if (!(current->role->roletype & GR_ROLE_GOD))
67633 + return;
67634 +
67635 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
67636 + p->role->rolename, gr_task_roletype_to_char(p),
67637 + p->acl->filename);
67638 +}
67639 +
67640 +int
67641 +gr_handle_ptrace(struct task_struct *task, const long request)
67642 +{
67643 + struct task_struct *tmp = task;
67644 + struct task_struct *curtemp = current;
67645 + __u32 retmode;
67646 +
67647 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67648 + if (unlikely(!(gr_status & GR_READY)))
67649 + return 0;
67650 +#endif
67651 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67652 + read_lock(&tasklist_lock);
67653 + while (task_pid_nr(tmp) > 0) {
67654 + if (tmp == curtemp)
67655 + break;
67656 + tmp = tmp->real_parent;
67657 + }
67658 +
67659 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67660 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
67661 + read_unlock(&tasklist_lock);
67662 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67663 + return 1;
67664 + }
67665 + read_unlock(&tasklist_lock);
67666 + }
67667 +
67668 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67669 + if (!(gr_status & GR_READY))
67670 + return 0;
67671 +#endif
67672 +
67673 + read_lock(&grsec_exec_file_lock);
67674 + if (unlikely(!task->exec_file)) {
67675 + read_unlock(&grsec_exec_file_lock);
67676 + return 0;
67677 + }
67678 +
67679 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
67680 + read_unlock(&grsec_exec_file_lock);
67681 +
67682 + if (retmode & GR_NOPTRACE) {
67683 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67684 + return 1;
67685 + }
67686 +
67687 + if (retmode & GR_PTRACERD) {
67688 + switch (request) {
67689 + case PTRACE_SEIZE:
67690 + case PTRACE_POKETEXT:
67691 + case PTRACE_POKEDATA:
67692 + case PTRACE_POKEUSR:
67693 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
67694 + case PTRACE_SETREGS:
67695 + case PTRACE_SETFPREGS:
67696 +#endif
67697 +#ifdef CONFIG_X86
67698 + case PTRACE_SETFPXREGS:
67699 +#endif
67700 +#ifdef CONFIG_ALTIVEC
67701 + case PTRACE_SETVRREGS:
67702 +#endif
67703 + return 1;
67704 + default:
67705 + return 0;
67706 + }
67707 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
67708 + !(current->role->roletype & GR_ROLE_GOD) &&
67709 + (current->acl != task->acl)) {
67710 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67711 + return 1;
67712 + }
67713 +
67714 + return 0;
67715 +}
67716 +
67717 +static int is_writable_mmap(const struct file *filp)
67718 +{
67719 + struct task_struct *task = current;
67720 + struct acl_object_label *obj, *obj2;
67721 +
67722 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
67723 + !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))) {
67724 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67725 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
67726 + task->role->root_label);
67727 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
67728 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
67729 + return 1;
67730 + }
67731 + }
67732 + return 0;
67733 +}
67734 +
67735 +int
67736 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
67737 +{
67738 + __u32 mode;
67739 +
67740 + if (unlikely(!file || !(prot & PROT_EXEC)))
67741 + return 1;
67742 +
67743 + if (is_writable_mmap(file))
67744 + return 0;
67745 +
67746 + mode =
67747 + gr_search_file(file->f_path.dentry,
67748 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67749 + file->f_path.mnt);
67750 +
67751 + if (!gr_tpe_allow(file))
67752 + return 0;
67753 +
67754 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67755 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67756 + return 0;
67757 + } else if (unlikely(!(mode & GR_EXEC))) {
67758 + return 0;
67759 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67760 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67761 + return 1;
67762 + }
67763 +
67764 + return 1;
67765 +}
67766 +
67767 +int
67768 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
67769 +{
67770 + __u32 mode;
67771 +
67772 + if (unlikely(!file || !(prot & PROT_EXEC)))
67773 + return 1;
67774 +
67775 + if (is_writable_mmap(file))
67776 + return 0;
67777 +
67778 + mode =
67779 + gr_search_file(file->f_path.dentry,
67780 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67781 + file->f_path.mnt);
67782 +
67783 + if (!gr_tpe_allow(file))
67784 + return 0;
67785 +
67786 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67787 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67788 + return 0;
67789 + } else if (unlikely(!(mode & GR_EXEC))) {
67790 + return 0;
67791 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67792 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67793 + return 1;
67794 + }
67795 +
67796 + return 1;
67797 +}
67798 +
67799 +void
67800 +gr_acl_handle_psacct(struct task_struct *task, const long code)
67801 +{
67802 + unsigned long runtime;
67803 + unsigned long cputime;
67804 + unsigned int wday, cday;
67805 + __u8 whr, chr;
67806 + __u8 wmin, cmin;
67807 + __u8 wsec, csec;
67808 + struct timespec timeval;
67809 +
67810 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
67811 + !(task->acl->mode & GR_PROCACCT)))
67812 + return;
67813 +
67814 + do_posix_clock_monotonic_gettime(&timeval);
67815 + runtime = timeval.tv_sec - task->start_time.tv_sec;
67816 + wday = runtime / (3600 * 24);
67817 + runtime -= wday * (3600 * 24);
67818 + whr = runtime / 3600;
67819 + runtime -= whr * 3600;
67820 + wmin = runtime / 60;
67821 + runtime -= wmin * 60;
67822 + wsec = runtime;
67823 +
67824 + cputime = (task->utime + task->stime) / HZ;
67825 + cday = cputime / (3600 * 24);
67826 + cputime -= cday * (3600 * 24);
67827 + chr = cputime / 3600;
67828 + cputime -= chr * 3600;
67829 + cmin = cputime / 60;
67830 + cputime -= cmin * 60;
67831 + csec = cputime;
67832 +
67833 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
67834 +
67835 + return;
67836 +}
67837 +
67838 +#ifdef CONFIG_TASKSTATS
67839 +int gr_is_taskstats_denied(int pid)
67840 +{
67841 + struct task_struct *task;
67842 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67843 + const struct cred *cred;
67844 +#endif
67845 + int ret = 0;
67846 +
67847 + /* restrict taskstats viewing to un-chrooted root users
67848 + who have the 'view' subject flag if the RBAC system is enabled
67849 + */
67850 +
67851 + rcu_read_lock();
67852 + read_lock(&tasklist_lock);
67853 + task = find_task_by_vpid(pid);
67854 + if (task) {
67855 +#ifdef CONFIG_GRKERNSEC_CHROOT
67856 + if (proc_is_chrooted(task))
67857 + ret = -EACCES;
67858 +#endif
67859 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67860 + cred = __task_cred(task);
67861 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67862 + if (gr_is_global_nonroot(cred->uid))
67863 + ret = -EACCES;
67864 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67865 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
67866 + ret = -EACCES;
67867 +#endif
67868 +#endif
67869 + if (gr_status & GR_READY) {
67870 + if (!(task->acl->mode & GR_VIEW))
67871 + ret = -EACCES;
67872 + }
67873 + } else
67874 + ret = -ENOENT;
67875 +
67876 + read_unlock(&tasklist_lock);
67877 + rcu_read_unlock();
67878 +
67879 + return ret;
67880 +}
67881 +#endif
67882 +
67883 +/* AUXV entries are filled via a descendant of search_binary_handler
67884 + after we've already applied the subject for the target
67885 +*/
67886 +int gr_acl_enable_at_secure(void)
67887 +{
67888 + if (unlikely(!(gr_status & GR_READY)))
67889 + return 0;
67890 +
67891 + if (current->acl->mode & GR_ATSECURE)
67892 + return 1;
67893 +
67894 + return 0;
67895 +}
67896 +
67897 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
67898 +{
67899 + struct task_struct *task = current;
67900 + struct dentry *dentry = file->f_path.dentry;
67901 + struct vfsmount *mnt = file->f_path.mnt;
67902 + struct acl_object_label *obj, *tmp;
67903 + struct acl_subject_label *subj;
67904 + unsigned int bufsize;
67905 + int is_not_root;
67906 + char *path;
67907 + dev_t dev = __get_dev(dentry);
67908 +
67909 + if (unlikely(!(gr_status & GR_READY)))
67910 + return 1;
67911 +
67912 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67913 + return 1;
67914 +
67915 + /* ignore Eric Biederman */
67916 + if (IS_PRIVATE(dentry->d_inode))
67917 + return 1;
67918 +
67919 + subj = task->acl;
67920 + read_lock(&gr_inode_lock);
67921 + do {
67922 + obj = lookup_acl_obj_label(ino, dev, subj);
67923 + if (obj != NULL) {
67924 + read_unlock(&gr_inode_lock);
67925 + return (obj->mode & GR_FIND) ? 1 : 0;
67926 + }
67927 + } while ((subj = subj->parent_subject));
67928 + read_unlock(&gr_inode_lock);
67929 +
67930 + /* this is purely an optimization since we're looking for an object
67931 + for the directory we're doing a readdir on
67932 + if it's possible for any globbed object to match the entry we're
67933 + filling into the directory, then the object we find here will be
67934 + an anchor point with attached globbed objects
67935 + */
67936 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
67937 + if (obj->globbed == NULL)
67938 + return (obj->mode & GR_FIND) ? 1 : 0;
67939 +
67940 + is_not_root = ((obj->filename[0] == '/') &&
67941 + (obj->filename[1] == '\0')) ? 0 : 1;
67942 + bufsize = PAGE_SIZE - namelen - is_not_root;
67943 +
67944 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
67945 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
67946 + return 1;
67947 +
67948 + preempt_disable();
67949 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67950 + bufsize);
67951 +
67952 + bufsize = strlen(path);
67953 +
67954 + /* if base is "/", don't append an additional slash */
67955 + if (is_not_root)
67956 + *(path + bufsize) = '/';
67957 + memcpy(path + bufsize + is_not_root, name, namelen);
67958 + *(path + bufsize + namelen + is_not_root) = '\0';
67959 +
67960 + tmp = obj->globbed;
67961 + while (tmp) {
67962 + if (!glob_match(tmp->filename, path)) {
67963 + preempt_enable();
67964 + return (tmp->mode & GR_FIND) ? 1 : 0;
67965 + }
67966 + tmp = tmp->next;
67967 + }
67968 + preempt_enable();
67969 + return (obj->mode & GR_FIND) ? 1 : 0;
67970 +}
67971 +
67972 +void gr_put_exec_file(struct task_struct *task)
67973 +{
67974 + struct file *filp;
67975 +
67976 + write_lock(&grsec_exec_file_lock);
67977 + filp = task->exec_file;
67978 + task->exec_file = NULL;
67979 + write_unlock(&grsec_exec_file_lock);
67980 +
67981 + if (filp)
67982 + fput(filp);
67983 +
67984 + return;
67985 +}
67986 +
67987 +
67988 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
67989 +EXPORT_SYMBOL(gr_acl_is_enabled);
67990 +#endif
67991 +#ifdef CONFIG_SECURITY
67992 +EXPORT_SYMBOL(gr_check_user_change);
67993 +EXPORT_SYMBOL(gr_check_group_change);
67994 +#endif
67995 +
67996 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
67997 new file mode 100644
67998 index 0000000..18ffbbd
67999 --- /dev/null
68000 +++ b/grsecurity/gracl_alloc.c
68001 @@ -0,0 +1,105 @@
68002 +#include <linux/kernel.h>
68003 +#include <linux/mm.h>
68004 +#include <linux/slab.h>
68005 +#include <linux/vmalloc.h>
68006 +#include <linux/gracl.h>
68007 +#include <linux/grsecurity.h>
68008 +
68009 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
68010 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
68011 +
68012 +static __inline__ int
68013 +alloc_pop(void)
68014 +{
68015 + if (current_alloc_state->alloc_stack_next == 1)
68016 + return 0;
68017 +
68018 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
68019 +
68020 + current_alloc_state->alloc_stack_next--;
68021 +
68022 + return 1;
68023 +}
68024 +
68025 +static __inline__ int
68026 +alloc_push(void *buf)
68027 +{
68028 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
68029 + return 1;
68030 +
68031 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
68032 +
68033 + current_alloc_state->alloc_stack_next++;
68034 +
68035 + return 0;
68036 +}
68037 +
68038 +void *
68039 +acl_alloc(unsigned long len)
68040 +{
68041 + void *ret = NULL;
68042 +
68043 + if (!len || len > PAGE_SIZE)
68044 + goto out;
68045 +
68046 + ret = kmalloc(len, GFP_KERNEL);
68047 +
68048 + if (ret) {
68049 + if (alloc_push(ret)) {
68050 + kfree(ret);
68051 + ret = NULL;
68052 + }
68053 + }
68054 +
68055 +out:
68056 + return ret;
68057 +}
68058 +
68059 +void *
68060 +acl_alloc_num(unsigned long num, unsigned long len)
68061 +{
68062 + if (!len || (num > (PAGE_SIZE / len)))
68063 + return NULL;
68064 +
68065 + return acl_alloc(num * len);
68066 +}
68067 +
68068 +void
68069 +acl_free_all(void)
68070 +{
68071 + if (!current_alloc_state->alloc_stack)
68072 + return;
68073 +
68074 + while (alloc_pop()) ;
68075 +
68076 + if (current_alloc_state->alloc_stack) {
68077 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
68078 + kfree(current_alloc_state->alloc_stack);
68079 + else
68080 + vfree(current_alloc_state->alloc_stack);
68081 + }
68082 +
68083 + current_alloc_state->alloc_stack = NULL;
68084 + current_alloc_state->alloc_stack_size = 1;
68085 + current_alloc_state->alloc_stack_next = 1;
68086 +
68087 + return;
68088 +}
68089 +
68090 +int
68091 +acl_alloc_stack_init(unsigned long size)
68092 +{
68093 + if ((size * sizeof (void *)) <= PAGE_SIZE)
68094 + current_alloc_state->alloc_stack =
68095 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
68096 + else
68097 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
68098 +
68099 + current_alloc_state->alloc_stack_size = size;
68100 + current_alloc_state->alloc_stack_next = 1;
68101 +
68102 + if (!current_alloc_state->alloc_stack)
68103 + return 0;
68104 + else
68105 + return 1;
68106 +}
68107 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
68108 new file mode 100644
68109 index 0000000..bdd51ea
68110 --- /dev/null
68111 +++ b/grsecurity/gracl_cap.c
68112 @@ -0,0 +1,110 @@
68113 +#include <linux/kernel.h>
68114 +#include <linux/module.h>
68115 +#include <linux/sched.h>
68116 +#include <linux/gracl.h>
68117 +#include <linux/grsecurity.h>
68118 +#include <linux/grinternal.h>
68119 +
68120 +extern const char *captab_log[];
68121 +extern int captab_log_entries;
68122 +
68123 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68124 +{
68125 + struct acl_subject_label *curracl;
68126 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68127 + kernel_cap_t cap_audit = __cap_empty_set;
68128 +
68129 + if (!gr_acl_is_enabled())
68130 + return 1;
68131 +
68132 + curracl = task->acl;
68133 +
68134 + cap_drop = curracl->cap_lower;
68135 + cap_mask = curracl->cap_mask;
68136 + cap_audit = curracl->cap_invert_audit;
68137 +
68138 + while ((curracl = curracl->parent_subject)) {
68139 + /* if the cap isn't specified in the current computed mask but is specified in the
68140 + current level subject, and is lowered in the current level subject, then add
68141 + it to the set of dropped capabilities
68142 + otherwise, add the current level subject's mask to the current computed mask
68143 + */
68144 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68145 + cap_raise(cap_mask, cap);
68146 + if (cap_raised(curracl->cap_lower, cap))
68147 + cap_raise(cap_drop, cap);
68148 + if (cap_raised(curracl->cap_invert_audit, cap))
68149 + cap_raise(cap_audit, cap);
68150 + }
68151 + }
68152 +
68153 + if (!cap_raised(cap_drop, cap)) {
68154 + if (cap_raised(cap_audit, cap))
68155 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
68156 + return 1;
68157 + }
68158 +
68159 + curracl = task->acl;
68160 +
68161 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
68162 + && cap_raised(cred->cap_effective, cap)) {
68163 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68164 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
68165 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
68166 + gr_to_filename(task->exec_file->f_path.dentry,
68167 + task->exec_file->f_path.mnt) : curracl->filename,
68168 + curracl->filename, 0UL,
68169 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
68170 + return 1;
68171 + }
68172 +
68173 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
68174 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
68175 +
68176 + return 0;
68177 +}
68178 +
68179 +int
68180 +gr_acl_is_capable(const int cap)
68181 +{
68182 + return gr_task_acl_is_capable(current, current_cred(), cap);
68183 +}
68184 +
68185 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
68186 +{
68187 + struct acl_subject_label *curracl;
68188 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68189 +
68190 + if (!gr_acl_is_enabled())
68191 + return 1;
68192 +
68193 + curracl = task->acl;
68194 +
68195 + cap_drop = curracl->cap_lower;
68196 + cap_mask = curracl->cap_mask;
68197 +
68198 + while ((curracl = curracl->parent_subject)) {
68199 + /* if the cap isn't specified in the current computed mask but is specified in the
68200 + current level subject, and is lowered in the current level subject, then add
68201 + it to the set of dropped capabilities
68202 + otherwise, add the current level subject's mask to the current computed mask
68203 + */
68204 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68205 + cap_raise(cap_mask, cap);
68206 + if (cap_raised(curracl->cap_lower, cap))
68207 + cap_raise(cap_drop, cap);
68208 + }
68209 + }
68210 +
68211 + if (!cap_raised(cap_drop, cap))
68212 + return 1;
68213 +
68214 + return 0;
68215 +}
68216 +
68217 +int
68218 +gr_acl_is_capable_nolog(const int cap)
68219 +{
68220 + return gr_task_acl_is_capable_nolog(current, cap);
68221 +}
68222 +
68223 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
68224 new file mode 100644
68225 index 0000000..ca25605
68226 --- /dev/null
68227 +++ b/grsecurity/gracl_compat.c
68228 @@ -0,0 +1,270 @@
68229 +#include <linux/kernel.h>
68230 +#include <linux/gracl.h>
68231 +#include <linux/compat.h>
68232 +#include <linux/gracl_compat.h>
68233 +
68234 +#include <asm/uaccess.h>
68235 +
68236 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
68237 +{
68238 + struct gr_arg_wrapper_compat uwrapcompat;
68239 +
68240 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
68241 + return -EFAULT;
68242 +
68243 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
68244 + (uwrapcompat.version != 0x2901)) ||
68245 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
68246 + return -EINVAL;
68247 +
68248 + uwrap->arg = compat_ptr(uwrapcompat.arg);
68249 + uwrap->version = uwrapcompat.version;
68250 + uwrap->size = sizeof(struct gr_arg);
68251 +
68252 + return 0;
68253 +}
68254 +
68255 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
68256 +{
68257 + struct gr_arg_compat argcompat;
68258 +
68259 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
68260 + return -EFAULT;
68261 +
68262 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
68263 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
68264 + arg->role_db.num_roles = argcompat.role_db.num_roles;
68265 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
68266 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
68267 + arg->role_db.num_objects = argcompat.role_db.num_objects;
68268 +
68269 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
68270 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
68271 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
68272 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
68273 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
68274 + arg->segv_device = argcompat.segv_device;
68275 + arg->segv_inode = argcompat.segv_inode;
68276 + arg->segv_uid = argcompat.segv_uid;
68277 + arg->num_sprole_pws = argcompat.num_sprole_pws;
68278 + arg->mode = argcompat.mode;
68279 +
68280 + return 0;
68281 +}
68282 +
68283 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
68284 +{
68285 + struct acl_object_label_compat objcompat;
68286 +
68287 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
68288 + return -EFAULT;
68289 +
68290 + obj->filename = compat_ptr(objcompat.filename);
68291 + obj->inode = objcompat.inode;
68292 + obj->device = objcompat.device;
68293 + obj->mode = objcompat.mode;
68294 +
68295 + obj->nested = compat_ptr(objcompat.nested);
68296 + obj->globbed = compat_ptr(objcompat.globbed);
68297 +
68298 + obj->prev = compat_ptr(objcompat.prev);
68299 + obj->next = compat_ptr(objcompat.next);
68300 +
68301 + return 0;
68302 +}
68303 +
68304 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
68305 +{
68306 + unsigned int i;
68307 + struct acl_subject_label_compat subjcompat;
68308 +
68309 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
68310 + return -EFAULT;
68311 +
68312 + subj->filename = compat_ptr(subjcompat.filename);
68313 + subj->inode = subjcompat.inode;
68314 + subj->device = subjcompat.device;
68315 + subj->mode = subjcompat.mode;
68316 + subj->cap_mask = subjcompat.cap_mask;
68317 + subj->cap_lower = subjcompat.cap_lower;
68318 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
68319 +
68320 + for (i = 0; i < GR_NLIMITS; i++) {
68321 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
68322 + subj->res[i].rlim_cur = RLIM_INFINITY;
68323 + else
68324 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
68325 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
68326 + subj->res[i].rlim_max = RLIM_INFINITY;
68327 + else
68328 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
68329 + }
68330 + subj->resmask = subjcompat.resmask;
68331 +
68332 + subj->user_trans_type = subjcompat.user_trans_type;
68333 + subj->group_trans_type = subjcompat.group_trans_type;
68334 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
68335 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
68336 + subj->user_trans_num = subjcompat.user_trans_num;
68337 + subj->group_trans_num = subjcompat.group_trans_num;
68338 +
68339 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
68340 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
68341 + subj->ip_type = subjcompat.ip_type;
68342 + subj->ips = compat_ptr(subjcompat.ips);
68343 + subj->ip_num = subjcompat.ip_num;
68344 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
68345 +
68346 + subj->crashes = subjcompat.crashes;
68347 + subj->expires = subjcompat.expires;
68348 +
68349 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
68350 + subj->hash = compat_ptr(subjcompat.hash);
68351 + subj->prev = compat_ptr(subjcompat.prev);
68352 + subj->next = compat_ptr(subjcompat.next);
68353 +
68354 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
68355 + subj->obj_hash_size = subjcompat.obj_hash_size;
68356 + subj->pax_flags = subjcompat.pax_flags;
68357 +
68358 + return 0;
68359 +}
68360 +
68361 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
68362 +{
68363 + struct acl_role_label_compat rolecompat;
68364 +
68365 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
68366 + return -EFAULT;
68367 +
68368 + role->rolename = compat_ptr(rolecompat.rolename);
68369 + role->uidgid = rolecompat.uidgid;
68370 + role->roletype = rolecompat.roletype;
68371 +
68372 + role->auth_attempts = rolecompat.auth_attempts;
68373 + role->expires = rolecompat.expires;
68374 +
68375 + role->root_label = compat_ptr(rolecompat.root_label);
68376 + role->hash = compat_ptr(rolecompat.hash);
68377 +
68378 + role->prev = compat_ptr(rolecompat.prev);
68379 + role->next = compat_ptr(rolecompat.next);
68380 +
68381 + role->transitions = compat_ptr(rolecompat.transitions);
68382 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
68383 + role->domain_children = compat_ptr(rolecompat.domain_children);
68384 + role->domain_child_num = rolecompat.domain_child_num;
68385 +
68386 + role->umask = rolecompat.umask;
68387 +
68388 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
68389 + role->subj_hash_size = rolecompat.subj_hash_size;
68390 +
68391 + return 0;
68392 +}
68393 +
68394 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
68395 +{
68396 + struct role_allowed_ip_compat roleip_compat;
68397 +
68398 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
68399 + return -EFAULT;
68400 +
68401 + roleip->addr = roleip_compat.addr;
68402 + roleip->netmask = roleip_compat.netmask;
68403 +
68404 + roleip->prev = compat_ptr(roleip_compat.prev);
68405 + roleip->next = compat_ptr(roleip_compat.next);
68406 +
68407 + return 0;
68408 +}
68409 +
68410 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
68411 +{
68412 + struct role_transition_compat trans_compat;
68413 +
68414 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
68415 + return -EFAULT;
68416 +
68417 + trans->rolename = compat_ptr(trans_compat.rolename);
68418 +
68419 + trans->prev = compat_ptr(trans_compat.prev);
68420 + trans->next = compat_ptr(trans_compat.next);
68421 +
68422 + return 0;
68423 +
68424 +}
68425 +
68426 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
68427 +{
68428 + struct gr_hash_struct_compat hash_compat;
68429 +
68430 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
68431 + return -EFAULT;
68432 +
68433 + hash->table = compat_ptr(hash_compat.table);
68434 + hash->nametable = compat_ptr(hash_compat.nametable);
68435 + hash->first = compat_ptr(hash_compat.first);
68436 +
68437 + hash->table_size = hash_compat.table_size;
68438 + hash->used_size = hash_compat.used_size;
68439 +
68440 + hash->type = hash_compat.type;
68441 +
68442 + return 0;
68443 +}
68444 +
68445 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
68446 +{
68447 + compat_uptr_t ptrcompat;
68448 +
68449 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
68450 + return -EFAULT;
68451 +
68452 + *(void **)ptr = compat_ptr(ptrcompat);
68453 +
68454 + return 0;
68455 +}
68456 +
68457 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
68458 +{
68459 + struct acl_ip_label_compat ip_compat;
68460 +
68461 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
68462 + return -EFAULT;
68463 +
68464 + ip->iface = compat_ptr(ip_compat.iface);
68465 + ip->addr = ip_compat.addr;
68466 + ip->netmask = ip_compat.netmask;
68467 + ip->low = ip_compat.low;
68468 + ip->high = ip_compat.high;
68469 + ip->mode = ip_compat.mode;
68470 + ip->type = ip_compat.type;
68471 +
68472 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
68473 +
68474 + ip->prev = compat_ptr(ip_compat.prev);
68475 + ip->next = compat_ptr(ip_compat.next);
68476 +
68477 + return 0;
68478 +}
68479 +
68480 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
68481 +{
68482 + struct sprole_pw_compat pw_compat;
68483 +
68484 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
68485 + return -EFAULT;
68486 +
68487 + pw->rolename = compat_ptr(pw_compat.rolename);
68488 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
68489 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
68490 +
68491 + return 0;
68492 +}
68493 +
68494 +size_t get_gr_arg_wrapper_size_compat(void)
68495 +{
68496 + return sizeof(struct gr_arg_wrapper_compat);
68497 +}
68498 +
68499 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
68500 new file mode 100644
68501 index 0000000..a89b1f4
68502 --- /dev/null
68503 +++ b/grsecurity/gracl_fs.c
68504 @@ -0,0 +1,437 @@
68505 +#include <linux/kernel.h>
68506 +#include <linux/sched.h>
68507 +#include <linux/types.h>
68508 +#include <linux/fs.h>
68509 +#include <linux/file.h>
68510 +#include <linux/stat.h>
68511 +#include <linux/grsecurity.h>
68512 +#include <linux/grinternal.h>
68513 +#include <linux/gracl.h>
68514 +
68515 +umode_t
68516 +gr_acl_umask(void)
68517 +{
68518 + if (unlikely(!gr_acl_is_enabled()))
68519 + return 0;
68520 +
68521 + return current->role->umask;
68522 +}
68523 +
68524 +__u32
68525 +gr_acl_handle_hidden_file(const struct dentry * dentry,
68526 + const struct vfsmount * mnt)
68527 +{
68528 + __u32 mode;
68529 +
68530 + if (unlikely(d_is_negative(dentry)))
68531 + return GR_FIND;
68532 +
68533 + mode =
68534 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
68535 +
68536 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
68537 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68538 + return mode;
68539 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
68540 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68541 + return 0;
68542 + } else if (unlikely(!(mode & GR_FIND)))
68543 + return 0;
68544 +
68545 + return GR_FIND;
68546 +}
68547 +
68548 +__u32
68549 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68550 + int acc_mode)
68551 +{
68552 + __u32 reqmode = GR_FIND;
68553 + __u32 mode;
68554 +
68555 + if (unlikely(d_is_negative(dentry)))
68556 + return reqmode;
68557 +
68558 + if (acc_mode & MAY_APPEND)
68559 + reqmode |= GR_APPEND;
68560 + else if (acc_mode & MAY_WRITE)
68561 + reqmode |= GR_WRITE;
68562 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
68563 + reqmode |= GR_READ;
68564 +
68565 + mode =
68566 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68567 + mnt);
68568 +
68569 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68570 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68571 + reqmode & GR_READ ? " reading" : "",
68572 + reqmode & GR_WRITE ? " writing" : reqmode &
68573 + GR_APPEND ? " appending" : "");
68574 + return reqmode;
68575 + } else
68576 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68577 + {
68578 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68579 + reqmode & GR_READ ? " reading" : "",
68580 + reqmode & GR_WRITE ? " writing" : reqmode &
68581 + GR_APPEND ? " appending" : "");
68582 + return 0;
68583 + } else if (unlikely((mode & reqmode) != reqmode))
68584 + return 0;
68585 +
68586 + return reqmode;
68587 +}
68588 +
68589 +__u32
68590 +gr_acl_handle_creat(const struct dentry * dentry,
68591 + const struct dentry * p_dentry,
68592 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68593 + const int imode)
68594 +{
68595 + __u32 reqmode = GR_WRITE | GR_CREATE;
68596 + __u32 mode;
68597 +
68598 + if (acc_mode & MAY_APPEND)
68599 + reqmode |= GR_APPEND;
68600 + // if a directory was required or the directory already exists, then
68601 + // don't count this open as a read
68602 + if ((acc_mode & MAY_READ) &&
68603 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
68604 + reqmode |= GR_READ;
68605 + if ((open_flags & O_CREAT) &&
68606 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68607 + reqmode |= GR_SETID;
68608 +
68609 + mode =
68610 + gr_check_create(dentry, p_dentry, p_mnt,
68611 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68612 +
68613 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68614 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68615 + reqmode & GR_READ ? " reading" : "",
68616 + reqmode & GR_WRITE ? " writing" : reqmode &
68617 + GR_APPEND ? " appending" : "");
68618 + return reqmode;
68619 + } else
68620 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68621 + {
68622 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68623 + reqmode & GR_READ ? " reading" : "",
68624 + reqmode & GR_WRITE ? " writing" : reqmode &
68625 + GR_APPEND ? " appending" : "");
68626 + return 0;
68627 + } else if (unlikely((mode & reqmode) != reqmode))
68628 + return 0;
68629 +
68630 + return reqmode;
68631 +}
68632 +
68633 +__u32
68634 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
68635 + const int fmode)
68636 +{
68637 + __u32 mode, reqmode = GR_FIND;
68638 +
68639 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
68640 + reqmode |= GR_EXEC;
68641 + if (fmode & S_IWOTH)
68642 + reqmode |= GR_WRITE;
68643 + if (fmode & S_IROTH)
68644 + reqmode |= GR_READ;
68645 +
68646 + mode =
68647 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68648 + mnt);
68649 +
68650 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68651 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68652 + reqmode & GR_READ ? " reading" : "",
68653 + reqmode & GR_WRITE ? " writing" : "",
68654 + reqmode & GR_EXEC ? " executing" : "");
68655 + return reqmode;
68656 + } else
68657 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68658 + {
68659 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68660 + reqmode & GR_READ ? " reading" : "",
68661 + reqmode & GR_WRITE ? " writing" : "",
68662 + reqmode & GR_EXEC ? " executing" : "");
68663 + return 0;
68664 + } else if (unlikely((mode & reqmode) != reqmode))
68665 + return 0;
68666 +
68667 + return reqmode;
68668 +}
68669 +
68670 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
68671 +{
68672 + __u32 mode;
68673 +
68674 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
68675 +
68676 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68677 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
68678 + return mode;
68679 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68680 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
68681 + return 0;
68682 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
68683 + return 0;
68684 +
68685 + return (reqmode);
68686 +}
68687 +
68688 +__u32
68689 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68690 +{
68691 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
68692 +}
68693 +
68694 +__u32
68695 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
68696 +{
68697 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
68698 +}
68699 +
68700 +__u32
68701 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
68702 +{
68703 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
68704 +}
68705 +
68706 +__u32
68707 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
68708 +{
68709 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
68710 +}
68711 +
68712 +__u32
68713 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
68714 + umode_t *modeptr)
68715 +{
68716 + umode_t mode;
68717 +
68718 + *modeptr &= ~gr_acl_umask();
68719 + mode = *modeptr;
68720 +
68721 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
68722 + return 1;
68723 +
68724 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
68725 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
68726 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
68727 + GR_CHMOD_ACL_MSG);
68728 + } else {
68729 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
68730 + }
68731 +}
68732 +
68733 +__u32
68734 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
68735 +{
68736 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
68737 +}
68738 +
68739 +__u32
68740 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
68741 +{
68742 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
68743 +}
68744 +
68745 +__u32
68746 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
68747 +{
68748 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
68749 +}
68750 +
68751 +__u32
68752 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
68753 +{
68754 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
68755 +}
68756 +
68757 +__u32
68758 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
68759 +{
68760 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
68761 + GR_UNIXCONNECT_ACL_MSG);
68762 +}
68763 +
68764 +/* hardlinks require at minimum create and link permission,
68765 + any additional privilege required is based on the
68766 + privilege of the file being linked to
68767 +*/
68768 +__u32
68769 +gr_acl_handle_link(const struct dentry * new_dentry,
68770 + const struct dentry * parent_dentry,
68771 + const struct vfsmount * parent_mnt,
68772 + const struct dentry * old_dentry,
68773 + const struct vfsmount * old_mnt, const struct filename *to)
68774 +{
68775 + __u32 mode;
68776 + __u32 needmode = GR_CREATE | GR_LINK;
68777 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
68778 +
68779 + mode =
68780 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
68781 + old_mnt);
68782 +
68783 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
68784 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68785 + return mode;
68786 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68787 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68788 + return 0;
68789 + } else if (unlikely((mode & needmode) != needmode))
68790 + return 0;
68791 +
68792 + return 1;
68793 +}
68794 +
68795 +__u32
68796 +gr_acl_handle_symlink(const struct dentry * new_dentry,
68797 + const struct dentry * parent_dentry,
68798 + const struct vfsmount * parent_mnt, const struct filename *from)
68799 +{
68800 + __u32 needmode = GR_WRITE | GR_CREATE;
68801 + __u32 mode;
68802 +
68803 + mode =
68804 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
68805 + GR_CREATE | GR_AUDIT_CREATE |
68806 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
68807 +
68808 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
68809 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68810 + return mode;
68811 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68812 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68813 + return 0;
68814 + } else if (unlikely((mode & needmode) != needmode))
68815 + return 0;
68816 +
68817 + return (GR_WRITE | GR_CREATE);
68818 +}
68819 +
68820 +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)
68821 +{
68822 + __u32 mode;
68823 +
68824 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68825 +
68826 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68827 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
68828 + return mode;
68829 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68830 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
68831 + return 0;
68832 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
68833 + return 0;
68834 +
68835 + return (reqmode);
68836 +}
68837 +
68838 +__u32
68839 +gr_acl_handle_mknod(const struct dentry * new_dentry,
68840 + const struct dentry * parent_dentry,
68841 + const struct vfsmount * parent_mnt,
68842 + const int mode)
68843 +{
68844 + __u32 reqmode = GR_WRITE | GR_CREATE;
68845 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68846 + reqmode |= GR_SETID;
68847 +
68848 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68849 + reqmode, GR_MKNOD_ACL_MSG);
68850 +}
68851 +
68852 +__u32
68853 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
68854 + const struct dentry *parent_dentry,
68855 + const struct vfsmount *parent_mnt)
68856 +{
68857 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68858 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
68859 +}
68860 +
68861 +#define RENAME_CHECK_SUCCESS(old, new) \
68862 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
68863 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
68864 +
68865 +int
68866 +gr_acl_handle_rename(struct dentry *new_dentry,
68867 + struct dentry *parent_dentry,
68868 + const struct vfsmount *parent_mnt,
68869 + struct dentry *old_dentry,
68870 + struct inode *old_parent_inode,
68871 + struct vfsmount *old_mnt, const struct filename *newname)
68872 +{
68873 + __u32 comp1, comp2;
68874 + int error = 0;
68875 +
68876 + if (unlikely(!gr_acl_is_enabled()))
68877 + return 0;
68878 +
68879 + if (d_is_negative(new_dentry)) {
68880 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
68881 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
68882 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
68883 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
68884 + GR_DELETE | GR_AUDIT_DELETE |
68885 + GR_AUDIT_READ | GR_AUDIT_WRITE |
68886 + GR_SUPPRESS, old_mnt);
68887 + } else {
68888 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
68889 + GR_CREATE | GR_DELETE |
68890 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
68891 + GR_AUDIT_READ | GR_AUDIT_WRITE |
68892 + GR_SUPPRESS, parent_mnt);
68893 + comp2 =
68894 + gr_search_file(old_dentry,
68895 + GR_READ | GR_WRITE | GR_AUDIT_READ |
68896 + GR_DELETE | GR_AUDIT_DELETE |
68897 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
68898 + }
68899 +
68900 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
68901 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
68902 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68903 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
68904 + && !(comp2 & GR_SUPPRESS)) {
68905 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
68906 + error = -EACCES;
68907 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
68908 + error = -EACCES;
68909 +
68910 + return error;
68911 +}
68912 +
68913 +void
68914 +gr_acl_handle_exit(void)
68915 +{
68916 + u16 id;
68917 + char *rolename;
68918 +
68919 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
68920 + !(current->role->roletype & GR_ROLE_PERSIST))) {
68921 + id = current->acl_role_id;
68922 + rolename = current->role->rolename;
68923 + gr_set_acls(1);
68924 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
68925 + }
68926 +
68927 + gr_put_exec_file(current);
68928 + return;
68929 +}
68930 +
68931 +int
68932 +gr_acl_handle_procpidmem(const struct task_struct *task)
68933 +{
68934 + if (unlikely(!gr_acl_is_enabled()))
68935 + return 0;
68936 +
68937 + if (task != current && task->acl->mode & GR_PROTPROCFD)
68938 + return -EACCES;
68939 +
68940 + return 0;
68941 +}
68942 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
68943 new file mode 100644
68944 index 0000000..f056b81
68945 --- /dev/null
68946 +++ b/grsecurity/gracl_ip.c
68947 @@ -0,0 +1,386 @@
68948 +#include <linux/kernel.h>
68949 +#include <asm/uaccess.h>
68950 +#include <asm/errno.h>
68951 +#include <net/sock.h>
68952 +#include <linux/file.h>
68953 +#include <linux/fs.h>
68954 +#include <linux/net.h>
68955 +#include <linux/in.h>
68956 +#include <linux/skbuff.h>
68957 +#include <linux/ip.h>
68958 +#include <linux/udp.h>
68959 +#include <linux/types.h>
68960 +#include <linux/sched.h>
68961 +#include <linux/netdevice.h>
68962 +#include <linux/inetdevice.h>
68963 +#include <linux/gracl.h>
68964 +#include <linux/grsecurity.h>
68965 +#include <linux/grinternal.h>
68966 +
68967 +#define GR_BIND 0x01
68968 +#define GR_CONNECT 0x02
68969 +#define GR_INVERT 0x04
68970 +#define GR_BINDOVERRIDE 0x08
68971 +#define GR_CONNECTOVERRIDE 0x10
68972 +#define GR_SOCK_FAMILY 0x20
68973 +
68974 +static const char * gr_protocols[IPPROTO_MAX] = {
68975 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
68976 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
68977 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
68978 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
68979 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
68980 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
68981 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
68982 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
68983 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
68984 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
68985 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
68986 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
68987 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
68988 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
68989 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
68990 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
68991 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
68992 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
68993 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
68994 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
68995 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
68996 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
68997 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
68998 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
68999 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
69000 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
69001 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
69002 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
69003 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
69004 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
69005 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
69006 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
69007 + };
69008 +
69009 +static const char * gr_socktypes[SOCK_MAX] = {
69010 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
69011 + "unknown:7", "unknown:8", "unknown:9", "packet"
69012 + };
69013 +
69014 +static const char * gr_sockfamilies[AF_MAX+1] = {
69015 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
69016 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
69017 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
69018 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
69019 + };
69020 +
69021 +const char *
69022 +gr_proto_to_name(unsigned char proto)
69023 +{
69024 + return gr_protocols[proto];
69025 +}
69026 +
69027 +const char *
69028 +gr_socktype_to_name(unsigned char type)
69029 +{
69030 + return gr_socktypes[type];
69031 +}
69032 +
69033 +const char *
69034 +gr_sockfamily_to_name(unsigned char family)
69035 +{
69036 + return gr_sockfamilies[family];
69037 +}
69038 +
69039 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
69040 +
69041 +int
69042 +gr_search_socket(const int domain, const int type, const int protocol)
69043 +{
69044 + struct acl_subject_label *curr;
69045 + const struct cred *cred = current_cred();
69046 +
69047 + if (unlikely(!gr_acl_is_enabled()))
69048 + goto exit;
69049 +
69050 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
69051 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
69052 + goto exit; // let the kernel handle it
69053 +
69054 + curr = current->acl;
69055 +
69056 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
69057 + /* the family is allowed, if this is PF_INET allow it only if
69058 + the extra sock type/protocol checks pass */
69059 + if (domain == PF_INET)
69060 + goto inet_check;
69061 + goto exit;
69062 + } else {
69063 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69064 + __u32 fakeip = 0;
69065 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69066 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69067 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69068 + gr_to_filename(current->exec_file->f_path.dentry,
69069 + current->exec_file->f_path.mnt) :
69070 + curr->filename, curr->filename,
69071 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
69072 + &current->signal->saved_ip);
69073 + goto exit;
69074 + }
69075 + goto exit_fail;
69076 + }
69077 +
69078 +inet_check:
69079 + /* the rest of this checking is for IPv4 only */
69080 + if (!curr->ips)
69081 + goto exit;
69082 +
69083 + if ((curr->ip_type & (1U << type)) &&
69084 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
69085 + goto exit;
69086 +
69087 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69088 + /* we don't place acls on raw sockets , and sometimes
69089 + dgram/ip sockets are opened for ioctl and not
69090 + bind/connect, so we'll fake a bind learn log */
69091 + if (type == SOCK_RAW || type == SOCK_PACKET) {
69092 + __u32 fakeip = 0;
69093 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69094 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69095 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69096 + gr_to_filename(current->exec_file->f_path.dentry,
69097 + current->exec_file->f_path.mnt) :
69098 + curr->filename, curr->filename,
69099 + &fakeip, 0, type,
69100 + protocol, GR_CONNECT, &current->signal->saved_ip);
69101 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
69102 + __u32 fakeip = 0;
69103 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69104 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69105 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69106 + gr_to_filename(current->exec_file->f_path.dentry,
69107 + current->exec_file->f_path.mnt) :
69108 + curr->filename, curr->filename,
69109 + &fakeip, 0, type,
69110 + protocol, GR_BIND, &current->signal->saved_ip);
69111 + }
69112 + /* we'll log when they use connect or bind */
69113 + goto exit;
69114 + }
69115 +
69116 +exit_fail:
69117 + if (domain == PF_INET)
69118 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
69119 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
69120 + else if (rcu_access_pointer(net_families[domain]) != NULL)
69121 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
69122 + gr_socktype_to_name(type), protocol);
69123 +
69124 + return 0;
69125 +exit:
69126 + return 1;
69127 +}
69128 +
69129 +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)
69130 +{
69131 + if ((ip->mode & mode) &&
69132 + (ip_port >= ip->low) &&
69133 + (ip_port <= ip->high) &&
69134 + ((ntohl(ip_addr) & our_netmask) ==
69135 + (ntohl(our_addr) & our_netmask))
69136 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
69137 + && (ip->type & (1U << type))) {
69138 + if (ip->mode & GR_INVERT)
69139 + return 2; // specifically denied
69140 + else
69141 + return 1; // allowed
69142 + }
69143 +
69144 + return 0; // not specifically allowed, may continue parsing
69145 +}
69146 +
69147 +static int
69148 +gr_search_connectbind(const int full_mode, struct sock *sk,
69149 + struct sockaddr_in *addr, const int type)
69150 +{
69151 + char iface[IFNAMSIZ] = {0};
69152 + struct acl_subject_label *curr;
69153 + struct acl_ip_label *ip;
69154 + struct inet_sock *isk;
69155 + struct net_device *dev;
69156 + struct in_device *idev;
69157 + unsigned long i;
69158 + int ret;
69159 + int mode = full_mode & (GR_BIND | GR_CONNECT);
69160 + __u32 ip_addr = 0;
69161 + __u32 our_addr;
69162 + __u32 our_netmask;
69163 + char *p;
69164 + __u16 ip_port = 0;
69165 + const struct cred *cred = current_cred();
69166 +
69167 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
69168 + return 0;
69169 +
69170 + curr = current->acl;
69171 + isk = inet_sk(sk);
69172 +
69173 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
69174 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
69175 + addr->sin_addr.s_addr = curr->inaddr_any_override;
69176 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
69177 + struct sockaddr_in saddr;
69178 + int err;
69179 +
69180 + saddr.sin_family = AF_INET;
69181 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
69182 + saddr.sin_port = isk->inet_sport;
69183 +
69184 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69185 + if (err)
69186 + return err;
69187 +
69188 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69189 + if (err)
69190 + return err;
69191 + }
69192 +
69193 + if (!curr->ips)
69194 + return 0;
69195 +
69196 + ip_addr = addr->sin_addr.s_addr;
69197 + ip_port = ntohs(addr->sin_port);
69198 +
69199 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69200 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69201 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69202 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69203 + gr_to_filename(current->exec_file->f_path.dentry,
69204 + current->exec_file->f_path.mnt) :
69205 + curr->filename, curr->filename,
69206 + &ip_addr, ip_port, type,
69207 + sk->sk_protocol, mode, &current->signal->saved_ip);
69208 + return 0;
69209 + }
69210 +
69211 + for (i = 0; i < curr->ip_num; i++) {
69212 + ip = *(curr->ips + i);
69213 + if (ip->iface != NULL) {
69214 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
69215 + p = strchr(iface, ':');
69216 + if (p != NULL)
69217 + *p = '\0';
69218 + dev = dev_get_by_name(sock_net(sk), iface);
69219 + if (dev == NULL)
69220 + continue;
69221 + idev = in_dev_get(dev);
69222 + if (idev == NULL) {
69223 + dev_put(dev);
69224 + continue;
69225 + }
69226 + rcu_read_lock();
69227 + for_ifa(idev) {
69228 + if (!strcmp(ip->iface, ifa->ifa_label)) {
69229 + our_addr = ifa->ifa_address;
69230 + our_netmask = 0xffffffff;
69231 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69232 + if (ret == 1) {
69233 + rcu_read_unlock();
69234 + in_dev_put(idev);
69235 + dev_put(dev);
69236 + return 0;
69237 + } else if (ret == 2) {
69238 + rcu_read_unlock();
69239 + in_dev_put(idev);
69240 + dev_put(dev);
69241 + goto denied;
69242 + }
69243 + }
69244 + } endfor_ifa(idev);
69245 + rcu_read_unlock();
69246 + in_dev_put(idev);
69247 + dev_put(dev);
69248 + } else {
69249 + our_addr = ip->addr;
69250 + our_netmask = ip->netmask;
69251 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69252 + if (ret == 1)
69253 + return 0;
69254 + else if (ret == 2)
69255 + goto denied;
69256 + }
69257 + }
69258 +
69259 +denied:
69260 + if (mode == GR_BIND)
69261 + 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));
69262 + else if (mode == GR_CONNECT)
69263 + 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));
69264 +
69265 + return -EACCES;
69266 +}
69267 +
69268 +int
69269 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
69270 +{
69271 + /* always allow disconnection of dgram sockets with connect */
69272 + if (addr->sin_family == AF_UNSPEC)
69273 + return 0;
69274 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
69275 +}
69276 +
69277 +int
69278 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
69279 +{
69280 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
69281 +}
69282 +
69283 +int gr_search_listen(struct socket *sock)
69284 +{
69285 + struct sock *sk = sock->sk;
69286 + struct sockaddr_in addr;
69287 +
69288 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69289 + addr.sin_port = inet_sk(sk)->inet_sport;
69290 +
69291 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69292 +}
69293 +
69294 +int gr_search_accept(struct socket *sock)
69295 +{
69296 + struct sock *sk = sock->sk;
69297 + struct sockaddr_in addr;
69298 +
69299 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69300 + addr.sin_port = inet_sk(sk)->inet_sport;
69301 +
69302 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69303 +}
69304 +
69305 +int
69306 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
69307 +{
69308 + if (addr)
69309 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
69310 + else {
69311 + struct sockaddr_in sin;
69312 + const struct inet_sock *inet = inet_sk(sk);
69313 +
69314 + sin.sin_addr.s_addr = inet->inet_daddr;
69315 + sin.sin_port = inet->inet_dport;
69316 +
69317 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69318 + }
69319 +}
69320 +
69321 +int
69322 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
69323 +{
69324 + struct sockaddr_in sin;
69325 +
69326 + if (unlikely(skb->len < sizeof (struct udphdr)))
69327 + return 0; // skip this packet
69328 +
69329 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
69330 + sin.sin_port = udp_hdr(skb)->source;
69331 +
69332 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69333 +}
69334 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
69335 new file mode 100644
69336 index 0000000..25f54ef
69337 --- /dev/null
69338 +++ b/grsecurity/gracl_learn.c
69339 @@ -0,0 +1,207 @@
69340 +#include <linux/kernel.h>
69341 +#include <linux/mm.h>
69342 +#include <linux/sched.h>
69343 +#include <linux/poll.h>
69344 +#include <linux/string.h>
69345 +#include <linux/file.h>
69346 +#include <linux/types.h>
69347 +#include <linux/vmalloc.h>
69348 +#include <linux/grinternal.h>
69349 +
69350 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
69351 + size_t count, loff_t *ppos);
69352 +extern int gr_acl_is_enabled(void);
69353 +
69354 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
69355 +static int gr_learn_attached;
69356 +
69357 +/* use a 512k buffer */
69358 +#define LEARN_BUFFER_SIZE (512 * 1024)
69359 +
69360 +static DEFINE_SPINLOCK(gr_learn_lock);
69361 +static DEFINE_MUTEX(gr_learn_user_mutex);
69362 +
69363 +/* we need to maintain two buffers, so that the kernel context of grlearn
69364 + uses a semaphore around the userspace copying, and the other kernel contexts
69365 + use a spinlock when copying into the buffer, since they cannot sleep
69366 +*/
69367 +static char *learn_buffer;
69368 +static char *learn_buffer_user;
69369 +static int learn_buffer_len;
69370 +static int learn_buffer_user_len;
69371 +
69372 +static ssize_t
69373 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
69374 +{
69375 + DECLARE_WAITQUEUE(wait, current);
69376 + ssize_t retval = 0;
69377 +
69378 + add_wait_queue(&learn_wait, &wait);
69379 + set_current_state(TASK_INTERRUPTIBLE);
69380 + do {
69381 + mutex_lock(&gr_learn_user_mutex);
69382 + spin_lock(&gr_learn_lock);
69383 + if (learn_buffer_len)
69384 + break;
69385 + spin_unlock(&gr_learn_lock);
69386 + mutex_unlock(&gr_learn_user_mutex);
69387 + if (file->f_flags & O_NONBLOCK) {
69388 + retval = -EAGAIN;
69389 + goto out;
69390 + }
69391 + if (signal_pending(current)) {
69392 + retval = -ERESTARTSYS;
69393 + goto out;
69394 + }
69395 +
69396 + schedule();
69397 + } while (1);
69398 +
69399 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
69400 + learn_buffer_user_len = learn_buffer_len;
69401 + retval = learn_buffer_len;
69402 + learn_buffer_len = 0;
69403 +
69404 + spin_unlock(&gr_learn_lock);
69405 +
69406 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
69407 + retval = -EFAULT;
69408 +
69409 + mutex_unlock(&gr_learn_user_mutex);
69410 +out:
69411 + set_current_state(TASK_RUNNING);
69412 + remove_wait_queue(&learn_wait, &wait);
69413 + return retval;
69414 +}
69415 +
69416 +static unsigned int
69417 +poll_learn(struct file * file, poll_table * wait)
69418 +{
69419 + poll_wait(file, &learn_wait, wait);
69420 +
69421 + if (learn_buffer_len)
69422 + return (POLLIN | POLLRDNORM);
69423 +
69424 + return 0;
69425 +}
69426 +
69427 +void
69428 +gr_clear_learn_entries(void)
69429 +{
69430 + char *tmp;
69431 +
69432 + mutex_lock(&gr_learn_user_mutex);
69433 + spin_lock(&gr_learn_lock);
69434 + tmp = learn_buffer;
69435 + learn_buffer = NULL;
69436 + spin_unlock(&gr_learn_lock);
69437 + if (tmp)
69438 + vfree(tmp);
69439 + if (learn_buffer_user != NULL) {
69440 + vfree(learn_buffer_user);
69441 + learn_buffer_user = NULL;
69442 + }
69443 + learn_buffer_len = 0;
69444 + mutex_unlock(&gr_learn_user_mutex);
69445 +
69446 + return;
69447 +}
69448 +
69449 +void
69450 +gr_add_learn_entry(const char *fmt, ...)
69451 +{
69452 + va_list args;
69453 + unsigned int len;
69454 +
69455 + if (!gr_learn_attached)
69456 + return;
69457 +
69458 + spin_lock(&gr_learn_lock);
69459 +
69460 + /* leave a gap at the end so we know when it's "full" but don't have to
69461 + compute the exact length of the string we're trying to append
69462 + */
69463 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
69464 + spin_unlock(&gr_learn_lock);
69465 + wake_up_interruptible(&learn_wait);
69466 + return;
69467 + }
69468 + if (learn_buffer == NULL) {
69469 + spin_unlock(&gr_learn_lock);
69470 + return;
69471 + }
69472 +
69473 + va_start(args, fmt);
69474 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
69475 + va_end(args);
69476 +
69477 + learn_buffer_len += len + 1;
69478 +
69479 + spin_unlock(&gr_learn_lock);
69480 + wake_up_interruptible(&learn_wait);
69481 +
69482 + return;
69483 +}
69484 +
69485 +static int
69486 +open_learn(struct inode *inode, struct file *file)
69487 +{
69488 + if (file->f_mode & FMODE_READ && gr_learn_attached)
69489 + return -EBUSY;
69490 + if (file->f_mode & FMODE_READ) {
69491 + int retval = 0;
69492 + mutex_lock(&gr_learn_user_mutex);
69493 + if (learn_buffer == NULL)
69494 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
69495 + if (learn_buffer_user == NULL)
69496 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
69497 + if (learn_buffer == NULL) {
69498 + retval = -ENOMEM;
69499 + goto out_error;
69500 + }
69501 + if (learn_buffer_user == NULL) {
69502 + retval = -ENOMEM;
69503 + goto out_error;
69504 + }
69505 + learn_buffer_len = 0;
69506 + learn_buffer_user_len = 0;
69507 + gr_learn_attached = 1;
69508 +out_error:
69509 + mutex_unlock(&gr_learn_user_mutex);
69510 + return retval;
69511 + }
69512 + return 0;
69513 +}
69514 +
69515 +static int
69516 +close_learn(struct inode *inode, struct file *file)
69517 +{
69518 + if (file->f_mode & FMODE_READ) {
69519 + char *tmp = NULL;
69520 + mutex_lock(&gr_learn_user_mutex);
69521 + spin_lock(&gr_learn_lock);
69522 + tmp = learn_buffer;
69523 + learn_buffer = NULL;
69524 + spin_unlock(&gr_learn_lock);
69525 + if (tmp)
69526 + vfree(tmp);
69527 + if (learn_buffer_user != NULL) {
69528 + vfree(learn_buffer_user);
69529 + learn_buffer_user = NULL;
69530 + }
69531 + learn_buffer_len = 0;
69532 + learn_buffer_user_len = 0;
69533 + gr_learn_attached = 0;
69534 + mutex_unlock(&gr_learn_user_mutex);
69535 + }
69536 +
69537 + return 0;
69538 +}
69539 +
69540 +const struct file_operations grsec_fops = {
69541 + .read = read_learn,
69542 + .write = write_grsec_handler,
69543 + .open = open_learn,
69544 + .release = close_learn,
69545 + .poll = poll_learn,
69546 +};
69547 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
69548 new file mode 100644
69549 index 0000000..361a099
69550 --- /dev/null
69551 +++ b/grsecurity/gracl_policy.c
69552 @@ -0,0 +1,1782 @@
69553 +#include <linux/kernel.h>
69554 +#include <linux/module.h>
69555 +#include <linux/sched.h>
69556 +#include <linux/mm.h>
69557 +#include <linux/file.h>
69558 +#include <linux/fs.h>
69559 +#include <linux/namei.h>
69560 +#include <linux/mount.h>
69561 +#include <linux/tty.h>
69562 +#include <linux/proc_fs.h>
69563 +#include <linux/lglock.h>
69564 +#include <linux/slab.h>
69565 +#include <linux/vmalloc.h>
69566 +#include <linux/types.h>
69567 +#include <linux/sysctl.h>
69568 +#include <linux/netdevice.h>
69569 +#include <linux/ptrace.h>
69570 +#include <linux/gracl.h>
69571 +#include <linux/gralloc.h>
69572 +#include <linux/security.h>
69573 +#include <linux/grinternal.h>
69574 +#include <linux/pid_namespace.h>
69575 +#include <linux/stop_machine.h>
69576 +#include <linux/fdtable.h>
69577 +#include <linux/percpu.h>
69578 +#include <linux/lglock.h>
69579 +#include <linux/hugetlb.h>
69580 +#include <linux/posix-timers.h>
69581 +#include "../fs/mount.h"
69582 +
69583 +#include <asm/uaccess.h>
69584 +#include <asm/errno.h>
69585 +#include <asm/mman.h>
69586 +
69587 +extern struct gr_policy_state *polstate;
69588 +
69589 +#define FOR_EACH_ROLE_START(role) \
69590 + role = polstate->role_list; \
69591 + while (role) {
69592 +
69593 +#define FOR_EACH_ROLE_END(role) \
69594 + role = role->prev; \
69595 + }
69596 +
69597 +struct path gr_real_root;
69598 +
69599 +extern struct gr_alloc_state *current_alloc_state;
69600 +
69601 +u16 acl_sp_role_value;
69602 +
69603 +static DEFINE_MUTEX(gr_dev_mutex);
69604 +
69605 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
69606 +extern void gr_clear_learn_entries(void);
69607 +
69608 +static struct gr_arg gr_usermode;
69609 +static unsigned char gr_system_salt[GR_SALT_LEN];
69610 +static unsigned char gr_system_sum[GR_SHA_LEN];
69611 +
69612 +static unsigned int gr_auth_attempts = 0;
69613 +static unsigned long gr_auth_expires = 0UL;
69614 +
69615 +struct acl_object_label *fakefs_obj_rw;
69616 +struct acl_object_label *fakefs_obj_rwx;
69617 +
69618 +extern int gr_init_uidset(void);
69619 +extern void gr_free_uidset(void);
69620 +extern void gr_remove_uid(uid_t uid);
69621 +extern int gr_find_uid(uid_t uid);
69622 +
69623 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
69624 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
69625 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
69626 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
69627 +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);
69628 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
69629 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
69630 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
69631 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
69632 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69633 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69634 +extern void assign_special_role(const char *rolename);
69635 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
69636 +extern int gr_rbac_disable(void *unused);
69637 +extern void gr_enable_rbac_system(void);
69638 +
69639 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
69640 +{
69641 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
69642 + return -EFAULT;
69643 +
69644 + return 0;
69645 +}
69646 +
69647 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69648 +{
69649 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
69650 + return -EFAULT;
69651 +
69652 + return 0;
69653 +}
69654 +
69655 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69656 +{
69657 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
69658 + return -EFAULT;
69659 +
69660 + return 0;
69661 +}
69662 +
69663 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
69664 +{
69665 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
69666 + return -EFAULT;
69667 +
69668 + return 0;
69669 +}
69670 +
69671 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69672 +{
69673 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
69674 + return -EFAULT;
69675 +
69676 + return 0;
69677 +}
69678 +
69679 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69680 +{
69681 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
69682 + return -EFAULT;
69683 +
69684 + return 0;
69685 +}
69686 +
69687 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69688 +{
69689 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
69690 + return -EFAULT;
69691 +
69692 + return 0;
69693 +}
69694 +
69695 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
69696 +{
69697 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
69698 + return -EFAULT;
69699 +
69700 + return 0;
69701 +}
69702 +
69703 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
69704 +{
69705 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
69706 + return -EFAULT;
69707 +
69708 + return 0;
69709 +}
69710 +
69711 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
69712 +{
69713 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
69714 + return -EFAULT;
69715 +
69716 + if (((uwrap->version != GRSECURITY_VERSION) &&
69717 + (uwrap->version != 0x2901)) ||
69718 + (uwrap->size != sizeof(struct gr_arg)))
69719 + return -EINVAL;
69720 +
69721 + return 0;
69722 +}
69723 +
69724 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
69725 +{
69726 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
69727 + return -EFAULT;
69728 +
69729 + return 0;
69730 +}
69731 +
69732 +static size_t get_gr_arg_wrapper_size_normal(void)
69733 +{
69734 + return sizeof(struct gr_arg_wrapper);
69735 +}
69736 +
69737 +#ifdef CONFIG_COMPAT
69738 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
69739 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
69740 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
69741 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
69742 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
69743 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
69744 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
69745 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
69746 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
69747 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
69748 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
69749 +extern size_t get_gr_arg_wrapper_size_compat(void);
69750 +
69751 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
69752 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
69753 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
69754 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
69755 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
69756 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
69757 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
69758 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
69759 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
69760 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
69761 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
69762 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
69763 +
69764 +#else
69765 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
69766 +#define copy_gr_arg copy_gr_arg_normal
69767 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
69768 +#define copy_acl_object_label copy_acl_object_label_normal
69769 +#define copy_acl_subject_label copy_acl_subject_label_normal
69770 +#define copy_acl_role_label copy_acl_role_label_normal
69771 +#define copy_acl_ip_label copy_acl_ip_label_normal
69772 +#define copy_pointer_from_array copy_pointer_from_array_normal
69773 +#define copy_sprole_pw copy_sprole_pw_normal
69774 +#define copy_role_transition copy_role_transition_normal
69775 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
69776 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
69777 +#endif
69778 +
69779 +static struct acl_subject_label *
69780 +lookup_subject_map(const struct acl_subject_label *userp)
69781 +{
69782 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
69783 + struct subject_map *match;
69784 +
69785 + match = polstate->subj_map_set.s_hash[index];
69786 +
69787 + while (match && match->user != userp)
69788 + match = match->next;
69789 +
69790 + if (match != NULL)
69791 + return match->kernel;
69792 + else
69793 + return NULL;
69794 +}
69795 +
69796 +static void
69797 +insert_subj_map_entry(struct subject_map *subjmap)
69798 +{
69799 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
69800 + struct subject_map **curr;
69801 +
69802 + subjmap->prev = NULL;
69803 +
69804 + curr = &polstate->subj_map_set.s_hash[index];
69805 + if (*curr != NULL)
69806 + (*curr)->prev = subjmap;
69807 +
69808 + subjmap->next = *curr;
69809 + *curr = subjmap;
69810 +
69811 + return;
69812 +}
69813 +
69814 +static void
69815 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
69816 +{
69817 + unsigned int index =
69818 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
69819 + struct acl_role_label **curr;
69820 + struct acl_role_label *tmp, *tmp2;
69821 +
69822 + curr = &polstate->acl_role_set.r_hash[index];
69823 +
69824 + /* simple case, slot is empty, just set it to our role */
69825 + if (*curr == NULL) {
69826 + *curr = role;
69827 + } else {
69828 + /* example:
69829 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
69830 + 2 -> 3
69831 + */
69832 + /* first check to see if we can already be reached via this slot */
69833 + tmp = *curr;
69834 + while (tmp && tmp != role)
69835 + tmp = tmp->next;
69836 + if (tmp == role) {
69837 + /* we don't need to add ourselves to this slot's chain */
69838 + return;
69839 + }
69840 + /* we need to add ourselves to this chain, two cases */
69841 + if (role->next == NULL) {
69842 + /* simple case, append the current chain to our role */
69843 + role->next = *curr;
69844 + *curr = role;
69845 + } else {
69846 + /* 1 -> 2 -> 3 -> 4
69847 + 2 -> 3 -> 4
69848 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
69849 + */
69850 + /* trickier case: walk our role's chain until we find
69851 + the role for the start of the current slot's chain */
69852 + tmp = role;
69853 + tmp2 = *curr;
69854 + while (tmp->next && tmp->next != tmp2)
69855 + tmp = tmp->next;
69856 + if (tmp->next == tmp2) {
69857 + /* from example above, we found 3, so just
69858 + replace this slot's chain with ours */
69859 + *curr = role;
69860 + } else {
69861 + /* we didn't find a subset of our role's chain
69862 + in the current slot's chain, so append their
69863 + chain to ours, and set us as the first role in
69864 + the slot's chain
69865 +
69866 + we could fold this case with the case above,
69867 + but making it explicit for clarity
69868 + */
69869 + tmp->next = tmp2;
69870 + *curr = role;
69871 + }
69872 + }
69873 + }
69874 +
69875 + return;
69876 +}
69877 +
69878 +static void
69879 +insert_acl_role_label(struct acl_role_label *role)
69880 +{
69881 + int i;
69882 +
69883 + if (polstate->role_list == NULL) {
69884 + polstate->role_list = role;
69885 + role->prev = NULL;
69886 + } else {
69887 + role->prev = polstate->role_list;
69888 + polstate->role_list = role;
69889 + }
69890 +
69891 + /* used for hash chains */
69892 + role->next = NULL;
69893 +
69894 + if (role->roletype & GR_ROLE_DOMAIN) {
69895 + for (i = 0; i < role->domain_child_num; i++)
69896 + __insert_acl_role_label(role, role->domain_children[i]);
69897 + } else
69898 + __insert_acl_role_label(role, role->uidgid);
69899 +}
69900 +
69901 +static int
69902 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
69903 +{
69904 + struct name_entry **curr, *nentry;
69905 + struct inodev_entry *ientry;
69906 + unsigned int len = strlen(name);
69907 + unsigned int key = full_name_hash(name, len);
69908 + unsigned int index = key % polstate->name_set.n_size;
69909 +
69910 + curr = &polstate->name_set.n_hash[index];
69911 +
69912 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
69913 + curr = &((*curr)->next);
69914 +
69915 + if (*curr != NULL)
69916 + return 1;
69917 +
69918 + nentry = acl_alloc(sizeof (struct name_entry));
69919 + if (nentry == NULL)
69920 + return 0;
69921 + ientry = acl_alloc(sizeof (struct inodev_entry));
69922 + if (ientry == NULL)
69923 + return 0;
69924 + ientry->nentry = nentry;
69925 +
69926 + nentry->key = key;
69927 + nentry->name = name;
69928 + nentry->inode = inode;
69929 + nentry->device = device;
69930 + nentry->len = len;
69931 + nentry->deleted = deleted;
69932 +
69933 + nentry->prev = NULL;
69934 + curr = &polstate->name_set.n_hash[index];
69935 + if (*curr != NULL)
69936 + (*curr)->prev = nentry;
69937 + nentry->next = *curr;
69938 + *curr = nentry;
69939 +
69940 + /* insert us into the table searchable by inode/dev */
69941 + __insert_inodev_entry(polstate, ientry);
69942 +
69943 + return 1;
69944 +}
69945 +
69946 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
69947 +
69948 +static void *
69949 +create_table(__u32 * len, int elementsize)
69950 +{
69951 + unsigned int table_sizes[] = {
69952 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
69953 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
69954 + 4194301, 8388593, 16777213, 33554393, 67108859
69955 + };
69956 + void *newtable = NULL;
69957 + unsigned int pwr = 0;
69958 +
69959 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
69960 + table_sizes[pwr] <= *len)
69961 + pwr++;
69962 +
69963 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
69964 + return newtable;
69965 +
69966 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
69967 + newtable =
69968 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
69969 + else
69970 + newtable = vmalloc(table_sizes[pwr] * elementsize);
69971 +
69972 + *len = table_sizes[pwr];
69973 +
69974 + return newtable;
69975 +}
69976 +
69977 +static int
69978 +init_variables(const struct gr_arg *arg, bool reload)
69979 +{
69980 + struct task_struct *reaper = init_pid_ns.child_reaper;
69981 + unsigned int stacksize;
69982 +
69983 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
69984 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
69985 + polstate->name_set.n_size = arg->role_db.num_objects;
69986 + polstate->inodev_set.i_size = arg->role_db.num_objects;
69987 +
69988 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
69989 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
69990 + return 1;
69991 +
69992 + if (!reload) {
69993 + if (!gr_init_uidset())
69994 + return 1;
69995 + }
69996 +
69997 + /* set up the stack that holds allocation info */
69998 +
69999 + stacksize = arg->role_db.num_pointers + 5;
70000 +
70001 + if (!acl_alloc_stack_init(stacksize))
70002 + return 1;
70003 +
70004 + if (!reload) {
70005 + /* grab reference for the real root dentry and vfsmount */
70006 + get_fs_root(reaper->fs, &gr_real_root);
70007 +
70008 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70009 + 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);
70010 +#endif
70011 +
70012 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70013 + if (fakefs_obj_rw == NULL)
70014 + return 1;
70015 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
70016 +
70017 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70018 + if (fakefs_obj_rwx == NULL)
70019 + return 1;
70020 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
70021 + }
70022 +
70023 + polstate->subj_map_set.s_hash =
70024 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
70025 + polstate->acl_role_set.r_hash =
70026 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
70027 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
70028 + polstate->inodev_set.i_hash =
70029 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
70030 +
70031 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
70032 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
70033 + return 1;
70034 +
70035 + memset(polstate->subj_map_set.s_hash, 0,
70036 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
70037 + memset(polstate->acl_role_set.r_hash, 0,
70038 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
70039 + memset(polstate->name_set.n_hash, 0,
70040 + sizeof (struct name_entry *) * polstate->name_set.n_size);
70041 + memset(polstate->inodev_set.i_hash, 0,
70042 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
70043 +
70044 + return 0;
70045 +}
70046 +
70047 +/* free information not needed after startup
70048 + currently contains user->kernel pointer mappings for subjects
70049 +*/
70050 +
70051 +static void
70052 +free_init_variables(void)
70053 +{
70054 + __u32 i;
70055 +
70056 + if (polstate->subj_map_set.s_hash) {
70057 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
70058 + if (polstate->subj_map_set.s_hash[i]) {
70059 + kfree(polstate->subj_map_set.s_hash[i]);
70060 + polstate->subj_map_set.s_hash[i] = NULL;
70061 + }
70062 + }
70063 +
70064 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
70065 + PAGE_SIZE)
70066 + kfree(polstate->subj_map_set.s_hash);
70067 + else
70068 + vfree(polstate->subj_map_set.s_hash);
70069 + }
70070 +
70071 + return;
70072 +}
70073 +
70074 +static void
70075 +free_variables(bool reload)
70076 +{
70077 + struct acl_subject_label *s;
70078 + struct acl_role_label *r;
70079 + struct task_struct *task, *task2;
70080 + unsigned int x;
70081 +
70082 + if (!reload) {
70083 + gr_clear_learn_entries();
70084 +
70085 + read_lock(&tasklist_lock);
70086 + do_each_thread(task2, task) {
70087 + task->acl_sp_role = 0;
70088 + task->acl_role_id = 0;
70089 + task->inherited = 0;
70090 + task->acl = NULL;
70091 + task->role = NULL;
70092 + } while_each_thread(task2, task);
70093 + read_unlock(&tasklist_lock);
70094 +
70095 + kfree(fakefs_obj_rw);
70096 + fakefs_obj_rw = NULL;
70097 + kfree(fakefs_obj_rwx);
70098 + fakefs_obj_rwx = NULL;
70099 +
70100 + /* release the reference to the real root dentry and vfsmount */
70101 + path_put(&gr_real_root);
70102 + memset(&gr_real_root, 0, sizeof(gr_real_root));
70103 + }
70104 +
70105 + /* free all object hash tables */
70106 +
70107 + FOR_EACH_ROLE_START(r)
70108 + if (r->subj_hash == NULL)
70109 + goto next_role;
70110 + FOR_EACH_SUBJECT_START(r, s, x)
70111 + if (s->obj_hash == NULL)
70112 + break;
70113 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70114 + kfree(s->obj_hash);
70115 + else
70116 + vfree(s->obj_hash);
70117 + FOR_EACH_SUBJECT_END(s, x)
70118 + FOR_EACH_NESTED_SUBJECT_START(r, s)
70119 + if (s->obj_hash == NULL)
70120 + break;
70121 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70122 + kfree(s->obj_hash);
70123 + else
70124 + vfree(s->obj_hash);
70125 + FOR_EACH_NESTED_SUBJECT_END(s)
70126 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
70127 + kfree(r->subj_hash);
70128 + else
70129 + vfree(r->subj_hash);
70130 + r->subj_hash = NULL;
70131 +next_role:
70132 + FOR_EACH_ROLE_END(r)
70133 +
70134 + acl_free_all();
70135 +
70136 + if (polstate->acl_role_set.r_hash) {
70137 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
70138 + PAGE_SIZE)
70139 + kfree(polstate->acl_role_set.r_hash);
70140 + else
70141 + vfree(polstate->acl_role_set.r_hash);
70142 + }
70143 + if (polstate->name_set.n_hash) {
70144 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
70145 + PAGE_SIZE)
70146 + kfree(polstate->name_set.n_hash);
70147 + else
70148 + vfree(polstate->name_set.n_hash);
70149 + }
70150 +
70151 + if (polstate->inodev_set.i_hash) {
70152 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
70153 + PAGE_SIZE)
70154 + kfree(polstate->inodev_set.i_hash);
70155 + else
70156 + vfree(polstate->inodev_set.i_hash);
70157 + }
70158 +
70159 + if (!reload)
70160 + gr_free_uidset();
70161 +
70162 + memset(&polstate->name_set, 0, sizeof (struct name_db));
70163 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
70164 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
70165 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
70166 +
70167 + polstate->default_role = NULL;
70168 + polstate->kernel_role = NULL;
70169 + polstate->role_list = NULL;
70170 +
70171 + return;
70172 +}
70173 +
70174 +static struct acl_subject_label *
70175 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
70176 +
70177 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
70178 +{
70179 + unsigned int len = strnlen_user(*name, maxlen);
70180 + char *tmp;
70181 +
70182 + if (!len || len >= maxlen)
70183 + return -EINVAL;
70184 +
70185 + if ((tmp = (char *) acl_alloc(len)) == NULL)
70186 + return -ENOMEM;
70187 +
70188 + if (copy_from_user(tmp, *name, len))
70189 + return -EFAULT;
70190 +
70191 + tmp[len-1] = '\0';
70192 + *name = tmp;
70193 +
70194 + return 0;
70195 +}
70196 +
70197 +static int
70198 +copy_user_glob(struct acl_object_label *obj)
70199 +{
70200 + struct acl_object_label *g_tmp, **guser;
70201 + int error;
70202 +
70203 + if (obj->globbed == NULL)
70204 + return 0;
70205 +
70206 + guser = &obj->globbed;
70207 + while (*guser) {
70208 + g_tmp = (struct acl_object_label *)
70209 + acl_alloc(sizeof (struct acl_object_label));
70210 + if (g_tmp == NULL)
70211 + return -ENOMEM;
70212 +
70213 + if (copy_acl_object_label(g_tmp, *guser))
70214 + return -EFAULT;
70215 +
70216 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
70217 + if (error)
70218 + return error;
70219 +
70220 + *guser = g_tmp;
70221 + guser = &(g_tmp->next);
70222 + }
70223 +
70224 + return 0;
70225 +}
70226 +
70227 +static int
70228 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
70229 + struct acl_role_label *role)
70230 +{
70231 + struct acl_object_label *o_tmp;
70232 + int ret;
70233 +
70234 + while (userp) {
70235 + if ((o_tmp = (struct acl_object_label *)
70236 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
70237 + return -ENOMEM;
70238 +
70239 + if (copy_acl_object_label(o_tmp, userp))
70240 + return -EFAULT;
70241 +
70242 + userp = o_tmp->prev;
70243 +
70244 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
70245 + if (ret)
70246 + return ret;
70247 +
70248 + insert_acl_obj_label(o_tmp, subj);
70249 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
70250 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
70251 + return -ENOMEM;
70252 +
70253 + ret = copy_user_glob(o_tmp);
70254 + if (ret)
70255 + return ret;
70256 +
70257 + if (o_tmp->nested) {
70258 + int already_copied;
70259 +
70260 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
70261 + if (IS_ERR(o_tmp->nested))
70262 + return PTR_ERR(o_tmp->nested);
70263 +
70264 + /* insert into nested subject list if we haven't copied this one yet
70265 + to prevent duplicate entries */
70266 + if (!already_copied) {
70267 + o_tmp->nested->next = role->hash->first;
70268 + role->hash->first = o_tmp->nested;
70269 + }
70270 + }
70271 + }
70272 +
70273 + return 0;
70274 +}
70275 +
70276 +static __u32
70277 +count_user_subjs(struct acl_subject_label *userp)
70278 +{
70279 + struct acl_subject_label s_tmp;
70280 + __u32 num = 0;
70281 +
70282 + while (userp) {
70283 + if (copy_acl_subject_label(&s_tmp, userp))
70284 + break;
70285 +
70286 + userp = s_tmp.prev;
70287 + }
70288 +
70289 + return num;
70290 +}
70291 +
70292 +static int
70293 +copy_user_allowedips(struct acl_role_label *rolep)
70294 +{
70295 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
70296 +
70297 + ruserip = rolep->allowed_ips;
70298 +
70299 + while (ruserip) {
70300 + rlast = rtmp;
70301 +
70302 + if ((rtmp = (struct role_allowed_ip *)
70303 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
70304 + return -ENOMEM;
70305 +
70306 + if (copy_role_allowed_ip(rtmp, ruserip))
70307 + return -EFAULT;
70308 +
70309 + ruserip = rtmp->prev;
70310 +
70311 + if (!rlast) {
70312 + rtmp->prev = NULL;
70313 + rolep->allowed_ips = rtmp;
70314 + } else {
70315 + rlast->next = rtmp;
70316 + rtmp->prev = rlast;
70317 + }
70318 +
70319 + if (!ruserip)
70320 + rtmp->next = NULL;
70321 + }
70322 +
70323 + return 0;
70324 +}
70325 +
70326 +static int
70327 +copy_user_transitions(struct acl_role_label *rolep)
70328 +{
70329 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
70330 + int error;
70331 +
70332 + rusertp = rolep->transitions;
70333 +
70334 + while (rusertp) {
70335 + rlast = rtmp;
70336 +
70337 + if ((rtmp = (struct role_transition *)
70338 + acl_alloc(sizeof (struct role_transition))) == NULL)
70339 + return -ENOMEM;
70340 +
70341 + if (copy_role_transition(rtmp, rusertp))
70342 + return -EFAULT;
70343 +
70344 + rusertp = rtmp->prev;
70345 +
70346 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
70347 + if (error)
70348 + return error;
70349 +
70350 + if (!rlast) {
70351 + rtmp->prev = NULL;
70352 + rolep->transitions = rtmp;
70353 + } else {
70354 + rlast->next = rtmp;
70355 + rtmp->prev = rlast;
70356 + }
70357 +
70358 + if (!rusertp)
70359 + rtmp->next = NULL;
70360 + }
70361 +
70362 + return 0;
70363 +}
70364 +
70365 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
70366 +{
70367 + struct acl_object_label o_tmp;
70368 + __u32 num = 0;
70369 +
70370 + while (userp) {
70371 + if (copy_acl_object_label(&o_tmp, userp))
70372 + break;
70373 +
70374 + userp = o_tmp.prev;
70375 + num++;
70376 + }
70377 +
70378 + return num;
70379 +}
70380 +
70381 +static struct acl_subject_label *
70382 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
70383 +{
70384 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
70385 + __u32 num_objs;
70386 + struct acl_ip_label **i_tmp, *i_utmp2;
70387 + struct gr_hash_struct ghash;
70388 + struct subject_map *subjmap;
70389 + unsigned int i_num;
70390 + int err;
70391 +
70392 + if (already_copied != NULL)
70393 + *already_copied = 0;
70394 +
70395 + s_tmp = lookup_subject_map(userp);
70396 +
70397 + /* we've already copied this subject into the kernel, just return
70398 + the reference to it, and don't copy it over again
70399 + */
70400 + if (s_tmp) {
70401 + if (already_copied != NULL)
70402 + *already_copied = 1;
70403 + return(s_tmp);
70404 + }
70405 +
70406 + if ((s_tmp = (struct acl_subject_label *)
70407 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
70408 + return ERR_PTR(-ENOMEM);
70409 +
70410 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
70411 + if (subjmap == NULL)
70412 + return ERR_PTR(-ENOMEM);
70413 +
70414 + subjmap->user = userp;
70415 + subjmap->kernel = s_tmp;
70416 + insert_subj_map_entry(subjmap);
70417 +
70418 + if (copy_acl_subject_label(s_tmp, userp))
70419 + return ERR_PTR(-EFAULT);
70420 +
70421 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
70422 + if (err)
70423 + return ERR_PTR(err);
70424 +
70425 + if (!strcmp(s_tmp->filename, "/"))
70426 + role->root_label = s_tmp;
70427 +
70428 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
70429 + return ERR_PTR(-EFAULT);
70430 +
70431 + /* copy user and group transition tables */
70432 +
70433 + if (s_tmp->user_trans_num) {
70434 + uid_t *uidlist;
70435 +
70436 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
70437 + if (uidlist == NULL)
70438 + return ERR_PTR(-ENOMEM);
70439 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
70440 + return ERR_PTR(-EFAULT);
70441 +
70442 + s_tmp->user_transitions = uidlist;
70443 + }
70444 +
70445 + if (s_tmp->group_trans_num) {
70446 + gid_t *gidlist;
70447 +
70448 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
70449 + if (gidlist == NULL)
70450 + return ERR_PTR(-ENOMEM);
70451 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
70452 + return ERR_PTR(-EFAULT);
70453 +
70454 + s_tmp->group_transitions = gidlist;
70455 + }
70456 +
70457 + /* set up object hash table */
70458 + num_objs = count_user_objs(ghash.first);
70459 +
70460 + s_tmp->obj_hash_size = num_objs;
70461 + s_tmp->obj_hash =
70462 + (struct acl_object_label **)
70463 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
70464 +
70465 + if (!s_tmp->obj_hash)
70466 + return ERR_PTR(-ENOMEM);
70467 +
70468 + memset(s_tmp->obj_hash, 0,
70469 + s_tmp->obj_hash_size *
70470 + sizeof (struct acl_object_label *));
70471 +
70472 + /* add in objects */
70473 + err = copy_user_objs(ghash.first, s_tmp, role);
70474 +
70475 + if (err)
70476 + return ERR_PTR(err);
70477 +
70478 + /* set pointer for parent subject */
70479 + if (s_tmp->parent_subject) {
70480 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
70481 +
70482 + if (IS_ERR(s_tmp2))
70483 + return s_tmp2;
70484 +
70485 + s_tmp->parent_subject = s_tmp2;
70486 + }
70487 +
70488 + /* add in ip acls */
70489 +
70490 + if (!s_tmp->ip_num) {
70491 + s_tmp->ips = NULL;
70492 + goto insert;
70493 + }
70494 +
70495 + i_tmp =
70496 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
70497 + sizeof (struct acl_ip_label *));
70498 +
70499 + if (!i_tmp)
70500 + return ERR_PTR(-ENOMEM);
70501 +
70502 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
70503 + *(i_tmp + i_num) =
70504 + (struct acl_ip_label *)
70505 + acl_alloc(sizeof (struct acl_ip_label));
70506 + if (!*(i_tmp + i_num))
70507 + return ERR_PTR(-ENOMEM);
70508 +
70509 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
70510 + return ERR_PTR(-EFAULT);
70511 +
70512 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
70513 + return ERR_PTR(-EFAULT);
70514 +
70515 + if ((*(i_tmp + i_num))->iface == NULL)
70516 + continue;
70517 +
70518 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
70519 + if (err)
70520 + return ERR_PTR(err);
70521 + }
70522 +
70523 + s_tmp->ips = i_tmp;
70524 +
70525 +insert:
70526 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
70527 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
70528 + return ERR_PTR(-ENOMEM);
70529 +
70530 + return s_tmp;
70531 +}
70532 +
70533 +static int
70534 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
70535 +{
70536 + struct acl_subject_label s_pre;
70537 + struct acl_subject_label * ret;
70538 + int err;
70539 +
70540 + while (userp) {
70541 + if (copy_acl_subject_label(&s_pre, userp))
70542 + return -EFAULT;
70543 +
70544 + ret = do_copy_user_subj(userp, role, NULL);
70545 +
70546 + err = PTR_ERR(ret);
70547 + if (IS_ERR(ret))
70548 + return err;
70549 +
70550 + insert_acl_subj_label(ret, role);
70551 +
70552 + userp = s_pre.prev;
70553 + }
70554 +
70555 + return 0;
70556 +}
70557 +
70558 +static int
70559 +copy_user_acl(struct gr_arg *arg)
70560 +{
70561 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
70562 + struct acl_subject_label *subj_list;
70563 + struct sprole_pw *sptmp;
70564 + struct gr_hash_struct *ghash;
70565 + uid_t *domainlist;
70566 + unsigned int r_num;
70567 + int err = 0;
70568 + __u16 i;
70569 + __u32 num_subjs;
70570 +
70571 + /* we need a default and kernel role */
70572 + if (arg->role_db.num_roles < 2)
70573 + return -EINVAL;
70574 +
70575 + /* copy special role authentication info from userspace */
70576 +
70577 + polstate->num_sprole_pws = arg->num_sprole_pws;
70578 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
70579 +
70580 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
70581 + return -ENOMEM;
70582 +
70583 + for (i = 0; i < polstate->num_sprole_pws; i++) {
70584 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
70585 + if (!sptmp)
70586 + return -ENOMEM;
70587 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
70588 + return -EFAULT;
70589 +
70590 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
70591 + if (err)
70592 + return err;
70593 +
70594 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70595 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
70596 +#endif
70597 +
70598 + polstate->acl_special_roles[i] = sptmp;
70599 + }
70600 +
70601 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
70602 +
70603 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
70604 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
70605 +
70606 + if (!r_tmp)
70607 + return -ENOMEM;
70608 +
70609 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
70610 + return -EFAULT;
70611 +
70612 + if (copy_acl_role_label(r_tmp, r_utmp2))
70613 + return -EFAULT;
70614 +
70615 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
70616 + if (err)
70617 + return err;
70618 +
70619 + if (!strcmp(r_tmp->rolename, "default")
70620 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
70621 + polstate->default_role = r_tmp;
70622 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
70623 + polstate->kernel_role = r_tmp;
70624 + }
70625 +
70626 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
70627 + return -ENOMEM;
70628 +
70629 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
70630 + return -EFAULT;
70631 +
70632 + r_tmp->hash = ghash;
70633 +
70634 + num_subjs = count_user_subjs(r_tmp->hash->first);
70635 +
70636 + r_tmp->subj_hash_size = num_subjs;
70637 + r_tmp->subj_hash =
70638 + (struct acl_subject_label **)
70639 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
70640 +
70641 + if (!r_tmp->subj_hash)
70642 + return -ENOMEM;
70643 +
70644 + err = copy_user_allowedips(r_tmp);
70645 + if (err)
70646 + return err;
70647 +
70648 + /* copy domain info */
70649 + if (r_tmp->domain_children != NULL) {
70650 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
70651 + if (domainlist == NULL)
70652 + return -ENOMEM;
70653 +
70654 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
70655 + return -EFAULT;
70656 +
70657 + r_tmp->domain_children = domainlist;
70658 + }
70659 +
70660 + err = copy_user_transitions(r_tmp);
70661 + if (err)
70662 + return err;
70663 +
70664 + memset(r_tmp->subj_hash, 0,
70665 + r_tmp->subj_hash_size *
70666 + sizeof (struct acl_subject_label *));
70667 +
70668 + /* acquire the list of subjects, then NULL out
70669 + the list prior to parsing the subjects for this role,
70670 + as during this parsing the list is replaced with a list
70671 + of *nested* subjects for the role
70672 + */
70673 + subj_list = r_tmp->hash->first;
70674 +
70675 + /* set nested subject list to null */
70676 + r_tmp->hash->first = NULL;
70677 +
70678 + err = copy_user_subjs(subj_list, r_tmp);
70679 +
70680 + if (err)
70681 + return err;
70682 +
70683 + insert_acl_role_label(r_tmp);
70684 + }
70685 +
70686 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
70687 + return -EINVAL;
70688 +
70689 + return err;
70690 +}
70691 +
70692 +static int gracl_reload_apply_policies(void *reload)
70693 +{
70694 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
70695 + struct task_struct *task, *task2;
70696 + struct acl_role_label *role, *rtmp;
70697 + struct acl_subject_label *subj;
70698 + const struct cred *cred;
70699 + int role_applied;
70700 + int ret = 0;
70701 +
70702 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
70703 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
70704 +
70705 + /* first make sure we'll be able to apply the new policy cleanly */
70706 + do_each_thread(task2, task) {
70707 + if (task->exec_file == NULL)
70708 + continue;
70709 + role_applied = 0;
70710 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70711 + /* preserve special roles */
70712 + FOR_EACH_ROLE_START(role)
70713 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70714 + rtmp = task->role;
70715 + task->role = role;
70716 + role_applied = 1;
70717 + break;
70718 + }
70719 + FOR_EACH_ROLE_END(role)
70720 + }
70721 + if (!role_applied) {
70722 + cred = __task_cred(task);
70723 + rtmp = task->role;
70724 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70725 + }
70726 + /* this handles non-nested inherited subjects, nested subjects will still
70727 + be dropped currently */
70728 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70729 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
70730 + /* change the role back so that we've made no modifications to the policy */
70731 + task->role = rtmp;
70732 +
70733 + if (subj == NULL || task->tmpacl == NULL) {
70734 + ret = -EINVAL;
70735 + goto out;
70736 + }
70737 + } while_each_thread(task2, task);
70738 +
70739 + /* now actually apply the policy */
70740 +
70741 + do_each_thread(task2, task) {
70742 + if (task->exec_file) {
70743 + role_applied = 0;
70744 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70745 + /* preserve special roles */
70746 + FOR_EACH_ROLE_START(role)
70747 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70748 + task->role = role;
70749 + role_applied = 1;
70750 + break;
70751 + }
70752 + FOR_EACH_ROLE_END(role)
70753 + }
70754 + if (!role_applied) {
70755 + cred = __task_cred(task);
70756 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70757 + }
70758 + /* this handles non-nested inherited subjects, nested subjects will still
70759 + be dropped currently */
70760 + if (!reload_state->oldmode && task->inherited)
70761 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70762 + else {
70763 + /* looked up and tagged to the task previously */
70764 + subj = task->tmpacl;
70765 + }
70766 + /* subj will be non-null */
70767 + __gr_apply_subject_to_task(polstate, task, subj);
70768 + if (reload_state->oldmode) {
70769 + task->acl_role_id = 0;
70770 + task->acl_sp_role = 0;
70771 + task->inherited = 0;
70772 + }
70773 + } else {
70774 + // it's a kernel process
70775 + task->role = polstate->kernel_role;
70776 + task->acl = polstate->kernel_role->root_label;
70777 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
70778 + task->acl->mode &= ~GR_PROCFIND;
70779 +#endif
70780 + }
70781 + } while_each_thread(task2, task);
70782 +
70783 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
70784 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
70785 +
70786 +out:
70787 +
70788 + return ret;
70789 +}
70790 +
70791 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
70792 +{
70793 + struct gr_reload_state new_reload_state = { };
70794 + int err;
70795 +
70796 + new_reload_state.oldpolicy_ptr = polstate;
70797 + new_reload_state.oldalloc_ptr = current_alloc_state;
70798 + new_reload_state.oldmode = oldmode;
70799 +
70800 + current_alloc_state = &new_reload_state.newalloc;
70801 + polstate = &new_reload_state.newpolicy;
70802 +
70803 + /* everything relevant is now saved off, copy in the new policy */
70804 + if (init_variables(args, true)) {
70805 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70806 + err = -ENOMEM;
70807 + goto error;
70808 + }
70809 +
70810 + err = copy_user_acl(args);
70811 + free_init_variables();
70812 + if (err)
70813 + goto error;
70814 + /* the new policy is copied in, with the old policy available via saved_state
70815 + first go through applying roles, making sure to preserve special roles
70816 + then apply new subjects, making sure to preserve inherited and nested subjects,
70817 + though currently only inherited subjects will be preserved
70818 + */
70819 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
70820 + if (err)
70821 + goto error;
70822 +
70823 + /* we've now applied the new policy, so restore the old policy state to free it */
70824 + polstate = &new_reload_state.oldpolicy;
70825 + current_alloc_state = &new_reload_state.oldalloc;
70826 + free_variables(true);
70827 +
70828 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
70829 + to running_polstate/current_alloc_state inside stop_machine
70830 + */
70831 + err = 0;
70832 + goto out;
70833 +error:
70834 + /* on error of loading the new policy, we'll just keep the previous
70835 + policy set around
70836 + */
70837 + free_variables(true);
70838 +
70839 + /* doesn't affect runtime, but maintains consistent state */
70840 +out:
70841 + polstate = new_reload_state.oldpolicy_ptr;
70842 + current_alloc_state = new_reload_state.oldalloc_ptr;
70843 +
70844 + return err;
70845 +}
70846 +
70847 +static int
70848 +gracl_init(struct gr_arg *args)
70849 +{
70850 + int error = 0;
70851 +
70852 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
70853 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
70854 +
70855 + if (init_variables(args, false)) {
70856 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70857 + error = -ENOMEM;
70858 + goto out;
70859 + }
70860 +
70861 + error = copy_user_acl(args);
70862 + free_init_variables();
70863 + if (error)
70864 + goto out;
70865 +
70866 + error = gr_set_acls(0);
70867 + if (error)
70868 + goto out;
70869 +
70870 + gr_enable_rbac_system();
70871 +
70872 + return 0;
70873 +
70874 +out:
70875 + free_variables(false);
70876 + return error;
70877 +}
70878 +
70879 +static int
70880 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
70881 + unsigned char **sum)
70882 +{
70883 + struct acl_role_label *r;
70884 + struct role_allowed_ip *ipp;
70885 + struct role_transition *trans;
70886 + unsigned int i;
70887 + int found = 0;
70888 + u32 curr_ip = current->signal->curr_ip;
70889 +
70890 + current->signal->saved_ip = curr_ip;
70891 +
70892 + /* check transition table */
70893 +
70894 + for (trans = current->role->transitions; trans; trans = trans->next) {
70895 + if (!strcmp(rolename, trans->rolename)) {
70896 + found = 1;
70897 + break;
70898 + }
70899 + }
70900 +
70901 + if (!found)
70902 + return 0;
70903 +
70904 + /* handle special roles that do not require authentication
70905 + and check ip */
70906 +
70907 + FOR_EACH_ROLE_START(r)
70908 + if (!strcmp(rolename, r->rolename) &&
70909 + (r->roletype & GR_ROLE_SPECIAL)) {
70910 + found = 0;
70911 + if (r->allowed_ips != NULL) {
70912 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
70913 + if ((ntohl(curr_ip) & ipp->netmask) ==
70914 + (ntohl(ipp->addr) & ipp->netmask))
70915 + found = 1;
70916 + }
70917 + } else
70918 + found = 2;
70919 + if (!found)
70920 + return 0;
70921 +
70922 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
70923 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
70924 + *salt = NULL;
70925 + *sum = NULL;
70926 + return 1;
70927 + }
70928 + }
70929 + FOR_EACH_ROLE_END(r)
70930 +
70931 + for (i = 0; i < polstate->num_sprole_pws; i++) {
70932 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
70933 + *salt = polstate->acl_special_roles[i]->salt;
70934 + *sum = polstate->acl_special_roles[i]->sum;
70935 + return 1;
70936 + }
70937 + }
70938 +
70939 + return 0;
70940 +}
70941 +
70942 +int gr_check_secure_terminal(struct task_struct *task)
70943 +{
70944 + struct task_struct *p, *p2, *p3;
70945 + struct files_struct *files;
70946 + struct fdtable *fdt;
70947 + struct file *our_file = NULL, *file;
70948 + int i;
70949 +
70950 + if (task->signal->tty == NULL)
70951 + return 1;
70952 +
70953 + files = get_files_struct(task);
70954 + if (files != NULL) {
70955 + rcu_read_lock();
70956 + fdt = files_fdtable(files);
70957 + for (i=0; i < fdt->max_fds; i++) {
70958 + file = fcheck_files(files, i);
70959 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
70960 + get_file(file);
70961 + our_file = file;
70962 + }
70963 + }
70964 + rcu_read_unlock();
70965 + put_files_struct(files);
70966 + }
70967 +
70968 + if (our_file == NULL)
70969 + return 1;
70970 +
70971 + read_lock(&tasklist_lock);
70972 + do_each_thread(p2, p) {
70973 + files = get_files_struct(p);
70974 + if (files == NULL ||
70975 + (p->signal && p->signal->tty == task->signal->tty)) {
70976 + if (files != NULL)
70977 + put_files_struct(files);
70978 + continue;
70979 + }
70980 + rcu_read_lock();
70981 + fdt = files_fdtable(files);
70982 + for (i=0; i < fdt->max_fds; i++) {
70983 + file = fcheck_files(files, i);
70984 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
70985 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
70986 + p3 = task;
70987 + while (task_pid_nr(p3) > 0) {
70988 + if (p3 == p)
70989 + break;
70990 + p3 = p3->real_parent;
70991 + }
70992 + if (p3 == p)
70993 + break;
70994 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
70995 + gr_handle_alertkill(p);
70996 + rcu_read_unlock();
70997 + put_files_struct(files);
70998 + read_unlock(&tasklist_lock);
70999 + fput(our_file);
71000 + return 0;
71001 + }
71002 + }
71003 + rcu_read_unlock();
71004 + put_files_struct(files);
71005 + } while_each_thread(p2, p);
71006 + read_unlock(&tasklist_lock);
71007 +
71008 + fput(our_file);
71009 + return 1;
71010 +}
71011 +
71012 +ssize_t
71013 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
71014 +{
71015 + struct gr_arg_wrapper uwrap;
71016 + unsigned char *sprole_salt = NULL;
71017 + unsigned char *sprole_sum = NULL;
71018 + int error = 0;
71019 + int error2 = 0;
71020 + size_t req_count = 0;
71021 + unsigned char oldmode = 0;
71022 +
71023 + mutex_lock(&gr_dev_mutex);
71024 +
71025 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
71026 + error = -EPERM;
71027 + goto out;
71028 + }
71029 +
71030 +#ifdef CONFIG_COMPAT
71031 + pax_open_kernel();
71032 + if (is_compat_task()) {
71033 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
71034 + copy_gr_arg = &copy_gr_arg_compat;
71035 + copy_acl_object_label = &copy_acl_object_label_compat;
71036 + copy_acl_subject_label = &copy_acl_subject_label_compat;
71037 + copy_acl_role_label = &copy_acl_role_label_compat;
71038 + copy_acl_ip_label = &copy_acl_ip_label_compat;
71039 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
71040 + copy_role_transition = &copy_role_transition_compat;
71041 + copy_sprole_pw = &copy_sprole_pw_compat;
71042 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
71043 + copy_pointer_from_array = &copy_pointer_from_array_compat;
71044 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
71045 + } else {
71046 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
71047 + copy_gr_arg = &copy_gr_arg_normal;
71048 + copy_acl_object_label = &copy_acl_object_label_normal;
71049 + copy_acl_subject_label = &copy_acl_subject_label_normal;
71050 + copy_acl_role_label = &copy_acl_role_label_normal;
71051 + copy_acl_ip_label = &copy_acl_ip_label_normal;
71052 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
71053 + copy_role_transition = &copy_role_transition_normal;
71054 + copy_sprole_pw = &copy_sprole_pw_normal;
71055 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
71056 + copy_pointer_from_array = &copy_pointer_from_array_normal;
71057 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
71058 + }
71059 + pax_close_kernel();
71060 +#endif
71061 +
71062 + req_count = get_gr_arg_wrapper_size();
71063 +
71064 + if (count != req_count) {
71065 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
71066 + error = -EINVAL;
71067 + goto out;
71068 + }
71069 +
71070 +
71071 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
71072 + gr_auth_expires = 0;
71073 + gr_auth_attempts = 0;
71074 + }
71075 +
71076 + error = copy_gr_arg_wrapper(buf, &uwrap);
71077 + if (error)
71078 + goto out;
71079 +
71080 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
71081 + if (error)
71082 + goto out;
71083 +
71084 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71085 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71086 + time_after(gr_auth_expires, get_seconds())) {
71087 + error = -EBUSY;
71088 + goto out;
71089 + }
71090 +
71091 + /* if non-root trying to do anything other than use a special role,
71092 + do not attempt authentication, do not count towards authentication
71093 + locking
71094 + */
71095 +
71096 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
71097 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71098 + gr_is_global_nonroot(current_uid())) {
71099 + error = -EPERM;
71100 + goto out;
71101 + }
71102 +
71103 + /* ensure pw and special role name are null terminated */
71104 +
71105 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
71106 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
71107 +
71108 + /* Okay.
71109 + * We have our enough of the argument structure..(we have yet
71110 + * to copy_from_user the tables themselves) . Copy the tables
71111 + * only if we need them, i.e. for loading operations. */
71112 +
71113 + switch (gr_usermode.mode) {
71114 + case GR_STATUS:
71115 + if (gr_acl_is_enabled()) {
71116 + error = 1;
71117 + if (!gr_check_secure_terminal(current))
71118 + error = 3;
71119 + } else
71120 + error = 2;
71121 + goto out;
71122 + case GR_SHUTDOWN:
71123 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71124 + stop_machine(gr_rbac_disable, NULL, NULL);
71125 + free_variables(false);
71126 + memset(&gr_usermode, 0, sizeof(gr_usermode));
71127 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
71128 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
71129 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
71130 + } else if (gr_acl_is_enabled()) {
71131 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
71132 + error = -EPERM;
71133 + } else {
71134 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
71135 + error = -EAGAIN;
71136 + }
71137 + break;
71138 + case GR_ENABLE:
71139 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
71140 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
71141 + else {
71142 + if (gr_acl_is_enabled())
71143 + error = -EAGAIN;
71144 + else
71145 + error = error2;
71146 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
71147 + }
71148 + break;
71149 + case GR_OLDRELOAD:
71150 + oldmode = 1;
71151 + case GR_RELOAD:
71152 + if (!gr_acl_is_enabled()) {
71153 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
71154 + error = -EAGAIN;
71155 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71156 + error2 = gracl_reload(&gr_usermode, oldmode);
71157 + if (!error2)
71158 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
71159 + else {
71160 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71161 + error = error2;
71162 + }
71163 + } else {
71164 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71165 + error = -EPERM;
71166 + }
71167 + break;
71168 + case GR_SEGVMOD:
71169 + if (unlikely(!gr_acl_is_enabled())) {
71170 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
71171 + error = -EAGAIN;
71172 + break;
71173 + }
71174 +
71175 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71176 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
71177 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
71178 + struct acl_subject_label *segvacl;
71179 + segvacl =
71180 + lookup_acl_subj_label(gr_usermode.segv_inode,
71181 + gr_usermode.segv_device,
71182 + current->role);
71183 + if (segvacl) {
71184 + segvacl->crashes = 0;
71185 + segvacl->expires = 0;
71186 + }
71187 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
71188 + gr_remove_uid(gr_usermode.segv_uid);
71189 + }
71190 + } else {
71191 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
71192 + error = -EPERM;
71193 + }
71194 + break;
71195 + case GR_SPROLE:
71196 + case GR_SPROLEPAM:
71197 + if (unlikely(!gr_acl_is_enabled())) {
71198 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
71199 + error = -EAGAIN;
71200 + break;
71201 + }
71202 +
71203 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
71204 + current->role->expires = 0;
71205 + current->role->auth_attempts = 0;
71206 + }
71207 +
71208 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71209 + time_after(current->role->expires, get_seconds())) {
71210 + error = -EBUSY;
71211 + goto out;
71212 + }
71213 +
71214 + if (lookup_special_role_auth
71215 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
71216 + && ((!sprole_salt && !sprole_sum)
71217 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
71218 + char *p = "";
71219 + assign_special_role(gr_usermode.sp_role);
71220 + read_lock(&tasklist_lock);
71221 + if (current->real_parent)
71222 + p = current->real_parent->role->rolename;
71223 + read_unlock(&tasklist_lock);
71224 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
71225 + p, acl_sp_role_value);
71226 + } else {
71227 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
71228 + error = -EPERM;
71229 + if(!(current->role->auth_attempts++))
71230 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71231 +
71232 + goto out;
71233 + }
71234 + break;
71235 + case GR_UNSPROLE:
71236 + if (unlikely(!gr_acl_is_enabled())) {
71237 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
71238 + error = -EAGAIN;
71239 + break;
71240 + }
71241 +
71242 + if (current->role->roletype & GR_ROLE_SPECIAL) {
71243 + char *p = "";
71244 + int i = 0;
71245 +
71246 + read_lock(&tasklist_lock);
71247 + if (current->real_parent) {
71248 + p = current->real_parent->role->rolename;
71249 + i = current->real_parent->acl_role_id;
71250 + }
71251 + read_unlock(&tasklist_lock);
71252 +
71253 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
71254 + gr_set_acls(1);
71255 + } else {
71256 + error = -EPERM;
71257 + goto out;
71258 + }
71259 + break;
71260 + default:
71261 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
71262 + error = -EINVAL;
71263 + break;
71264 + }
71265 +
71266 + if (error != -EPERM)
71267 + goto out;
71268 +
71269 + if(!(gr_auth_attempts++))
71270 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71271 +
71272 + out:
71273 + mutex_unlock(&gr_dev_mutex);
71274 +
71275 + if (!error)
71276 + error = req_count;
71277 +
71278 + return error;
71279 +}
71280 +
71281 +int
71282 +gr_set_acls(const int type)
71283 +{
71284 + struct task_struct *task, *task2;
71285 + struct acl_role_label *role = current->role;
71286 + struct acl_subject_label *subj;
71287 + __u16 acl_role_id = current->acl_role_id;
71288 + const struct cred *cred;
71289 + int ret;
71290 +
71291 + rcu_read_lock();
71292 + read_lock(&tasklist_lock);
71293 + read_lock(&grsec_exec_file_lock);
71294 + do_each_thread(task2, task) {
71295 + /* check to see if we're called from the exit handler,
71296 + if so, only replace ACLs that have inherited the admin
71297 + ACL */
71298 +
71299 + if (type && (task->role != role ||
71300 + task->acl_role_id != acl_role_id))
71301 + continue;
71302 +
71303 + task->acl_role_id = 0;
71304 + task->acl_sp_role = 0;
71305 + task->inherited = 0;
71306 +
71307 + if (task->exec_file) {
71308 + cred = __task_cred(task);
71309 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71310 + subj = __gr_get_subject_for_task(polstate, task, NULL);
71311 + if (subj == NULL) {
71312 + ret = -EINVAL;
71313 + read_unlock(&grsec_exec_file_lock);
71314 + read_unlock(&tasklist_lock);
71315 + rcu_read_unlock();
71316 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
71317 + return ret;
71318 + }
71319 + __gr_apply_subject_to_task(polstate, task, subj);
71320 + } else {
71321 + // it's a kernel process
71322 + task->role = polstate->kernel_role;
71323 + task->acl = polstate->kernel_role->root_label;
71324 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71325 + task->acl->mode &= ~GR_PROCFIND;
71326 +#endif
71327 + }
71328 + } while_each_thread(task2, task);
71329 + read_unlock(&grsec_exec_file_lock);
71330 + read_unlock(&tasklist_lock);
71331 + rcu_read_unlock();
71332 +
71333 + return 0;
71334 +}
71335 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
71336 new file mode 100644
71337 index 0000000..39645c9
71338 --- /dev/null
71339 +++ b/grsecurity/gracl_res.c
71340 @@ -0,0 +1,68 @@
71341 +#include <linux/kernel.h>
71342 +#include <linux/sched.h>
71343 +#include <linux/gracl.h>
71344 +#include <linux/grinternal.h>
71345 +
71346 +static const char *restab_log[] = {
71347 + [RLIMIT_CPU] = "RLIMIT_CPU",
71348 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
71349 + [RLIMIT_DATA] = "RLIMIT_DATA",
71350 + [RLIMIT_STACK] = "RLIMIT_STACK",
71351 + [RLIMIT_CORE] = "RLIMIT_CORE",
71352 + [RLIMIT_RSS] = "RLIMIT_RSS",
71353 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
71354 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
71355 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
71356 + [RLIMIT_AS] = "RLIMIT_AS",
71357 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
71358 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
71359 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
71360 + [RLIMIT_NICE] = "RLIMIT_NICE",
71361 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
71362 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
71363 + [GR_CRASH_RES] = "RLIMIT_CRASH"
71364 +};
71365 +
71366 +void
71367 +gr_log_resource(const struct task_struct *task,
71368 + const int res, const unsigned long wanted, const int gt)
71369 +{
71370 + const struct cred *cred;
71371 + unsigned long rlim;
71372 +
71373 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
71374 + return;
71375 +
71376 + // not yet supported resource
71377 + if (unlikely(!restab_log[res]))
71378 + return;
71379 +
71380 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
71381 + rlim = task_rlimit_max(task, res);
71382 + else
71383 + rlim = task_rlimit(task, res);
71384 +
71385 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
71386 + return;
71387 +
71388 + rcu_read_lock();
71389 + cred = __task_cred(task);
71390 +
71391 + if (res == RLIMIT_NPROC &&
71392 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
71393 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
71394 + goto out_rcu_unlock;
71395 + else if (res == RLIMIT_MEMLOCK &&
71396 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
71397 + goto out_rcu_unlock;
71398 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
71399 + goto out_rcu_unlock;
71400 + rcu_read_unlock();
71401 +
71402 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
71403 +
71404 + return;
71405 +out_rcu_unlock:
71406 + rcu_read_unlock();
71407 + return;
71408 +}
71409 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
71410 new file mode 100644
71411 index 0000000..2040e61
71412 --- /dev/null
71413 +++ b/grsecurity/gracl_segv.c
71414 @@ -0,0 +1,313 @@
71415 +#include <linux/kernel.h>
71416 +#include <linux/mm.h>
71417 +#include <asm/uaccess.h>
71418 +#include <asm/errno.h>
71419 +#include <asm/mman.h>
71420 +#include <net/sock.h>
71421 +#include <linux/file.h>
71422 +#include <linux/fs.h>
71423 +#include <linux/net.h>
71424 +#include <linux/in.h>
71425 +#include <linux/slab.h>
71426 +#include <linux/types.h>
71427 +#include <linux/sched.h>
71428 +#include <linux/timer.h>
71429 +#include <linux/gracl.h>
71430 +#include <linux/grsecurity.h>
71431 +#include <linux/grinternal.h>
71432 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71433 +#include <linux/magic.h>
71434 +#include <linux/pagemap.h>
71435 +#include "../fs/btrfs/async-thread.h"
71436 +#include "../fs/btrfs/ctree.h"
71437 +#include "../fs/btrfs/btrfs_inode.h"
71438 +#endif
71439 +
71440 +static struct crash_uid *uid_set;
71441 +static unsigned short uid_used;
71442 +static DEFINE_SPINLOCK(gr_uid_lock);
71443 +extern rwlock_t gr_inode_lock;
71444 +extern struct acl_subject_label *
71445 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
71446 + struct acl_role_label *role);
71447 +
71448 +static inline dev_t __get_dev(const struct dentry *dentry)
71449 +{
71450 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71451 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
71452 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
71453 + else
71454 +#endif
71455 + return dentry->d_sb->s_dev;
71456 +}
71457 +
71458 +int
71459 +gr_init_uidset(void)
71460 +{
71461 + uid_set =
71462 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
71463 + uid_used = 0;
71464 +
71465 + return uid_set ? 1 : 0;
71466 +}
71467 +
71468 +void
71469 +gr_free_uidset(void)
71470 +{
71471 + if (uid_set) {
71472 + struct crash_uid *tmpset;
71473 + spin_lock(&gr_uid_lock);
71474 + tmpset = uid_set;
71475 + uid_set = NULL;
71476 + uid_used = 0;
71477 + spin_unlock(&gr_uid_lock);
71478 + if (tmpset)
71479 + kfree(tmpset);
71480 + }
71481 +
71482 + return;
71483 +}
71484 +
71485 +int
71486 +gr_find_uid(const uid_t uid)
71487 +{
71488 + struct crash_uid *tmp = uid_set;
71489 + uid_t buid;
71490 + int low = 0, high = uid_used - 1, mid;
71491 +
71492 + while (high >= low) {
71493 + mid = (low + high) >> 1;
71494 + buid = tmp[mid].uid;
71495 + if (buid == uid)
71496 + return mid;
71497 + if (buid > uid)
71498 + high = mid - 1;
71499 + if (buid < uid)
71500 + low = mid + 1;
71501 + }
71502 +
71503 + return -1;
71504 +}
71505 +
71506 +static __inline__ void
71507 +gr_insertsort(void)
71508 +{
71509 + unsigned short i, j;
71510 + struct crash_uid index;
71511 +
71512 + for (i = 1; i < uid_used; i++) {
71513 + index = uid_set[i];
71514 + j = i;
71515 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
71516 + uid_set[j] = uid_set[j - 1];
71517 + j--;
71518 + }
71519 + uid_set[j] = index;
71520 + }
71521 +
71522 + return;
71523 +}
71524 +
71525 +static __inline__ void
71526 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
71527 +{
71528 + int loc;
71529 + uid_t uid = GR_GLOBAL_UID(kuid);
71530 +
71531 + if (uid_used == GR_UIDTABLE_MAX)
71532 + return;
71533 +
71534 + loc = gr_find_uid(uid);
71535 +
71536 + if (loc >= 0) {
71537 + uid_set[loc].expires = expires;
71538 + return;
71539 + }
71540 +
71541 + uid_set[uid_used].uid = uid;
71542 + uid_set[uid_used].expires = expires;
71543 + uid_used++;
71544 +
71545 + gr_insertsort();
71546 +
71547 + return;
71548 +}
71549 +
71550 +void
71551 +gr_remove_uid(const unsigned short loc)
71552 +{
71553 + unsigned short i;
71554 +
71555 + for (i = loc + 1; i < uid_used; i++)
71556 + uid_set[i - 1] = uid_set[i];
71557 +
71558 + uid_used--;
71559 +
71560 + return;
71561 +}
71562 +
71563 +int
71564 +gr_check_crash_uid(const kuid_t kuid)
71565 +{
71566 + int loc;
71567 + int ret = 0;
71568 + uid_t uid;
71569 +
71570 + if (unlikely(!gr_acl_is_enabled()))
71571 + return 0;
71572 +
71573 + uid = GR_GLOBAL_UID(kuid);
71574 +
71575 + spin_lock(&gr_uid_lock);
71576 + loc = gr_find_uid(uid);
71577 +
71578 + if (loc < 0)
71579 + goto out_unlock;
71580 +
71581 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
71582 + gr_remove_uid(loc);
71583 + else
71584 + ret = 1;
71585 +
71586 +out_unlock:
71587 + spin_unlock(&gr_uid_lock);
71588 + return ret;
71589 +}
71590 +
71591 +static __inline__ int
71592 +proc_is_setxid(const struct cred *cred)
71593 +{
71594 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
71595 + !uid_eq(cred->uid, cred->fsuid))
71596 + return 1;
71597 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
71598 + !gid_eq(cred->gid, cred->fsgid))
71599 + return 1;
71600 +
71601 + return 0;
71602 +}
71603 +
71604 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
71605 +
71606 +void
71607 +gr_handle_crash(struct task_struct *task, const int sig)
71608 +{
71609 + struct acl_subject_label *curr;
71610 + struct task_struct *tsk, *tsk2;
71611 + const struct cred *cred;
71612 + const struct cred *cred2;
71613 +
71614 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
71615 + return;
71616 +
71617 + if (unlikely(!gr_acl_is_enabled()))
71618 + return;
71619 +
71620 + curr = task->acl;
71621 +
71622 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
71623 + return;
71624 +
71625 + if (time_before_eq(curr->expires, get_seconds())) {
71626 + curr->expires = 0;
71627 + curr->crashes = 0;
71628 + }
71629 +
71630 + curr->crashes++;
71631 +
71632 + if (!curr->expires)
71633 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
71634 +
71635 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71636 + time_after(curr->expires, get_seconds())) {
71637 + rcu_read_lock();
71638 + cred = __task_cred(task);
71639 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
71640 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71641 + spin_lock(&gr_uid_lock);
71642 + gr_insert_uid(cred->uid, curr->expires);
71643 + spin_unlock(&gr_uid_lock);
71644 + curr->expires = 0;
71645 + curr->crashes = 0;
71646 + read_lock(&tasklist_lock);
71647 + do_each_thread(tsk2, tsk) {
71648 + cred2 = __task_cred(tsk);
71649 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
71650 + gr_fake_force_sig(SIGKILL, tsk);
71651 + } while_each_thread(tsk2, tsk);
71652 + read_unlock(&tasklist_lock);
71653 + } else {
71654 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71655 + read_lock(&tasklist_lock);
71656 + read_lock(&grsec_exec_file_lock);
71657 + do_each_thread(tsk2, tsk) {
71658 + if (likely(tsk != task)) {
71659 + // if this thread has the same subject as the one that triggered
71660 + // RES_CRASH and it's the same binary, kill it
71661 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
71662 + gr_fake_force_sig(SIGKILL, tsk);
71663 + }
71664 + } while_each_thread(tsk2, tsk);
71665 + read_unlock(&grsec_exec_file_lock);
71666 + read_unlock(&tasklist_lock);
71667 + }
71668 + rcu_read_unlock();
71669 + }
71670 +
71671 + return;
71672 +}
71673 +
71674 +int
71675 +gr_check_crash_exec(const struct file *filp)
71676 +{
71677 + struct acl_subject_label *curr;
71678 +
71679 + if (unlikely(!gr_acl_is_enabled()))
71680 + return 0;
71681 +
71682 + read_lock(&gr_inode_lock);
71683 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
71684 + __get_dev(filp->f_path.dentry),
71685 + current->role);
71686 + read_unlock(&gr_inode_lock);
71687 +
71688 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
71689 + (!curr->crashes && !curr->expires))
71690 + return 0;
71691 +
71692 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71693 + time_after(curr->expires, get_seconds()))
71694 + return 1;
71695 + else if (time_before_eq(curr->expires, get_seconds())) {
71696 + curr->crashes = 0;
71697 + curr->expires = 0;
71698 + }
71699 +
71700 + return 0;
71701 +}
71702 +
71703 +void
71704 +gr_handle_alertkill(struct task_struct *task)
71705 +{
71706 + struct acl_subject_label *curracl;
71707 + __u32 curr_ip;
71708 + struct task_struct *p, *p2;
71709 +
71710 + if (unlikely(!gr_acl_is_enabled()))
71711 + return;
71712 +
71713 + curracl = task->acl;
71714 + curr_ip = task->signal->curr_ip;
71715 +
71716 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
71717 + read_lock(&tasklist_lock);
71718 + do_each_thread(p2, p) {
71719 + if (p->signal->curr_ip == curr_ip)
71720 + gr_fake_force_sig(SIGKILL, p);
71721 + } while_each_thread(p2, p);
71722 + read_unlock(&tasklist_lock);
71723 + } else if (curracl->mode & GR_KILLPROC)
71724 + gr_fake_force_sig(SIGKILL, task);
71725 +
71726 + return;
71727 +}
71728 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
71729 new file mode 100644
71730 index 0000000..98011b0
71731 --- /dev/null
71732 +++ b/grsecurity/gracl_shm.c
71733 @@ -0,0 +1,40 @@
71734 +#include <linux/kernel.h>
71735 +#include <linux/mm.h>
71736 +#include <linux/sched.h>
71737 +#include <linux/file.h>
71738 +#include <linux/ipc.h>
71739 +#include <linux/gracl.h>
71740 +#include <linux/grsecurity.h>
71741 +#include <linux/grinternal.h>
71742 +
71743 +int
71744 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71745 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
71746 +{
71747 + struct task_struct *task;
71748 +
71749 + if (!gr_acl_is_enabled())
71750 + return 1;
71751 +
71752 + rcu_read_lock();
71753 + read_lock(&tasklist_lock);
71754 +
71755 + task = find_task_by_vpid(shm_cprid);
71756 +
71757 + if (unlikely(!task))
71758 + task = find_task_by_vpid(shm_lapid);
71759 +
71760 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
71761 + (task_pid_nr(task) == shm_lapid)) &&
71762 + (task->acl->mode & GR_PROTSHM) &&
71763 + (task->acl != current->acl))) {
71764 + read_unlock(&tasklist_lock);
71765 + rcu_read_unlock();
71766 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
71767 + return 0;
71768 + }
71769 + read_unlock(&tasklist_lock);
71770 + rcu_read_unlock();
71771 +
71772 + return 1;
71773 +}
71774 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
71775 new file mode 100644
71776 index 0000000..bc0be01
71777 --- /dev/null
71778 +++ b/grsecurity/grsec_chdir.c
71779 @@ -0,0 +1,19 @@
71780 +#include <linux/kernel.h>
71781 +#include <linux/sched.h>
71782 +#include <linux/fs.h>
71783 +#include <linux/file.h>
71784 +#include <linux/grsecurity.h>
71785 +#include <linux/grinternal.h>
71786 +
71787 +void
71788 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
71789 +{
71790 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71791 + if ((grsec_enable_chdir && grsec_enable_group &&
71792 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
71793 + !grsec_enable_group)) {
71794 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
71795 + }
71796 +#endif
71797 + return;
71798 +}
71799 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
71800 new file mode 100644
71801 index 0000000..e10b319
71802 --- /dev/null
71803 +++ b/grsecurity/grsec_chroot.c
71804 @@ -0,0 +1,370 @@
71805 +#include <linux/kernel.h>
71806 +#include <linux/module.h>
71807 +#include <linux/sched.h>
71808 +#include <linux/file.h>
71809 +#include <linux/fs.h>
71810 +#include <linux/mount.h>
71811 +#include <linux/types.h>
71812 +#include "../fs/mount.h"
71813 +#include <linux/grsecurity.h>
71814 +#include <linux/grinternal.h>
71815 +
71816 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71817 +int gr_init_ran;
71818 +#endif
71819 +
71820 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
71821 +{
71822 +#ifdef CONFIG_GRKERNSEC
71823 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
71824 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
71825 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71826 + && gr_init_ran
71827 +#endif
71828 + )
71829 + task->gr_is_chrooted = 1;
71830 + else {
71831 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71832 + if (task_pid_nr(task) == 1 && !gr_init_ran)
71833 + gr_init_ran = 1;
71834 +#endif
71835 + task->gr_is_chrooted = 0;
71836 + }
71837 +
71838 + task->gr_chroot_dentry = path->dentry;
71839 +#endif
71840 + return;
71841 +}
71842 +
71843 +void gr_clear_chroot_entries(struct task_struct *task)
71844 +{
71845 +#ifdef CONFIG_GRKERNSEC
71846 + task->gr_is_chrooted = 0;
71847 + task->gr_chroot_dentry = NULL;
71848 +#endif
71849 + return;
71850 +}
71851 +
71852 +int
71853 +gr_handle_chroot_unix(const pid_t pid)
71854 +{
71855 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71856 + struct task_struct *p;
71857 +
71858 + if (unlikely(!grsec_enable_chroot_unix))
71859 + return 1;
71860 +
71861 + if (likely(!proc_is_chrooted(current)))
71862 + return 1;
71863 +
71864 + rcu_read_lock();
71865 + read_lock(&tasklist_lock);
71866 + p = find_task_by_vpid_unrestricted(pid);
71867 + if (unlikely(p && !have_same_root(current, p))) {
71868 + read_unlock(&tasklist_lock);
71869 + rcu_read_unlock();
71870 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
71871 + return 0;
71872 + }
71873 + read_unlock(&tasklist_lock);
71874 + rcu_read_unlock();
71875 +#endif
71876 + return 1;
71877 +}
71878 +
71879 +int
71880 +gr_handle_chroot_nice(void)
71881 +{
71882 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71883 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
71884 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
71885 + return -EPERM;
71886 + }
71887 +#endif
71888 + return 0;
71889 +}
71890 +
71891 +int
71892 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
71893 +{
71894 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71895 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
71896 + && proc_is_chrooted(current)) {
71897 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
71898 + return -EACCES;
71899 + }
71900 +#endif
71901 + return 0;
71902 +}
71903 +
71904 +int
71905 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
71906 +{
71907 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71908 + struct task_struct *p;
71909 + int ret = 0;
71910 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
71911 + return ret;
71912 +
71913 + read_lock(&tasklist_lock);
71914 + do_each_pid_task(pid, type, p) {
71915 + if (!have_same_root(current, p)) {
71916 + ret = 1;
71917 + goto out;
71918 + }
71919 + } while_each_pid_task(pid, type, p);
71920 +out:
71921 + read_unlock(&tasklist_lock);
71922 + return ret;
71923 +#endif
71924 + return 0;
71925 +}
71926 +
71927 +int
71928 +gr_pid_is_chrooted(struct task_struct *p)
71929 +{
71930 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71931 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
71932 + return 0;
71933 +
71934 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
71935 + !have_same_root(current, p)) {
71936 + return 1;
71937 + }
71938 +#endif
71939 + return 0;
71940 +}
71941 +
71942 +EXPORT_SYMBOL(gr_pid_is_chrooted);
71943 +
71944 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
71945 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
71946 +{
71947 + struct path path, currentroot;
71948 + int ret = 0;
71949 +
71950 + path.dentry = (struct dentry *)u_dentry;
71951 + path.mnt = (struct vfsmount *)u_mnt;
71952 + get_fs_root(current->fs, &currentroot);
71953 + if (path_is_under(&path, &currentroot))
71954 + ret = 1;
71955 + path_put(&currentroot);
71956 +
71957 + return ret;
71958 +}
71959 +#endif
71960 +
71961 +int
71962 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
71963 +{
71964 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71965 + if (!grsec_enable_chroot_fchdir)
71966 + return 1;
71967 +
71968 + if (!proc_is_chrooted(current))
71969 + return 1;
71970 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
71971 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
71972 + return 0;
71973 + }
71974 +#endif
71975 + return 1;
71976 +}
71977 +
71978 +int
71979 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71980 + const time_t shm_createtime)
71981 +{
71982 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71983 + struct task_struct *p;
71984 + time_t starttime;
71985 +
71986 + if (unlikely(!grsec_enable_chroot_shmat))
71987 + return 1;
71988 +
71989 + if (likely(!proc_is_chrooted(current)))
71990 + return 1;
71991 +
71992 + rcu_read_lock();
71993 + read_lock(&tasklist_lock);
71994 +
71995 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
71996 + starttime = p->start_time.tv_sec;
71997 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
71998 + if (have_same_root(current, p)) {
71999 + goto allow;
72000 + } else {
72001 + read_unlock(&tasklist_lock);
72002 + rcu_read_unlock();
72003 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72004 + return 0;
72005 + }
72006 + }
72007 + /* creator exited, pid reuse, fall through to next check */
72008 + }
72009 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
72010 + if (unlikely(!have_same_root(current, p))) {
72011 + read_unlock(&tasklist_lock);
72012 + rcu_read_unlock();
72013 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72014 + return 0;
72015 + }
72016 + }
72017 +
72018 +allow:
72019 + read_unlock(&tasklist_lock);
72020 + rcu_read_unlock();
72021 +#endif
72022 + return 1;
72023 +}
72024 +
72025 +void
72026 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
72027 +{
72028 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72029 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
72030 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
72031 +#endif
72032 + return;
72033 +}
72034 +
72035 +int
72036 +gr_handle_chroot_mknod(const struct dentry *dentry,
72037 + const struct vfsmount *mnt, const int mode)
72038 +{
72039 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72040 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
72041 + proc_is_chrooted(current)) {
72042 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
72043 + return -EPERM;
72044 + }
72045 +#endif
72046 + return 0;
72047 +}
72048 +
72049 +int
72050 +gr_handle_chroot_mount(const struct dentry *dentry,
72051 + const struct vfsmount *mnt, const char *dev_name)
72052 +{
72053 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72054 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
72055 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
72056 + return -EPERM;
72057 + }
72058 +#endif
72059 + return 0;
72060 +}
72061 +
72062 +int
72063 +gr_handle_chroot_pivot(void)
72064 +{
72065 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72066 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
72067 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
72068 + return -EPERM;
72069 + }
72070 +#endif
72071 + return 0;
72072 +}
72073 +
72074 +int
72075 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
72076 +{
72077 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72078 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
72079 + !gr_is_outside_chroot(dentry, mnt)) {
72080 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
72081 + return -EPERM;
72082 + }
72083 +#endif
72084 + return 0;
72085 +}
72086 +
72087 +extern const char *captab_log[];
72088 +extern int captab_log_entries;
72089 +
72090 +int
72091 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72092 +{
72093 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72094 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72095 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72096 + if (cap_raised(chroot_caps, cap)) {
72097 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
72098 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
72099 + }
72100 + return 0;
72101 + }
72102 + }
72103 +#endif
72104 + return 1;
72105 +}
72106 +
72107 +int
72108 +gr_chroot_is_capable(const int cap)
72109 +{
72110 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72111 + return gr_task_chroot_is_capable(current, current_cred(), cap);
72112 +#endif
72113 + return 1;
72114 +}
72115 +
72116 +int
72117 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
72118 +{
72119 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72120 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72121 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72122 + if (cap_raised(chroot_caps, cap)) {
72123 + return 0;
72124 + }
72125 + }
72126 +#endif
72127 + return 1;
72128 +}
72129 +
72130 +int
72131 +gr_chroot_is_capable_nolog(const int cap)
72132 +{
72133 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72134 + return gr_task_chroot_is_capable_nolog(current, cap);
72135 +#endif
72136 + return 1;
72137 +}
72138 +
72139 +int
72140 +gr_handle_chroot_sysctl(const int op)
72141 +{
72142 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72143 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
72144 + proc_is_chrooted(current))
72145 + return -EACCES;
72146 +#endif
72147 + return 0;
72148 +}
72149 +
72150 +void
72151 +gr_handle_chroot_chdir(const struct path *path)
72152 +{
72153 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72154 + if (grsec_enable_chroot_chdir)
72155 + set_fs_pwd(current->fs, path);
72156 +#endif
72157 + return;
72158 +}
72159 +
72160 +int
72161 +gr_handle_chroot_chmod(const struct dentry *dentry,
72162 + const struct vfsmount *mnt, const int mode)
72163 +{
72164 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72165 + /* allow chmod +s on directories, but not files */
72166 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
72167 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
72168 + proc_is_chrooted(current)) {
72169 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
72170 + return -EPERM;
72171 + }
72172 +#endif
72173 + return 0;
72174 +}
72175 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
72176 new file mode 100644
72177 index 0000000..52b3e30
72178 --- /dev/null
72179 +++ b/grsecurity/grsec_disabled.c
72180 @@ -0,0 +1,433 @@
72181 +#include <linux/kernel.h>
72182 +#include <linux/module.h>
72183 +#include <linux/sched.h>
72184 +#include <linux/file.h>
72185 +#include <linux/fs.h>
72186 +#include <linux/kdev_t.h>
72187 +#include <linux/net.h>
72188 +#include <linux/in.h>
72189 +#include <linux/ip.h>
72190 +#include <linux/skbuff.h>
72191 +#include <linux/sysctl.h>
72192 +
72193 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
72194 +void
72195 +pax_set_initial_flags(struct linux_binprm *bprm)
72196 +{
72197 + return;
72198 +}
72199 +#endif
72200 +
72201 +#ifdef CONFIG_SYSCTL
72202 +__u32
72203 +gr_handle_sysctl(const struct ctl_table * table, const int op)
72204 +{
72205 + return 0;
72206 +}
72207 +#endif
72208 +
72209 +#ifdef CONFIG_TASKSTATS
72210 +int gr_is_taskstats_denied(int pid)
72211 +{
72212 + return 0;
72213 +}
72214 +#endif
72215 +
72216 +int
72217 +gr_acl_is_enabled(void)
72218 +{
72219 + return 0;
72220 +}
72221 +
72222 +void
72223 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
72224 +{
72225 + return;
72226 +}
72227 +
72228 +int
72229 +gr_handle_rawio(const struct inode *inode)
72230 +{
72231 + return 0;
72232 +}
72233 +
72234 +void
72235 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72236 +{
72237 + return;
72238 +}
72239 +
72240 +int
72241 +gr_handle_ptrace(struct task_struct *task, const long request)
72242 +{
72243 + return 0;
72244 +}
72245 +
72246 +int
72247 +gr_handle_proc_ptrace(struct task_struct *task)
72248 +{
72249 + return 0;
72250 +}
72251 +
72252 +int
72253 +gr_set_acls(const int type)
72254 +{
72255 + return 0;
72256 +}
72257 +
72258 +int
72259 +gr_check_hidden_task(const struct task_struct *tsk)
72260 +{
72261 + return 0;
72262 +}
72263 +
72264 +int
72265 +gr_check_protected_task(const struct task_struct *task)
72266 +{
72267 + return 0;
72268 +}
72269 +
72270 +int
72271 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
72272 +{
72273 + return 0;
72274 +}
72275 +
72276 +void
72277 +gr_copy_label(struct task_struct *tsk)
72278 +{
72279 + return;
72280 +}
72281 +
72282 +void
72283 +gr_set_pax_flags(struct task_struct *task)
72284 +{
72285 + return;
72286 +}
72287 +
72288 +int
72289 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72290 + const int unsafe_share)
72291 +{
72292 + return 0;
72293 +}
72294 +
72295 +void
72296 +gr_handle_delete(const ino_t ino, const dev_t dev)
72297 +{
72298 + return;
72299 +}
72300 +
72301 +void
72302 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72303 +{
72304 + return;
72305 +}
72306 +
72307 +void
72308 +gr_handle_crash(struct task_struct *task, const int sig)
72309 +{
72310 + return;
72311 +}
72312 +
72313 +int
72314 +gr_check_crash_exec(const struct file *filp)
72315 +{
72316 + return 0;
72317 +}
72318 +
72319 +int
72320 +gr_check_crash_uid(const kuid_t uid)
72321 +{
72322 + return 0;
72323 +}
72324 +
72325 +void
72326 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72327 + struct dentry *old_dentry,
72328 + struct dentry *new_dentry,
72329 + struct vfsmount *mnt, const __u8 replace)
72330 +{
72331 + return;
72332 +}
72333 +
72334 +int
72335 +gr_search_socket(const int family, const int type, const int protocol)
72336 +{
72337 + return 1;
72338 +}
72339 +
72340 +int
72341 +gr_search_connectbind(const int mode, const struct socket *sock,
72342 + const struct sockaddr_in *addr)
72343 +{
72344 + return 0;
72345 +}
72346 +
72347 +void
72348 +gr_handle_alertkill(struct task_struct *task)
72349 +{
72350 + return;
72351 +}
72352 +
72353 +__u32
72354 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
72355 +{
72356 + return 1;
72357 +}
72358 +
72359 +__u32
72360 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72361 + const struct vfsmount * mnt)
72362 +{
72363 + return 1;
72364 +}
72365 +
72366 +__u32
72367 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72368 + int acc_mode)
72369 +{
72370 + return 1;
72371 +}
72372 +
72373 +__u32
72374 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72375 +{
72376 + return 1;
72377 +}
72378 +
72379 +__u32
72380 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
72381 +{
72382 + return 1;
72383 +}
72384 +
72385 +int
72386 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
72387 + unsigned int *vm_flags)
72388 +{
72389 + return 1;
72390 +}
72391 +
72392 +__u32
72393 +gr_acl_handle_truncate(const struct dentry * dentry,
72394 + const struct vfsmount * mnt)
72395 +{
72396 + return 1;
72397 +}
72398 +
72399 +__u32
72400 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
72401 +{
72402 + return 1;
72403 +}
72404 +
72405 +__u32
72406 +gr_acl_handle_access(const struct dentry * dentry,
72407 + const struct vfsmount * mnt, const int fmode)
72408 +{
72409 + return 1;
72410 +}
72411 +
72412 +__u32
72413 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
72414 + umode_t *mode)
72415 +{
72416 + return 1;
72417 +}
72418 +
72419 +__u32
72420 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
72421 +{
72422 + return 1;
72423 +}
72424 +
72425 +__u32
72426 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
72427 +{
72428 + return 1;
72429 +}
72430 +
72431 +__u32
72432 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
72433 +{
72434 + return 1;
72435 +}
72436 +
72437 +void
72438 +grsecurity_init(void)
72439 +{
72440 + return;
72441 +}
72442 +
72443 +umode_t gr_acl_umask(void)
72444 +{
72445 + return 0;
72446 +}
72447 +
72448 +__u32
72449 +gr_acl_handle_mknod(const struct dentry * new_dentry,
72450 + const struct dentry * parent_dentry,
72451 + const struct vfsmount * parent_mnt,
72452 + const int mode)
72453 +{
72454 + return 1;
72455 +}
72456 +
72457 +__u32
72458 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
72459 + const struct dentry * parent_dentry,
72460 + const struct vfsmount * parent_mnt)
72461 +{
72462 + return 1;
72463 +}
72464 +
72465 +__u32
72466 +gr_acl_handle_symlink(const struct dentry * new_dentry,
72467 + const struct dentry * parent_dentry,
72468 + const struct vfsmount * parent_mnt, const struct filename *from)
72469 +{
72470 + return 1;
72471 +}
72472 +
72473 +__u32
72474 +gr_acl_handle_link(const struct dentry * new_dentry,
72475 + const struct dentry * parent_dentry,
72476 + const struct vfsmount * parent_mnt,
72477 + const struct dentry * old_dentry,
72478 + const struct vfsmount * old_mnt, const struct filename *to)
72479 +{
72480 + return 1;
72481 +}
72482 +
72483 +int
72484 +gr_acl_handle_rename(const struct dentry *new_dentry,
72485 + const struct dentry *parent_dentry,
72486 + const struct vfsmount *parent_mnt,
72487 + const struct dentry *old_dentry,
72488 + const struct inode *old_parent_inode,
72489 + const struct vfsmount *old_mnt, const struct filename *newname)
72490 +{
72491 + return 0;
72492 +}
72493 +
72494 +int
72495 +gr_acl_handle_filldir(const struct file *file, const char *name,
72496 + const int namelen, const ino_t ino)
72497 +{
72498 + return 1;
72499 +}
72500 +
72501 +int
72502 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72503 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
72504 +{
72505 + return 1;
72506 +}
72507 +
72508 +int
72509 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
72510 +{
72511 + return 0;
72512 +}
72513 +
72514 +int
72515 +gr_search_accept(const struct socket *sock)
72516 +{
72517 + return 0;
72518 +}
72519 +
72520 +int
72521 +gr_search_listen(const struct socket *sock)
72522 +{
72523 + return 0;
72524 +}
72525 +
72526 +int
72527 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
72528 +{
72529 + return 0;
72530 +}
72531 +
72532 +__u32
72533 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
72534 +{
72535 + return 1;
72536 +}
72537 +
72538 +__u32
72539 +gr_acl_handle_creat(const struct dentry * dentry,
72540 + const struct dentry * p_dentry,
72541 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72542 + const int imode)
72543 +{
72544 + return 1;
72545 +}
72546 +
72547 +void
72548 +gr_acl_handle_exit(void)
72549 +{
72550 + return;
72551 +}
72552 +
72553 +int
72554 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72555 +{
72556 + return 1;
72557 +}
72558 +
72559 +void
72560 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
72561 +{
72562 + return;
72563 +}
72564 +
72565 +int
72566 +gr_acl_handle_procpidmem(const struct task_struct *task)
72567 +{
72568 + return 0;
72569 +}
72570 +
72571 +int
72572 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
72573 +{
72574 + return 0;
72575 +}
72576 +
72577 +int
72578 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
72579 +{
72580 + return 0;
72581 +}
72582 +
72583 +int
72584 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
72585 +{
72586 + return 0;
72587 +}
72588 +
72589 +int
72590 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72591 +{
72592 + return 0;
72593 +}
72594 +
72595 +int gr_acl_enable_at_secure(void)
72596 +{
72597 + return 0;
72598 +}
72599 +
72600 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
72601 +{
72602 + return dentry->d_sb->s_dev;
72603 +}
72604 +
72605 +void gr_put_exec_file(struct task_struct *task)
72606 +{
72607 + return;
72608 +}
72609 +
72610 +#ifdef CONFIG_SECURITY
72611 +EXPORT_SYMBOL(gr_check_user_change);
72612 +EXPORT_SYMBOL(gr_check_group_change);
72613 +#endif
72614 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
72615 new file mode 100644
72616 index 0000000..387032b
72617 --- /dev/null
72618 +++ b/grsecurity/grsec_exec.c
72619 @@ -0,0 +1,187 @@
72620 +#include <linux/kernel.h>
72621 +#include <linux/sched.h>
72622 +#include <linux/file.h>
72623 +#include <linux/binfmts.h>
72624 +#include <linux/fs.h>
72625 +#include <linux/types.h>
72626 +#include <linux/grdefs.h>
72627 +#include <linux/grsecurity.h>
72628 +#include <linux/grinternal.h>
72629 +#include <linux/capability.h>
72630 +#include <linux/module.h>
72631 +#include <linux/compat.h>
72632 +
72633 +#include <asm/uaccess.h>
72634 +
72635 +#ifdef CONFIG_GRKERNSEC_EXECLOG
72636 +static char gr_exec_arg_buf[132];
72637 +static DEFINE_MUTEX(gr_exec_arg_mutex);
72638 +#endif
72639 +
72640 +struct user_arg_ptr {
72641 +#ifdef CONFIG_COMPAT
72642 + bool is_compat;
72643 +#endif
72644 + union {
72645 + const char __user *const __user *native;
72646 +#ifdef CONFIG_COMPAT
72647 + const compat_uptr_t __user *compat;
72648 +#endif
72649 + } ptr;
72650 +};
72651 +
72652 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
72653 +
72654 +void
72655 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
72656 +{
72657 +#ifdef CONFIG_GRKERNSEC_EXECLOG
72658 + char *grarg = gr_exec_arg_buf;
72659 + unsigned int i, x, execlen = 0;
72660 + char c;
72661 +
72662 + if (!((grsec_enable_execlog && grsec_enable_group &&
72663 + in_group_p(grsec_audit_gid))
72664 + || (grsec_enable_execlog && !grsec_enable_group)))
72665 + return;
72666 +
72667 + mutex_lock(&gr_exec_arg_mutex);
72668 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
72669 +
72670 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
72671 + const char __user *p;
72672 + unsigned int len;
72673 +
72674 + p = get_user_arg_ptr(argv, i);
72675 + if (IS_ERR(p))
72676 + goto log;
72677 +
72678 + len = strnlen_user(p, 128 - execlen);
72679 + if (len > 128 - execlen)
72680 + len = 128 - execlen;
72681 + else if (len > 0)
72682 + len--;
72683 + if (copy_from_user(grarg + execlen, p, len))
72684 + goto log;
72685 +
72686 + /* rewrite unprintable characters */
72687 + for (x = 0; x < len; x++) {
72688 + c = *(grarg + execlen + x);
72689 + if (c < 32 || c > 126)
72690 + *(grarg + execlen + x) = ' ';
72691 + }
72692 +
72693 + execlen += len;
72694 + *(grarg + execlen) = ' ';
72695 + *(grarg + execlen + 1) = '\0';
72696 + execlen++;
72697 + }
72698 +
72699 + log:
72700 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
72701 + bprm->file->f_path.mnt, grarg);
72702 + mutex_unlock(&gr_exec_arg_mutex);
72703 +#endif
72704 + return;
72705 +}
72706 +
72707 +#ifdef CONFIG_GRKERNSEC
72708 +extern int gr_acl_is_capable(const int cap);
72709 +extern int gr_acl_is_capable_nolog(const int cap);
72710 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72711 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
72712 +extern int gr_chroot_is_capable(const int cap);
72713 +extern int gr_chroot_is_capable_nolog(const int cap);
72714 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72715 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
72716 +#endif
72717 +
72718 +const char *captab_log[] = {
72719 + "CAP_CHOWN",
72720 + "CAP_DAC_OVERRIDE",
72721 + "CAP_DAC_READ_SEARCH",
72722 + "CAP_FOWNER",
72723 + "CAP_FSETID",
72724 + "CAP_KILL",
72725 + "CAP_SETGID",
72726 + "CAP_SETUID",
72727 + "CAP_SETPCAP",
72728 + "CAP_LINUX_IMMUTABLE",
72729 + "CAP_NET_BIND_SERVICE",
72730 + "CAP_NET_BROADCAST",
72731 + "CAP_NET_ADMIN",
72732 + "CAP_NET_RAW",
72733 + "CAP_IPC_LOCK",
72734 + "CAP_IPC_OWNER",
72735 + "CAP_SYS_MODULE",
72736 + "CAP_SYS_RAWIO",
72737 + "CAP_SYS_CHROOT",
72738 + "CAP_SYS_PTRACE",
72739 + "CAP_SYS_PACCT",
72740 + "CAP_SYS_ADMIN",
72741 + "CAP_SYS_BOOT",
72742 + "CAP_SYS_NICE",
72743 + "CAP_SYS_RESOURCE",
72744 + "CAP_SYS_TIME",
72745 + "CAP_SYS_TTY_CONFIG",
72746 + "CAP_MKNOD",
72747 + "CAP_LEASE",
72748 + "CAP_AUDIT_WRITE",
72749 + "CAP_AUDIT_CONTROL",
72750 + "CAP_SETFCAP",
72751 + "CAP_MAC_OVERRIDE",
72752 + "CAP_MAC_ADMIN",
72753 + "CAP_SYSLOG",
72754 + "CAP_WAKE_ALARM"
72755 +};
72756 +
72757 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
72758 +
72759 +int gr_is_capable(const int cap)
72760 +{
72761 +#ifdef CONFIG_GRKERNSEC
72762 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
72763 + return 1;
72764 + return 0;
72765 +#else
72766 + return 1;
72767 +#endif
72768 +}
72769 +
72770 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72771 +{
72772 +#ifdef CONFIG_GRKERNSEC
72773 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
72774 + return 1;
72775 + return 0;
72776 +#else
72777 + return 1;
72778 +#endif
72779 +}
72780 +
72781 +int gr_is_capable_nolog(const int cap)
72782 +{
72783 +#ifdef CONFIG_GRKERNSEC
72784 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
72785 + return 1;
72786 + return 0;
72787 +#else
72788 + return 1;
72789 +#endif
72790 +}
72791 +
72792 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
72793 +{
72794 +#ifdef CONFIG_GRKERNSEC
72795 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
72796 + return 1;
72797 + return 0;
72798 +#else
72799 + return 1;
72800 +#endif
72801 +}
72802 +
72803 +EXPORT_SYMBOL(gr_is_capable);
72804 +EXPORT_SYMBOL(gr_is_capable_nolog);
72805 +EXPORT_SYMBOL(gr_task_is_capable);
72806 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
72807 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
72808 new file mode 100644
72809 index 0000000..06cc6ea
72810 --- /dev/null
72811 +++ b/grsecurity/grsec_fifo.c
72812 @@ -0,0 +1,24 @@
72813 +#include <linux/kernel.h>
72814 +#include <linux/sched.h>
72815 +#include <linux/fs.h>
72816 +#include <linux/file.h>
72817 +#include <linux/grinternal.h>
72818 +
72819 +int
72820 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
72821 + const struct dentry *dir, const int flag, const int acc_mode)
72822 +{
72823 +#ifdef CONFIG_GRKERNSEC_FIFO
72824 + const struct cred *cred = current_cred();
72825 +
72826 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
72827 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
72828 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
72829 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
72830 + if (!inode_permission(dentry->d_inode, acc_mode))
72831 + 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));
72832 + return -EACCES;
72833 + }
72834 +#endif
72835 + return 0;
72836 +}
72837 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
72838 new file mode 100644
72839 index 0000000..8ca18bf
72840 --- /dev/null
72841 +++ b/grsecurity/grsec_fork.c
72842 @@ -0,0 +1,23 @@
72843 +#include <linux/kernel.h>
72844 +#include <linux/sched.h>
72845 +#include <linux/grsecurity.h>
72846 +#include <linux/grinternal.h>
72847 +#include <linux/errno.h>
72848 +
72849 +void
72850 +gr_log_forkfail(const int retval)
72851 +{
72852 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
72853 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
72854 + switch (retval) {
72855 + case -EAGAIN:
72856 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
72857 + break;
72858 + case -ENOMEM:
72859 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
72860 + break;
72861 + }
72862 + }
72863 +#endif
72864 + return;
72865 +}
72866 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
72867 new file mode 100644
72868 index 0000000..a88e901
72869 --- /dev/null
72870 +++ b/grsecurity/grsec_init.c
72871 @@ -0,0 +1,272 @@
72872 +#include <linux/kernel.h>
72873 +#include <linux/sched.h>
72874 +#include <linux/mm.h>
72875 +#include <linux/gracl.h>
72876 +#include <linux/slab.h>
72877 +#include <linux/vmalloc.h>
72878 +#include <linux/percpu.h>
72879 +#include <linux/module.h>
72880 +
72881 +int grsec_enable_ptrace_readexec;
72882 +int grsec_enable_setxid;
72883 +int grsec_enable_symlinkown;
72884 +kgid_t grsec_symlinkown_gid;
72885 +int grsec_enable_brute;
72886 +int grsec_enable_link;
72887 +int grsec_enable_dmesg;
72888 +int grsec_enable_harden_ptrace;
72889 +int grsec_enable_harden_ipc;
72890 +int grsec_enable_fifo;
72891 +int grsec_enable_execlog;
72892 +int grsec_enable_signal;
72893 +int grsec_enable_forkfail;
72894 +int grsec_enable_audit_ptrace;
72895 +int grsec_enable_time;
72896 +int grsec_enable_group;
72897 +kgid_t grsec_audit_gid;
72898 +int grsec_enable_chdir;
72899 +int grsec_enable_mount;
72900 +int grsec_enable_rofs;
72901 +int grsec_deny_new_usb;
72902 +int grsec_enable_chroot_findtask;
72903 +int grsec_enable_chroot_mount;
72904 +int grsec_enable_chroot_shmat;
72905 +int grsec_enable_chroot_fchdir;
72906 +int grsec_enable_chroot_double;
72907 +int grsec_enable_chroot_pivot;
72908 +int grsec_enable_chroot_chdir;
72909 +int grsec_enable_chroot_chmod;
72910 +int grsec_enable_chroot_mknod;
72911 +int grsec_enable_chroot_nice;
72912 +int grsec_enable_chroot_execlog;
72913 +int grsec_enable_chroot_caps;
72914 +int grsec_enable_chroot_sysctl;
72915 +int grsec_enable_chroot_unix;
72916 +int grsec_enable_tpe;
72917 +kgid_t grsec_tpe_gid;
72918 +int grsec_enable_blackhole;
72919 +#ifdef CONFIG_IPV6_MODULE
72920 +EXPORT_SYMBOL(grsec_enable_blackhole);
72921 +#endif
72922 +int grsec_lastack_retries;
72923 +int grsec_enable_tpe_all;
72924 +int grsec_enable_tpe_invert;
72925 +int grsec_enable_socket_all;
72926 +kgid_t grsec_socket_all_gid;
72927 +int grsec_enable_socket_client;
72928 +kgid_t grsec_socket_client_gid;
72929 +int grsec_enable_socket_server;
72930 +kgid_t grsec_socket_server_gid;
72931 +int grsec_resource_logging;
72932 +int grsec_disable_privio;
72933 +int grsec_enable_log_rwxmaps;
72934 +int grsec_lock;
72935 +
72936 +DEFINE_SPINLOCK(grsec_alert_lock);
72937 +unsigned long grsec_alert_wtime = 0;
72938 +unsigned long grsec_alert_fyet = 0;
72939 +
72940 +DEFINE_SPINLOCK(grsec_audit_lock);
72941 +
72942 +DEFINE_RWLOCK(grsec_exec_file_lock);
72943 +
72944 +char *gr_shared_page[4];
72945 +
72946 +char *gr_alert_log_fmt;
72947 +char *gr_audit_log_fmt;
72948 +char *gr_alert_log_buf;
72949 +char *gr_audit_log_buf;
72950 +
72951 +void __init
72952 +grsecurity_init(void)
72953 +{
72954 + int j;
72955 + /* create the per-cpu shared pages */
72956 +
72957 +#ifdef CONFIG_X86
72958 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
72959 +#endif
72960 +
72961 + for (j = 0; j < 4; j++) {
72962 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
72963 + if (gr_shared_page[j] == NULL) {
72964 + panic("Unable to allocate grsecurity shared page");
72965 + return;
72966 + }
72967 + }
72968 +
72969 + /* allocate log buffers */
72970 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
72971 + if (!gr_alert_log_fmt) {
72972 + panic("Unable to allocate grsecurity alert log format buffer");
72973 + return;
72974 + }
72975 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
72976 + if (!gr_audit_log_fmt) {
72977 + panic("Unable to allocate grsecurity audit log format buffer");
72978 + return;
72979 + }
72980 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
72981 + if (!gr_alert_log_buf) {
72982 + panic("Unable to allocate grsecurity alert log buffer");
72983 + return;
72984 + }
72985 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
72986 + if (!gr_audit_log_buf) {
72987 + panic("Unable to allocate grsecurity audit log buffer");
72988 + return;
72989 + }
72990 +
72991 +#ifdef CONFIG_GRKERNSEC_IO
72992 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
72993 + grsec_disable_privio = 1;
72994 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
72995 + grsec_disable_privio = 1;
72996 +#else
72997 + grsec_disable_privio = 0;
72998 +#endif
72999 +#endif
73000 +
73001 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73002 + /* for backward compatibility, tpe_invert always defaults to on if
73003 + enabled in the kernel
73004 + */
73005 + grsec_enable_tpe_invert = 1;
73006 +#endif
73007 +
73008 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73009 +#ifndef CONFIG_GRKERNSEC_SYSCTL
73010 + grsec_lock = 1;
73011 +#endif
73012 +
73013 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73014 + grsec_enable_log_rwxmaps = 1;
73015 +#endif
73016 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
73017 + grsec_enable_group = 1;
73018 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
73019 +#endif
73020 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73021 + grsec_enable_ptrace_readexec = 1;
73022 +#endif
73023 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73024 + grsec_enable_chdir = 1;
73025 +#endif
73026 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73027 + grsec_enable_harden_ptrace = 1;
73028 +#endif
73029 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73030 + grsec_enable_harden_ipc = 1;
73031 +#endif
73032 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73033 + grsec_enable_mount = 1;
73034 +#endif
73035 +#ifdef CONFIG_GRKERNSEC_LINK
73036 + grsec_enable_link = 1;
73037 +#endif
73038 +#ifdef CONFIG_GRKERNSEC_BRUTE
73039 + grsec_enable_brute = 1;
73040 +#endif
73041 +#ifdef CONFIG_GRKERNSEC_DMESG
73042 + grsec_enable_dmesg = 1;
73043 +#endif
73044 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73045 + grsec_enable_blackhole = 1;
73046 + grsec_lastack_retries = 4;
73047 +#endif
73048 +#ifdef CONFIG_GRKERNSEC_FIFO
73049 + grsec_enable_fifo = 1;
73050 +#endif
73051 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73052 + grsec_enable_execlog = 1;
73053 +#endif
73054 +#ifdef CONFIG_GRKERNSEC_SETXID
73055 + grsec_enable_setxid = 1;
73056 +#endif
73057 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73058 + grsec_enable_signal = 1;
73059 +#endif
73060 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73061 + grsec_enable_forkfail = 1;
73062 +#endif
73063 +#ifdef CONFIG_GRKERNSEC_TIME
73064 + grsec_enable_time = 1;
73065 +#endif
73066 +#ifdef CONFIG_GRKERNSEC_RESLOG
73067 + grsec_resource_logging = 1;
73068 +#endif
73069 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73070 + grsec_enable_chroot_findtask = 1;
73071 +#endif
73072 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73073 + grsec_enable_chroot_unix = 1;
73074 +#endif
73075 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73076 + grsec_enable_chroot_mount = 1;
73077 +#endif
73078 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73079 + grsec_enable_chroot_fchdir = 1;
73080 +#endif
73081 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73082 + grsec_enable_chroot_shmat = 1;
73083 +#endif
73084 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73085 + grsec_enable_audit_ptrace = 1;
73086 +#endif
73087 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73088 + grsec_enable_chroot_double = 1;
73089 +#endif
73090 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73091 + grsec_enable_chroot_pivot = 1;
73092 +#endif
73093 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73094 + grsec_enable_chroot_chdir = 1;
73095 +#endif
73096 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73097 + grsec_enable_chroot_chmod = 1;
73098 +#endif
73099 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73100 + grsec_enable_chroot_mknod = 1;
73101 +#endif
73102 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73103 + grsec_enable_chroot_nice = 1;
73104 +#endif
73105 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73106 + grsec_enable_chroot_execlog = 1;
73107 +#endif
73108 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73109 + grsec_enable_chroot_caps = 1;
73110 +#endif
73111 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73112 + grsec_enable_chroot_sysctl = 1;
73113 +#endif
73114 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73115 + grsec_enable_symlinkown = 1;
73116 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
73117 +#endif
73118 +#ifdef CONFIG_GRKERNSEC_TPE
73119 + grsec_enable_tpe = 1;
73120 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
73121 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
73122 + grsec_enable_tpe_all = 1;
73123 +#endif
73124 +#endif
73125 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
73126 + grsec_enable_socket_all = 1;
73127 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
73128 +#endif
73129 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
73130 + grsec_enable_socket_client = 1;
73131 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
73132 +#endif
73133 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
73134 + grsec_enable_socket_server = 1;
73135 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
73136 +#endif
73137 +#endif
73138 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
73139 + grsec_deny_new_usb = 1;
73140 +#endif
73141 +
73142 + return;
73143 +}
73144 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
73145 new file mode 100644
73146 index 0000000..78d1680
73147 --- /dev/null
73148 +++ b/grsecurity/grsec_ipc.c
73149 @@ -0,0 +1,48 @@
73150 +#include <linux/kernel.h>
73151 +#include <linux/mm.h>
73152 +#include <linux/sched.h>
73153 +#include <linux/file.h>
73154 +#include <linux/ipc.h>
73155 +#include <linux/ipc_namespace.h>
73156 +#include <linux/grsecurity.h>
73157 +#include <linux/grinternal.h>
73158 +
73159 +int
73160 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
73161 +{
73162 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73163 + int write;
73164 + int orig_granted_mode;
73165 + kuid_t euid;
73166 + kgid_t egid;
73167 +
73168 + if (!grsec_enable_harden_ipc)
73169 + return 0;
73170 +
73171 + euid = current_euid();
73172 + egid = current_egid();
73173 +
73174 + write = requested_mode & 00002;
73175 + orig_granted_mode = ipcp->mode;
73176 +
73177 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
73178 + orig_granted_mode >>= 6;
73179 + else {
73180 + /* if likely wrong permissions, lock to user */
73181 + if (orig_granted_mode & 0007)
73182 + orig_granted_mode = 0;
73183 + /* otherwise do a egid-only check */
73184 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
73185 + orig_granted_mode >>= 3;
73186 + /* otherwise, no access */
73187 + else
73188 + orig_granted_mode = 0;
73189 + }
73190 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
73191 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
73192 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
73193 + return 0;
73194 + }
73195 +#endif
73196 + return 1;
73197 +}
73198 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
73199 new file mode 100644
73200 index 0000000..5e05e20
73201 --- /dev/null
73202 +++ b/grsecurity/grsec_link.c
73203 @@ -0,0 +1,58 @@
73204 +#include <linux/kernel.h>
73205 +#include <linux/sched.h>
73206 +#include <linux/fs.h>
73207 +#include <linux/file.h>
73208 +#include <linux/grinternal.h>
73209 +
73210 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
73211 +{
73212 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73213 + const struct inode *link_inode = link->dentry->d_inode;
73214 +
73215 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
73216 + /* ignore root-owned links, e.g. /proc/self */
73217 + gr_is_global_nonroot(link_inode->i_uid) && target &&
73218 + !uid_eq(link_inode->i_uid, target->i_uid)) {
73219 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
73220 + return 1;
73221 + }
73222 +#endif
73223 + return 0;
73224 +}
73225 +
73226 +int
73227 +gr_handle_follow_link(const struct inode *parent,
73228 + const struct inode *inode,
73229 + const struct dentry *dentry, const struct vfsmount *mnt)
73230 +{
73231 +#ifdef CONFIG_GRKERNSEC_LINK
73232 + const struct cred *cred = current_cred();
73233 +
73234 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
73235 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
73236 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
73237 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
73238 + return -EACCES;
73239 + }
73240 +#endif
73241 + return 0;
73242 +}
73243 +
73244 +int
73245 +gr_handle_hardlink(const struct dentry *dentry,
73246 + const struct vfsmount *mnt,
73247 + struct inode *inode, const int mode, const struct filename *to)
73248 +{
73249 +#ifdef CONFIG_GRKERNSEC_LINK
73250 + const struct cred *cred = current_cred();
73251 +
73252 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
73253 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
73254 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
73255 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
73256 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
73257 + return -EPERM;
73258 + }
73259 +#endif
73260 + return 0;
73261 +}
73262 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
73263 new file mode 100644
73264 index 0000000..dbe0a6b
73265 --- /dev/null
73266 +++ b/grsecurity/grsec_log.c
73267 @@ -0,0 +1,341 @@
73268 +#include <linux/kernel.h>
73269 +#include <linux/sched.h>
73270 +#include <linux/file.h>
73271 +#include <linux/tty.h>
73272 +#include <linux/fs.h>
73273 +#include <linux/mm.h>
73274 +#include <linux/grinternal.h>
73275 +
73276 +#ifdef CONFIG_TREE_PREEMPT_RCU
73277 +#define DISABLE_PREEMPT() preempt_disable()
73278 +#define ENABLE_PREEMPT() preempt_enable()
73279 +#else
73280 +#define DISABLE_PREEMPT()
73281 +#define ENABLE_PREEMPT()
73282 +#endif
73283 +
73284 +#define BEGIN_LOCKS(x) \
73285 + DISABLE_PREEMPT(); \
73286 + rcu_read_lock(); \
73287 + read_lock(&tasklist_lock); \
73288 + read_lock(&grsec_exec_file_lock); \
73289 + if (x != GR_DO_AUDIT) \
73290 + spin_lock(&grsec_alert_lock); \
73291 + else \
73292 + spin_lock(&grsec_audit_lock)
73293 +
73294 +#define END_LOCKS(x) \
73295 + if (x != GR_DO_AUDIT) \
73296 + spin_unlock(&grsec_alert_lock); \
73297 + else \
73298 + spin_unlock(&grsec_audit_lock); \
73299 + read_unlock(&grsec_exec_file_lock); \
73300 + read_unlock(&tasklist_lock); \
73301 + rcu_read_unlock(); \
73302 + ENABLE_PREEMPT(); \
73303 + if (x == GR_DONT_AUDIT) \
73304 + gr_handle_alertkill(current)
73305 +
73306 +enum {
73307 + FLOODING,
73308 + NO_FLOODING
73309 +};
73310 +
73311 +extern char *gr_alert_log_fmt;
73312 +extern char *gr_audit_log_fmt;
73313 +extern char *gr_alert_log_buf;
73314 +extern char *gr_audit_log_buf;
73315 +
73316 +static int gr_log_start(int audit)
73317 +{
73318 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
73319 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
73320 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73321 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
73322 + unsigned long curr_secs = get_seconds();
73323 +
73324 + if (audit == GR_DO_AUDIT)
73325 + goto set_fmt;
73326 +
73327 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
73328 + grsec_alert_wtime = curr_secs;
73329 + grsec_alert_fyet = 0;
73330 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
73331 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
73332 + grsec_alert_fyet++;
73333 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
73334 + grsec_alert_wtime = curr_secs;
73335 + grsec_alert_fyet++;
73336 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
73337 + return FLOODING;
73338 + }
73339 + else return FLOODING;
73340 +
73341 +set_fmt:
73342 +#endif
73343 + memset(buf, 0, PAGE_SIZE);
73344 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
73345 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
73346 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73347 + } else if (current->signal->curr_ip) {
73348 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
73349 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
73350 + } else if (gr_acl_is_enabled()) {
73351 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
73352 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73353 + } else {
73354 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
73355 + strcpy(buf, fmt);
73356 + }
73357 +
73358 + return NO_FLOODING;
73359 +}
73360 +
73361 +static void gr_log_middle(int audit, const char *msg, va_list ap)
73362 + __attribute__ ((format (printf, 2, 0)));
73363 +
73364 +static void gr_log_middle(int audit, const char *msg, va_list ap)
73365 +{
73366 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73367 + unsigned int len = strlen(buf);
73368 +
73369 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73370 +
73371 + return;
73372 +}
73373 +
73374 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
73375 + __attribute__ ((format (printf, 2, 3)));
73376 +
73377 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
73378 +{
73379 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73380 + unsigned int len = strlen(buf);
73381 + va_list ap;
73382 +
73383 + va_start(ap, msg);
73384 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73385 + va_end(ap);
73386 +
73387 + return;
73388 +}
73389 +
73390 +static void gr_log_end(int audit, int append_default)
73391 +{
73392 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73393 + if (append_default) {
73394 + struct task_struct *task = current;
73395 + struct task_struct *parent = task->real_parent;
73396 + const struct cred *cred = __task_cred(task);
73397 + const struct cred *pcred = __task_cred(parent);
73398 + unsigned int len = strlen(buf);
73399 +
73400 + 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));
73401 + }
73402 +
73403 + printk("%s\n", buf);
73404 +
73405 + return;
73406 +}
73407 +
73408 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
73409 +{
73410 + int logtype;
73411 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
73412 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
73413 + void *voidptr = NULL;
73414 + int num1 = 0, num2 = 0;
73415 + unsigned long ulong1 = 0, ulong2 = 0;
73416 + struct dentry *dentry = NULL;
73417 + struct vfsmount *mnt = NULL;
73418 + struct file *file = NULL;
73419 + struct task_struct *task = NULL;
73420 + struct vm_area_struct *vma = NULL;
73421 + const struct cred *cred, *pcred;
73422 + va_list ap;
73423 +
73424 + BEGIN_LOCKS(audit);
73425 + logtype = gr_log_start(audit);
73426 + if (logtype == FLOODING) {
73427 + END_LOCKS(audit);
73428 + return;
73429 + }
73430 + va_start(ap, argtypes);
73431 + switch (argtypes) {
73432 + case GR_TTYSNIFF:
73433 + task = va_arg(ap, struct task_struct *);
73434 + 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));
73435 + break;
73436 + case GR_SYSCTL_HIDDEN:
73437 + str1 = va_arg(ap, char *);
73438 + gr_log_middle_varargs(audit, msg, result, str1);
73439 + break;
73440 + case GR_RBAC:
73441 + dentry = va_arg(ap, struct dentry *);
73442 + mnt = va_arg(ap, struct vfsmount *);
73443 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
73444 + break;
73445 + case GR_RBAC_STR:
73446 + dentry = va_arg(ap, struct dentry *);
73447 + mnt = va_arg(ap, struct vfsmount *);
73448 + str1 = va_arg(ap, char *);
73449 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
73450 + break;
73451 + case GR_STR_RBAC:
73452 + str1 = va_arg(ap, char *);
73453 + dentry = va_arg(ap, struct dentry *);
73454 + mnt = va_arg(ap, struct vfsmount *);
73455 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
73456 + break;
73457 + case GR_RBAC_MODE2:
73458 + dentry = va_arg(ap, struct dentry *);
73459 + mnt = va_arg(ap, struct vfsmount *);
73460 + str1 = va_arg(ap, char *);
73461 + str2 = va_arg(ap, char *);
73462 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
73463 + break;
73464 + case GR_RBAC_MODE3:
73465 + dentry = va_arg(ap, struct dentry *);
73466 + mnt = va_arg(ap, struct vfsmount *);
73467 + str1 = va_arg(ap, char *);
73468 + str2 = va_arg(ap, char *);
73469 + str3 = va_arg(ap, char *);
73470 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
73471 + break;
73472 + case GR_FILENAME:
73473 + dentry = va_arg(ap, struct dentry *);
73474 + mnt = va_arg(ap, struct vfsmount *);
73475 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
73476 + break;
73477 + case GR_STR_FILENAME:
73478 + str1 = va_arg(ap, char *);
73479 + dentry = va_arg(ap, struct dentry *);
73480 + mnt = va_arg(ap, struct vfsmount *);
73481 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
73482 + break;
73483 + case GR_FILENAME_STR:
73484 + dentry = va_arg(ap, struct dentry *);
73485 + mnt = va_arg(ap, struct vfsmount *);
73486 + str1 = va_arg(ap, char *);
73487 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
73488 + break;
73489 + case GR_FILENAME_TWO_INT:
73490 + dentry = va_arg(ap, struct dentry *);
73491 + mnt = va_arg(ap, struct vfsmount *);
73492 + num1 = va_arg(ap, int);
73493 + num2 = va_arg(ap, int);
73494 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
73495 + break;
73496 + case GR_FILENAME_TWO_INT_STR:
73497 + dentry = va_arg(ap, struct dentry *);
73498 + mnt = va_arg(ap, struct vfsmount *);
73499 + num1 = va_arg(ap, int);
73500 + num2 = va_arg(ap, int);
73501 + str1 = va_arg(ap, char *);
73502 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
73503 + break;
73504 + case GR_TEXTREL:
73505 + file = va_arg(ap, struct file *);
73506 + ulong1 = va_arg(ap, unsigned long);
73507 + ulong2 = va_arg(ap, unsigned long);
73508 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
73509 + break;
73510 + case GR_PTRACE:
73511 + task = va_arg(ap, struct task_struct *);
73512 + 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));
73513 + break;
73514 + case GR_RESOURCE:
73515 + task = va_arg(ap, struct task_struct *);
73516 + cred = __task_cred(task);
73517 + pcred = __task_cred(task->real_parent);
73518 + ulong1 = va_arg(ap, unsigned long);
73519 + str1 = va_arg(ap, char *);
73520 + ulong2 = va_arg(ap, unsigned long);
73521 + 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));
73522 + break;
73523 + case GR_CAP:
73524 + task = va_arg(ap, struct task_struct *);
73525 + cred = __task_cred(task);
73526 + pcred = __task_cred(task->real_parent);
73527 + str1 = va_arg(ap, char *);
73528 + 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));
73529 + break;
73530 + case GR_SIG:
73531 + str1 = va_arg(ap, char *);
73532 + voidptr = va_arg(ap, void *);
73533 + gr_log_middle_varargs(audit, msg, str1, voidptr);
73534 + break;
73535 + case GR_SIG2:
73536 + task = va_arg(ap, struct task_struct *);
73537 + cred = __task_cred(task);
73538 + pcred = __task_cred(task->real_parent);
73539 + num1 = va_arg(ap, int);
73540 + 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));
73541 + break;
73542 + case GR_CRASH1:
73543 + task = va_arg(ap, struct task_struct *);
73544 + cred = __task_cred(task);
73545 + pcred = __task_cred(task->real_parent);
73546 + ulong1 = va_arg(ap, unsigned long);
73547 + 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);
73548 + break;
73549 + case GR_CRASH2:
73550 + task = va_arg(ap, struct task_struct *);
73551 + cred = __task_cred(task);
73552 + pcred = __task_cred(task->real_parent);
73553 + ulong1 = va_arg(ap, unsigned long);
73554 + 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);
73555 + break;
73556 + case GR_RWXMAP:
73557 + file = va_arg(ap, struct file *);
73558 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
73559 + break;
73560 + case GR_RWXMAPVMA:
73561 + vma = va_arg(ap, struct vm_area_struct *);
73562 + if (vma->vm_file)
73563 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
73564 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
73565 + str1 = "<stack>";
73566 + else if (vma->vm_start <= current->mm->brk &&
73567 + vma->vm_end >= current->mm->start_brk)
73568 + str1 = "<heap>";
73569 + else
73570 + str1 = "<anonymous mapping>";
73571 + gr_log_middle_varargs(audit, msg, str1);
73572 + break;
73573 + case GR_PSACCT:
73574 + {
73575 + unsigned int wday, cday;
73576 + __u8 whr, chr;
73577 + __u8 wmin, cmin;
73578 + __u8 wsec, csec;
73579 + char cur_tty[64] = { 0 };
73580 + char parent_tty[64] = { 0 };
73581 +
73582 + task = va_arg(ap, struct task_struct *);
73583 + wday = va_arg(ap, unsigned int);
73584 + cday = va_arg(ap, unsigned int);
73585 + whr = va_arg(ap, int);
73586 + chr = va_arg(ap, int);
73587 + wmin = va_arg(ap, int);
73588 + cmin = va_arg(ap, int);
73589 + wsec = va_arg(ap, int);
73590 + csec = va_arg(ap, int);
73591 + ulong1 = va_arg(ap, unsigned long);
73592 + cred = __task_cred(task);
73593 + pcred = __task_cred(task->real_parent);
73594 +
73595 + 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));
73596 + }
73597 + break;
73598 + default:
73599 + gr_log_middle(audit, msg, ap);
73600 + }
73601 + va_end(ap);
73602 + // these don't need DEFAULTSECARGS printed on the end
73603 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
73604 + gr_log_end(audit, 0);
73605 + else
73606 + gr_log_end(audit, 1);
73607 + END_LOCKS(audit);
73608 +}
73609 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
73610 new file mode 100644
73611 index 0000000..f536303
73612 --- /dev/null
73613 +++ b/grsecurity/grsec_mem.c
73614 @@ -0,0 +1,40 @@
73615 +#include <linux/kernel.h>
73616 +#include <linux/sched.h>
73617 +#include <linux/mm.h>
73618 +#include <linux/mman.h>
73619 +#include <linux/grinternal.h>
73620 +
73621 +void
73622 +gr_handle_ioperm(void)
73623 +{
73624 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
73625 + return;
73626 +}
73627 +
73628 +void
73629 +gr_handle_iopl(void)
73630 +{
73631 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
73632 + return;
73633 +}
73634 +
73635 +void
73636 +gr_handle_mem_readwrite(u64 from, u64 to)
73637 +{
73638 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
73639 + return;
73640 +}
73641 +
73642 +void
73643 +gr_handle_vm86(void)
73644 +{
73645 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
73646 + return;
73647 +}
73648 +
73649 +void
73650 +gr_log_badprocpid(const char *entry)
73651 +{
73652 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
73653 + return;
73654 +}
73655 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
73656 new file mode 100644
73657 index 0000000..cd9e124
73658 --- /dev/null
73659 +++ b/grsecurity/grsec_mount.c
73660 @@ -0,0 +1,65 @@
73661 +#include <linux/kernel.h>
73662 +#include <linux/sched.h>
73663 +#include <linux/mount.h>
73664 +#include <linux/major.h>
73665 +#include <linux/grsecurity.h>
73666 +#include <linux/grinternal.h>
73667 +
73668 +void
73669 +gr_log_remount(const char *devname, const int retval)
73670 +{
73671 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73672 + if (grsec_enable_mount && (retval >= 0))
73673 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
73674 +#endif
73675 + return;
73676 +}
73677 +
73678 +void
73679 +gr_log_unmount(const char *devname, const int retval)
73680 +{
73681 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73682 + if (grsec_enable_mount && (retval >= 0))
73683 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
73684 +#endif
73685 + return;
73686 +}
73687 +
73688 +void
73689 +gr_log_mount(const char *from, const char *to, const int retval)
73690 +{
73691 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73692 + if (grsec_enable_mount && (retval >= 0))
73693 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
73694 +#endif
73695 + return;
73696 +}
73697 +
73698 +int
73699 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
73700 +{
73701 +#ifdef CONFIG_GRKERNSEC_ROFS
73702 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
73703 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
73704 + return -EPERM;
73705 + } else
73706 + return 0;
73707 +#endif
73708 + return 0;
73709 +}
73710 +
73711 +int
73712 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
73713 +{
73714 +#ifdef CONFIG_GRKERNSEC_ROFS
73715 + struct inode *inode = dentry->d_inode;
73716 +
73717 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
73718 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
73719 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
73720 + return -EPERM;
73721 + } else
73722 + return 0;
73723 +#endif
73724 + return 0;
73725 +}
73726 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
73727 new file mode 100644
73728 index 0000000..6ee9d50
73729 --- /dev/null
73730 +++ b/grsecurity/grsec_pax.c
73731 @@ -0,0 +1,45 @@
73732 +#include <linux/kernel.h>
73733 +#include <linux/sched.h>
73734 +#include <linux/mm.h>
73735 +#include <linux/file.h>
73736 +#include <linux/grinternal.h>
73737 +#include <linux/grsecurity.h>
73738 +
73739 +void
73740 +gr_log_textrel(struct vm_area_struct * vma)
73741 +{
73742 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73743 + if (grsec_enable_log_rwxmaps)
73744 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
73745 +#endif
73746 + return;
73747 +}
73748 +
73749 +void gr_log_ptgnustack(struct file *file)
73750 +{
73751 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73752 + if (grsec_enable_log_rwxmaps)
73753 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
73754 +#endif
73755 + return;
73756 +}
73757 +
73758 +void
73759 +gr_log_rwxmmap(struct file *file)
73760 +{
73761 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73762 + if (grsec_enable_log_rwxmaps)
73763 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
73764 +#endif
73765 + return;
73766 +}
73767 +
73768 +void
73769 +gr_log_rwxmprotect(struct vm_area_struct *vma)
73770 +{
73771 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73772 + if (grsec_enable_log_rwxmaps)
73773 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
73774 +#endif
73775 + return;
73776 +}
73777 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
73778 new file mode 100644
73779 index 0000000..f7f29aa
73780 --- /dev/null
73781 +++ b/grsecurity/grsec_ptrace.c
73782 @@ -0,0 +1,30 @@
73783 +#include <linux/kernel.h>
73784 +#include <linux/sched.h>
73785 +#include <linux/grinternal.h>
73786 +#include <linux/security.h>
73787 +
73788 +void
73789 +gr_audit_ptrace(struct task_struct *task)
73790 +{
73791 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73792 + if (grsec_enable_audit_ptrace)
73793 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
73794 +#endif
73795 + return;
73796 +}
73797 +
73798 +int
73799 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
73800 +{
73801 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73802 + const struct dentry *dentry = file->f_path.dentry;
73803 + const struct vfsmount *mnt = file->f_path.mnt;
73804 +
73805 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
73806 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
73807 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
73808 + return -EACCES;
73809 + }
73810 +#endif
73811 + return 0;
73812 +}
73813 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
73814 new file mode 100644
73815 index 0000000..3860c7e
73816 --- /dev/null
73817 +++ b/grsecurity/grsec_sig.c
73818 @@ -0,0 +1,236 @@
73819 +#include <linux/kernel.h>
73820 +#include <linux/sched.h>
73821 +#include <linux/fs.h>
73822 +#include <linux/delay.h>
73823 +#include <linux/grsecurity.h>
73824 +#include <linux/grinternal.h>
73825 +#include <linux/hardirq.h>
73826 +
73827 +char *signames[] = {
73828 + [SIGSEGV] = "Segmentation fault",
73829 + [SIGILL] = "Illegal instruction",
73830 + [SIGABRT] = "Abort",
73831 + [SIGBUS] = "Invalid alignment/Bus error"
73832 +};
73833 +
73834 +void
73835 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
73836 +{
73837 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73838 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
73839 + (sig == SIGABRT) || (sig == SIGBUS))) {
73840 + if (task_pid_nr(t) == task_pid_nr(current)) {
73841 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
73842 + } else {
73843 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
73844 + }
73845 + }
73846 +#endif
73847 + return;
73848 +}
73849 +
73850 +int
73851 +gr_handle_signal(const struct task_struct *p, const int sig)
73852 +{
73853 +#ifdef CONFIG_GRKERNSEC
73854 + /* ignore the 0 signal for protected task checks */
73855 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
73856 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
73857 + return -EPERM;
73858 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
73859 + return -EPERM;
73860 + }
73861 +#endif
73862 + return 0;
73863 +}
73864 +
73865 +#ifdef CONFIG_GRKERNSEC
73866 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
73867 +
73868 +int gr_fake_force_sig(int sig, struct task_struct *t)
73869 +{
73870 + unsigned long int flags;
73871 + int ret, blocked, ignored;
73872 + struct k_sigaction *action;
73873 +
73874 + spin_lock_irqsave(&t->sighand->siglock, flags);
73875 + action = &t->sighand->action[sig-1];
73876 + ignored = action->sa.sa_handler == SIG_IGN;
73877 + blocked = sigismember(&t->blocked, sig);
73878 + if (blocked || ignored) {
73879 + action->sa.sa_handler = SIG_DFL;
73880 + if (blocked) {
73881 + sigdelset(&t->blocked, sig);
73882 + recalc_sigpending_and_wake(t);
73883 + }
73884 + }
73885 + if (action->sa.sa_handler == SIG_DFL)
73886 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
73887 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
73888 +
73889 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
73890 +
73891 + return ret;
73892 +}
73893 +#endif
73894 +
73895 +#define GR_USER_BAN_TIME (15 * 60)
73896 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
73897 +
73898 +void gr_handle_brute_attach(int dumpable)
73899 +{
73900 +#ifdef CONFIG_GRKERNSEC_BRUTE
73901 + struct task_struct *p = current;
73902 + kuid_t uid = GLOBAL_ROOT_UID;
73903 + int daemon = 0;
73904 +
73905 + if (!grsec_enable_brute)
73906 + return;
73907 +
73908 + rcu_read_lock();
73909 + read_lock(&tasklist_lock);
73910 + read_lock(&grsec_exec_file_lock);
73911 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
73912 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
73913 + p->real_parent->brute = 1;
73914 + daemon = 1;
73915 + } else {
73916 + const struct cred *cred = __task_cred(p), *cred2;
73917 + struct task_struct *tsk, *tsk2;
73918 +
73919 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
73920 + struct user_struct *user;
73921 +
73922 + uid = cred->uid;
73923 +
73924 + /* this is put upon execution past expiration */
73925 + user = find_user(uid);
73926 + if (user == NULL)
73927 + goto unlock;
73928 + user->suid_banned = 1;
73929 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
73930 + if (user->suid_ban_expires == ~0UL)
73931 + user->suid_ban_expires--;
73932 +
73933 + /* only kill other threads of the same binary, from the same user */
73934 + do_each_thread(tsk2, tsk) {
73935 + cred2 = __task_cred(tsk);
73936 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
73937 + gr_fake_force_sig(SIGKILL, tsk);
73938 + } while_each_thread(tsk2, tsk);
73939 + }
73940 + }
73941 +unlock:
73942 + read_unlock(&grsec_exec_file_lock);
73943 + read_unlock(&tasklist_lock);
73944 + rcu_read_unlock();
73945 +
73946 + if (gr_is_global_nonroot(uid))
73947 + 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);
73948 + else if (daemon)
73949 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
73950 +
73951 +#endif
73952 + return;
73953 +}
73954 +
73955 +void gr_handle_brute_check(void)
73956 +{
73957 +#ifdef CONFIG_GRKERNSEC_BRUTE
73958 + struct task_struct *p = current;
73959 +
73960 + if (unlikely(p->brute)) {
73961 + if (!grsec_enable_brute)
73962 + p->brute = 0;
73963 + else if (time_before(get_seconds(), p->brute_expires))
73964 + msleep(30 * 1000);
73965 + }
73966 +#endif
73967 + return;
73968 +}
73969 +
73970 +void gr_handle_kernel_exploit(void)
73971 +{
73972 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
73973 + const struct cred *cred;
73974 + struct task_struct *tsk, *tsk2;
73975 + struct user_struct *user;
73976 + kuid_t uid;
73977 +
73978 + if (in_irq() || in_serving_softirq() || in_nmi())
73979 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
73980 +
73981 + uid = current_uid();
73982 +
73983 + if (gr_is_global_root(uid))
73984 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
73985 + else {
73986 + /* kill all the processes of this user, hold a reference
73987 + to their creds struct, and prevent them from creating
73988 + another process until system reset
73989 + */
73990 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
73991 + GR_GLOBAL_UID(uid));
73992 + /* we intentionally leak this ref */
73993 + user = get_uid(current->cred->user);
73994 + if (user)
73995 + user->kernel_banned = 1;
73996 +
73997 + /* kill all processes of this user */
73998 + read_lock(&tasklist_lock);
73999 + do_each_thread(tsk2, tsk) {
74000 + cred = __task_cred(tsk);
74001 + if (uid_eq(cred->uid, uid))
74002 + gr_fake_force_sig(SIGKILL, tsk);
74003 + } while_each_thread(tsk2, tsk);
74004 + read_unlock(&tasklist_lock);
74005 + }
74006 +#endif
74007 +}
74008 +
74009 +#ifdef CONFIG_GRKERNSEC_BRUTE
74010 +static bool suid_ban_expired(struct user_struct *user)
74011 +{
74012 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
74013 + user->suid_banned = 0;
74014 + user->suid_ban_expires = 0;
74015 + free_uid(user);
74016 + return true;
74017 + }
74018 +
74019 + return false;
74020 +}
74021 +#endif
74022 +
74023 +int gr_process_kernel_exec_ban(void)
74024 +{
74025 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74026 + if (unlikely(current->cred->user->kernel_banned))
74027 + return -EPERM;
74028 +#endif
74029 + return 0;
74030 +}
74031 +
74032 +int gr_process_kernel_setuid_ban(struct user_struct *user)
74033 +{
74034 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74035 + if (unlikely(user->kernel_banned))
74036 + gr_fake_force_sig(SIGKILL, current);
74037 +#endif
74038 + return 0;
74039 +}
74040 +
74041 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
74042 +{
74043 +#ifdef CONFIG_GRKERNSEC_BRUTE
74044 + struct user_struct *user = current->cred->user;
74045 + if (unlikely(user->suid_banned)) {
74046 + if (suid_ban_expired(user))
74047 + return 0;
74048 + /* disallow execution of suid binaries only */
74049 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
74050 + return -EPERM;
74051 + }
74052 +#endif
74053 + return 0;
74054 +}
74055 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
74056 new file mode 100644
74057 index 0000000..4030d57
74058 --- /dev/null
74059 +++ b/grsecurity/grsec_sock.c
74060 @@ -0,0 +1,244 @@
74061 +#include <linux/kernel.h>
74062 +#include <linux/module.h>
74063 +#include <linux/sched.h>
74064 +#include <linux/file.h>
74065 +#include <linux/net.h>
74066 +#include <linux/in.h>
74067 +#include <linux/ip.h>
74068 +#include <net/sock.h>
74069 +#include <net/inet_sock.h>
74070 +#include <linux/grsecurity.h>
74071 +#include <linux/grinternal.h>
74072 +#include <linux/gracl.h>
74073 +
74074 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
74075 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
74076 +
74077 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
74078 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
74079 +
74080 +#ifdef CONFIG_UNIX_MODULE
74081 +EXPORT_SYMBOL(gr_acl_handle_unix);
74082 +EXPORT_SYMBOL(gr_acl_handle_mknod);
74083 +EXPORT_SYMBOL(gr_handle_chroot_unix);
74084 +EXPORT_SYMBOL(gr_handle_create);
74085 +#endif
74086 +
74087 +#ifdef CONFIG_GRKERNSEC
74088 +#define gr_conn_table_size 32749
74089 +struct conn_table_entry {
74090 + struct conn_table_entry *next;
74091 + struct signal_struct *sig;
74092 +};
74093 +
74094 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
74095 +DEFINE_SPINLOCK(gr_conn_table_lock);
74096 +
74097 +extern const char * gr_socktype_to_name(unsigned char type);
74098 +extern const char * gr_proto_to_name(unsigned char proto);
74099 +extern const char * gr_sockfamily_to_name(unsigned char family);
74100 +
74101 +static __inline__ int
74102 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
74103 +{
74104 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
74105 +}
74106 +
74107 +static __inline__ int
74108 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
74109 + __u16 sport, __u16 dport)
74110 +{
74111 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
74112 + sig->gr_sport == sport && sig->gr_dport == dport))
74113 + return 1;
74114 + else
74115 + return 0;
74116 +}
74117 +
74118 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
74119 +{
74120 + struct conn_table_entry **match;
74121 + unsigned int index;
74122 +
74123 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74124 + sig->gr_sport, sig->gr_dport,
74125 + gr_conn_table_size);
74126 +
74127 + newent->sig = sig;
74128 +
74129 + match = &gr_conn_table[index];
74130 + newent->next = *match;
74131 + *match = newent;
74132 +
74133 + return;
74134 +}
74135 +
74136 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
74137 +{
74138 + struct conn_table_entry *match, *last = NULL;
74139 + unsigned int index;
74140 +
74141 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74142 + sig->gr_sport, sig->gr_dport,
74143 + gr_conn_table_size);
74144 +
74145 + match = gr_conn_table[index];
74146 + while (match && !conn_match(match->sig,
74147 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
74148 + sig->gr_dport)) {
74149 + last = match;
74150 + match = match->next;
74151 + }
74152 +
74153 + if (match) {
74154 + if (last)
74155 + last->next = match->next;
74156 + else
74157 + gr_conn_table[index] = NULL;
74158 + kfree(match);
74159 + }
74160 +
74161 + return;
74162 +}
74163 +
74164 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
74165 + __u16 sport, __u16 dport)
74166 +{
74167 + struct conn_table_entry *match;
74168 + unsigned int index;
74169 +
74170 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
74171 +
74172 + match = gr_conn_table[index];
74173 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
74174 + match = match->next;
74175 +
74176 + if (match)
74177 + return match->sig;
74178 + else
74179 + return NULL;
74180 +}
74181 +
74182 +#endif
74183 +
74184 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
74185 +{
74186 +#ifdef CONFIG_GRKERNSEC
74187 + struct signal_struct *sig = task->signal;
74188 + struct conn_table_entry *newent;
74189 +
74190 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
74191 + if (newent == NULL)
74192 + return;
74193 + /* no bh lock needed since we are called with bh disabled */
74194 + spin_lock(&gr_conn_table_lock);
74195 + gr_del_task_from_ip_table_nolock(sig);
74196 + sig->gr_saddr = inet->inet_rcv_saddr;
74197 + sig->gr_daddr = inet->inet_daddr;
74198 + sig->gr_sport = inet->inet_sport;
74199 + sig->gr_dport = inet->inet_dport;
74200 + gr_add_to_task_ip_table_nolock(sig, newent);
74201 + spin_unlock(&gr_conn_table_lock);
74202 +#endif
74203 + return;
74204 +}
74205 +
74206 +void gr_del_task_from_ip_table(struct task_struct *task)
74207 +{
74208 +#ifdef CONFIG_GRKERNSEC
74209 + spin_lock_bh(&gr_conn_table_lock);
74210 + gr_del_task_from_ip_table_nolock(task->signal);
74211 + spin_unlock_bh(&gr_conn_table_lock);
74212 +#endif
74213 + return;
74214 +}
74215 +
74216 +void
74217 +gr_attach_curr_ip(const struct sock *sk)
74218 +{
74219 +#ifdef CONFIG_GRKERNSEC
74220 + struct signal_struct *p, *set;
74221 + const struct inet_sock *inet = inet_sk(sk);
74222 +
74223 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
74224 + return;
74225 +
74226 + set = current->signal;
74227 +
74228 + spin_lock_bh(&gr_conn_table_lock);
74229 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
74230 + inet->inet_dport, inet->inet_sport);
74231 + if (unlikely(p != NULL)) {
74232 + set->curr_ip = p->curr_ip;
74233 + set->used_accept = 1;
74234 + gr_del_task_from_ip_table_nolock(p);
74235 + spin_unlock_bh(&gr_conn_table_lock);
74236 + return;
74237 + }
74238 + spin_unlock_bh(&gr_conn_table_lock);
74239 +
74240 + set->curr_ip = inet->inet_daddr;
74241 + set->used_accept = 1;
74242 +#endif
74243 + return;
74244 +}
74245 +
74246 +int
74247 +gr_handle_sock_all(const int family, const int type, const int protocol)
74248 +{
74249 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74250 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
74251 + (family != AF_UNIX)) {
74252 + if (family == AF_INET)
74253 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
74254 + else
74255 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
74256 + return -EACCES;
74257 + }
74258 +#endif
74259 + return 0;
74260 +}
74261 +
74262 +int
74263 +gr_handle_sock_server(const struct sockaddr *sck)
74264 +{
74265 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74266 + if (grsec_enable_socket_server &&
74267 + in_group_p(grsec_socket_server_gid) &&
74268 + sck && (sck->sa_family != AF_UNIX) &&
74269 + (sck->sa_family != AF_LOCAL)) {
74270 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74271 + return -EACCES;
74272 + }
74273 +#endif
74274 + return 0;
74275 +}
74276 +
74277 +int
74278 +gr_handle_sock_server_other(const struct sock *sck)
74279 +{
74280 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74281 + if (grsec_enable_socket_server &&
74282 + in_group_p(grsec_socket_server_gid) &&
74283 + sck && (sck->sk_family != AF_UNIX) &&
74284 + (sck->sk_family != AF_LOCAL)) {
74285 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74286 + return -EACCES;
74287 + }
74288 +#endif
74289 + return 0;
74290 +}
74291 +
74292 +int
74293 +gr_handle_sock_client(const struct sockaddr *sck)
74294 +{
74295 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74296 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
74297 + sck && (sck->sa_family != AF_UNIX) &&
74298 + (sck->sa_family != AF_LOCAL)) {
74299 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
74300 + return -EACCES;
74301 + }
74302 +#endif
74303 + return 0;
74304 +}
74305 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
74306 new file mode 100644
74307 index 0000000..8159888
74308 --- /dev/null
74309 +++ b/grsecurity/grsec_sysctl.c
74310 @@ -0,0 +1,479 @@
74311 +#include <linux/kernel.h>
74312 +#include <linux/sched.h>
74313 +#include <linux/sysctl.h>
74314 +#include <linux/grsecurity.h>
74315 +#include <linux/grinternal.h>
74316 +
74317 +int
74318 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
74319 +{
74320 +#ifdef CONFIG_GRKERNSEC_SYSCTL
74321 + if (dirname == NULL || name == NULL)
74322 + return 0;
74323 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
74324 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
74325 + return -EACCES;
74326 + }
74327 +#endif
74328 + return 0;
74329 +}
74330 +
74331 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
74332 +static int __maybe_unused __read_only one = 1;
74333 +#endif
74334 +
74335 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
74336 + defined(CONFIG_GRKERNSEC_DENYUSB)
74337 +struct ctl_table grsecurity_table[] = {
74338 +#ifdef CONFIG_GRKERNSEC_SYSCTL
74339 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
74340 +#ifdef CONFIG_GRKERNSEC_IO
74341 + {
74342 + .procname = "disable_priv_io",
74343 + .data = &grsec_disable_privio,
74344 + .maxlen = sizeof(int),
74345 + .mode = 0600,
74346 + .proc_handler = &proc_dointvec,
74347 + },
74348 +#endif
74349 +#endif
74350 +#ifdef CONFIG_GRKERNSEC_LINK
74351 + {
74352 + .procname = "linking_restrictions",
74353 + .data = &grsec_enable_link,
74354 + .maxlen = sizeof(int),
74355 + .mode = 0600,
74356 + .proc_handler = &proc_dointvec,
74357 + },
74358 +#endif
74359 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74360 + {
74361 + .procname = "enforce_symlinksifowner",
74362 + .data = &grsec_enable_symlinkown,
74363 + .maxlen = sizeof(int),
74364 + .mode = 0600,
74365 + .proc_handler = &proc_dointvec,
74366 + },
74367 + {
74368 + .procname = "symlinkown_gid",
74369 + .data = &grsec_symlinkown_gid,
74370 + .maxlen = sizeof(int),
74371 + .mode = 0600,
74372 + .proc_handler = &proc_dointvec,
74373 + },
74374 +#endif
74375 +#ifdef CONFIG_GRKERNSEC_BRUTE
74376 + {
74377 + .procname = "deter_bruteforce",
74378 + .data = &grsec_enable_brute,
74379 + .maxlen = sizeof(int),
74380 + .mode = 0600,
74381 + .proc_handler = &proc_dointvec,
74382 + },
74383 +#endif
74384 +#ifdef CONFIG_GRKERNSEC_FIFO
74385 + {
74386 + .procname = "fifo_restrictions",
74387 + .data = &grsec_enable_fifo,
74388 + .maxlen = sizeof(int),
74389 + .mode = 0600,
74390 + .proc_handler = &proc_dointvec,
74391 + },
74392 +#endif
74393 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74394 + {
74395 + .procname = "ptrace_readexec",
74396 + .data = &grsec_enable_ptrace_readexec,
74397 + .maxlen = sizeof(int),
74398 + .mode = 0600,
74399 + .proc_handler = &proc_dointvec,
74400 + },
74401 +#endif
74402 +#ifdef CONFIG_GRKERNSEC_SETXID
74403 + {
74404 + .procname = "consistent_setxid",
74405 + .data = &grsec_enable_setxid,
74406 + .maxlen = sizeof(int),
74407 + .mode = 0600,
74408 + .proc_handler = &proc_dointvec,
74409 + },
74410 +#endif
74411 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74412 + {
74413 + .procname = "ip_blackhole",
74414 + .data = &grsec_enable_blackhole,
74415 + .maxlen = sizeof(int),
74416 + .mode = 0600,
74417 + .proc_handler = &proc_dointvec,
74418 + },
74419 + {
74420 + .procname = "lastack_retries",
74421 + .data = &grsec_lastack_retries,
74422 + .maxlen = sizeof(int),
74423 + .mode = 0600,
74424 + .proc_handler = &proc_dointvec,
74425 + },
74426 +#endif
74427 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74428 + {
74429 + .procname = "exec_logging",
74430 + .data = &grsec_enable_execlog,
74431 + .maxlen = sizeof(int),
74432 + .mode = 0600,
74433 + .proc_handler = &proc_dointvec,
74434 + },
74435 +#endif
74436 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74437 + {
74438 + .procname = "rwxmap_logging",
74439 + .data = &grsec_enable_log_rwxmaps,
74440 + .maxlen = sizeof(int),
74441 + .mode = 0600,
74442 + .proc_handler = &proc_dointvec,
74443 + },
74444 +#endif
74445 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74446 + {
74447 + .procname = "signal_logging",
74448 + .data = &grsec_enable_signal,
74449 + .maxlen = sizeof(int),
74450 + .mode = 0600,
74451 + .proc_handler = &proc_dointvec,
74452 + },
74453 +#endif
74454 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74455 + {
74456 + .procname = "forkfail_logging",
74457 + .data = &grsec_enable_forkfail,
74458 + .maxlen = sizeof(int),
74459 + .mode = 0600,
74460 + .proc_handler = &proc_dointvec,
74461 + },
74462 +#endif
74463 +#ifdef CONFIG_GRKERNSEC_TIME
74464 + {
74465 + .procname = "timechange_logging",
74466 + .data = &grsec_enable_time,
74467 + .maxlen = sizeof(int),
74468 + .mode = 0600,
74469 + .proc_handler = &proc_dointvec,
74470 + },
74471 +#endif
74472 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74473 + {
74474 + .procname = "chroot_deny_shmat",
74475 + .data = &grsec_enable_chroot_shmat,
74476 + .maxlen = sizeof(int),
74477 + .mode = 0600,
74478 + .proc_handler = &proc_dointvec,
74479 + },
74480 +#endif
74481 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74482 + {
74483 + .procname = "chroot_deny_unix",
74484 + .data = &grsec_enable_chroot_unix,
74485 + .maxlen = sizeof(int),
74486 + .mode = 0600,
74487 + .proc_handler = &proc_dointvec,
74488 + },
74489 +#endif
74490 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74491 + {
74492 + .procname = "chroot_deny_mount",
74493 + .data = &grsec_enable_chroot_mount,
74494 + .maxlen = sizeof(int),
74495 + .mode = 0600,
74496 + .proc_handler = &proc_dointvec,
74497 + },
74498 +#endif
74499 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74500 + {
74501 + .procname = "chroot_deny_fchdir",
74502 + .data = &grsec_enable_chroot_fchdir,
74503 + .maxlen = sizeof(int),
74504 + .mode = 0600,
74505 + .proc_handler = &proc_dointvec,
74506 + },
74507 +#endif
74508 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74509 + {
74510 + .procname = "chroot_deny_chroot",
74511 + .data = &grsec_enable_chroot_double,
74512 + .maxlen = sizeof(int),
74513 + .mode = 0600,
74514 + .proc_handler = &proc_dointvec,
74515 + },
74516 +#endif
74517 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74518 + {
74519 + .procname = "chroot_deny_pivot",
74520 + .data = &grsec_enable_chroot_pivot,
74521 + .maxlen = sizeof(int),
74522 + .mode = 0600,
74523 + .proc_handler = &proc_dointvec,
74524 + },
74525 +#endif
74526 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74527 + {
74528 + .procname = "chroot_enforce_chdir",
74529 + .data = &grsec_enable_chroot_chdir,
74530 + .maxlen = sizeof(int),
74531 + .mode = 0600,
74532 + .proc_handler = &proc_dointvec,
74533 + },
74534 +#endif
74535 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74536 + {
74537 + .procname = "chroot_deny_chmod",
74538 + .data = &grsec_enable_chroot_chmod,
74539 + .maxlen = sizeof(int),
74540 + .mode = 0600,
74541 + .proc_handler = &proc_dointvec,
74542 + },
74543 +#endif
74544 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74545 + {
74546 + .procname = "chroot_deny_mknod",
74547 + .data = &grsec_enable_chroot_mknod,
74548 + .maxlen = sizeof(int),
74549 + .mode = 0600,
74550 + .proc_handler = &proc_dointvec,
74551 + },
74552 +#endif
74553 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74554 + {
74555 + .procname = "chroot_restrict_nice",
74556 + .data = &grsec_enable_chroot_nice,
74557 + .maxlen = sizeof(int),
74558 + .mode = 0600,
74559 + .proc_handler = &proc_dointvec,
74560 + },
74561 +#endif
74562 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74563 + {
74564 + .procname = "chroot_execlog",
74565 + .data = &grsec_enable_chroot_execlog,
74566 + .maxlen = sizeof(int),
74567 + .mode = 0600,
74568 + .proc_handler = &proc_dointvec,
74569 + },
74570 +#endif
74571 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74572 + {
74573 + .procname = "chroot_caps",
74574 + .data = &grsec_enable_chroot_caps,
74575 + .maxlen = sizeof(int),
74576 + .mode = 0600,
74577 + .proc_handler = &proc_dointvec,
74578 + },
74579 +#endif
74580 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74581 + {
74582 + .procname = "chroot_deny_sysctl",
74583 + .data = &grsec_enable_chroot_sysctl,
74584 + .maxlen = sizeof(int),
74585 + .mode = 0600,
74586 + .proc_handler = &proc_dointvec,
74587 + },
74588 +#endif
74589 +#ifdef CONFIG_GRKERNSEC_TPE
74590 + {
74591 + .procname = "tpe",
74592 + .data = &grsec_enable_tpe,
74593 + .maxlen = sizeof(int),
74594 + .mode = 0600,
74595 + .proc_handler = &proc_dointvec,
74596 + },
74597 + {
74598 + .procname = "tpe_gid",
74599 + .data = &grsec_tpe_gid,
74600 + .maxlen = sizeof(int),
74601 + .mode = 0600,
74602 + .proc_handler = &proc_dointvec,
74603 + },
74604 +#endif
74605 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74606 + {
74607 + .procname = "tpe_invert",
74608 + .data = &grsec_enable_tpe_invert,
74609 + .maxlen = sizeof(int),
74610 + .mode = 0600,
74611 + .proc_handler = &proc_dointvec,
74612 + },
74613 +#endif
74614 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74615 + {
74616 + .procname = "tpe_restrict_all",
74617 + .data = &grsec_enable_tpe_all,
74618 + .maxlen = sizeof(int),
74619 + .mode = 0600,
74620 + .proc_handler = &proc_dointvec,
74621 + },
74622 +#endif
74623 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74624 + {
74625 + .procname = "socket_all",
74626 + .data = &grsec_enable_socket_all,
74627 + .maxlen = sizeof(int),
74628 + .mode = 0600,
74629 + .proc_handler = &proc_dointvec,
74630 + },
74631 + {
74632 + .procname = "socket_all_gid",
74633 + .data = &grsec_socket_all_gid,
74634 + .maxlen = sizeof(int),
74635 + .mode = 0600,
74636 + .proc_handler = &proc_dointvec,
74637 + },
74638 +#endif
74639 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74640 + {
74641 + .procname = "socket_client",
74642 + .data = &grsec_enable_socket_client,
74643 + .maxlen = sizeof(int),
74644 + .mode = 0600,
74645 + .proc_handler = &proc_dointvec,
74646 + },
74647 + {
74648 + .procname = "socket_client_gid",
74649 + .data = &grsec_socket_client_gid,
74650 + .maxlen = sizeof(int),
74651 + .mode = 0600,
74652 + .proc_handler = &proc_dointvec,
74653 + },
74654 +#endif
74655 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74656 + {
74657 + .procname = "socket_server",
74658 + .data = &grsec_enable_socket_server,
74659 + .maxlen = sizeof(int),
74660 + .mode = 0600,
74661 + .proc_handler = &proc_dointvec,
74662 + },
74663 + {
74664 + .procname = "socket_server_gid",
74665 + .data = &grsec_socket_server_gid,
74666 + .maxlen = sizeof(int),
74667 + .mode = 0600,
74668 + .proc_handler = &proc_dointvec,
74669 + },
74670 +#endif
74671 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74672 + {
74673 + .procname = "audit_group",
74674 + .data = &grsec_enable_group,
74675 + .maxlen = sizeof(int),
74676 + .mode = 0600,
74677 + .proc_handler = &proc_dointvec,
74678 + },
74679 + {
74680 + .procname = "audit_gid",
74681 + .data = &grsec_audit_gid,
74682 + .maxlen = sizeof(int),
74683 + .mode = 0600,
74684 + .proc_handler = &proc_dointvec,
74685 + },
74686 +#endif
74687 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74688 + {
74689 + .procname = "audit_chdir",
74690 + .data = &grsec_enable_chdir,
74691 + .maxlen = sizeof(int),
74692 + .mode = 0600,
74693 + .proc_handler = &proc_dointvec,
74694 + },
74695 +#endif
74696 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74697 + {
74698 + .procname = "audit_mount",
74699 + .data = &grsec_enable_mount,
74700 + .maxlen = sizeof(int),
74701 + .mode = 0600,
74702 + .proc_handler = &proc_dointvec,
74703 + },
74704 +#endif
74705 +#ifdef CONFIG_GRKERNSEC_DMESG
74706 + {
74707 + .procname = "dmesg",
74708 + .data = &grsec_enable_dmesg,
74709 + .maxlen = sizeof(int),
74710 + .mode = 0600,
74711 + .proc_handler = &proc_dointvec,
74712 + },
74713 +#endif
74714 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74715 + {
74716 + .procname = "chroot_findtask",
74717 + .data = &grsec_enable_chroot_findtask,
74718 + .maxlen = sizeof(int),
74719 + .mode = 0600,
74720 + .proc_handler = &proc_dointvec,
74721 + },
74722 +#endif
74723 +#ifdef CONFIG_GRKERNSEC_RESLOG
74724 + {
74725 + .procname = "resource_logging",
74726 + .data = &grsec_resource_logging,
74727 + .maxlen = sizeof(int),
74728 + .mode = 0600,
74729 + .proc_handler = &proc_dointvec,
74730 + },
74731 +#endif
74732 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74733 + {
74734 + .procname = "audit_ptrace",
74735 + .data = &grsec_enable_audit_ptrace,
74736 + .maxlen = sizeof(int),
74737 + .mode = 0600,
74738 + .proc_handler = &proc_dointvec,
74739 + },
74740 +#endif
74741 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74742 + {
74743 + .procname = "harden_ptrace",
74744 + .data = &grsec_enable_harden_ptrace,
74745 + .maxlen = sizeof(int),
74746 + .mode = 0600,
74747 + .proc_handler = &proc_dointvec,
74748 + },
74749 +#endif
74750 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74751 + {
74752 + .procname = "harden_ipc",
74753 + .data = &grsec_enable_harden_ipc,
74754 + .maxlen = sizeof(int),
74755 + .mode = 0600,
74756 + .proc_handler = &proc_dointvec,
74757 + },
74758 +#endif
74759 + {
74760 + .procname = "grsec_lock",
74761 + .data = &grsec_lock,
74762 + .maxlen = sizeof(int),
74763 + .mode = 0600,
74764 + .proc_handler = &proc_dointvec,
74765 + },
74766 +#endif
74767 +#ifdef CONFIG_GRKERNSEC_ROFS
74768 + {
74769 + .procname = "romount_protect",
74770 + .data = &grsec_enable_rofs,
74771 + .maxlen = sizeof(int),
74772 + .mode = 0600,
74773 + .proc_handler = &proc_dointvec_minmax,
74774 + .extra1 = &one,
74775 + .extra2 = &one,
74776 + },
74777 +#endif
74778 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
74779 + {
74780 + .procname = "deny_new_usb",
74781 + .data = &grsec_deny_new_usb,
74782 + .maxlen = sizeof(int),
74783 + .mode = 0600,
74784 + .proc_handler = &proc_dointvec,
74785 + },
74786 +#endif
74787 + { }
74788 +};
74789 +#endif
74790 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
74791 new file mode 100644
74792 index 0000000..0dc13c3
74793 --- /dev/null
74794 +++ b/grsecurity/grsec_time.c
74795 @@ -0,0 +1,16 @@
74796 +#include <linux/kernel.h>
74797 +#include <linux/sched.h>
74798 +#include <linux/grinternal.h>
74799 +#include <linux/module.h>
74800 +
74801 +void
74802 +gr_log_timechange(void)
74803 +{
74804 +#ifdef CONFIG_GRKERNSEC_TIME
74805 + if (grsec_enable_time)
74806 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
74807 +#endif
74808 + return;
74809 +}
74810 +
74811 +EXPORT_SYMBOL(gr_log_timechange);
74812 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
74813 new file mode 100644
74814 index 0000000..ee57dcf
74815 --- /dev/null
74816 +++ b/grsecurity/grsec_tpe.c
74817 @@ -0,0 +1,73 @@
74818 +#include <linux/kernel.h>
74819 +#include <linux/sched.h>
74820 +#include <linux/file.h>
74821 +#include <linux/fs.h>
74822 +#include <linux/grinternal.h>
74823 +
74824 +extern int gr_acl_tpe_check(void);
74825 +
74826 +int
74827 +gr_tpe_allow(const struct file *file)
74828 +{
74829 +#ifdef CONFIG_GRKERNSEC
74830 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
74831 + const struct cred *cred = current_cred();
74832 + char *msg = NULL;
74833 + char *msg2 = NULL;
74834 +
74835 + // never restrict root
74836 + if (gr_is_global_root(cred->uid))
74837 + return 1;
74838 +
74839 + if (grsec_enable_tpe) {
74840 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74841 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
74842 + msg = "not being in trusted group";
74843 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
74844 + msg = "being in untrusted group";
74845 +#else
74846 + if (in_group_p(grsec_tpe_gid))
74847 + msg = "being in untrusted group";
74848 +#endif
74849 + }
74850 + if (!msg && gr_acl_tpe_check())
74851 + msg = "being in untrusted role";
74852 +
74853 + // not in any affected group/role
74854 + if (!msg)
74855 + goto next_check;
74856 +
74857 + if (gr_is_global_nonroot(inode->i_uid))
74858 + msg2 = "file in non-root-owned directory";
74859 + else if (inode->i_mode & S_IWOTH)
74860 + msg2 = "file in world-writable directory";
74861 + else if (inode->i_mode & S_IWGRP)
74862 + msg2 = "file in group-writable directory";
74863 +
74864 + if (msg && msg2) {
74865 + char fullmsg[70] = {0};
74866 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
74867 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
74868 + return 0;
74869 + }
74870 + msg = NULL;
74871 +next_check:
74872 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74873 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
74874 + return 1;
74875 +
74876 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
74877 + msg = "directory not owned by user";
74878 + else if (inode->i_mode & S_IWOTH)
74879 + msg = "file in world-writable directory";
74880 + else if (inode->i_mode & S_IWGRP)
74881 + msg = "file in group-writable directory";
74882 +
74883 + if (msg) {
74884 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
74885 + return 0;
74886 + }
74887 +#endif
74888 +#endif
74889 + return 1;
74890 +}
74891 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
74892 new file mode 100644
74893 index 0000000..ae02d8e
74894 --- /dev/null
74895 +++ b/grsecurity/grsec_usb.c
74896 @@ -0,0 +1,15 @@
74897 +#include <linux/kernel.h>
74898 +#include <linux/grinternal.h>
74899 +#include <linux/module.h>
74900 +
74901 +int gr_handle_new_usb(void)
74902 +{
74903 +#ifdef CONFIG_GRKERNSEC_DENYUSB
74904 + if (grsec_deny_new_usb) {
74905 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
74906 + return 1;
74907 + }
74908 +#endif
74909 + return 0;
74910 +}
74911 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
74912 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
74913 new file mode 100644
74914 index 0000000..9f7b1ac
74915 --- /dev/null
74916 +++ b/grsecurity/grsum.c
74917 @@ -0,0 +1,61 @@
74918 +#include <linux/err.h>
74919 +#include <linux/kernel.h>
74920 +#include <linux/sched.h>
74921 +#include <linux/mm.h>
74922 +#include <linux/scatterlist.h>
74923 +#include <linux/crypto.h>
74924 +#include <linux/gracl.h>
74925 +
74926 +
74927 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
74928 +#error "crypto and sha256 must be built into the kernel"
74929 +#endif
74930 +
74931 +int
74932 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
74933 +{
74934 + char *p;
74935 + struct crypto_hash *tfm;
74936 + struct hash_desc desc;
74937 + struct scatterlist sg;
74938 + unsigned char temp_sum[GR_SHA_LEN];
74939 + volatile int retval = 0;
74940 + volatile int dummy = 0;
74941 + unsigned int i;
74942 +
74943 + sg_init_table(&sg, 1);
74944 +
74945 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
74946 + if (IS_ERR(tfm)) {
74947 + /* should never happen, since sha256 should be built in */
74948 + return 1;
74949 + }
74950 +
74951 + desc.tfm = tfm;
74952 + desc.flags = 0;
74953 +
74954 + crypto_hash_init(&desc);
74955 +
74956 + p = salt;
74957 + sg_set_buf(&sg, p, GR_SALT_LEN);
74958 + crypto_hash_update(&desc, &sg, sg.length);
74959 +
74960 + p = entry->pw;
74961 + sg_set_buf(&sg, p, strlen(p));
74962 +
74963 + crypto_hash_update(&desc, &sg, sg.length);
74964 +
74965 + crypto_hash_final(&desc, temp_sum);
74966 +
74967 + memset(entry->pw, 0, GR_PW_LEN);
74968 +
74969 + for (i = 0; i < GR_SHA_LEN; i++)
74970 + if (sum[i] != temp_sum[i])
74971 + retval = 1;
74972 + else
74973 + dummy = 1; // waste a cycle
74974 +
74975 + crypto_free_hash(tfm);
74976 +
74977 + return retval;
74978 +}
74979 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
74980 index 77ff547..181834f 100644
74981 --- a/include/asm-generic/4level-fixup.h
74982 +++ b/include/asm-generic/4level-fixup.h
74983 @@ -13,8 +13,10 @@
74984 #define pmd_alloc(mm, pud, address) \
74985 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
74986 NULL: pmd_offset(pud, address))
74987 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
74988
74989 #define pud_alloc(mm, pgd, address) (pgd)
74990 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
74991 #define pud_offset(pgd, start) (pgd)
74992 #define pud_none(pud) 0
74993 #define pud_bad(pud) 0
74994 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
74995 index b7babf0..97f4c4f 100644
74996 --- a/include/asm-generic/atomic-long.h
74997 +++ b/include/asm-generic/atomic-long.h
74998 @@ -22,6 +22,12 @@
74999
75000 typedef atomic64_t atomic_long_t;
75001
75002 +#ifdef CONFIG_PAX_REFCOUNT
75003 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
75004 +#else
75005 +typedef atomic64_t atomic_long_unchecked_t;
75006 +#endif
75007 +
75008 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
75009
75010 static inline long atomic_long_read(atomic_long_t *l)
75011 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75012 return (long)atomic64_read(v);
75013 }
75014
75015 +#ifdef CONFIG_PAX_REFCOUNT
75016 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75017 +{
75018 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75019 +
75020 + return (long)atomic64_read_unchecked(v);
75021 +}
75022 +#endif
75023 +
75024 static inline void atomic_long_set(atomic_long_t *l, long i)
75025 {
75026 atomic64_t *v = (atomic64_t *)l;
75027 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75028 atomic64_set(v, i);
75029 }
75030
75031 +#ifdef CONFIG_PAX_REFCOUNT
75032 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75033 +{
75034 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75035 +
75036 + atomic64_set_unchecked(v, i);
75037 +}
75038 +#endif
75039 +
75040 static inline void atomic_long_inc(atomic_long_t *l)
75041 {
75042 atomic64_t *v = (atomic64_t *)l;
75043 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75044 atomic64_inc(v);
75045 }
75046
75047 +#ifdef CONFIG_PAX_REFCOUNT
75048 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75049 +{
75050 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75051 +
75052 + atomic64_inc_unchecked(v);
75053 +}
75054 +#endif
75055 +
75056 static inline void atomic_long_dec(atomic_long_t *l)
75057 {
75058 atomic64_t *v = (atomic64_t *)l;
75059 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75060 atomic64_dec(v);
75061 }
75062
75063 +#ifdef CONFIG_PAX_REFCOUNT
75064 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75065 +{
75066 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75067 +
75068 + atomic64_dec_unchecked(v);
75069 +}
75070 +#endif
75071 +
75072 static inline void atomic_long_add(long i, atomic_long_t *l)
75073 {
75074 atomic64_t *v = (atomic64_t *)l;
75075 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75076 atomic64_add(i, v);
75077 }
75078
75079 +#ifdef CONFIG_PAX_REFCOUNT
75080 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75081 +{
75082 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75083 +
75084 + atomic64_add_unchecked(i, v);
75085 +}
75086 +#endif
75087 +
75088 static inline void atomic_long_sub(long i, atomic_long_t *l)
75089 {
75090 atomic64_t *v = (atomic64_t *)l;
75091 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75092 atomic64_sub(i, v);
75093 }
75094
75095 +#ifdef CONFIG_PAX_REFCOUNT
75096 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75097 +{
75098 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75099 +
75100 + atomic64_sub_unchecked(i, v);
75101 +}
75102 +#endif
75103 +
75104 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75105 {
75106 atomic64_t *v = (atomic64_t *)l;
75107 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
75108 return atomic64_add_negative(i, v);
75109 }
75110
75111 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
75112 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
75113 {
75114 atomic64_t *v = (atomic64_t *)l;
75115
75116 return (long)atomic64_add_return(i, v);
75117 }
75118
75119 +#ifdef CONFIG_PAX_REFCOUNT
75120 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75121 +{
75122 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75123 +
75124 + return (long)atomic64_add_return_unchecked(i, v);
75125 +}
75126 +#endif
75127 +
75128 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75129 {
75130 atomic64_t *v = (atomic64_t *)l;
75131 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75132 return (long)atomic64_inc_return(v);
75133 }
75134
75135 +#ifdef CONFIG_PAX_REFCOUNT
75136 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75137 +{
75138 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75139 +
75140 + return (long)atomic64_inc_return_unchecked(v);
75141 +}
75142 +#endif
75143 +
75144 static inline long atomic_long_dec_return(atomic_long_t *l)
75145 {
75146 atomic64_t *v = (atomic64_t *)l;
75147 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75148
75149 typedef atomic_t atomic_long_t;
75150
75151 +#ifdef CONFIG_PAX_REFCOUNT
75152 +typedef atomic_unchecked_t atomic_long_unchecked_t;
75153 +#else
75154 +typedef atomic_t atomic_long_unchecked_t;
75155 +#endif
75156 +
75157 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
75158 static inline long atomic_long_read(atomic_long_t *l)
75159 {
75160 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75161 return (long)atomic_read(v);
75162 }
75163
75164 +#ifdef CONFIG_PAX_REFCOUNT
75165 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75166 +{
75167 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75168 +
75169 + return (long)atomic_read_unchecked(v);
75170 +}
75171 +#endif
75172 +
75173 static inline void atomic_long_set(atomic_long_t *l, long i)
75174 {
75175 atomic_t *v = (atomic_t *)l;
75176 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75177 atomic_set(v, i);
75178 }
75179
75180 +#ifdef CONFIG_PAX_REFCOUNT
75181 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75182 +{
75183 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75184 +
75185 + atomic_set_unchecked(v, i);
75186 +}
75187 +#endif
75188 +
75189 static inline void atomic_long_inc(atomic_long_t *l)
75190 {
75191 atomic_t *v = (atomic_t *)l;
75192 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75193 atomic_inc(v);
75194 }
75195
75196 +#ifdef CONFIG_PAX_REFCOUNT
75197 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75198 +{
75199 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75200 +
75201 + atomic_inc_unchecked(v);
75202 +}
75203 +#endif
75204 +
75205 static inline void atomic_long_dec(atomic_long_t *l)
75206 {
75207 atomic_t *v = (atomic_t *)l;
75208 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75209 atomic_dec(v);
75210 }
75211
75212 +#ifdef CONFIG_PAX_REFCOUNT
75213 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75214 +{
75215 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75216 +
75217 + atomic_dec_unchecked(v);
75218 +}
75219 +#endif
75220 +
75221 static inline void atomic_long_add(long i, atomic_long_t *l)
75222 {
75223 atomic_t *v = (atomic_t *)l;
75224 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75225 atomic_add(i, v);
75226 }
75227
75228 +#ifdef CONFIG_PAX_REFCOUNT
75229 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75230 +{
75231 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75232 +
75233 + atomic_add_unchecked(i, v);
75234 +}
75235 +#endif
75236 +
75237 static inline void atomic_long_sub(long i, atomic_long_t *l)
75238 {
75239 atomic_t *v = (atomic_t *)l;
75240 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75241 atomic_sub(i, v);
75242 }
75243
75244 +#ifdef CONFIG_PAX_REFCOUNT
75245 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75246 +{
75247 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75248 +
75249 + atomic_sub_unchecked(i, v);
75250 +}
75251 +#endif
75252 +
75253 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75254 {
75255 atomic_t *v = (atomic_t *)l;
75256 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
75257 return (long)atomic_add_return(i, v);
75258 }
75259
75260 +#ifdef CONFIG_PAX_REFCOUNT
75261 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75262 +{
75263 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75264 +
75265 + return (long)atomic_add_return_unchecked(i, v);
75266 +}
75267 +
75268 +#endif
75269 +
75270 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75271 {
75272 atomic_t *v = (atomic_t *)l;
75273 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75274 return (long)atomic_inc_return(v);
75275 }
75276
75277 +#ifdef CONFIG_PAX_REFCOUNT
75278 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75279 +{
75280 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75281 +
75282 + return (long)atomic_inc_return_unchecked(v);
75283 +}
75284 +#endif
75285 +
75286 static inline long atomic_long_dec_return(atomic_long_t *l)
75287 {
75288 atomic_t *v = (atomic_t *)l;
75289 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75290
75291 #endif /* BITS_PER_LONG == 64 */
75292
75293 +#ifdef CONFIG_PAX_REFCOUNT
75294 +static inline void pax_refcount_needs_these_functions(void)
75295 +{
75296 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
75297 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
75298 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
75299 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
75300 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
75301 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
75302 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
75303 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
75304 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
75305 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
75306 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
75307 +#ifdef CONFIG_X86
75308 + atomic_clear_mask_unchecked(0, NULL);
75309 + atomic_set_mask_unchecked(0, NULL);
75310 +#endif
75311 +
75312 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
75313 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
75314 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
75315 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
75316 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
75317 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
75318 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
75319 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
75320 +}
75321 +#else
75322 +#define atomic_read_unchecked(v) atomic_read(v)
75323 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
75324 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
75325 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
75326 +#define atomic_inc_unchecked(v) atomic_inc(v)
75327 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
75328 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
75329 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
75330 +#define atomic_dec_unchecked(v) atomic_dec(v)
75331 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
75332 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
75333 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
75334 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
75335 +
75336 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
75337 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
75338 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
75339 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
75340 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
75341 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
75342 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
75343 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
75344 +#endif
75345 +
75346 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
75347 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
75348 index 33bd2de..f31bff97 100644
75349 --- a/include/asm-generic/atomic.h
75350 +++ b/include/asm-generic/atomic.h
75351 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
75352 * Atomically clears the bits set in @mask from @v
75353 */
75354 #ifndef atomic_clear_mask
75355 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
75356 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
75357 {
75358 unsigned long flags;
75359
75360 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
75361 index b18ce4f..2ee2843 100644
75362 --- a/include/asm-generic/atomic64.h
75363 +++ b/include/asm-generic/atomic64.h
75364 @@ -16,6 +16,8 @@ typedef struct {
75365 long long counter;
75366 } atomic64_t;
75367
75368 +typedef atomic64_t atomic64_unchecked_t;
75369 +
75370 #define ATOMIC64_INIT(i) { (i) }
75371
75372 extern long long atomic64_read(const atomic64_t *v);
75373 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
75374 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
75375 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
75376
75377 +#define atomic64_read_unchecked(v) atomic64_read(v)
75378 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
75379 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
75380 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
75381 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
75382 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
75383 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
75384 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
75385 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
75386 +
75387 #endif /* _ASM_GENERIC_ATOMIC64_H */
75388 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
75389 index a60a7cc..0fe12f2 100644
75390 --- a/include/asm-generic/bitops/__fls.h
75391 +++ b/include/asm-generic/bitops/__fls.h
75392 @@ -9,7 +9,7 @@
75393 *
75394 * Undefined if no set bit exists, so code should check against 0 first.
75395 */
75396 -static __always_inline unsigned long __fls(unsigned long word)
75397 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
75398 {
75399 int num = BITS_PER_LONG - 1;
75400
75401 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
75402 index 0576d1f..dad6c71 100644
75403 --- a/include/asm-generic/bitops/fls.h
75404 +++ b/include/asm-generic/bitops/fls.h
75405 @@ -9,7 +9,7 @@
75406 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
75407 */
75408
75409 -static __always_inline int fls(int x)
75410 +static __always_inline int __intentional_overflow(-1) fls(int x)
75411 {
75412 int r = 32;
75413
75414 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
75415 index b097cf8..3d40e14 100644
75416 --- a/include/asm-generic/bitops/fls64.h
75417 +++ b/include/asm-generic/bitops/fls64.h
75418 @@ -15,7 +15,7 @@
75419 * at position 64.
75420 */
75421 #if BITS_PER_LONG == 32
75422 -static __always_inline int fls64(__u64 x)
75423 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75424 {
75425 __u32 h = x >> 32;
75426 if (h)
75427 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
75428 return fls(x);
75429 }
75430 #elif BITS_PER_LONG == 64
75431 -static __always_inline int fls64(__u64 x)
75432 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75433 {
75434 if (x == 0)
75435 return 0;
75436 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
75437 index 1bfcfe5..e04c5c9 100644
75438 --- a/include/asm-generic/cache.h
75439 +++ b/include/asm-generic/cache.h
75440 @@ -6,7 +6,7 @@
75441 * cache lines need to provide their own cache.h.
75442 */
75443
75444 -#define L1_CACHE_SHIFT 5
75445 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
75446 +#define L1_CACHE_SHIFT 5UL
75447 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
75448
75449 #endif /* __ASM_GENERIC_CACHE_H */
75450 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
75451 index 0d68a1e..b74a761 100644
75452 --- a/include/asm-generic/emergency-restart.h
75453 +++ b/include/asm-generic/emergency-restart.h
75454 @@ -1,7 +1,7 @@
75455 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
75456 #define _ASM_GENERIC_EMERGENCY_RESTART_H
75457
75458 -static inline void machine_emergency_restart(void)
75459 +static inline __noreturn void machine_emergency_restart(void)
75460 {
75461 machine_restart(NULL);
75462 }
75463 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
75464 index 90f99c7..00ce236 100644
75465 --- a/include/asm-generic/kmap_types.h
75466 +++ b/include/asm-generic/kmap_types.h
75467 @@ -2,9 +2,9 @@
75468 #define _ASM_GENERIC_KMAP_TYPES_H
75469
75470 #ifdef __WITH_KM_FENCE
75471 -# define KM_TYPE_NR 41
75472 +# define KM_TYPE_NR 42
75473 #else
75474 -# define KM_TYPE_NR 20
75475 +# define KM_TYPE_NR 21
75476 #endif
75477
75478 #endif
75479 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
75480 index 9ceb03b..62b0b8f 100644
75481 --- a/include/asm-generic/local.h
75482 +++ b/include/asm-generic/local.h
75483 @@ -23,24 +23,37 @@ typedef struct
75484 atomic_long_t a;
75485 } local_t;
75486
75487 +typedef struct {
75488 + atomic_long_unchecked_t a;
75489 +} local_unchecked_t;
75490 +
75491 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
75492
75493 #define local_read(l) atomic_long_read(&(l)->a)
75494 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
75495 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
75496 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
75497 #define local_inc(l) atomic_long_inc(&(l)->a)
75498 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
75499 #define local_dec(l) atomic_long_dec(&(l)->a)
75500 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
75501 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
75502 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
75503 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
75504 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
75505
75506 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
75507 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
75508 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
75509 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
75510 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
75511 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
75512 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
75513 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
75514 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
75515
75516 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75517 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75518 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
75519 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
75520 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
75521 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
75522 index 725612b..9cc513a 100644
75523 --- a/include/asm-generic/pgtable-nopmd.h
75524 +++ b/include/asm-generic/pgtable-nopmd.h
75525 @@ -1,14 +1,19 @@
75526 #ifndef _PGTABLE_NOPMD_H
75527 #define _PGTABLE_NOPMD_H
75528
75529 -#ifndef __ASSEMBLY__
75530 -
75531 #include <asm-generic/pgtable-nopud.h>
75532
75533 -struct mm_struct;
75534 -
75535 #define __PAGETABLE_PMD_FOLDED
75536
75537 +#define PMD_SHIFT PUD_SHIFT
75538 +#define PTRS_PER_PMD 1
75539 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
75540 +#define PMD_MASK (~(PMD_SIZE-1))
75541 +
75542 +#ifndef __ASSEMBLY__
75543 +
75544 +struct mm_struct;
75545 +
75546 /*
75547 * Having the pmd type consist of a pud gets the size right, and allows
75548 * us to conceptually access the pud entry that this pmd is folded into
75549 @@ -16,11 +21,6 @@ struct mm_struct;
75550 */
75551 typedef struct { pud_t pud; } pmd_t;
75552
75553 -#define PMD_SHIFT PUD_SHIFT
75554 -#define PTRS_PER_PMD 1
75555 -#define PMD_SIZE (1UL << PMD_SHIFT)
75556 -#define PMD_MASK (~(PMD_SIZE-1))
75557 -
75558 /*
75559 * The "pud_xxx()" functions here are trivial for a folded two-level
75560 * setup: the pmd is never bad, and a pmd always exists (as it's folded
75561 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
75562 index 810431d..0ec4804f 100644
75563 --- a/include/asm-generic/pgtable-nopud.h
75564 +++ b/include/asm-generic/pgtable-nopud.h
75565 @@ -1,10 +1,15 @@
75566 #ifndef _PGTABLE_NOPUD_H
75567 #define _PGTABLE_NOPUD_H
75568
75569 -#ifndef __ASSEMBLY__
75570 -
75571 #define __PAGETABLE_PUD_FOLDED
75572
75573 +#define PUD_SHIFT PGDIR_SHIFT
75574 +#define PTRS_PER_PUD 1
75575 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
75576 +#define PUD_MASK (~(PUD_SIZE-1))
75577 +
75578 +#ifndef __ASSEMBLY__
75579 +
75580 /*
75581 * Having the pud type consist of a pgd gets the size right, and allows
75582 * us to conceptually access the pgd entry that this pud is folded into
75583 @@ -12,11 +17,6 @@
75584 */
75585 typedef struct { pgd_t pgd; } pud_t;
75586
75587 -#define PUD_SHIFT PGDIR_SHIFT
75588 -#define PTRS_PER_PUD 1
75589 -#define PUD_SIZE (1UL << PUD_SHIFT)
75590 -#define PUD_MASK (~(PUD_SIZE-1))
75591 -
75592 /*
75593 * The "pgd_xxx()" functions here are trivial for a folded two-level
75594 * setup: the pud is never bad, and a pud always exists (as it's folded
75595 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
75596 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
75597
75598 #define pgd_populate(mm, pgd, pud) do { } while (0)
75599 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
75600 /*
75601 * (puds are folded into pgds so this doesn't get actually called,
75602 * but the define is needed for a generic inline function.)
75603 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
75604 index db09234..86683e3 100644
75605 --- a/include/asm-generic/pgtable.h
75606 +++ b/include/asm-generic/pgtable.h
75607 @@ -736,6 +736,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
75608 }
75609 #endif /* CONFIG_NUMA_BALANCING */
75610
75611 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
75612 +#ifdef CONFIG_PAX_KERNEXEC
75613 +#error KERNEXEC requires pax_open_kernel
75614 +#else
75615 +static inline unsigned long pax_open_kernel(void) { return 0; }
75616 +#endif
75617 +#endif
75618 +
75619 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
75620 +#ifdef CONFIG_PAX_KERNEXEC
75621 +#error KERNEXEC requires pax_close_kernel
75622 +#else
75623 +static inline unsigned long pax_close_kernel(void) { return 0; }
75624 +#endif
75625 +#endif
75626 +
75627 #endif /* CONFIG_MMU */
75628
75629 #endif /* !__ASSEMBLY__ */
75630 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
75631 index dc1269c..48a4f51 100644
75632 --- a/include/asm-generic/uaccess.h
75633 +++ b/include/asm-generic/uaccess.h
75634 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
75635 return __clear_user(to, n);
75636 }
75637
75638 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
75639 +#ifdef CONFIG_PAX_MEMORY_UDEREF
75640 +#error UDEREF requires pax_open_userland
75641 +#else
75642 +static inline unsigned long pax_open_userland(void) { return 0; }
75643 +#endif
75644 +#endif
75645 +
75646 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
75647 +#ifdef CONFIG_PAX_MEMORY_UDEREF
75648 +#error UDEREF requires pax_close_userland
75649 +#else
75650 +static inline unsigned long pax_close_userland(void) { return 0; }
75651 +#endif
75652 +#endif
75653 +
75654 #endif /* __ASM_GENERIC_UACCESS_H */
75655 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
75656 index bc2121f..2f41f9a 100644
75657 --- a/include/asm-generic/vmlinux.lds.h
75658 +++ b/include/asm-generic/vmlinux.lds.h
75659 @@ -232,6 +232,7 @@
75660 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
75661 VMLINUX_SYMBOL(__start_rodata) = .; \
75662 *(.rodata) *(.rodata.*) \
75663 + *(.data..read_only) \
75664 *(__vermagic) /* Kernel version magic */ \
75665 . = ALIGN(8); \
75666 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
75667 @@ -716,17 +717,18 @@
75668 * section in the linker script will go there too. @phdr should have
75669 * a leading colon.
75670 *
75671 - * Note that this macros defines __per_cpu_load as an absolute symbol.
75672 + * Note that this macros defines per_cpu_load as an absolute symbol.
75673 * If there is no need to put the percpu section at a predetermined
75674 * address, use PERCPU_SECTION.
75675 */
75676 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
75677 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
75678 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
75679 + per_cpu_load = .; \
75680 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
75681 - LOAD_OFFSET) { \
75682 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
75683 PERCPU_INPUT(cacheline) \
75684 } phdr \
75685 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
75686 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
75687
75688 /**
75689 * PERCPU_SECTION - define output section for percpu area, simple version
75690 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
75691 index e73c19e..5b89e00 100644
75692 --- a/include/crypto/algapi.h
75693 +++ b/include/crypto/algapi.h
75694 @@ -34,7 +34,7 @@ struct crypto_type {
75695 unsigned int maskclear;
75696 unsigned int maskset;
75697 unsigned int tfmsize;
75698 -};
75699 +} __do_const;
75700
75701 struct crypto_instance {
75702 struct crypto_alg alg;
75703 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
75704 index 1d4a920..53a3229 100644
75705 --- a/include/drm/drmP.h
75706 +++ b/include/drm/drmP.h
75707 @@ -66,6 +66,7 @@
75708 #include <linux/workqueue.h>
75709 #include <linux/poll.h>
75710 #include <asm/pgalloc.h>
75711 +#include <asm/local.h>
75712 #include <drm/drm.h>
75713 #include <drm/drm_sarea.h>
75714 #include <drm/drm_vma_manager.h>
75715 @@ -278,10 +279,12 @@ do { \
75716 * \param cmd command.
75717 * \param arg argument.
75718 */
75719 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
75720 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
75721 + struct drm_file *file_priv);
75722 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
75723 struct drm_file *file_priv);
75724
75725 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75726 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
75727 unsigned long arg);
75728
75729 #define DRM_IOCTL_NR(n) _IOC_NR(n)
75730 @@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75731 struct drm_ioctl_desc {
75732 unsigned int cmd;
75733 int flags;
75734 - drm_ioctl_t *func;
75735 + drm_ioctl_t func;
75736 unsigned int cmd_drv;
75737 const char *name;
75738 -};
75739 +} __do_const;
75740
75741 /**
75742 * Creates a driver or general drm_ioctl_desc array entry for the given
75743 @@ -1013,7 +1016,7 @@ struct drm_info_list {
75744 int (*show)(struct seq_file*, void*); /** show callback */
75745 u32 driver_features; /**< Required driver features for this entry */
75746 void *data;
75747 -};
75748 +} __do_const;
75749
75750 /**
75751 * debugfs node structure. This structure represents a debugfs file.
75752 @@ -1097,7 +1100,7 @@ struct drm_device {
75753
75754 /** \name Usage Counters */
75755 /*@{ */
75756 - int open_count; /**< Outstanding files open */
75757 + local_t open_count; /**< Outstanding files open */
75758 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
75759 atomic_t vma_count; /**< Outstanding vma areas open */
75760 int buf_use; /**< Buffers in use -- cannot alloc */
75761 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
75762 index ef6ad3a..be34b16 100644
75763 --- a/include/drm/drm_crtc_helper.h
75764 +++ b/include/drm/drm_crtc_helper.h
75765 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
75766 struct drm_connector *connector);
75767 /* disable encoder when not in use - more explicit than dpms off */
75768 void (*disable)(struct drm_encoder *encoder);
75769 -};
75770 +} __no_const;
75771
75772 /**
75773 * drm_connector_helper_funcs - helper operations for connectors
75774 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
75775 index 940ece4..8cb727f 100644
75776 --- a/include/drm/i915_pciids.h
75777 +++ b/include/drm/i915_pciids.h
75778 @@ -37,7 +37,7 @@
75779 */
75780 #define INTEL_VGA_DEVICE(id, info) { \
75781 0x8086, id, \
75782 - ~0, ~0, \
75783 + PCI_ANY_ID, PCI_ANY_ID, \
75784 0x030000, 0xff0000, \
75785 (unsigned long) info }
75786
75787 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
75788 index 72dcbe8..8db58d7 100644
75789 --- a/include/drm/ttm/ttm_memory.h
75790 +++ b/include/drm/ttm/ttm_memory.h
75791 @@ -48,7 +48,7 @@
75792
75793 struct ttm_mem_shrink {
75794 int (*do_shrink) (struct ttm_mem_shrink *);
75795 -};
75796 +} __no_const;
75797
75798 /**
75799 * struct ttm_mem_global - Global memory accounting structure.
75800 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
75801 index 4b840e8..155d235 100644
75802 --- a/include/keys/asymmetric-subtype.h
75803 +++ b/include/keys/asymmetric-subtype.h
75804 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
75805 /* Verify the signature on a key of this subtype (optional) */
75806 int (*verify_signature)(const struct key *key,
75807 const struct public_key_signature *sig);
75808 -};
75809 +} __do_const;
75810
75811 /**
75812 * asymmetric_key_subtype - Get the subtype from an asymmetric key
75813 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
75814 index c1da539..1dcec55 100644
75815 --- a/include/linux/atmdev.h
75816 +++ b/include/linux/atmdev.h
75817 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
75818 #endif
75819
75820 struct k_atm_aal_stats {
75821 -#define __HANDLE_ITEM(i) atomic_t i
75822 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
75823 __AAL_STAT_ITEMS
75824 #undef __HANDLE_ITEM
75825 };
75826 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
75827 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
75828 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
75829 struct module *owner;
75830 -};
75831 +} __do_const ;
75832
75833 struct atmphy_ops {
75834 int (*start)(struct atm_dev *dev);
75835 diff --git a/include/linux/audit.h b/include/linux/audit.h
75836 index a406419..c2bb164 100644
75837 --- a/include/linux/audit.h
75838 +++ b/include/linux/audit.h
75839 @@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
75840 extern unsigned int audit_serial(void);
75841 extern int auditsc_get_stamp(struct audit_context *ctx,
75842 struct timespec *t, unsigned int *serial);
75843 -extern int audit_set_loginuid(kuid_t loginuid);
75844 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
75845
75846 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
75847 {
75848 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
75849 index fd8bf32..2cccd5a 100644
75850 --- a/include/linux/binfmts.h
75851 +++ b/include/linux/binfmts.h
75852 @@ -74,8 +74,10 @@ struct linux_binfmt {
75853 int (*load_binary)(struct linux_binprm *);
75854 int (*load_shlib)(struct file *);
75855 int (*core_dump)(struct coredump_params *cprm);
75856 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
75857 + void (*handle_mmap)(struct file *);
75858 unsigned long min_coredump; /* minimal dump size */
75859 -};
75860 +} __do_const;
75861
75862 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
75863
75864 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
75865 index abc9ca7..e54ee27 100644
75866 --- a/include/linux/bitops.h
75867 +++ b/include/linux/bitops.h
75868 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
75869 * @word: value to rotate
75870 * @shift: bits to roll
75871 */
75872 -static inline __u32 rol32(__u32 word, unsigned int shift)
75873 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
75874 {
75875 return (word << shift) | (word >> (32 - shift));
75876 }
75877 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
75878 * @word: value to rotate
75879 * @shift: bits to roll
75880 */
75881 -static inline __u32 ror32(__u32 word, unsigned int shift)
75882 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
75883 {
75884 return (word >> shift) | (word << (32 - shift));
75885 }
75886 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
75887 return (__s32)(value << shift) >> shift;
75888 }
75889
75890 -static inline unsigned fls_long(unsigned long l)
75891 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
75892 {
75893 if (sizeof(l) == 4)
75894 return fls(l);
75895 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
75896 index 1b135d4..59fc876 100644
75897 --- a/include/linux/blkdev.h
75898 +++ b/include/linux/blkdev.h
75899 @@ -1578,7 +1578,7 @@ struct block_device_operations {
75900 /* this callback is with swap_lock and sometimes page table lock held */
75901 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
75902 struct module *owner;
75903 -};
75904 +} __do_const;
75905
75906 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
75907 unsigned long);
75908 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
75909 index afc1343..9735539 100644
75910 --- a/include/linux/blktrace_api.h
75911 +++ b/include/linux/blktrace_api.h
75912 @@ -25,7 +25,7 @@ struct blk_trace {
75913 struct dentry *dropped_file;
75914 struct dentry *msg_file;
75915 struct list_head running_list;
75916 - atomic_t dropped;
75917 + atomic_unchecked_t dropped;
75918 };
75919
75920 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
75921 diff --git a/include/linux/cache.h b/include/linux/cache.h
75922 index 4c57065..40346da 100644
75923 --- a/include/linux/cache.h
75924 +++ b/include/linux/cache.h
75925 @@ -16,6 +16,14 @@
75926 #define __read_mostly
75927 #endif
75928
75929 +#ifndef __read_only
75930 +#ifdef CONFIG_PAX_KERNEXEC
75931 +#error KERNEXEC requires __read_only
75932 +#else
75933 +#define __read_only __read_mostly
75934 +#endif
75935 +#endif
75936 +
75937 #ifndef ____cacheline_aligned
75938 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
75939 #endif
75940 diff --git a/include/linux/capability.h b/include/linux/capability.h
75941 index a6ee1f9..e1ca49d 100644
75942 --- a/include/linux/capability.h
75943 +++ b/include/linux/capability.h
75944 @@ -212,8 +212,13 @@ extern bool capable(int cap);
75945 extern bool ns_capable(struct user_namespace *ns, int cap);
75946 extern bool inode_capable(const struct inode *inode, int cap);
75947 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
75948 +extern bool capable_nolog(int cap);
75949 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
75950 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
75951
75952 /* audit system wants to get cap info from files as well */
75953 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
75954
75955 +extern int is_privileged_binary(const struct dentry *dentry);
75956 +
75957 #endif /* !_LINUX_CAPABILITY_H */
75958 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
75959 index 8609d57..86e4d79 100644
75960 --- a/include/linux/cdrom.h
75961 +++ b/include/linux/cdrom.h
75962 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
75963
75964 /* driver specifications */
75965 const int capability; /* capability flags */
75966 - int n_minors; /* number of active minor devices */
75967 /* handle uniform packets for scsi type devices (scsi,atapi) */
75968 int (*generic_packet) (struct cdrom_device_info *,
75969 struct packet_command *);
75970 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
75971 index 4ce9056..86caac6 100644
75972 --- a/include/linux/cleancache.h
75973 +++ b/include/linux/cleancache.h
75974 @@ -31,7 +31,7 @@ struct cleancache_ops {
75975 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
75976 void (*invalidate_inode)(int, struct cleancache_filekey);
75977 void (*invalidate_fs)(int);
75978 -};
75979 +} __no_const;
75980
75981 extern struct cleancache_ops *
75982 cleancache_register_ops(struct cleancache_ops *ops);
75983 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
75984 index 7e59253..d6e4cae 100644
75985 --- a/include/linux/clk-provider.h
75986 +++ b/include/linux/clk-provider.h
75987 @@ -141,6 +141,7 @@ struct clk_ops {
75988 unsigned long);
75989 void (*init)(struct clk_hw *hw);
75990 };
75991 +typedef struct clk_ops __no_const clk_ops_no_const;
75992
75993 /**
75994 * struct clk_init_data - holds init data that's common to all clocks and is
75995 diff --git a/include/linux/compat.h b/include/linux/compat.h
75996 index eb8a49d..6b66ed9 100644
75997 --- a/include/linux/compat.h
75998 +++ b/include/linux/compat.h
75999 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
76000 compat_size_t __user *len_ptr);
76001
76002 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
76003 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
76004 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
76005 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
76006 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
76007 compat_ssize_t msgsz, int msgflg);
76008 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
76009 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
76010 compat_ulong_t addr, compat_ulong_t data);
76011 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76012 - compat_long_t addr, compat_long_t data);
76013 + compat_ulong_t addr, compat_ulong_t data);
76014
76015 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
76016 /*
76017 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
76018 index ded4299..ddcbe31 100644
76019 --- a/include/linux/compiler-gcc4.h
76020 +++ b/include/linux/compiler-gcc4.h
76021 @@ -39,9 +39,34 @@
76022 # define __compiletime_warning(message) __attribute__((warning(message)))
76023 # define __compiletime_error(message) __attribute__((error(message)))
76024 #endif /* __CHECKER__ */
76025 +
76026 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
76027 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
76028 +#define __bos0(ptr) __bos((ptr), 0)
76029 +#define __bos1(ptr) __bos((ptr), 1)
76030 #endif /* GCC_VERSION >= 40300 */
76031
76032 #if GCC_VERSION >= 40500
76033 +
76034 +#ifdef RANDSTRUCT_PLUGIN
76035 +#define __randomize_layout __attribute__((randomize_layout))
76036 +#define __no_randomize_layout __attribute__((no_randomize_layout))
76037 +#endif
76038 +
76039 +#ifdef CONSTIFY_PLUGIN
76040 +#define __no_const __attribute__((no_const))
76041 +#define __do_const __attribute__((do_const))
76042 +#endif
76043 +
76044 +#ifdef SIZE_OVERFLOW_PLUGIN
76045 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
76046 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
76047 +#endif
76048 +
76049 +#ifdef LATENT_ENTROPY_PLUGIN
76050 +#define __latent_entropy __attribute__((latent_entropy))
76051 +#endif
76052 +
76053 /*
76054 * Mark a position in code as unreachable. This can be used to
76055 * suppress control flow warnings after asm blocks that transfer
76056 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
76057 index 92669cd..cc564c0 100644
76058 --- a/include/linux/compiler.h
76059 +++ b/include/linux/compiler.h
76060 @@ -5,11 +5,14 @@
76061
76062 #ifdef __CHECKER__
76063 # define __user __attribute__((noderef, address_space(1)))
76064 +# define __force_user __force __user
76065 # define __kernel __attribute__((address_space(0)))
76066 +# define __force_kernel __force __kernel
76067 # define __safe __attribute__((safe))
76068 # define __force __attribute__((force))
76069 # define __nocast __attribute__((nocast))
76070 # define __iomem __attribute__((noderef, address_space(2)))
76071 +# define __force_iomem __force __iomem
76072 # define __must_hold(x) __attribute__((context(x,1,1)))
76073 # define __acquires(x) __attribute__((context(x,0,1)))
76074 # define __releases(x) __attribute__((context(x,1,0)))
76075 @@ -17,20 +20,37 @@
76076 # define __release(x) __context__(x,-1)
76077 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
76078 # define __percpu __attribute__((noderef, address_space(3)))
76079 +# define __force_percpu __force __percpu
76080 #ifdef CONFIG_SPARSE_RCU_POINTER
76081 # define __rcu __attribute__((noderef, address_space(4)))
76082 +# define __force_rcu __force __rcu
76083 #else
76084 # define __rcu
76085 +# define __force_rcu
76086 #endif
76087 extern void __chk_user_ptr(const volatile void __user *);
76088 extern void __chk_io_ptr(const volatile void __iomem *);
76089 #else
76090 -# define __user
76091 -# define __kernel
76092 +# ifdef CHECKER_PLUGIN
76093 +//# define __user
76094 +//# define __force_user
76095 +//# define __kernel
76096 +//# define __force_kernel
76097 +# else
76098 +# ifdef STRUCTLEAK_PLUGIN
76099 +# define __user __attribute__((user))
76100 +# else
76101 +# define __user
76102 +# endif
76103 +# define __force_user
76104 +# define __kernel
76105 +# define __force_kernel
76106 +# endif
76107 # define __safe
76108 # define __force
76109 # define __nocast
76110 # define __iomem
76111 +# define __force_iomem
76112 # define __chk_user_ptr(x) (void)0
76113 # define __chk_io_ptr(x) (void)0
76114 # define __builtin_warning(x, y...) (1)
76115 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
76116 # define __release(x) (void)0
76117 # define __cond_lock(x,c) (c)
76118 # define __percpu
76119 +# define __force_percpu
76120 # define __rcu
76121 +# define __force_rcu
76122 #endif
76123
76124 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
76125 @@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76126 # define __attribute_const__ /* unimplemented */
76127 #endif
76128
76129 +#ifndef __randomize_layout
76130 +# define __randomize_layout
76131 +#endif
76132 +
76133 +#ifndef __no_randomize_layout
76134 +# define __no_randomize_layout
76135 +#endif
76136 +
76137 +#ifndef __no_const
76138 +# define __no_const
76139 +#endif
76140 +
76141 +#ifndef __do_const
76142 +# define __do_const
76143 +#endif
76144 +
76145 +#ifndef __size_overflow
76146 +# define __size_overflow(...)
76147 +#endif
76148 +
76149 +#ifndef __intentional_overflow
76150 +# define __intentional_overflow(...)
76151 +#endif
76152 +
76153 +#ifndef __latent_entropy
76154 +# define __latent_entropy
76155 +#endif
76156 +
76157 /*
76158 * Tell gcc if a function is cold. The compiler will assume any path
76159 * directly leading to the call is unlikely.
76160 @@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76161 #define __cold
76162 #endif
76163
76164 +#ifndef __alloc_size
76165 +#define __alloc_size(...)
76166 +#endif
76167 +
76168 +#ifndef __bos
76169 +#define __bos(ptr, arg)
76170 +#endif
76171 +
76172 +#ifndef __bos0
76173 +#define __bos0(ptr)
76174 +#endif
76175 +
76176 +#ifndef __bos1
76177 +#define __bos1(ptr)
76178 +#endif
76179 +
76180 /* Simple shorthand for a section definition */
76181 #ifndef __section
76182 # define __section(S) __attribute__ ((__section__(#S)))
76183 @@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76184 * use is to mediate communication between process-level code and irq/NMI
76185 * handlers, all running on the same CPU.
76186 */
76187 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
76188 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
76189 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
76190
76191 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
76192 #ifdef CONFIG_KPROBES
76193 diff --git a/include/linux/completion.h b/include/linux/completion.h
76194 index 5d5aaae..0ea9b84 100644
76195 --- a/include/linux/completion.h
76196 +++ b/include/linux/completion.h
76197 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
76198
76199 extern void wait_for_completion(struct completion *);
76200 extern void wait_for_completion_io(struct completion *);
76201 -extern int wait_for_completion_interruptible(struct completion *x);
76202 -extern int wait_for_completion_killable(struct completion *x);
76203 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
76204 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
76205 extern unsigned long wait_for_completion_timeout(struct completion *x,
76206 - unsigned long timeout);
76207 + unsigned long timeout) __intentional_overflow(-1);
76208 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
76209 - unsigned long timeout);
76210 + unsigned long timeout) __intentional_overflow(-1);
76211 extern long wait_for_completion_interruptible_timeout(
76212 - struct completion *x, unsigned long timeout);
76213 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76214 extern long wait_for_completion_killable_timeout(
76215 - struct completion *x, unsigned long timeout);
76216 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76217 extern bool try_wait_for_completion(struct completion *x);
76218 extern bool completion_done(struct completion *x);
76219
76220 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
76221 index 34025df..d94bbbc 100644
76222 --- a/include/linux/configfs.h
76223 +++ b/include/linux/configfs.h
76224 @@ -125,7 +125,7 @@ struct configfs_attribute {
76225 const char *ca_name;
76226 struct module *ca_owner;
76227 umode_t ca_mode;
76228 -};
76229 +} __do_const;
76230
76231 /*
76232 * Users often need to create attribute structures for their configurable
76233 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
76234 index dc196bb..c55a50f 100644
76235 --- a/include/linux/cpufreq.h
76236 +++ b/include/linux/cpufreq.h
76237 @@ -189,6 +189,7 @@ struct global_attr {
76238 ssize_t (*store)(struct kobject *a, struct attribute *b,
76239 const char *c, size_t count);
76240 };
76241 +typedef struct global_attr __no_const global_attr_no_const;
76242
76243 #define define_one_global_ro(_name) \
76244 static struct global_attr _name = \
76245 @@ -225,7 +226,7 @@ struct cpufreq_driver {
76246 int (*suspend) (struct cpufreq_policy *policy);
76247 int (*resume) (struct cpufreq_policy *policy);
76248 struct freq_attr **attr;
76249 -};
76250 +} __do_const;
76251
76252 /* flags */
76253 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
76254 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
76255 index 50fcbb0..9d2dbd9 100644
76256 --- a/include/linux/cpuidle.h
76257 +++ b/include/linux/cpuidle.h
76258 @@ -50,7 +50,8 @@ struct cpuidle_state {
76259 int index);
76260
76261 int (*enter_dead) (struct cpuidle_device *dev, int index);
76262 -};
76263 +} __do_const;
76264 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
76265
76266 /* Idle State Flags */
76267 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
76268 @@ -192,7 +193,7 @@ struct cpuidle_governor {
76269 void (*reflect) (struct cpuidle_device *dev, int index);
76270
76271 struct module *owner;
76272 -};
76273 +} __do_const;
76274
76275 #ifdef CONFIG_CPU_IDLE
76276 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
76277 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
76278 index d08e4d2..95fad61 100644
76279 --- a/include/linux/cpumask.h
76280 +++ b/include/linux/cpumask.h
76281 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76282 }
76283
76284 /* Valid inputs for n are -1 and 0. */
76285 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76286 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76287 {
76288 return n+1;
76289 }
76290
76291 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76292 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76293 {
76294 return n+1;
76295 }
76296
76297 -static inline unsigned int cpumask_next_and(int n,
76298 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
76299 const struct cpumask *srcp,
76300 const struct cpumask *andp)
76301 {
76302 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76303 *
76304 * Returns >= nr_cpu_ids if no further cpus set.
76305 */
76306 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76307 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76308 {
76309 /* -1 is a legal arg here. */
76310 if (n != -1)
76311 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76312 *
76313 * Returns >= nr_cpu_ids if no further cpus unset.
76314 */
76315 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76316 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76317 {
76318 /* -1 is a legal arg here. */
76319 if (n != -1)
76320 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76321 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
76322 }
76323
76324 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
76325 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
76326 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
76327
76328 /**
76329 diff --git a/include/linux/cred.h b/include/linux/cred.h
76330 index 04421e8..117e17a 100644
76331 --- a/include/linux/cred.h
76332 +++ b/include/linux/cred.h
76333 @@ -35,7 +35,7 @@ struct group_info {
76334 int nblocks;
76335 kgid_t small_block[NGROUPS_SMALL];
76336 kgid_t *blocks[0];
76337 -};
76338 +} __randomize_layout;
76339
76340 /**
76341 * get_group_info - Get a reference to a group info structure
76342 @@ -136,7 +136,7 @@ struct cred {
76343 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
76344 struct group_info *group_info; /* supplementary groups for euid/fsgid */
76345 struct rcu_head rcu; /* RCU deletion hook */
76346 -};
76347 +} __randomize_layout;
76348
76349 extern void __put_cred(struct cred *);
76350 extern void exit_creds(struct task_struct *);
76351 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
76352 static inline void validate_process_creds(void)
76353 {
76354 }
76355 +static inline void validate_task_creds(struct task_struct *task)
76356 +{
76357 +}
76358 #endif
76359
76360 /**
76361 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
76362 index b92eadf..b4ecdc1 100644
76363 --- a/include/linux/crypto.h
76364 +++ b/include/linux/crypto.h
76365 @@ -373,7 +373,7 @@ struct cipher_tfm {
76366 const u8 *key, unsigned int keylen);
76367 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76368 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76369 -};
76370 +} __no_const;
76371
76372 struct hash_tfm {
76373 int (*init)(struct hash_desc *desc);
76374 @@ -394,13 +394,13 @@ struct compress_tfm {
76375 int (*cot_decompress)(struct crypto_tfm *tfm,
76376 const u8 *src, unsigned int slen,
76377 u8 *dst, unsigned int *dlen);
76378 -};
76379 +} __no_const;
76380
76381 struct rng_tfm {
76382 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
76383 unsigned int dlen);
76384 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
76385 -};
76386 +} __no_const;
76387
76388 #define crt_ablkcipher crt_u.ablkcipher
76389 #define crt_aead crt_u.aead
76390 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
76391 index 653589e..4ef254a 100644
76392 --- a/include/linux/ctype.h
76393 +++ b/include/linux/ctype.h
76394 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
76395 * Fast implementation of tolower() for internal usage. Do not use in your
76396 * code.
76397 */
76398 -static inline char _tolower(const char c)
76399 +static inline unsigned char _tolower(const unsigned char c)
76400 {
76401 return c | 0x20;
76402 }
76403 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
76404 index bf72e9a..4ca7927 100644
76405 --- a/include/linux/dcache.h
76406 +++ b/include/linux/dcache.h
76407 @@ -133,7 +133,7 @@ struct dentry {
76408 } d_u;
76409 struct list_head d_subdirs; /* our children */
76410 struct hlist_node d_alias; /* inode alias list */
76411 -};
76412 +} __randomize_layout;
76413
76414 /*
76415 * dentry->d_lock spinlock nesting subclasses:
76416 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
76417 index 7925bf0..d5143d2 100644
76418 --- a/include/linux/decompress/mm.h
76419 +++ b/include/linux/decompress/mm.h
76420 @@ -77,7 +77,7 @@ static void free(void *where)
76421 * warnings when not needed (indeed large_malloc / large_free are not
76422 * needed by inflate */
76423
76424 -#define malloc(a) kmalloc(a, GFP_KERNEL)
76425 +#define malloc(a) kmalloc((a), GFP_KERNEL)
76426 #define free(a) kfree(a)
76427
76428 #define large_malloc(a) vmalloc(a)
76429 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
76430 index d48dc00..211ee54 100644
76431 --- a/include/linux/devfreq.h
76432 +++ b/include/linux/devfreq.h
76433 @@ -114,7 +114,7 @@ struct devfreq_governor {
76434 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
76435 int (*event_handler)(struct devfreq *devfreq,
76436 unsigned int event, void *data);
76437 -};
76438 +} __do_const;
76439
76440 /**
76441 * struct devfreq - Device devfreq structure
76442 diff --git a/include/linux/device.h b/include/linux/device.h
76443 index 952b010..d5b7691 100644
76444 --- a/include/linux/device.h
76445 +++ b/include/linux/device.h
76446 @@ -310,7 +310,7 @@ struct subsys_interface {
76447 struct list_head node;
76448 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
76449 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
76450 -};
76451 +} __do_const;
76452
76453 int subsys_interface_register(struct subsys_interface *sif);
76454 void subsys_interface_unregister(struct subsys_interface *sif);
76455 @@ -506,7 +506,7 @@ struct device_type {
76456 void (*release)(struct device *dev);
76457
76458 const struct dev_pm_ops *pm;
76459 -};
76460 +} __do_const;
76461
76462 /* interface for exporting device attributes */
76463 struct device_attribute {
76464 @@ -516,11 +516,12 @@ struct device_attribute {
76465 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
76466 const char *buf, size_t count);
76467 };
76468 +typedef struct device_attribute __no_const device_attribute_no_const;
76469
76470 struct dev_ext_attribute {
76471 struct device_attribute attr;
76472 void *var;
76473 -};
76474 +} __do_const;
76475
76476 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
76477 char *buf);
76478 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
76479 index fd4aee2..1f28db9 100644
76480 --- a/include/linux/dma-mapping.h
76481 +++ b/include/linux/dma-mapping.h
76482 @@ -54,7 +54,7 @@ struct dma_map_ops {
76483 u64 (*get_required_mask)(struct device *dev);
76484 #endif
76485 int is_phys;
76486 -};
76487 +} __do_const;
76488
76489 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
76490
76491 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
76492 index 41cf0c3..f3b771c 100644
76493 --- a/include/linux/dmaengine.h
76494 +++ b/include/linux/dmaengine.h
76495 @@ -1114,9 +1114,9 @@ struct dma_pinned_list {
76496 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
76497 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
76498
76499 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76500 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76501 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
76502 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76503 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76504 struct dma_pinned_list *pinned_list, struct page *page,
76505 unsigned int offset, size_t len);
76506
76507 diff --git a/include/linux/efi.h b/include/linux/efi.h
76508 index 11ce678..7b8c69c 100644
76509 --- a/include/linux/efi.h
76510 +++ b/include/linux/efi.h
76511 @@ -764,6 +764,7 @@ struct efivar_operations {
76512 efi_set_variable_t *set_variable;
76513 efi_query_variable_store_t *query_variable_store;
76514 };
76515 +typedef struct efivar_operations __no_const efivar_operations_no_const;
76516
76517 struct efivars {
76518 /*
76519 diff --git a/include/linux/elf.h b/include/linux/elf.h
76520 index 67a5fa7..b817372 100644
76521 --- a/include/linux/elf.h
76522 +++ b/include/linux/elf.h
76523 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
76524 #define elf_note elf32_note
76525 #define elf_addr_t Elf32_Off
76526 #define Elf_Half Elf32_Half
76527 +#define elf_dyn Elf32_Dyn
76528
76529 #else
76530
76531 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
76532 #define elf_note elf64_note
76533 #define elf_addr_t Elf64_Off
76534 #define Elf_Half Elf64_Half
76535 +#define elf_dyn Elf64_Dyn
76536
76537 #endif
76538
76539 diff --git a/include/linux/err.h b/include/linux/err.h
76540 index 15f92e0..e825a8e 100644
76541 --- a/include/linux/err.h
76542 +++ b/include/linux/err.h
76543 @@ -19,12 +19,12 @@
76544
76545 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
76546
76547 -static inline void * __must_check ERR_PTR(long error)
76548 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
76549 {
76550 return (void *) error;
76551 }
76552
76553 -static inline long __must_check PTR_ERR(__force const void *ptr)
76554 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
76555 {
76556 return (long) ptr;
76557 }
76558 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
76559 index 21c59af..6057a03 100644
76560 --- a/include/linux/extcon.h
76561 +++ b/include/linux/extcon.h
76562 @@ -135,7 +135,7 @@ struct extcon_dev {
76563 /* /sys/class/extcon/.../mutually_exclusive/... */
76564 struct attribute_group attr_g_muex;
76565 struct attribute **attrs_muex;
76566 - struct device_attribute *d_attrs_muex;
76567 + device_attribute_no_const *d_attrs_muex;
76568 };
76569
76570 /**
76571 diff --git a/include/linux/fb.h b/include/linux/fb.h
76572 index 70c4836..ff3daec 100644
76573 --- a/include/linux/fb.h
76574 +++ b/include/linux/fb.h
76575 @@ -304,7 +304,7 @@ struct fb_ops {
76576 /* called at KDB enter and leave time to prepare the console */
76577 int (*fb_debug_enter)(struct fb_info *info);
76578 int (*fb_debug_leave)(struct fb_info *info);
76579 -};
76580 +} __do_const;
76581
76582 #ifdef CONFIG_FB_TILEBLITTING
76583 #define FB_TILE_CURSOR_NONE 0
76584 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
76585 index 085197b..0fa6f0b 100644
76586 --- a/include/linux/fdtable.h
76587 +++ b/include/linux/fdtable.h
76588 @@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
76589 void put_files_struct(struct files_struct *fs);
76590 void reset_files_struct(struct files_struct *);
76591 int unshare_files(struct files_struct **);
76592 -struct files_struct *dup_fd(struct files_struct *, int *);
76593 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
76594 void do_close_on_exec(struct files_struct *);
76595 int iterate_fd(struct files_struct *, unsigned,
76596 int (*)(const void *, struct file *, unsigned),
76597 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
76598 index 8293262..2b3b8bd 100644
76599 --- a/include/linux/frontswap.h
76600 +++ b/include/linux/frontswap.h
76601 @@ -11,7 +11,7 @@ struct frontswap_ops {
76602 int (*load)(unsigned, pgoff_t, struct page *);
76603 void (*invalidate_page)(unsigned, pgoff_t);
76604 void (*invalidate_area)(unsigned);
76605 -};
76606 +} __no_const;
76607
76608 extern bool frontswap_enabled;
76609 extern struct frontswap_ops *
76610 diff --git a/include/linux/fs.h b/include/linux/fs.h
76611 index 121f11f..0f2a863 100644
76612 --- a/include/linux/fs.h
76613 +++ b/include/linux/fs.h
76614 @@ -423,7 +423,7 @@ struct address_space {
76615 spinlock_t private_lock; /* for use by the address_space */
76616 struct list_head private_list; /* ditto */
76617 void *private_data; /* ditto */
76618 -} __attribute__((aligned(sizeof(long))));
76619 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
76620 /*
76621 * On most architectures that alignment is already the case; but
76622 * must be enforced here for CRIS, to let the least significant bit
76623 @@ -466,7 +466,7 @@ struct block_device {
76624 int bd_fsfreeze_count;
76625 /* Mutex for freeze */
76626 struct mutex bd_fsfreeze_mutex;
76627 -};
76628 +} __randomize_layout;
76629
76630 /*
76631 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
76632 @@ -610,7 +610,7 @@ struct inode {
76633 atomic_t i_readcount; /* struct files open RO */
76634 #endif
76635 void *i_private; /* fs or device private pointer */
76636 -};
76637 +} __randomize_layout;
76638
76639 static inline int inode_unhashed(struct inode *inode)
76640 {
76641 @@ -808,7 +808,7 @@ struct file {
76642 #ifdef CONFIG_DEBUG_WRITECOUNT
76643 unsigned long f_mnt_write_state;
76644 #endif
76645 -};
76646 +} __randomize_layout;
76647
76648 struct file_handle {
76649 __u32 handle_bytes;
76650 @@ -978,7 +978,7 @@ struct file_lock {
76651 int state; /* state of grant or error if -ve */
76652 } afs;
76653 } fl_u;
76654 -};
76655 +} __randomize_layout;
76656
76657 /* The following constant reflects the upper bound of the file/locking space */
76658 #ifndef OFFSET_MAX
76659 @@ -1325,7 +1325,7 @@ struct super_block {
76660 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
76661 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
76662 struct rcu_head rcu;
76663 -};
76664 +} __randomize_layout;
76665
76666 extern struct timespec current_fs_time(struct super_block *sb);
76667
76668 @@ -1547,7 +1547,8 @@ struct file_operations {
76669 long (*fallocate)(struct file *file, int mode, loff_t offset,
76670 loff_t len);
76671 int (*show_fdinfo)(struct seq_file *m, struct file *f);
76672 -};
76673 +} __do_const __randomize_layout;
76674 +typedef struct file_operations __no_const file_operations_no_const;
76675
76676 struct inode_operations {
76677 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
76678 @@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
76679 return !IS_DEADDIR(inode);
76680 }
76681
76682 +static inline bool is_sidechannel_device(const struct inode *inode)
76683 +{
76684 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
76685 + umode_t mode = inode->i_mode;
76686 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
76687 +#else
76688 + return false;
76689 +#endif
76690 +}
76691 +
76692 #endif /* _LINUX_FS_H */
76693 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
76694 index 0efc3e6..fd23610 100644
76695 --- a/include/linux/fs_struct.h
76696 +++ b/include/linux/fs_struct.h
76697 @@ -6,13 +6,13 @@
76698 #include <linux/seqlock.h>
76699
76700 struct fs_struct {
76701 - int users;
76702 + atomic_t users;
76703 spinlock_t lock;
76704 seqcount_t seq;
76705 int umask;
76706 int in_exec;
76707 struct path root, pwd;
76708 -};
76709 +} __randomize_layout;
76710
76711 extern struct kmem_cache *fs_cachep;
76712
76713 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
76714 index 7714849..a4a5c7a 100644
76715 --- a/include/linux/fscache-cache.h
76716 +++ b/include/linux/fscache-cache.h
76717 @@ -113,7 +113,7 @@ struct fscache_operation {
76718 fscache_operation_release_t release;
76719 };
76720
76721 -extern atomic_t fscache_op_debug_id;
76722 +extern atomic_unchecked_t fscache_op_debug_id;
76723 extern void fscache_op_work_func(struct work_struct *work);
76724
76725 extern void fscache_enqueue_operation(struct fscache_operation *);
76726 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
76727 INIT_WORK(&op->work, fscache_op_work_func);
76728 atomic_set(&op->usage, 1);
76729 op->state = FSCACHE_OP_ST_INITIALISED;
76730 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
76731 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
76732 op->processor = processor;
76733 op->release = release;
76734 INIT_LIST_HEAD(&op->pend_link);
76735 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
76736 index 115bb81..e7b812b 100644
76737 --- a/include/linux/fscache.h
76738 +++ b/include/linux/fscache.h
76739 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
76740 * - this is mandatory for any object that may have data
76741 */
76742 void (*now_uncached)(void *cookie_netfs_data);
76743 -};
76744 +} __do_const;
76745
76746 /*
76747 * fscache cached network filesystem type
76748 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
76749 index 1c804b0..1432c2b 100644
76750 --- a/include/linux/fsnotify.h
76751 +++ b/include/linux/fsnotify.h
76752 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
76753 struct inode *inode = file_inode(file);
76754 __u32 mask = FS_ACCESS;
76755
76756 + if (is_sidechannel_device(inode))
76757 + return;
76758 +
76759 if (S_ISDIR(inode->i_mode))
76760 mask |= FS_ISDIR;
76761
76762 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
76763 struct inode *inode = file_inode(file);
76764 __u32 mask = FS_MODIFY;
76765
76766 + if (is_sidechannel_device(inode))
76767 + return;
76768 +
76769 if (S_ISDIR(inode->i_mode))
76770 mask |= FS_ISDIR;
76771
76772 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
76773 */
76774 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
76775 {
76776 - return kstrdup(name, GFP_KERNEL);
76777 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
76778 }
76779
76780 /*
76781 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
76782 index 9f3c275..8bdff5d 100644
76783 --- a/include/linux/genhd.h
76784 +++ b/include/linux/genhd.h
76785 @@ -194,7 +194,7 @@ struct gendisk {
76786 struct kobject *slave_dir;
76787
76788 struct timer_rand_state *random;
76789 - atomic_t sync_io; /* RAID */
76790 + atomic_unchecked_t sync_io; /* RAID */
76791 struct disk_events *ev;
76792 #ifdef CONFIG_BLK_DEV_INTEGRITY
76793 struct blk_integrity *integrity;
76794 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
76795 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
76796
76797 /* drivers/char/random.c */
76798 -extern void add_disk_randomness(struct gendisk *disk);
76799 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
76800 extern void rand_initialize_disk(struct gendisk *disk);
76801
76802 static inline sector_t get_start_sect(struct block_device *bdev)
76803 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
76804 index c0894dd..2fbf10c 100644
76805 --- a/include/linux/genl_magic_func.h
76806 +++ b/include/linux/genl_magic_func.h
76807 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
76808 },
76809
76810 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
76811 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
76812 +static struct genl_ops ZZZ_genl_ops[] = {
76813 #include GENL_MAGIC_INCLUDE_FILE
76814 };
76815
76816 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
76817 index 9b4dd49..61fd41d 100644
76818 --- a/include/linux/gfp.h
76819 +++ b/include/linux/gfp.h
76820 @@ -35,6 +35,13 @@ struct vm_area_struct;
76821 #define ___GFP_NO_KSWAPD 0x400000u
76822 #define ___GFP_OTHER_NODE 0x800000u
76823 #define ___GFP_WRITE 0x1000000u
76824 +
76825 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76826 +#define ___GFP_USERCOPY 0x2000000u
76827 +#else
76828 +#define ___GFP_USERCOPY 0
76829 +#endif
76830 +
76831 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
76832
76833 /*
76834 @@ -92,6 +99,7 @@ struct vm_area_struct;
76835 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
76836 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
76837 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
76838 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
76839
76840 /*
76841 * This may seem redundant, but it's a way of annotating false positives vs.
76842 @@ -99,7 +107,7 @@ struct vm_area_struct;
76843 */
76844 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
76845
76846 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
76847 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
76848 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
76849
76850 /* This equals 0, but use constants in case they ever change */
76851 @@ -153,6 +161,8 @@ struct vm_area_struct;
76852 /* 4GB DMA on some platforms */
76853 #define GFP_DMA32 __GFP_DMA32
76854
76855 +#define GFP_USERCOPY __GFP_USERCOPY
76856 +
76857 /* Convert GFP flags to their corresponding migrate type */
76858 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
76859 {
76860 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
76861 new file mode 100644
76862 index 0000000..edb2cb6
76863 --- /dev/null
76864 +++ b/include/linux/gracl.h
76865 @@ -0,0 +1,340 @@
76866 +#ifndef GR_ACL_H
76867 +#define GR_ACL_H
76868 +
76869 +#include <linux/grdefs.h>
76870 +#include <linux/resource.h>
76871 +#include <linux/capability.h>
76872 +#include <linux/dcache.h>
76873 +#include <asm/resource.h>
76874 +
76875 +/* Major status information */
76876 +
76877 +#define GR_VERSION "grsecurity 3.0"
76878 +#define GRSECURITY_VERSION 0x3000
76879 +
76880 +enum {
76881 + GR_SHUTDOWN = 0,
76882 + GR_ENABLE = 1,
76883 + GR_SPROLE = 2,
76884 + GR_OLDRELOAD = 3,
76885 + GR_SEGVMOD = 4,
76886 + GR_STATUS = 5,
76887 + GR_UNSPROLE = 6,
76888 + GR_PASSSET = 7,
76889 + GR_SPROLEPAM = 8,
76890 + GR_RELOAD = 9,
76891 +};
76892 +
76893 +/* Password setup definitions
76894 + * kernel/grhash.c */
76895 +enum {
76896 + GR_PW_LEN = 128,
76897 + GR_SALT_LEN = 16,
76898 + GR_SHA_LEN = 32,
76899 +};
76900 +
76901 +enum {
76902 + GR_SPROLE_LEN = 64,
76903 +};
76904 +
76905 +enum {
76906 + GR_NO_GLOB = 0,
76907 + GR_REG_GLOB,
76908 + GR_CREATE_GLOB
76909 +};
76910 +
76911 +#define GR_NLIMITS 32
76912 +
76913 +/* Begin Data Structures */
76914 +
76915 +struct sprole_pw {
76916 + unsigned char *rolename;
76917 + unsigned char salt[GR_SALT_LEN];
76918 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
76919 +};
76920 +
76921 +struct name_entry {
76922 + __u32 key;
76923 + ino_t inode;
76924 + dev_t device;
76925 + char *name;
76926 + __u16 len;
76927 + __u8 deleted;
76928 + struct name_entry *prev;
76929 + struct name_entry *next;
76930 +};
76931 +
76932 +struct inodev_entry {
76933 + struct name_entry *nentry;
76934 + struct inodev_entry *prev;
76935 + struct inodev_entry *next;
76936 +};
76937 +
76938 +struct acl_role_db {
76939 + struct acl_role_label **r_hash;
76940 + __u32 r_size;
76941 +};
76942 +
76943 +struct inodev_db {
76944 + struct inodev_entry **i_hash;
76945 + __u32 i_size;
76946 +};
76947 +
76948 +struct name_db {
76949 + struct name_entry **n_hash;
76950 + __u32 n_size;
76951 +};
76952 +
76953 +struct crash_uid {
76954 + uid_t uid;
76955 + unsigned long expires;
76956 +};
76957 +
76958 +struct gr_hash_struct {
76959 + void **table;
76960 + void **nametable;
76961 + void *first;
76962 + __u32 table_size;
76963 + __u32 used_size;
76964 + int type;
76965 +};
76966 +
76967 +/* Userspace Grsecurity ACL data structures */
76968 +
76969 +struct acl_subject_label {
76970 + char *filename;
76971 + ino_t inode;
76972 + dev_t device;
76973 + __u32 mode;
76974 + kernel_cap_t cap_mask;
76975 + kernel_cap_t cap_lower;
76976 + kernel_cap_t cap_invert_audit;
76977 +
76978 + struct rlimit res[GR_NLIMITS];
76979 + __u32 resmask;
76980 +
76981 + __u8 user_trans_type;
76982 + __u8 group_trans_type;
76983 + uid_t *user_transitions;
76984 + gid_t *group_transitions;
76985 + __u16 user_trans_num;
76986 + __u16 group_trans_num;
76987 +
76988 + __u32 sock_families[2];
76989 + __u32 ip_proto[8];
76990 + __u32 ip_type;
76991 + struct acl_ip_label **ips;
76992 + __u32 ip_num;
76993 + __u32 inaddr_any_override;
76994 +
76995 + __u32 crashes;
76996 + unsigned long expires;
76997 +
76998 + struct acl_subject_label *parent_subject;
76999 + struct gr_hash_struct *hash;
77000 + struct acl_subject_label *prev;
77001 + struct acl_subject_label *next;
77002 +
77003 + struct acl_object_label **obj_hash;
77004 + __u32 obj_hash_size;
77005 + __u16 pax_flags;
77006 +};
77007 +
77008 +struct role_allowed_ip {
77009 + __u32 addr;
77010 + __u32 netmask;
77011 +
77012 + struct role_allowed_ip *prev;
77013 + struct role_allowed_ip *next;
77014 +};
77015 +
77016 +struct role_transition {
77017 + char *rolename;
77018 +
77019 + struct role_transition *prev;
77020 + struct role_transition *next;
77021 +};
77022 +
77023 +struct acl_role_label {
77024 + char *rolename;
77025 + uid_t uidgid;
77026 + __u16 roletype;
77027 +
77028 + __u16 auth_attempts;
77029 + unsigned long expires;
77030 +
77031 + struct acl_subject_label *root_label;
77032 + struct gr_hash_struct *hash;
77033 +
77034 + struct acl_role_label *prev;
77035 + struct acl_role_label *next;
77036 +
77037 + struct role_transition *transitions;
77038 + struct role_allowed_ip *allowed_ips;
77039 + uid_t *domain_children;
77040 + __u16 domain_child_num;
77041 +
77042 + umode_t umask;
77043 +
77044 + struct acl_subject_label **subj_hash;
77045 + __u32 subj_hash_size;
77046 +};
77047 +
77048 +struct user_acl_role_db {
77049 + struct acl_role_label **r_table;
77050 + __u32 num_pointers; /* Number of allocations to track */
77051 + __u32 num_roles; /* Number of roles */
77052 + __u32 num_domain_children; /* Number of domain children */
77053 + __u32 num_subjects; /* Number of subjects */
77054 + __u32 num_objects; /* Number of objects */
77055 +};
77056 +
77057 +struct acl_object_label {
77058 + char *filename;
77059 + ino_t inode;
77060 + dev_t device;
77061 + __u32 mode;
77062 +
77063 + struct acl_subject_label *nested;
77064 + struct acl_object_label *globbed;
77065 +
77066 + /* next two structures not used */
77067 +
77068 + struct acl_object_label *prev;
77069 + struct acl_object_label *next;
77070 +};
77071 +
77072 +struct acl_ip_label {
77073 + char *iface;
77074 + __u32 addr;
77075 + __u32 netmask;
77076 + __u16 low, high;
77077 + __u8 mode;
77078 + __u32 type;
77079 + __u32 proto[8];
77080 +
77081 + /* next two structures not used */
77082 +
77083 + struct acl_ip_label *prev;
77084 + struct acl_ip_label *next;
77085 +};
77086 +
77087 +struct gr_arg {
77088 + struct user_acl_role_db role_db;
77089 + unsigned char pw[GR_PW_LEN];
77090 + unsigned char salt[GR_SALT_LEN];
77091 + unsigned char sum[GR_SHA_LEN];
77092 + unsigned char sp_role[GR_SPROLE_LEN];
77093 + struct sprole_pw *sprole_pws;
77094 + dev_t segv_device;
77095 + ino_t segv_inode;
77096 + uid_t segv_uid;
77097 + __u16 num_sprole_pws;
77098 + __u16 mode;
77099 +};
77100 +
77101 +struct gr_arg_wrapper {
77102 + struct gr_arg *arg;
77103 + __u32 version;
77104 + __u32 size;
77105 +};
77106 +
77107 +struct subject_map {
77108 + struct acl_subject_label *user;
77109 + struct acl_subject_label *kernel;
77110 + struct subject_map *prev;
77111 + struct subject_map *next;
77112 +};
77113 +
77114 +struct acl_subj_map_db {
77115 + struct subject_map **s_hash;
77116 + __u32 s_size;
77117 +};
77118 +
77119 +struct gr_policy_state {
77120 + struct sprole_pw **acl_special_roles;
77121 + __u16 num_sprole_pws;
77122 + struct acl_role_label *kernel_role;
77123 + struct acl_role_label *role_list;
77124 + struct acl_role_label *default_role;
77125 + struct acl_role_db acl_role_set;
77126 + struct acl_subj_map_db subj_map_set;
77127 + struct name_db name_set;
77128 + struct inodev_db inodev_set;
77129 +};
77130 +
77131 +struct gr_alloc_state {
77132 + unsigned long alloc_stack_next;
77133 + unsigned long alloc_stack_size;
77134 + void **alloc_stack;
77135 +};
77136 +
77137 +struct gr_reload_state {
77138 + struct gr_policy_state oldpolicy;
77139 + struct gr_alloc_state oldalloc;
77140 + struct gr_policy_state newpolicy;
77141 + struct gr_alloc_state newalloc;
77142 + struct gr_policy_state *oldpolicy_ptr;
77143 + struct gr_alloc_state *oldalloc_ptr;
77144 + unsigned char oldmode;
77145 +};
77146 +
77147 +/* End Data Structures Section */
77148 +
77149 +/* Hash functions generated by empirical testing by Brad Spengler
77150 + Makes good use of the low bits of the inode. Generally 0-1 times
77151 + in loop for successful match. 0-3 for unsuccessful match.
77152 + Shift/add algorithm with modulus of table size and an XOR*/
77153 +
77154 +static __inline__ unsigned int
77155 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
77156 +{
77157 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
77158 +}
77159 +
77160 + static __inline__ unsigned int
77161 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
77162 +{
77163 + return ((const unsigned long)userp % sz);
77164 +}
77165 +
77166 +static __inline__ unsigned int
77167 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
77168 +{
77169 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
77170 +}
77171 +
77172 +static __inline__ unsigned int
77173 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
77174 +{
77175 + return full_name_hash((const unsigned char *)name, len) % sz;
77176 +}
77177 +
77178 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
77179 + subj = NULL; \
77180 + iter = 0; \
77181 + while (iter < role->subj_hash_size) { \
77182 + if (subj == NULL) \
77183 + subj = role->subj_hash[iter]; \
77184 + if (subj == NULL) { \
77185 + iter++; \
77186 + continue; \
77187 + }
77188 +
77189 +#define FOR_EACH_SUBJECT_END(subj,iter) \
77190 + subj = subj->next; \
77191 + if (subj == NULL) \
77192 + iter++; \
77193 + }
77194 +
77195 +
77196 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
77197 + subj = role->hash->first; \
77198 + while (subj != NULL) {
77199 +
77200 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
77201 + subj = subj->next; \
77202 + }
77203 +
77204 +#endif
77205 +
77206 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
77207 new file mode 100644
77208 index 0000000..33ebd1f
77209 --- /dev/null
77210 +++ b/include/linux/gracl_compat.h
77211 @@ -0,0 +1,156 @@
77212 +#ifndef GR_ACL_COMPAT_H
77213 +#define GR_ACL_COMPAT_H
77214 +
77215 +#include <linux/resource.h>
77216 +#include <asm/resource.h>
77217 +
77218 +struct sprole_pw_compat {
77219 + compat_uptr_t rolename;
77220 + unsigned char salt[GR_SALT_LEN];
77221 + unsigned char sum[GR_SHA_LEN];
77222 +};
77223 +
77224 +struct gr_hash_struct_compat {
77225 + compat_uptr_t table;
77226 + compat_uptr_t nametable;
77227 + compat_uptr_t first;
77228 + __u32 table_size;
77229 + __u32 used_size;
77230 + int type;
77231 +};
77232 +
77233 +struct acl_subject_label_compat {
77234 + compat_uptr_t filename;
77235 + compat_ino_t inode;
77236 + __u32 device;
77237 + __u32 mode;
77238 + kernel_cap_t cap_mask;
77239 + kernel_cap_t cap_lower;
77240 + kernel_cap_t cap_invert_audit;
77241 +
77242 + struct compat_rlimit res[GR_NLIMITS];
77243 + __u32 resmask;
77244 +
77245 + __u8 user_trans_type;
77246 + __u8 group_trans_type;
77247 + compat_uptr_t user_transitions;
77248 + compat_uptr_t group_transitions;
77249 + __u16 user_trans_num;
77250 + __u16 group_trans_num;
77251 +
77252 + __u32 sock_families[2];
77253 + __u32 ip_proto[8];
77254 + __u32 ip_type;
77255 + compat_uptr_t ips;
77256 + __u32 ip_num;
77257 + __u32 inaddr_any_override;
77258 +
77259 + __u32 crashes;
77260 + compat_ulong_t expires;
77261 +
77262 + compat_uptr_t parent_subject;
77263 + compat_uptr_t hash;
77264 + compat_uptr_t prev;
77265 + compat_uptr_t next;
77266 +
77267 + compat_uptr_t obj_hash;
77268 + __u32 obj_hash_size;
77269 + __u16 pax_flags;
77270 +};
77271 +
77272 +struct role_allowed_ip_compat {
77273 + __u32 addr;
77274 + __u32 netmask;
77275 +
77276 + compat_uptr_t prev;
77277 + compat_uptr_t next;
77278 +};
77279 +
77280 +struct role_transition_compat {
77281 + compat_uptr_t rolename;
77282 +
77283 + compat_uptr_t prev;
77284 + compat_uptr_t next;
77285 +};
77286 +
77287 +struct acl_role_label_compat {
77288 + compat_uptr_t rolename;
77289 + uid_t uidgid;
77290 + __u16 roletype;
77291 +
77292 + __u16 auth_attempts;
77293 + compat_ulong_t expires;
77294 +
77295 + compat_uptr_t root_label;
77296 + compat_uptr_t hash;
77297 +
77298 + compat_uptr_t prev;
77299 + compat_uptr_t next;
77300 +
77301 + compat_uptr_t transitions;
77302 + compat_uptr_t allowed_ips;
77303 + compat_uptr_t domain_children;
77304 + __u16 domain_child_num;
77305 +
77306 + umode_t umask;
77307 +
77308 + compat_uptr_t subj_hash;
77309 + __u32 subj_hash_size;
77310 +};
77311 +
77312 +struct user_acl_role_db_compat {
77313 + compat_uptr_t r_table;
77314 + __u32 num_pointers;
77315 + __u32 num_roles;
77316 + __u32 num_domain_children;
77317 + __u32 num_subjects;
77318 + __u32 num_objects;
77319 +};
77320 +
77321 +struct acl_object_label_compat {
77322 + compat_uptr_t filename;
77323 + compat_ino_t inode;
77324 + __u32 device;
77325 + __u32 mode;
77326 +
77327 + compat_uptr_t nested;
77328 + compat_uptr_t globbed;
77329 +
77330 + compat_uptr_t prev;
77331 + compat_uptr_t next;
77332 +};
77333 +
77334 +struct acl_ip_label_compat {
77335 + compat_uptr_t iface;
77336 + __u32 addr;
77337 + __u32 netmask;
77338 + __u16 low, high;
77339 + __u8 mode;
77340 + __u32 type;
77341 + __u32 proto[8];
77342 +
77343 + compat_uptr_t prev;
77344 + compat_uptr_t next;
77345 +};
77346 +
77347 +struct gr_arg_compat {
77348 + struct user_acl_role_db_compat role_db;
77349 + unsigned char pw[GR_PW_LEN];
77350 + unsigned char salt[GR_SALT_LEN];
77351 + unsigned char sum[GR_SHA_LEN];
77352 + unsigned char sp_role[GR_SPROLE_LEN];
77353 + compat_uptr_t sprole_pws;
77354 + __u32 segv_device;
77355 + compat_ino_t segv_inode;
77356 + uid_t segv_uid;
77357 + __u16 num_sprole_pws;
77358 + __u16 mode;
77359 +};
77360 +
77361 +struct gr_arg_wrapper_compat {
77362 + compat_uptr_t arg;
77363 + __u32 version;
77364 + __u32 size;
77365 +};
77366 +
77367 +#endif
77368 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
77369 new file mode 100644
77370 index 0000000..323ecf2
77371 --- /dev/null
77372 +++ b/include/linux/gralloc.h
77373 @@ -0,0 +1,9 @@
77374 +#ifndef __GRALLOC_H
77375 +#define __GRALLOC_H
77376 +
77377 +void acl_free_all(void);
77378 +int acl_alloc_stack_init(unsigned long size);
77379 +void *acl_alloc(unsigned long len);
77380 +void *acl_alloc_num(unsigned long num, unsigned long len);
77381 +
77382 +#endif
77383 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
77384 new file mode 100644
77385 index 0000000..be66033
77386 --- /dev/null
77387 +++ b/include/linux/grdefs.h
77388 @@ -0,0 +1,140 @@
77389 +#ifndef GRDEFS_H
77390 +#define GRDEFS_H
77391 +
77392 +/* Begin grsecurity status declarations */
77393 +
77394 +enum {
77395 + GR_READY = 0x01,
77396 + GR_STATUS_INIT = 0x00 // disabled state
77397 +};
77398 +
77399 +/* Begin ACL declarations */
77400 +
77401 +/* Role flags */
77402 +
77403 +enum {
77404 + GR_ROLE_USER = 0x0001,
77405 + GR_ROLE_GROUP = 0x0002,
77406 + GR_ROLE_DEFAULT = 0x0004,
77407 + GR_ROLE_SPECIAL = 0x0008,
77408 + GR_ROLE_AUTH = 0x0010,
77409 + GR_ROLE_NOPW = 0x0020,
77410 + GR_ROLE_GOD = 0x0040,
77411 + GR_ROLE_LEARN = 0x0080,
77412 + GR_ROLE_TPE = 0x0100,
77413 + GR_ROLE_DOMAIN = 0x0200,
77414 + GR_ROLE_PAM = 0x0400,
77415 + GR_ROLE_PERSIST = 0x0800
77416 +};
77417 +
77418 +/* ACL Subject and Object mode flags */
77419 +enum {
77420 + GR_DELETED = 0x80000000
77421 +};
77422 +
77423 +/* ACL Object-only mode flags */
77424 +enum {
77425 + GR_READ = 0x00000001,
77426 + GR_APPEND = 0x00000002,
77427 + GR_WRITE = 0x00000004,
77428 + GR_EXEC = 0x00000008,
77429 + GR_FIND = 0x00000010,
77430 + GR_INHERIT = 0x00000020,
77431 + GR_SETID = 0x00000040,
77432 + GR_CREATE = 0x00000080,
77433 + GR_DELETE = 0x00000100,
77434 + GR_LINK = 0x00000200,
77435 + GR_AUDIT_READ = 0x00000400,
77436 + GR_AUDIT_APPEND = 0x00000800,
77437 + GR_AUDIT_WRITE = 0x00001000,
77438 + GR_AUDIT_EXEC = 0x00002000,
77439 + GR_AUDIT_FIND = 0x00004000,
77440 + GR_AUDIT_INHERIT= 0x00008000,
77441 + GR_AUDIT_SETID = 0x00010000,
77442 + GR_AUDIT_CREATE = 0x00020000,
77443 + GR_AUDIT_DELETE = 0x00040000,
77444 + GR_AUDIT_LINK = 0x00080000,
77445 + GR_PTRACERD = 0x00100000,
77446 + GR_NOPTRACE = 0x00200000,
77447 + GR_SUPPRESS = 0x00400000,
77448 + GR_NOLEARN = 0x00800000,
77449 + GR_INIT_TRANSFER= 0x01000000
77450 +};
77451 +
77452 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
77453 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
77454 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
77455 +
77456 +/* ACL subject-only mode flags */
77457 +enum {
77458 + GR_KILL = 0x00000001,
77459 + GR_VIEW = 0x00000002,
77460 + GR_PROTECTED = 0x00000004,
77461 + GR_LEARN = 0x00000008,
77462 + GR_OVERRIDE = 0x00000010,
77463 + /* just a placeholder, this mode is only used in userspace */
77464 + GR_DUMMY = 0x00000020,
77465 + GR_PROTSHM = 0x00000040,
77466 + GR_KILLPROC = 0x00000080,
77467 + GR_KILLIPPROC = 0x00000100,
77468 + /* just a placeholder, this mode is only used in userspace */
77469 + GR_NOTROJAN = 0x00000200,
77470 + GR_PROTPROCFD = 0x00000400,
77471 + GR_PROCACCT = 0x00000800,
77472 + GR_RELAXPTRACE = 0x00001000,
77473 + //GR_NESTED = 0x00002000,
77474 + GR_INHERITLEARN = 0x00004000,
77475 + GR_PROCFIND = 0x00008000,
77476 + GR_POVERRIDE = 0x00010000,
77477 + GR_KERNELAUTH = 0x00020000,
77478 + GR_ATSECURE = 0x00040000,
77479 + GR_SHMEXEC = 0x00080000
77480 +};
77481 +
77482 +enum {
77483 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
77484 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
77485 + GR_PAX_ENABLE_MPROTECT = 0x0004,
77486 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
77487 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
77488 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
77489 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
77490 + GR_PAX_DISABLE_MPROTECT = 0x0400,
77491 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
77492 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
77493 +};
77494 +
77495 +enum {
77496 + GR_ID_USER = 0x01,
77497 + GR_ID_GROUP = 0x02,
77498 +};
77499 +
77500 +enum {
77501 + GR_ID_ALLOW = 0x01,
77502 + GR_ID_DENY = 0x02,
77503 +};
77504 +
77505 +#define GR_CRASH_RES 31
77506 +#define GR_UIDTABLE_MAX 500
77507 +
77508 +/* begin resource learning section */
77509 +enum {
77510 + GR_RLIM_CPU_BUMP = 60,
77511 + GR_RLIM_FSIZE_BUMP = 50000,
77512 + GR_RLIM_DATA_BUMP = 10000,
77513 + GR_RLIM_STACK_BUMP = 1000,
77514 + GR_RLIM_CORE_BUMP = 10000,
77515 + GR_RLIM_RSS_BUMP = 500000,
77516 + GR_RLIM_NPROC_BUMP = 1,
77517 + GR_RLIM_NOFILE_BUMP = 5,
77518 + GR_RLIM_MEMLOCK_BUMP = 50000,
77519 + GR_RLIM_AS_BUMP = 500000,
77520 + GR_RLIM_LOCKS_BUMP = 2,
77521 + GR_RLIM_SIGPENDING_BUMP = 5,
77522 + GR_RLIM_MSGQUEUE_BUMP = 10000,
77523 + GR_RLIM_NICE_BUMP = 1,
77524 + GR_RLIM_RTPRIO_BUMP = 1,
77525 + GR_RLIM_RTTIME_BUMP = 1000000
77526 +};
77527 +
77528 +#endif
77529 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
77530 new file mode 100644
77531 index 0000000..d25522e
77532 --- /dev/null
77533 +++ b/include/linux/grinternal.h
77534 @@ -0,0 +1,229 @@
77535 +#ifndef __GRINTERNAL_H
77536 +#define __GRINTERNAL_H
77537 +
77538 +#ifdef CONFIG_GRKERNSEC
77539 +
77540 +#include <linux/fs.h>
77541 +#include <linux/mnt_namespace.h>
77542 +#include <linux/nsproxy.h>
77543 +#include <linux/gracl.h>
77544 +#include <linux/grdefs.h>
77545 +#include <linux/grmsg.h>
77546 +
77547 +void gr_add_learn_entry(const char *fmt, ...)
77548 + __attribute__ ((format (printf, 1, 2)));
77549 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
77550 + const struct vfsmount *mnt);
77551 +__u32 gr_check_create(const struct dentry *new_dentry,
77552 + const struct dentry *parent,
77553 + const struct vfsmount *mnt, const __u32 mode);
77554 +int gr_check_protected_task(const struct task_struct *task);
77555 +__u32 to_gr_audit(const __u32 reqmode);
77556 +int gr_set_acls(const int type);
77557 +int gr_acl_is_enabled(void);
77558 +char gr_roletype_to_char(void);
77559 +
77560 +void gr_handle_alertkill(struct task_struct *task);
77561 +char *gr_to_filename(const struct dentry *dentry,
77562 + const struct vfsmount *mnt);
77563 +char *gr_to_filename1(const struct dentry *dentry,
77564 + const struct vfsmount *mnt);
77565 +char *gr_to_filename2(const struct dentry *dentry,
77566 + const struct vfsmount *mnt);
77567 +char *gr_to_filename3(const struct dentry *dentry,
77568 + const struct vfsmount *mnt);
77569 +
77570 +extern int grsec_enable_ptrace_readexec;
77571 +extern int grsec_enable_harden_ptrace;
77572 +extern int grsec_enable_link;
77573 +extern int grsec_enable_fifo;
77574 +extern int grsec_enable_execve;
77575 +extern int grsec_enable_shm;
77576 +extern int grsec_enable_execlog;
77577 +extern int grsec_enable_signal;
77578 +extern int grsec_enable_audit_ptrace;
77579 +extern int grsec_enable_forkfail;
77580 +extern int grsec_enable_time;
77581 +extern int grsec_enable_rofs;
77582 +extern int grsec_deny_new_usb;
77583 +extern int grsec_enable_chroot_shmat;
77584 +extern int grsec_enable_chroot_mount;
77585 +extern int grsec_enable_chroot_double;
77586 +extern int grsec_enable_chroot_pivot;
77587 +extern int grsec_enable_chroot_chdir;
77588 +extern int grsec_enable_chroot_chmod;
77589 +extern int grsec_enable_chroot_mknod;
77590 +extern int grsec_enable_chroot_fchdir;
77591 +extern int grsec_enable_chroot_nice;
77592 +extern int grsec_enable_chroot_execlog;
77593 +extern int grsec_enable_chroot_caps;
77594 +extern int grsec_enable_chroot_sysctl;
77595 +extern int grsec_enable_chroot_unix;
77596 +extern int grsec_enable_symlinkown;
77597 +extern kgid_t grsec_symlinkown_gid;
77598 +extern int grsec_enable_tpe;
77599 +extern kgid_t grsec_tpe_gid;
77600 +extern int grsec_enable_tpe_all;
77601 +extern int grsec_enable_tpe_invert;
77602 +extern int grsec_enable_socket_all;
77603 +extern kgid_t grsec_socket_all_gid;
77604 +extern int grsec_enable_socket_client;
77605 +extern kgid_t grsec_socket_client_gid;
77606 +extern int grsec_enable_socket_server;
77607 +extern kgid_t grsec_socket_server_gid;
77608 +extern kgid_t grsec_audit_gid;
77609 +extern int grsec_enable_group;
77610 +extern int grsec_enable_log_rwxmaps;
77611 +extern int grsec_enable_mount;
77612 +extern int grsec_enable_chdir;
77613 +extern int grsec_resource_logging;
77614 +extern int grsec_enable_blackhole;
77615 +extern int grsec_lastack_retries;
77616 +extern int grsec_enable_brute;
77617 +extern int grsec_enable_harden_ipc;
77618 +extern int grsec_lock;
77619 +
77620 +extern spinlock_t grsec_alert_lock;
77621 +extern unsigned long grsec_alert_wtime;
77622 +extern unsigned long grsec_alert_fyet;
77623 +
77624 +extern spinlock_t grsec_audit_lock;
77625 +
77626 +extern rwlock_t grsec_exec_file_lock;
77627 +
77628 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
77629 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
77630 + (tsk)->exec_file->f_path.mnt) : "/")
77631 +
77632 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
77633 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
77634 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77635 +
77636 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
77637 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
77638 + (tsk)->exec_file->f_path.mnt) : "/")
77639 +
77640 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
77641 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
77642 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77643 +
77644 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
77645 +
77646 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
77647 +
77648 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
77649 +{
77650 + if (file1 && file2) {
77651 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
77652 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
77653 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
77654 + return true;
77655 + }
77656 +
77657 + return false;
77658 +}
77659 +
77660 +#define GR_CHROOT_CAPS {{ \
77661 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
77662 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
77663 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
77664 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
77665 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
77666 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
77667 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
77668 +
77669 +#define security_learn(normal_msg,args...) \
77670 +({ \
77671 + read_lock(&grsec_exec_file_lock); \
77672 + gr_add_learn_entry(normal_msg "\n", ## args); \
77673 + read_unlock(&grsec_exec_file_lock); \
77674 +})
77675 +
77676 +enum {
77677 + GR_DO_AUDIT,
77678 + GR_DONT_AUDIT,
77679 + /* used for non-audit messages that we shouldn't kill the task on */
77680 + GR_DONT_AUDIT_GOOD
77681 +};
77682 +
77683 +enum {
77684 + GR_TTYSNIFF,
77685 + GR_RBAC,
77686 + GR_RBAC_STR,
77687 + GR_STR_RBAC,
77688 + GR_RBAC_MODE2,
77689 + GR_RBAC_MODE3,
77690 + GR_FILENAME,
77691 + GR_SYSCTL_HIDDEN,
77692 + GR_NOARGS,
77693 + GR_ONE_INT,
77694 + GR_ONE_INT_TWO_STR,
77695 + GR_ONE_STR,
77696 + GR_STR_INT,
77697 + GR_TWO_STR_INT,
77698 + GR_TWO_INT,
77699 + GR_TWO_U64,
77700 + GR_THREE_INT,
77701 + GR_FIVE_INT_TWO_STR,
77702 + GR_TWO_STR,
77703 + GR_THREE_STR,
77704 + GR_FOUR_STR,
77705 + GR_STR_FILENAME,
77706 + GR_FILENAME_STR,
77707 + GR_FILENAME_TWO_INT,
77708 + GR_FILENAME_TWO_INT_STR,
77709 + GR_TEXTREL,
77710 + GR_PTRACE,
77711 + GR_RESOURCE,
77712 + GR_CAP,
77713 + GR_SIG,
77714 + GR_SIG2,
77715 + GR_CRASH1,
77716 + GR_CRASH2,
77717 + GR_PSACCT,
77718 + GR_RWXMAP,
77719 + GR_RWXMAPVMA
77720 +};
77721 +
77722 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
77723 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
77724 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
77725 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
77726 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
77727 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
77728 +#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)
77729 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
77730 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
77731 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
77732 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
77733 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
77734 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
77735 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
77736 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
77737 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
77738 +#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)
77739 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
77740 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
77741 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
77742 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
77743 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
77744 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
77745 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
77746 +#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)
77747 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
77748 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
77749 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
77750 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
77751 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
77752 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
77753 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
77754 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
77755 +#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)
77756 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
77757 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
77758 +
77759 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
77760 +
77761 +#endif
77762 +
77763 +#endif
77764 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
77765 new file mode 100644
77766 index 0000000..195cbe4
77767 --- /dev/null
77768 +++ b/include/linux/grmsg.h
77769 @@ -0,0 +1,115 @@
77770 +#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"
77771 +#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"
77772 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
77773 +#define GR_STOPMOD_MSG "denied modification of module state by "
77774 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
77775 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
77776 +#define GR_IOPERM_MSG "denied use of ioperm() by "
77777 +#define GR_IOPL_MSG "denied use of iopl() by "
77778 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
77779 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
77780 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
77781 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
77782 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
77783 +#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"
77784 +#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"
77785 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
77786 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
77787 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
77788 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
77789 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
77790 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
77791 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
77792 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
77793 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
77794 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
77795 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
77796 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
77797 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
77798 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
77799 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
77800 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
77801 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
77802 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
77803 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
77804 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
77805 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
77806 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
77807 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
77808 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
77809 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
77810 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
77811 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
77812 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
77813 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
77814 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
77815 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
77816 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
77817 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
77818 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
77819 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
77820 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
77821 +#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"
77822 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
77823 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
77824 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
77825 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
77826 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
77827 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
77828 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
77829 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
77830 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
77831 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
77832 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
77833 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
77834 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
77835 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
77836 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
77837 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
77838 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
77839 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
77840 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
77841 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
77842 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
77843 +#define GR_NICE_CHROOT_MSG "denied priority change by "
77844 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
77845 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
77846 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
77847 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
77848 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
77849 +#define GR_TIME_MSG "time set by "
77850 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
77851 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
77852 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
77853 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
77854 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
77855 +#define GR_BIND_MSG "denied bind() by "
77856 +#define GR_CONNECT_MSG "denied connect() by "
77857 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
77858 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
77859 +#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"
77860 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
77861 +#define GR_CAP_ACL_MSG "use of %s denied for "
77862 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
77863 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
77864 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
77865 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
77866 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
77867 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
77868 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
77869 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
77870 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
77871 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
77872 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
77873 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
77874 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
77875 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
77876 +#define GR_VM86_MSG "denied use of vm86 by "
77877 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
77878 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
77879 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
77880 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
77881 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
77882 +#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 "
77883 +#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 "
77884 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
77885 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
77886 new file mode 100644
77887 index 0000000..d8b5b48
77888 --- /dev/null
77889 +++ b/include/linux/grsecurity.h
77890 @@ -0,0 +1,245 @@
77891 +#ifndef GR_SECURITY_H
77892 +#define GR_SECURITY_H
77893 +#include <linux/fs.h>
77894 +#include <linux/fs_struct.h>
77895 +#include <linux/binfmts.h>
77896 +#include <linux/gracl.h>
77897 +
77898 +/* notify of brain-dead configs */
77899 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77900 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
77901 +#endif
77902 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
77903 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
77904 +#endif
77905 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
77906 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
77907 +#endif
77908 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
77909 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
77910 +#endif
77911 +
77912 +int gr_handle_new_usb(void);
77913 +
77914 +void gr_handle_brute_attach(int dumpable);
77915 +void gr_handle_brute_check(void);
77916 +void gr_handle_kernel_exploit(void);
77917 +
77918 +char gr_roletype_to_char(void);
77919 +
77920 +int gr_acl_enable_at_secure(void);
77921 +
77922 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
77923 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
77924 +
77925 +void gr_del_task_from_ip_table(struct task_struct *p);
77926 +
77927 +int gr_pid_is_chrooted(struct task_struct *p);
77928 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
77929 +int gr_handle_chroot_nice(void);
77930 +int gr_handle_chroot_sysctl(const int op);
77931 +int gr_handle_chroot_setpriority(struct task_struct *p,
77932 + const int niceval);
77933 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
77934 +int gr_handle_chroot_chroot(const struct dentry *dentry,
77935 + const struct vfsmount *mnt);
77936 +void gr_handle_chroot_chdir(const struct path *path);
77937 +int gr_handle_chroot_chmod(const struct dentry *dentry,
77938 + const struct vfsmount *mnt, const int mode);
77939 +int gr_handle_chroot_mknod(const struct dentry *dentry,
77940 + const struct vfsmount *mnt, const int mode);
77941 +int gr_handle_chroot_mount(const struct dentry *dentry,
77942 + const struct vfsmount *mnt,
77943 + const char *dev_name);
77944 +int gr_handle_chroot_pivot(void);
77945 +int gr_handle_chroot_unix(const pid_t pid);
77946 +
77947 +int gr_handle_rawio(const struct inode *inode);
77948 +
77949 +void gr_handle_ioperm(void);
77950 +void gr_handle_iopl(void);
77951 +
77952 +umode_t gr_acl_umask(void);
77953 +
77954 +int gr_tpe_allow(const struct file *file);
77955 +
77956 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
77957 +void gr_clear_chroot_entries(struct task_struct *task);
77958 +
77959 +void gr_log_forkfail(const int retval);
77960 +void gr_log_timechange(void);
77961 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
77962 +void gr_log_chdir(const struct dentry *dentry,
77963 + const struct vfsmount *mnt);
77964 +void gr_log_chroot_exec(const struct dentry *dentry,
77965 + const struct vfsmount *mnt);
77966 +void gr_log_remount(const char *devname, const int retval);
77967 +void gr_log_unmount(const char *devname, const int retval);
77968 +void gr_log_mount(const char *from, const char *to, const int retval);
77969 +void gr_log_textrel(struct vm_area_struct *vma);
77970 +void gr_log_ptgnustack(struct file *file);
77971 +void gr_log_rwxmmap(struct file *file);
77972 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
77973 +
77974 +int gr_handle_follow_link(const struct inode *parent,
77975 + const struct inode *inode,
77976 + const struct dentry *dentry,
77977 + const struct vfsmount *mnt);
77978 +int gr_handle_fifo(const struct dentry *dentry,
77979 + const struct vfsmount *mnt,
77980 + const struct dentry *dir, const int flag,
77981 + const int acc_mode);
77982 +int gr_handle_hardlink(const struct dentry *dentry,
77983 + const struct vfsmount *mnt,
77984 + struct inode *inode,
77985 + const int mode, const struct filename *to);
77986 +
77987 +int gr_is_capable(const int cap);
77988 +int gr_is_capable_nolog(const int cap);
77989 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77990 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
77991 +
77992 +void gr_copy_label(struct task_struct *tsk);
77993 +void gr_handle_crash(struct task_struct *task, const int sig);
77994 +int gr_handle_signal(const struct task_struct *p, const int sig);
77995 +int gr_check_crash_uid(const kuid_t uid);
77996 +int gr_check_protected_task(const struct task_struct *task);
77997 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
77998 +int gr_acl_handle_mmap(const struct file *file,
77999 + const unsigned long prot);
78000 +int gr_acl_handle_mprotect(const struct file *file,
78001 + const unsigned long prot);
78002 +int gr_check_hidden_task(const struct task_struct *tsk);
78003 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
78004 + const struct vfsmount *mnt);
78005 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
78006 + const struct vfsmount *mnt);
78007 +__u32 gr_acl_handle_access(const struct dentry *dentry,
78008 + const struct vfsmount *mnt, const int fmode);
78009 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
78010 + const struct vfsmount *mnt, umode_t *mode);
78011 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
78012 + const struct vfsmount *mnt);
78013 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
78014 + const struct vfsmount *mnt);
78015 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
78016 + const struct vfsmount *mnt);
78017 +int gr_handle_ptrace(struct task_struct *task, const long request);
78018 +int gr_handle_proc_ptrace(struct task_struct *task);
78019 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
78020 + const struct vfsmount *mnt);
78021 +int gr_check_crash_exec(const struct file *filp);
78022 +int gr_acl_is_enabled(void);
78023 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
78024 + const kgid_t gid);
78025 +int gr_set_proc_label(const struct dentry *dentry,
78026 + const struct vfsmount *mnt,
78027 + const int unsafe_flags);
78028 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
78029 + const struct vfsmount *mnt);
78030 +__u32 gr_acl_handle_open(const struct dentry *dentry,
78031 + const struct vfsmount *mnt, int acc_mode);
78032 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
78033 + const struct dentry *p_dentry,
78034 + const struct vfsmount *p_mnt,
78035 + int open_flags, int acc_mode, const int imode);
78036 +void gr_handle_create(const struct dentry *dentry,
78037 + const struct vfsmount *mnt);
78038 +void gr_handle_proc_create(const struct dentry *dentry,
78039 + const struct inode *inode);
78040 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
78041 + const struct dentry *parent_dentry,
78042 + const struct vfsmount *parent_mnt,
78043 + const int mode);
78044 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
78045 + const struct dentry *parent_dentry,
78046 + const struct vfsmount *parent_mnt);
78047 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
78048 + const struct vfsmount *mnt);
78049 +void gr_handle_delete(const ino_t ino, const dev_t dev);
78050 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
78051 + const struct vfsmount *mnt);
78052 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
78053 + const struct dentry *parent_dentry,
78054 + const struct vfsmount *parent_mnt,
78055 + const struct filename *from);
78056 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
78057 + const struct dentry *parent_dentry,
78058 + const struct vfsmount *parent_mnt,
78059 + const struct dentry *old_dentry,
78060 + const struct vfsmount *old_mnt, const struct filename *to);
78061 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
78062 +int gr_acl_handle_rename(struct dentry *new_dentry,
78063 + struct dentry *parent_dentry,
78064 + const struct vfsmount *parent_mnt,
78065 + struct dentry *old_dentry,
78066 + struct inode *old_parent_inode,
78067 + struct vfsmount *old_mnt, const struct filename *newname);
78068 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
78069 + struct dentry *old_dentry,
78070 + struct dentry *new_dentry,
78071 + struct vfsmount *mnt, const __u8 replace);
78072 +__u32 gr_check_link(const struct dentry *new_dentry,
78073 + const struct dentry *parent_dentry,
78074 + const struct vfsmount *parent_mnt,
78075 + const struct dentry *old_dentry,
78076 + const struct vfsmount *old_mnt);
78077 +int gr_acl_handle_filldir(const struct file *file, const char *name,
78078 + const unsigned int namelen, const ino_t ino);
78079 +
78080 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
78081 + const struct vfsmount *mnt);
78082 +void gr_acl_handle_exit(void);
78083 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
78084 +int gr_acl_handle_procpidmem(const struct task_struct *task);
78085 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
78086 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
78087 +void gr_audit_ptrace(struct task_struct *task);
78088 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
78089 +void gr_put_exec_file(struct task_struct *task);
78090 +
78091 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
78092 +
78093 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
78094 +extern void gr_learn_resource(const struct task_struct *task, const int res,
78095 + const unsigned long wanted, const int gt);
78096 +#else
78097 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
78098 + const unsigned long wanted, const int gt)
78099 +{
78100 +}
78101 +#endif
78102 +
78103 +#ifdef CONFIG_GRKERNSEC_RESLOG
78104 +extern void gr_log_resource(const struct task_struct *task, const int res,
78105 + const unsigned long wanted, const int gt);
78106 +#else
78107 +static inline void gr_log_resource(const struct task_struct *task, const int res,
78108 + const unsigned long wanted, const int gt)
78109 +{
78110 +}
78111 +#endif
78112 +
78113 +#ifdef CONFIG_GRKERNSEC
78114 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
78115 +void gr_handle_vm86(void);
78116 +void gr_handle_mem_readwrite(u64 from, u64 to);
78117 +
78118 +void gr_log_badprocpid(const char *entry);
78119 +
78120 +extern int grsec_enable_dmesg;
78121 +extern int grsec_disable_privio;
78122 +
78123 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78124 +extern kgid_t grsec_proc_gid;
78125 +#endif
78126 +
78127 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78128 +extern int grsec_enable_chroot_findtask;
78129 +#endif
78130 +#ifdef CONFIG_GRKERNSEC_SETXID
78131 +extern int grsec_enable_setxid;
78132 +#endif
78133 +#endif
78134 +
78135 +#endif
78136 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
78137 new file mode 100644
78138 index 0000000..e7ffaaf
78139 --- /dev/null
78140 +++ b/include/linux/grsock.h
78141 @@ -0,0 +1,19 @@
78142 +#ifndef __GRSOCK_H
78143 +#define __GRSOCK_H
78144 +
78145 +extern void gr_attach_curr_ip(const struct sock *sk);
78146 +extern int gr_handle_sock_all(const int family, const int type,
78147 + const int protocol);
78148 +extern int gr_handle_sock_server(const struct sockaddr *sck);
78149 +extern int gr_handle_sock_server_other(const struct sock *sck);
78150 +extern int gr_handle_sock_client(const struct sockaddr *sck);
78151 +extern int gr_search_connect(struct socket * sock,
78152 + struct sockaddr_in * addr);
78153 +extern int gr_search_bind(struct socket * sock,
78154 + struct sockaddr_in * addr);
78155 +extern int gr_search_listen(struct socket * sock);
78156 +extern int gr_search_accept(struct socket * sock);
78157 +extern int gr_search_socket(const int domain, const int type,
78158 + const int protocol);
78159 +
78160 +#endif
78161 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
78162 index 7fb31da..08b5114 100644
78163 --- a/include/linux/highmem.h
78164 +++ b/include/linux/highmem.h
78165 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
78166 kunmap_atomic(kaddr);
78167 }
78168
78169 +static inline void sanitize_highpage(struct page *page)
78170 +{
78171 + void *kaddr;
78172 + unsigned long flags;
78173 +
78174 + local_irq_save(flags);
78175 + kaddr = kmap_atomic(page);
78176 + clear_page(kaddr);
78177 + kunmap_atomic(kaddr);
78178 + local_irq_restore(flags);
78179 +}
78180 +
78181 static inline void zero_user_segments(struct page *page,
78182 unsigned start1, unsigned end1,
78183 unsigned start2, unsigned end2)
78184 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
78185 index 1c7b89a..7dda400 100644
78186 --- a/include/linux/hwmon-sysfs.h
78187 +++ b/include/linux/hwmon-sysfs.h
78188 @@ -25,7 +25,8 @@
78189 struct sensor_device_attribute{
78190 struct device_attribute dev_attr;
78191 int index;
78192 -};
78193 +} __do_const;
78194 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
78195 #define to_sensor_dev_attr(_dev_attr) \
78196 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
78197
78198 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
78199 struct device_attribute dev_attr;
78200 u8 index;
78201 u8 nr;
78202 -};
78203 +} __do_const;
78204 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
78205 #define to_sensor_dev_attr_2(_dev_attr) \
78206 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
78207
78208 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
78209 index d9c8dbd3..def6e5a 100644
78210 --- a/include/linux/i2c.h
78211 +++ b/include/linux/i2c.h
78212 @@ -364,6 +364,7 @@ struct i2c_algorithm {
78213 /* To determine what the adapter supports */
78214 u32 (*functionality) (struct i2c_adapter *);
78215 };
78216 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
78217
78218 /**
78219 * struct i2c_bus_recovery_info - I2C bus recovery information
78220 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
78221 index d23c3c2..eb63c81 100644
78222 --- a/include/linux/i2o.h
78223 +++ b/include/linux/i2o.h
78224 @@ -565,7 +565,7 @@ struct i2o_controller {
78225 struct i2o_device *exec; /* Executive */
78226 #if BITS_PER_LONG == 64
78227 spinlock_t context_list_lock; /* lock for context_list */
78228 - atomic_t context_list_counter; /* needed for unique contexts */
78229 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
78230 struct list_head context_list; /* list of context id's
78231 and pointers */
78232 #endif
78233 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
78234 index aff7ad8..3942bbd 100644
78235 --- a/include/linux/if_pppox.h
78236 +++ b/include/linux/if_pppox.h
78237 @@ -76,7 +76,7 @@ struct pppox_proto {
78238 int (*ioctl)(struct socket *sock, unsigned int cmd,
78239 unsigned long arg);
78240 struct module *owner;
78241 -};
78242 +} __do_const;
78243
78244 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
78245 extern void unregister_pppox_proto(int proto_num);
78246 diff --git a/include/linux/init.h b/include/linux/init.h
78247 index 8e68a64..3f977a0 100644
78248 --- a/include/linux/init.h
78249 +++ b/include/linux/init.h
78250 @@ -37,9 +37,17 @@
78251 * section.
78252 */
78253
78254 +#define add_init_latent_entropy __latent_entropy
78255 +
78256 +#ifdef CONFIG_MEMORY_HOTPLUG
78257 +#define add_meminit_latent_entropy
78258 +#else
78259 +#define add_meminit_latent_entropy __latent_entropy
78260 +#endif
78261 +
78262 /* These are for everybody (although not all archs will actually
78263 discard it in modules) */
78264 -#define __init __section(.init.text) __cold notrace
78265 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
78266 #define __initdata __section(.init.data)
78267 #define __initconst __constsection(.init.rodata)
78268 #define __exitdata __section(.exit.data)
78269 @@ -100,7 +108,7 @@
78270 #define __cpuexitconst
78271
78272 /* Used for MEMORY_HOTPLUG */
78273 -#define __meminit __section(.meminit.text) __cold notrace
78274 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
78275 #define __meminitdata __section(.meminit.data)
78276 #define __meminitconst __constsection(.meminit.rodata)
78277 #define __memexit __section(.memexit.text) __exitused __cold notrace
78278 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
78279 index b0ed422..d79ea23 100644
78280 --- a/include/linux/init_task.h
78281 +++ b/include/linux/init_task.h
78282 @@ -154,6 +154,12 @@ extern struct task_group root_task_group;
78283
78284 #define INIT_TASK_COMM "swapper"
78285
78286 +#ifdef CONFIG_X86
78287 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
78288 +#else
78289 +#define INIT_TASK_THREAD_INFO
78290 +#endif
78291 +
78292 /*
78293 * INIT_TASK is used to set up the first task table, touch at
78294 * your own risk!. Base=0, limit=0x1fffff (=2MB)
78295 @@ -193,6 +199,7 @@ extern struct task_group root_task_group;
78296 RCU_POINTER_INITIALIZER(cred, &init_cred), \
78297 .comm = INIT_TASK_COMM, \
78298 .thread = INIT_THREAD, \
78299 + INIT_TASK_THREAD_INFO \
78300 .fs = &init_fs, \
78301 .files = &init_files, \
78302 .signal = &init_signals, \
78303 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
78304 index db43b58..5d5084b 100644
78305 --- a/include/linux/interrupt.h
78306 +++ b/include/linux/interrupt.h
78307 @@ -360,7 +360,7 @@ enum
78308 /* map softirq index to softirq name. update 'softirq_to_name' in
78309 * kernel/softirq.c when adding a new softirq.
78310 */
78311 -extern char *softirq_to_name[NR_SOFTIRQS];
78312 +extern const char * const softirq_to_name[NR_SOFTIRQS];
78313
78314 /* softirq mask and active fields moved to irq_cpustat_t in
78315 * asm/hardirq.h to get better cache usage. KAO
78316 @@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
78317
78318 struct softirq_action
78319 {
78320 - void (*action)(struct softirq_action *);
78321 -};
78322 + void (*action)(void);
78323 +} __no_const;
78324
78325 asmlinkage void do_softirq(void);
78326 asmlinkage void __do_softirq(void);
78327 @@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
78328 }
78329 #endif
78330
78331 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
78332 +extern void open_softirq(int nr, void (*action)(void));
78333 extern void softirq_init(void);
78334 extern void __raise_softirq_irqoff(unsigned int nr);
78335
78336 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
78337 index a444c79..8c41ea9 100644
78338 --- a/include/linux/iommu.h
78339 +++ b/include/linux/iommu.h
78340 @@ -130,7 +130,7 @@ struct iommu_ops {
78341 u32 (*domain_get_windows)(struct iommu_domain *domain);
78342
78343 unsigned long pgsize_bitmap;
78344 -};
78345 +} __do_const;
78346
78347 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
78348 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
78349 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
78350 index 89b7c24..382af74 100644
78351 --- a/include/linux/ioport.h
78352 +++ b/include/linux/ioport.h
78353 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
78354 int adjust_resource(struct resource *res, resource_size_t start,
78355 resource_size_t size);
78356 resource_size_t resource_alignment(struct resource *res);
78357 -static inline resource_size_t resource_size(const struct resource *res)
78358 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
78359 {
78360 return res->end - res->start + 1;
78361 }
78362 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
78363 index f6c82de..de8619e 100644
78364 --- a/include/linux/ipc_namespace.h
78365 +++ b/include/linux/ipc_namespace.h
78366 @@ -70,7 +70,7 @@ struct ipc_namespace {
78367 struct user_namespace *user_ns;
78368
78369 unsigned int proc_inum;
78370 -};
78371 +} __randomize_layout;
78372
78373 extern struct ipc_namespace init_ipc_ns;
78374 extern atomic_t nr_ipc_ns;
78375 diff --git a/include/linux/irq.h b/include/linux/irq.h
78376 index 7dc1003..407327b 100644
78377 --- a/include/linux/irq.h
78378 +++ b/include/linux/irq.h
78379 @@ -338,7 +338,8 @@ struct irq_chip {
78380 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
78381
78382 unsigned long flags;
78383 -};
78384 +} __do_const;
78385 +typedef struct irq_chip __no_const irq_chip_no_const;
78386
78387 /*
78388 * irq_chip specific flags
78389 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
78390 index cac496b..ffa0567 100644
78391 --- a/include/linux/irqchip/arm-gic.h
78392 +++ b/include/linux/irqchip/arm-gic.h
78393 @@ -61,9 +61,11 @@
78394
78395 #ifndef __ASSEMBLY__
78396
78397 +#include <linux/irq.h>
78398 +
78399 struct device_node;
78400
78401 -extern struct irq_chip gic_arch_extn;
78402 +extern irq_chip_no_const gic_arch_extn;
78403
78404 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
78405 u32 offset, struct device_node *);
78406 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
78407 index d235e88..8ccbe74 100644
78408 --- a/include/linux/jiffies.h
78409 +++ b/include/linux/jiffies.h
78410 @@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
78411 /*
78412 * Convert various time units to each other:
78413 */
78414 -extern unsigned int jiffies_to_msecs(const unsigned long j);
78415 -extern unsigned int jiffies_to_usecs(const unsigned long j);
78416 -extern unsigned long msecs_to_jiffies(const unsigned int m);
78417 -extern unsigned long usecs_to_jiffies(const unsigned int u);
78418 -extern unsigned long timespec_to_jiffies(const struct timespec *value);
78419 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
78420 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
78421 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
78422 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
78423 +extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
78424 extern void jiffies_to_timespec(const unsigned long jiffies,
78425 struct timespec *value);
78426 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
78427 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
78428 extern void jiffies_to_timeval(const unsigned long jiffies,
78429 struct timeval *value);
78430
78431 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
78432 index 6883e19..e854fcb 100644
78433 --- a/include/linux/kallsyms.h
78434 +++ b/include/linux/kallsyms.h
78435 @@ -15,7 +15,8 @@
78436
78437 struct module;
78438
78439 -#ifdef CONFIG_KALLSYMS
78440 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
78441 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
78442 /* Lookup the address for a symbol. Returns 0 if not found. */
78443 unsigned long kallsyms_lookup_name(const char *name);
78444
78445 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
78446 /* Stupid that this does nothing, but I didn't create this mess. */
78447 #define __print_symbol(fmt, addr)
78448 #endif /*CONFIG_KALLSYMS*/
78449 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
78450 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
78451 +extern unsigned long kallsyms_lookup_name(const char *name);
78452 +extern void __print_symbol(const char *fmt, unsigned long address);
78453 +extern int sprint_backtrace(char *buffer, unsigned long address);
78454 +extern int sprint_symbol(char *buffer, unsigned long address);
78455 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
78456 +const char *kallsyms_lookup(unsigned long addr,
78457 + unsigned long *symbolsize,
78458 + unsigned long *offset,
78459 + char **modname, char *namebuf);
78460 +extern int kallsyms_lookup_size_offset(unsigned long addr,
78461 + unsigned long *symbolsize,
78462 + unsigned long *offset);
78463 +#endif
78464
78465 /* This macro allows us to keep printk typechecking */
78466 static __printf(1, 2)
78467 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
78468 index a74c3a8..28d3f21 100644
78469 --- a/include/linux/key-type.h
78470 +++ b/include/linux/key-type.h
78471 @@ -131,7 +131,7 @@ struct key_type {
78472 /* internal fields */
78473 struct list_head link; /* link in types list */
78474 struct lock_class_key lock_class; /* key->sem lock class */
78475 -};
78476 +} __do_const;
78477
78478 extern struct key_type key_type_keyring;
78479
78480 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
78481 index dfb4f2f..7927e62 100644
78482 --- a/include/linux/kgdb.h
78483 +++ b/include/linux/kgdb.h
78484 @@ -52,7 +52,7 @@ extern int kgdb_connected;
78485 extern int kgdb_io_module_registered;
78486
78487 extern atomic_t kgdb_setting_breakpoint;
78488 -extern atomic_t kgdb_cpu_doing_single_step;
78489 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
78490
78491 extern struct task_struct *kgdb_usethread;
78492 extern struct task_struct *kgdb_contthread;
78493 @@ -254,7 +254,7 @@ struct kgdb_arch {
78494 void (*correct_hw_break)(void);
78495
78496 void (*enable_nmi)(bool on);
78497 -};
78498 +} __do_const;
78499
78500 /**
78501 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
78502 @@ -279,7 +279,7 @@ struct kgdb_io {
78503 void (*pre_exception) (void);
78504 void (*post_exception) (void);
78505 int is_console;
78506 -};
78507 +} __do_const;
78508
78509 extern struct kgdb_arch arch_kgdb_ops;
78510
78511 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
78512 index 0555cc6..40116ce 100644
78513 --- a/include/linux/kmod.h
78514 +++ b/include/linux/kmod.h
78515 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
78516 * usually useless though. */
78517 extern __printf(2, 3)
78518 int __request_module(bool wait, const char *name, ...);
78519 +extern __printf(3, 4)
78520 +int ___request_module(bool wait, char *param_name, const char *name, ...);
78521 #define request_module(mod...) __request_module(true, mod)
78522 #define request_module_nowait(mod...) __request_module(false, mod)
78523 #define try_then_request_module(x, mod...) \
78524 @@ -57,6 +59,9 @@ struct subprocess_info {
78525 struct work_struct work;
78526 struct completion *complete;
78527 char *path;
78528 +#ifdef CONFIG_GRKERNSEC
78529 + char *origpath;
78530 +#endif
78531 char **argv;
78532 char **envp;
78533 int wait;
78534 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
78535 index e7ba650..0af3acb 100644
78536 --- a/include/linux/kobject.h
78537 +++ b/include/linux/kobject.h
78538 @@ -116,7 +116,7 @@ struct kobj_type {
78539 struct attribute **default_attrs;
78540 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
78541 const void *(*namespace)(struct kobject *kobj);
78542 -};
78543 +} __do_const;
78544
78545 struct kobj_uevent_env {
78546 char *envp[UEVENT_NUM_ENVP];
78547 @@ -139,6 +139,7 @@ struct kobj_attribute {
78548 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
78549 const char *buf, size_t count);
78550 };
78551 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
78552
78553 extern const struct sysfs_ops kobj_sysfs_ops;
78554
78555 @@ -166,7 +167,7 @@ struct kset {
78556 spinlock_t list_lock;
78557 struct kobject kobj;
78558 const struct kset_uevent_ops *uevent_ops;
78559 -};
78560 +} __randomize_layout;
78561
78562 extern void kset_init(struct kset *kset);
78563 extern int __must_check kset_register(struct kset *kset);
78564 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
78565 index df32d25..fb52e27 100644
78566 --- a/include/linux/kobject_ns.h
78567 +++ b/include/linux/kobject_ns.h
78568 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
78569 const void *(*netlink_ns)(struct sock *sk);
78570 const void *(*initial_ns)(void);
78571 void (*drop_ns)(void *);
78572 -};
78573 +} __do_const;
78574
78575 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
78576 int kobj_ns_type_registered(enum kobj_ns_type type);
78577 diff --git a/include/linux/kref.h b/include/linux/kref.h
78578 index 484604d..0f6c5b6 100644
78579 --- a/include/linux/kref.h
78580 +++ b/include/linux/kref.h
78581 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
78582 static inline int kref_sub(struct kref *kref, unsigned int count,
78583 void (*release)(struct kref *kref))
78584 {
78585 - WARN_ON(release == NULL);
78586 + BUG_ON(release == NULL);
78587
78588 if (atomic_sub_and_test((int) count, &kref->refcount)) {
78589 release(kref);
78590 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
78591 index 9523d2a..16c0424 100644
78592 --- a/include/linux/kvm_host.h
78593 +++ b/include/linux/kvm_host.h
78594 @@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
78595 {
78596 }
78597 #endif
78598 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78599 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78600 struct module *module);
78601 void kvm_exit(void);
78602
78603 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
78604 struct kvm_guest_debug *dbg);
78605 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
78606
78607 -int kvm_arch_init(void *opaque);
78608 +int kvm_arch_init(const void *opaque);
78609 void kvm_arch_exit(void);
78610
78611 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
78612 diff --git a/include/linux/libata.h b/include/linux/libata.h
78613 index 9b50337..712d748 100644
78614 --- a/include/linux/libata.h
78615 +++ b/include/linux/libata.h
78616 @@ -973,7 +973,7 @@ struct ata_port_operations {
78617 * fields must be pointers.
78618 */
78619 const struct ata_port_operations *inherits;
78620 -};
78621 +} __do_const;
78622
78623 struct ata_port_info {
78624 unsigned long flags;
78625 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
78626 index d3e8ad2..a949f68 100644
78627 --- a/include/linux/linkage.h
78628 +++ b/include/linux/linkage.h
78629 @@ -31,6 +31,7 @@
78630 #endif
78631
78632 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
78633 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
78634 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
78635
78636 /*
78637 diff --git a/include/linux/list.h b/include/linux/list.h
78638 index ef95941..82db65a 100644
78639 --- a/include/linux/list.h
78640 +++ b/include/linux/list.h
78641 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
78642 extern void list_del(struct list_head *entry);
78643 #endif
78644
78645 +extern void __pax_list_add(struct list_head *new,
78646 + struct list_head *prev,
78647 + struct list_head *next);
78648 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
78649 +{
78650 + __pax_list_add(new, head, head->next);
78651 +}
78652 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
78653 +{
78654 + __pax_list_add(new, head->prev, head);
78655 +}
78656 +extern void pax_list_del(struct list_head *entry);
78657 +
78658 /**
78659 * list_replace - replace old entry by new one
78660 * @old : the element to be replaced
78661 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
78662 INIT_LIST_HEAD(entry);
78663 }
78664
78665 +extern void pax_list_del_init(struct list_head *entry);
78666 +
78667 /**
78668 * list_move - delete from one list and add as another's head
78669 * @list: the entry to move
78670 diff --git a/include/linux/math64.h b/include/linux/math64.h
78671 index c45c089..298841c 100644
78672 --- a/include/linux/math64.h
78673 +++ b/include/linux/math64.h
78674 @@ -15,7 +15,7 @@
78675 * This is commonly provided by 32bit archs to provide an optimized 64bit
78676 * divide.
78677 */
78678 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78679 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78680 {
78681 *remainder = dividend % divisor;
78682 return dividend / divisor;
78683 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
78684 /**
78685 * div64_u64 - unsigned 64bit divide with 64bit divisor
78686 */
78687 -static inline u64 div64_u64(u64 dividend, u64 divisor)
78688 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
78689 {
78690 return dividend / divisor;
78691 }
78692 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
78693 #define div64_ul(x, y) div_u64((x), (y))
78694
78695 #ifndef div_u64_rem
78696 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78697 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78698 {
78699 *remainder = do_div(dividend, divisor);
78700 return dividend;
78701 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
78702 #endif
78703
78704 #ifndef div64_u64
78705 -extern u64 div64_u64(u64 dividend, u64 divisor);
78706 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
78707 #endif
78708
78709 #ifndef div64_s64
78710 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
78711 * divide.
78712 */
78713 #ifndef div_u64
78714 -static inline u64 div_u64(u64 dividend, u32 divisor)
78715 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
78716 {
78717 u32 remainder;
78718 return div_u64_rem(dividend, divisor, &remainder);
78719 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
78720 index 9fe426b..8148be6 100644
78721 --- a/include/linux/mempolicy.h
78722 +++ b/include/linux/mempolicy.h
78723 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
78724 }
78725
78726 #define vma_policy(vma) ((vma)->vm_policy)
78727 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78728 +{
78729 + vma->vm_policy = pol;
78730 +}
78731
78732 static inline void mpol_get(struct mempolicy *pol)
78733 {
78734 @@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
78735 }
78736
78737 #define vma_policy(vma) NULL
78738 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78739 +{
78740 +}
78741
78742 static inline int
78743 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
78744 diff --git a/include/linux/mm.h b/include/linux/mm.h
78745 index 9fac6dd..158ca43 100644
78746 --- a/include/linux/mm.h
78747 +++ b/include/linux/mm.h
78748 @@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
78749 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
78750 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
78751 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
78752 +
78753 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
78754 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
78755 +#endif
78756 +
78757 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
78758
78759 #ifdef CONFIG_MEM_SOFT_DIRTY
78760 @@ -219,8 +224,8 @@ struct vm_operations_struct {
78761 /* called by access_process_vm when get_user_pages() fails, typically
78762 * for use by special VMAs that can switch between memory and hardware
78763 */
78764 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
78765 - void *buf, int len, int write);
78766 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
78767 + void *buf, size_t len, int write);
78768 #ifdef CONFIG_NUMA
78769 /*
78770 * set_policy() op must add a reference to any non-NULL @new mempolicy
78771 @@ -250,6 +255,7 @@ struct vm_operations_struct {
78772 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
78773 unsigned long size, pgoff_t pgoff);
78774 };
78775 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
78776
78777 struct mmu_gather;
78778 struct inode;
78779 @@ -1064,8 +1070,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
78780 unsigned long *pfn);
78781 int follow_phys(struct vm_area_struct *vma, unsigned long address,
78782 unsigned int flags, unsigned long *prot, resource_size_t *phys);
78783 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78784 - void *buf, int len, int write);
78785 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78786 + void *buf, size_t len, int write);
78787
78788 static inline void unmap_shared_mapping_range(struct address_space *mapping,
78789 loff_t const holebegin, loff_t const holelen)
78790 @@ -1104,9 +1110,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
78791 }
78792 #endif
78793
78794 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
78795 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
78796 - void *buf, int len, int write);
78797 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
78798 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
78799 + void *buf, size_t len, int write);
78800
78801 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
78802 unsigned long start, unsigned long nr_pages,
78803 @@ -1138,34 +1144,6 @@ int set_page_dirty(struct page *page);
78804 int set_page_dirty_lock(struct page *page);
78805 int clear_page_dirty_for_io(struct page *page);
78806
78807 -/* Is the vma a continuation of the stack vma above it? */
78808 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
78809 -{
78810 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
78811 -}
78812 -
78813 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
78814 - unsigned long addr)
78815 -{
78816 - return (vma->vm_flags & VM_GROWSDOWN) &&
78817 - (vma->vm_start == addr) &&
78818 - !vma_growsdown(vma->vm_prev, addr);
78819 -}
78820 -
78821 -/* Is the vma a continuation of the stack vma below it? */
78822 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
78823 -{
78824 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
78825 -}
78826 -
78827 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
78828 - unsigned long addr)
78829 -{
78830 - return (vma->vm_flags & VM_GROWSUP) &&
78831 - (vma->vm_end == addr) &&
78832 - !vma_growsup(vma->vm_next, addr);
78833 -}
78834 -
78835 extern pid_t
78836 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
78837
78838 @@ -1265,6 +1243,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
78839 }
78840 #endif
78841
78842 +#ifdef CONFIG_MMU
78843 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
78844 +#else
78845 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
78846 +{
78847 + return __pgprot(0);
78848 +}
78849 +#endif
78850 +
78851 int vma_wants_writenotify(struct vm_area_struct *vma);
78852
78853 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
78854 @@ -1283,8 +1270,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
78855 {
78856 return 0;
78857 }
78858 +
78859 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
78860 + unsigned long address)
78861 +{
78862 + return 0;
78863 +}
78864 #else
78865 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
78866 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
78867 #endif
78868
78869 #ifdef __PAGETABLE_PMD_FOLDED
78870 @@ -1293,8 +1287,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
78871 {
78872 return 0;
78873 }
78874 +
78875 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
78876 + unsigned long address)
78877 +{
78878 + return 0;
78879 +}
78880 #else
78881 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
78882 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
78883 #endif
78884
78885 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
78886 @@ -1312,11 +1313,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
78887 NULL: pud_offset(pgd, address);
78888 }
78889
78890 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
78891 +{
78892 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
78893 + NULL: pud_offset(pgd, address);
78894 +}
78895 +
78896 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
78897 {
78898 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
78899 NULL: pmd_offset(pud, address);
78900 }
78901 +
78902 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
78903 +{
78904 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
78905 + NULL: pmd_offset(pud, address);
78906 +}
78907 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
78908
78909 #if USE_SPLIT_PTE_PTLOCKS
78910 @@ -1694,7 +1707,7 @@ extern int install_special_mapping(struct mm_struct *mm,
78911 unsigned long addr, unsigned long len,
78912 unsigned long flags, struct page **pages);
78913
78914 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
78915 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
78916
78917 extern unsigned long mmap_region(struct file *file, unsigned long addr,
78918 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
78919 @@ -1702,6 +1715,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
78920 unsigned long len, unsigned long prot, unsigned long flags,
78921 unsigned long pgoff, unsigned long *populate);
78922 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
78923 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
78924
78925 #ifdef CONFIG_MMU
78926 extern int __mm_populate(unsigned long addr, unsigned long len,
78927 @@ -1730,10 +1744,11 @@ struct vm_unmapped_area_info {
78928 unsigned long high_limit;
78929 unsigned long align_mask;
78930 unsigned long align_offset;
78931 + unsigned long threadstack_offset;
78932 };
78933
78934 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
78935 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
78936 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
78937 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
78938
78939 /*
78940 * Search for an unmapped address range.
78941 @@ -1745,7 +1760,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
78942 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
78943 */
78944 static inline unsigned long
78945 -vm_unmapped_area(struct vm_unmapped_area_info *info)
78946 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
78947 {
78948 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
78949 return unmapped_area(info);
78950 @@ -1808,6 +1823,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
78951 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
78952 struct vm_area_struct **pprev);
78953
78954 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
78955 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
78956 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
78957 +
78958 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
78959 NULL if none. Assume start_addr < end_addr. */
78960 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
78961 @@ -1836,15 +1855,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
78962 return vma;
78963 }
78964
78965 -#ifdef CONFIG_MMU
78966 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
78967 -#else
78968 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
78969 -{
78970 - return __pgprot(0);
78971 -}
78972 -#endif
78973 -
78974 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
78975 unsigned long change_prot_numa(struct vm_area_struct *vma,
78976 unsigned long start, unsigned long end);
78977 @@ -1896,6 +1906,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
78978 static inline void vm_stat_account(struct mm_struct *mm,
78979 unsigned long flags, struct file *file, long pages)
78980 {
78981 +
78982 +#ifdef CONFIG_PAX_RANDMMAP
78983 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
78984 +#endif
78985 +
78986 mm->total_vm += pages;
78987 }
78988 #endif /* CONFIG_PROC_FS */
78989 @@ -1977,7 +1992,7 @@ extern int unpoison_memory(unsigned long pfn);
78990 extern int sysctl_memory_failure_early_kill;
78991 extern int sysctl_memory_failure_recovery;
78992 extern void shake_page(struct page *p, int access);
78993 -extern atomic_long_t num_poisoned_pages;
78994 +extern atomic_long_unchecked_t num_poisoned_pages;
78995 extern int soft_offline_page(struct page *page, int flags);
78996
78997 extern void dump_page(struct page *page);
78998 @@ -2014,5 +2029,11 @@ void __init setup_nr_node_ids(void);
78999 static inline void setup_nr_node_ids(void) {}
79000 #endif
79001
79002 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
79003 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
79004 +#else
79005 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
79006 +#endif
79007 +
79008 #endif /* __KERNEL__ */
79009 #endif /* _LINUX_MM_H */
79010 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
79011 index 290901a..e99b01c 100644
79012 --- a/include/linux/mm_types.h
79013 +++ b/include/linux/mm_types.h
79014 @@ -307,7 +307,9 @@ struct vm_area_struct {
79015 #ifdef CONFIG_NUMA
79016 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
79017 #endif
79018 -};
79019 +
79020 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
79021 +} __randomize_layout;
79022
79023 struct core_thread {
79024 struct task_struct *task;
79025 @@ -453,7 +455,25 @@ struct mm_struct {
79026 bool tlb_flush_pending;
79027 #endif
79028 struct uprobes_state uprobes_state;
79029 -};
79030 +
79031 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
79032 + unsigned long pax_flags;
79033 +#endif
79034 +
79035 +#ifdef CONFIG_PAX_DLRESOLVE
79036 + unsigned long call_dl_resolve;
79037 +#endif
79038 +
79039 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
79040 + unsigned long call_syscall;
79041 +#endif
79042 +
79043 +#ifdef CONFIG_PAX_ASLR
79044 + unsigned long delta_mmap; /* randomized offset */
79045 + unsigned long delta_stack; /* randomized offset */
79046 +#endif
79047 +
79048 +} __randomize_layout;
79049
79050 static inline void mm_init_cpumask(struct mm_struct *mm)
79051 {
79052 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
79053 index c5d5278..f0b68c8 100644
79054 --- a/include/linux/mmiotrace.h
79055 +++ b/include/linux/mmiotrace.h
79056 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
79057 /* Called from ioremap.c */
79058 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
79059 void __iomem *addr);
79060 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
79061 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
79062
79063 /* For anyone to insert markers. Remember trailing newline. */
79064 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
79065 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
79066 {
79067 }
79068
79069 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
79070 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
79071 {
79072 }
79073
79074 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
79075 index bd791e4..8617c34f 100644
79076 --- a/include/linux/mmzone.h
79077 +++ b/include/linux/mmzone.h
79078 @@ -396,7 +396,7 @@ struct zone {
79079 unsigned long flags; /* zone flags, see below */
79080
79081 /* Zone statistics */
79082 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79083 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79084
79085 /*
79086 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
79087 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
79088 index 45e9214..a7227d6 100644
79089 --- a/include/linux/mod_devicetable.h
79090 +++ b/include/linux/mod_devicetable.h
79091 @@ -13,7 +13,7 @@
79092 typedef unsigned long kernel_ulong_t;
79093 #endif
79094
79095 -#define PCI_ANY_ID (~0)
79096 +#define PCI_ANY_ID ((__u16)~0)
79097
79098 struct pci_device_id {
79099 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
79100 @@ -139,7 +139,7 @@ struct usb_device_id {
79101 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
79102 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
79103
79104 -#define HID_ANY_ID (~0)
79105 +#define HID_ANY_ID (~0U)
79106 #define HID_BUS_ANY 0xffff
79107 #define HID_GROUP_ANY 0x0000
79108
79109 @@ -467,7 +467,7 @@ struct dmi_system_id {
79110 const char *ident;
79111 struct dmi_strmatch matches[4];
79112 void *driver_data;
79113 -};
79114 +} __do_const;
79115 /*
79116 * struct dmi_device_id appears during expansion of
79117 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
79118 diff --git a/include/linux/module.h b/include/linux/module.h
79119 index 15cd6b1..f6e2e6a 100644
79120 --- a/include/linux/module.h
79121 +++ b/include/linux/module.h
79122 @@ -17,9 +17,11 @@
79123 #include <linux/moduleparam.h>
79124 #include <linux/tracepoint.h>
79125 #include <linux/export.h>
79126 +#include <linux/fs.h>
79127
79128 #include <linux/percpu.h>
79129 #include <asm/module.h>
79130 +#include <asm/pgtable.h>
79131
79132 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
79133 #define MODULE_SIG_STRING "~Module signature appended~\n"
79134 @@ -43,7 +45,7 @@ struct module_kobject {
79135 struct kobject *drivers_dir;
79136 struct module_param_attrs *mp;
79137 struct completion *kobj_completion;
79138 -};
79139 +} __randomize_layout;
79140
79141 struct module_attribute {
79142 struct attribute attr;
79143 @@ -55,12 +57,13 @@ struct module_attribute {
79144 int (*test)(struct module *);
79145 void (*free)(struct module *);
79146 };
79147 +typedef struct module_attribute __no_const module_attribute_no_const;
79148
79149 struct module_version_attribute {
79150 struct module_attribute mattr;
79151 const char *module_name;
79152 const char *version;
79153 -} __attribute__ ((__aligned__(sizeof(void *))));
79154 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
79155
79156 extern ssize_t __modver_version_show(struct module_attribute *,
79157 struct module_kobject *, char *);
79158 @@ -238,7 +241,7 @@ struct module
79159
79160 /* Sysfs stuff. */
79161 struct module_kobject mkobj;
79162 - struct module_attribute *modinfo_attrs;
79163 + module_attribute_no_const *modinfo_attrs;
79164 const char *version;
79165 const char *srcversion;
79166 struct kobject *holders_dir;
79167 @@ -287,19 +290,16 @@ struct module
79168 int (*init)(void);
79169
79170 /* If this is non-NULL, vfree after init() returns */
79171 - void *module_init;
79172 + void *module_init_rx, *module_init_rw;
79173
79174 /* Here is the actual code + data, vfree'd on unload. */
79175 - void *module_core;
79176 + void *module_core_rx, *module_core_rw;
79177
79178 /* Here are the sizes of the init and core sections */
79179 - unsigned int init_size, core_size;
79180 + unsigned int init_size_rw, core_size_rw;
79181
79182 /* The size of the executable code in each section. */
79183 - unsigned int init_text_size, core_text_size;
79184 -
79185 - /* Size of RO sections of the module (text+rodata) */
79186 - unsigned int init_ro_size, core_ro_size;
79187 + unsigned int init_size_rx, core_size_rx;
79188
79189 /* Arch-specific module values */
79190 struct mod_arch_specific arch;
79191 @@ -355,6 +355,10 @@ struct module
79192 #ifdef CONFIG_EVENT_TRACING
79193 struct ftrace_event_call **trace_events;
79194 unsigned int num_trace_events;
79195 + struct file_operations trace_id;
79196 + struct file_operations trace_enable;
79197 + struct file_operations trace_format;
79198 + struct file_operations trace_filter;
79199 #endif
79200 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
79201 unsigned int num_ftrace_callsites;
79202 @@ -378,7 +382,7 @@ struct module
79203 ctor_fn_t *ctors;
79204 unsigned int num_ctors;
79205 #endif
79206 -};
79207 +} __randomize_layout;
79208 #ifndef MODULE_ARCH_INIT
79209 #define MODULE_ARCH_INIT {}
79210 #endif
79211 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
79212 bool is_module_percpu_address(unsigned long addr);
79213 bool is_module_text_address(unsigned long addr);
79214
79215 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
79216 +{
79217 +
79218 +#ifdef CONFIG_PAX_KERNEXEC
79219 + if (ktla_ktva(addr) >= (unsigned long)start &&
79220 + ktla_ktva(addr) < (unsigned long)start + size)
79221 + return 1;
79222 +#endif
79223 +
79224 + return ((void *)addr >= start && (void *)addr < start + size);
79225 +}
79226 +
79227 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
79228 +{
79229 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
79230 +}
79231 +
79232 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
79233 +{
79234 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
79235 +}
79236 +
79237 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
79238 +{
79239 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
79240 +}
79241 +
79242 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
79243 +{
79244 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
79245 +}
79246 +
79247 static inline int within_module_core(unsigned long addr, const struct module *mod)
79248 {
79249 - return (unsigned long)mod->module_core <= addr &&
79250 - addr < (unsigned long)mod->module_core + mod->core_size;
79251 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
79252 }
79253
79254 static inline int within_module_init(unsigned long addr, const struct module *mod)
79255 {
79256 - return (unsigned long)mod->module_init <= addr &&
79257 - addr < (unsigned long)mod->module_init + mod->init_size;
79258 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
79259 }
79260
79261 /* Search for module by name: must hold module_mutex. */
79262 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
79263 index 560ca53..ef621ef 100644
79264 --- a/include/linux/moduleloader.h
79265 +++ b/include/linux/moduleloader.h
79266 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
79267 sections. Returns NULL on failure. */
79268 void *module_alloc(unsigned long size);
79269
79270 +#ifdef CONFIG_PAX_KERNEXEC
79271 +void *module_alloc_exec(unsigned long size);
79272 +#else
79273 +#define module_alloc_exec(x) module_alloc(x)
79274 +#endif
79275 +
79276 /* Free memory returned from module_alloc. */
79277 void module_free(struct module *mod, void *module_region);
79278
79279 +#ifdef CONFIG_PAX_KERNEXEC
79280 +void module_free_exec(struct module *mod, void *module_region);
79281 +#else
79282 +#define module_free_exec(x, y) module_free((x), (y))
79283 +#endif
79284 +
79285 /*
79286 * Apply the given relocation to the (simplified) ELF. Return -error
79287 * or 0.
79288 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
79289 unsigned int relsec,
79290 struct module *me)
79291 {
79292 +#ifdef CONFIG_MODULES
79293 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79294 +#endif
79295 return -ENOEXEC;
79296 }
79297 #endif
79298 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
79299 unsigned int relsec,
79300 struct module *me)
79301 {
79302 +#ifdef CONFIG_MODULES
79303 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79304 +#endif
79305 return -ENOEXEC;
79306 }
79307 #endif
79308 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
79309 index c3eb102..073c4a6 100644
79310 --- a/include/linux/moduleparam.h
79311 +++ b/include/linux/moduleparam.h
79312 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
79313 * @len is usually just sizeof(string).
79314 */
79315 #define module_param_string(name, string, len, perm) \
79316 - static const struct kparam_string __param_string_##name \
79317 + static const struct kparam_string __param_string_##name __used \
79318 = { len, string }; \
79319 __module_param_call(MODULE_PARAM_PREFIX, name, \
79320 &param_ops_string, \
79321 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
79322 */
79323 #define module_param_array_named(name, array, type, nump, perm) \
79324 param_check_##type(name, &(array)[0]); \
79325 - static const struct kparam_array __param_arr_##name \
79326 + static const struct kparam_array __param_arr_##name __used \
79327 = { .max = ARRAY_SIZE(array), .num = nump, \
79328 .ops = &param_ops_##type, \
79329 .elemsize = sizeof(array[0]), .elem = array }; \
79330 diff --git a/include/linux/mount.h b/include/linux/mount.h
79331 index 371d346..fba2819 100644
79332 --- a/include/linux/mount.h
79333 +++ b/include/linux/mount.h
79334 @@ -56,7 +56,7 @@ struct vfsmount {
79335 struct dentry *mnt_root; /* root of the mounted tree */
79336 struct super_block *mnt_sb; /* pointer to superblock */
79337 int mnt_flags;
79338 -};
79339 +} __randomize_layout;
79340
79341 struct file; /* forward dec */
79342
79343 diff --git a/include/linux/namei.h b/include/linux/namei.h
79344 index 492de72..1bddcd4 100644
79345 --- a/include/linux/namei.h
79346 +++ b/include/linux/namei.h
79347 @@ -19,7 +19,7 @@ struct nameidata {
79348 unsigned seq, m_seq;
79349 int last_type;
79350 unsigned depth;
79351 - char *saved_names[MAX_NESTED_LINKS + 1];
79352 + const char *saved_names[MAX_NESTED_LINKS + 1];
79353 };
79354
79355 /*
79356 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
79357
79358 extern void nd_jump_link(struct nameidata *nd, struct path *path);
79359
79360 -static inline void nd_set_link(struct nameidata *nd, char *path)
79361 +static inline void nd_set_link(struct nameidata *nd, const char *path)
79362 {
79363 nd->saved_names[nd->depth] = path;
79364 }
79365
79366 -static inline char *nd_get_link(struct nameidata *nd)
79367 +static inline const char *nd_get_link(const struct nameidata *nd)
79368 {
79369 return nd->saved_names[nd->depth];
79370 }
79371 diff --git a/include/linux/net.h b/include/linux/net.h
79372 index 69be3e6..0fb422d 100644
79373 --- a/include/linux/net.h
79374 +++ b/include/linux/net.h
79375 @@ -192,7 +192,7 @@ struct net_proto_family {
79376 int (*create)(struct net *net, struct socket *sock,
79377 int protocol, int kern);
79378 struct module *owner;
79379 -};
79380 +} __do_const;
79381
79382 struct iovec;
79383 struct kvec;
79384 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
79385 index ce2a1f5..cb9bc8c 100644
79386 --- a/include/linux/netdevice.h
79387 +++ b/include/linux/netdevice.h
79388 @@ -1129,6 +1129,7 @@ struct net_device_ops {
79389 struct net_device *dev,
79390 void *priv);
79391 };
79392 +typedef struct net_device_ops __no_const net_device_ops_no_const;
79393
79394 /*
79395 * The DEVICE structure.
79396 @@ -1211,7 +1212,7 @@ struct net_device {
79397 int iflink;
79398
79399 struct net_device_stats stats;
79400 - atomic_long_t rx_dropped; /* dropped packets by core network
79401 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
79402 * Do not use this in drivers.
79403 */
79404
79405 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
79406 index 2077489..a15e561 100644
79407 --- a/include/linux/netfilter.h
79408 +++ b/include/linux/netfilter.h
79409 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
79410 #endif
79411 /* Use the module struct to lock set/get code in place */
79412 struct module *owner;
79413 -};
79414 +} __do_const;
79415
79416 /* Function to register/unregister hook points. */
79417 int nf_register_hook(struct nf_hook_ops *reg);
79418 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
79419 index 28c7436..2d6156a 100644
79420 --- a/include/linux/netfilter/nfnetlink.h
79421 +++ b/include/linux/netfilter/nfnetlink.h
79422 @@ -19,7 +19,7 @@ struct nfnl_callback {
79423 const struct nlattr * const cda[]);
79424 const struct nla_policy *policy; /* netlink attribute policy */
79425 const u_int16_t attr_count; /* number of nlattr's */
79426 -};
79427 +} __do_const;
79428
79429 struct nfnetlink_subsystem {
79430 const char *name;
79431 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
79432 new file mode 100644
79433 index 0000000..33f4af8
79434 --- /dev/null
79435 +++ b/include/linux/netfilter/xt_gradm.h
79436 @@ -0,0 +1,9 @@
79437 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
79438 +#define _LINUX_NETFILTER_XT_GRADM_H 1
79439 +
79440 +struct xt_gradm_mtinfo {
79441 + __u16 flags;
79442 + __u16 invflags;
79443 +};
79444 +
79445 +#endif
79446 diff --git a/include/linux/nls.h b/include/linux/nls.h
79447 index 5dc635f..35f5e11 100644
79448 --- a/include/linux/nls.h
79449 +++ b/include/linux/nls.h
79450 @@ -31,7 +31,7 @@ struct nls_table {
79451 const unsigned char *charset2upper;
79452 struct module *owner;
79453 struct nls_table *next;
79454 -};
79455 +} __do_const;
79456
79457 /* this value hold the maximum octet of charset */
79458 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
79459 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
79460 index d14a4c3..a078786 100644
79461 --- a/include/linux/notifier.h
79462 +++ b/include/linux/notifier.h
79463 @@ -54,7 +54,8 @@ struct notifier_block {
79464 notifier_fn_t notifier_call;
79465 struct notifier_block __rcu *next;
79466 int priority;
79467 -};
79468 +} __do_const;
79469 +typedef struct notifier_block __no_const notifier_block_no_const;
79470
79471 struct atomic_notifier_head {
79472 spinlock_t lock;
79473 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
79474 index b2a0f15..4d7da32 100644
79475 --- a/include/linux/oprofile.h
79476 +++ b/include/linux/oprofile.h
79477 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
79478 int oprofilefs_create_ro_ulong(struct dentry * root,
79479 char const * name, ulong * val);
79480
79481 -/** Create a file for read-only access to an atomic_t. */
79482 +/** Create a file for read-only access to an atomic_unchecked_t. */
79483 int oprofilefs_create_ro_atomic(struct dentry * root,
79484 - char const * name, atomic_t * val);
79485 + char const * name, atomic_unchecked_t * val);
79486
79487 /** create a directory */
79488 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
79489 diff --git a/include/linux/padata.h b/include/linux/padata.h
79490 index 4386946..f50c615 100644
79491 --- a/include/linux/padata.h
79492 +++ b/include/linux/padata.h
79493 @@ -129,7 +129,7 @@ struct parallel_data {
79494 struct padata_serial_queue __percpu *squeue;
79495 atomic_t reorder_objects;
79496 atomic_t refcnt;
79497 - atomic_t seq_nr;
79498 + atomic_unchecked_t seq_nr;
79499 struct padata_cpumask cpumask;
79500 spinlock_t lock ____cacheline_aligned;
79501 unsigned int processed;
79502 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
79503 index a2e2f1d..8a391d2 100644
79504 --- a/include/linux/pci_hotplug.h
79505 +++ b/include/linux/pci_hotplug.h
79506 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
79507 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
79508 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
79509 int (*reset_slot) (struct hotplug_slot *slot, int probe);
79510 -};
79511 +} __do_const;
79512 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
79513
79514 /**
79515 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
79516 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
79517 index 2e069d1..27054b8 100644
79518 --- a/include/linux/perf_event.h
79519 +++ b/include/linux/perf_event.h
79520 @@ -327,8 +327,8 @@ struct perf_event {
79521
79522 enum perf_event_active_state state;
79523 unsigned int attach_state;
79524 - local64_t count;
79525 - atomic64_t child_count;
79526 + local64_t count; /* PaX: fix it one day */
79527 + atomic64_unchecked_t child_count;
79528
79529 /*
79530 * These are the total time in nanoseconds that the event
79531 @@ -379,8 +379,8 @@ struct perf_event {
79532 * These accumulate total time (in nanoseconds) that children
79533 * events have been enabled and running, respectively.
79534 */
79535 - atomic64_t child_total_time_enabled;
79536 - atomic64_t child_total_time_running;
79537 + atomic64_unchecked_t child_total_time_enabled;
79538 + atomic64_unchecked_t child_total_time_running;
79539
79540 /*
79541 * Protect attach/detach and child_list:
79542 @@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
79543 entry->ip[entry->nr++] = ip;
79544 }
79545
79546 -extern int sysctl_perf_event_paranoid;
79547 +extern int sysctl_perf_event_legitimately_concerned;
79548 extern int sysctl_perf_event_mlock;
79549 extern int sysctl_perf_event_sample_rate;
79550 extern int sysctl_perf_cpu_time_max_percent;
79551 @@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
79552 loff_t *ppos);
79553
79554
79555 +static inline bool perf_paranoid_any(void)
79556 +{
79557 + return sysctl_perf_event_legitimately_concerned > 2;
79558 +}
79559 +
79560 static inline bool perf_paranoid_tracepoint_raw(void)
79561 {
79562 - return sysctl_perf_event_paranoid > -1;
79563 + return sysctl_perf_event_legitimately_concerned > -1;
79564 }
79565
79566 static inline bool perf_paranoid_cpu(void)
79567 {
79568 - return sysctl_perf_event_paranoid > 0;
79569 + return sysctl_perf_event_legitimately_concerned > 0;
79570 }
79571
79572 static inline bool perf_paranoid_kernel(void)
79573 {
79574 - return sysctl_perf_event_paranoid > 1;
79575 + return sysctl_perf_event_legitimately_concerned > 1;
79576 }
79577
79578 extern void perf_event_init(void);
79579 @@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
79580 struct device_attribute attr;
79581 u64 id;
79582 const char *event_str;
79583 -};
79584 +} __do_const;
79585
79586 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
79587 static struct perf_pmu_events_attr _var = { \
79588 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
79589 index 7246ef3..1539ea4 100644
79590 --- a/include/linux/pid_namespace.h
79591 +++ b/include/linux/pid_namespace.h
79592 @@ -43,7 +43,7 @@ struct pid_namespace {
79593 int hide_pid;
79594 int reboot; /* group exit code if this pidns was rebooted */
79595 unsigned int proc_inum;
79596 -};
79597 +} __randomize_layout;
79598
79599 extern struct pid_namespace init_pid_ns;
79600
79601 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
79602 index b8809fe..ae4ccd0 100644
79603 --- a/include/linux/pipe_fs_i.h
79604 +++ b/include/linux/pipe_fs_i.h
79605 @@ -47,10 +47,10 @@ struct pipe_inode_info {
79606 struct mutex mutex;
79607 wait_queue_head_t wait;
79608 unsigned int nrbufs, curbuf, buffers;
79609 - unsigned int readers;
79610 - unsigned int writers;
79611 - unsigned int files;
79612 - unsigned int waiting_writers;
79613 + atomic_t readers;
79614 + atomic_t writers;
79615 + atomic_t files;
79616 + atomic_t waiting_writers;
79617 unsigned int r_counter;
79618 unsigned int w_counter;
79619 struct page *tmp_page;
79620 diff --git a/include/linux/pm.h b/include/linux/pm.h
79621 index a224c7f..92d8a97 100644
79622 --- a/include/linux/pm.h
79623 +++ b/include/linux/pm.h
79624 @@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
79625 struct dev_pm_domain {
79626 struct dev_pm_ops ops;
79627 };
79628 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
79629
79630 /*
79631 * The PM_EVENT_ messages are also used by drivers implementing the legacy
79632 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
79633 index 7c1d252..c5c773e 100644
79634 --- a/include/linux/pm_domain.h
79635 +++ b/include/linux/pm_domain.h
79636 @@ -48,7 +48,7 @@ struct gpd_dev_ops {
79637
79638 struct gpd_cpu_data {
79639 unsigned int saved_exit_latency;
79640 - struct cpuidle_state *idle_state;
79641 + cpuidle_state_no_const *idle_state;
79642 };
79643
79644 struct generic_pm_domain {
79645 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
79646 index 6fa7cea..7bf6415 100644
79647 --- a/include/linux/pm_runtime.h
79648 +++ b/include/linux/pm_runtime.h
79649 @@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
79650
79651 static inline void pm_runtime_mark_last_busy(struct device *dev)
79652 {
79653 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
79654 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
79655 }
79656
79657 #else /* !CONFIG_PM_RUNTIME */
79658 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
79659 index 195aafc..49a7bc2 100644
79660 --- a/include/linux/pnp.h
79661 +++ b/include/linux/pnp.h
79662 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
79663 struct pnp_fixup {
79664 char id[7];
79665 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
79666 -};
79667 +} __do_const;
79668
79669 /* config parameters */
79670 #define PNP_CONFIG_NORMAL 0x0001
79671 diff --git a/include/linux/poison.h b/include/linux/poison.h
79672 index 2110a81..13a11bb 100644
79673 --- a/include/linux/poison.h
79674 +++ b/include/linux/poison.h
79675 @@ -19,8 +19,8 @@
79676 * under normal circumstances, used to verify that nobody uses
79677 * non-initialized list entries.
79678 */
79679 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
79680 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
79681 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
79682 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
79683
79684 /********** include/linux/timer.h **********/
79685 /*
79686 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
79687 index d8b187c3..9a9257a 100644
79688 --- a/include/linux/power/smartreflex.h
79689 +++ b/include/linux/power/smartreflex.h
79690 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
79691 int (*notify)(struct omap_sr *sr, u32 status);
79692 u8 notify_flags;
79693 u8 class_type;
79694 -};
79695 +} __do_const;
79696
79697 /**
79698 * struct omap_sr_nvalue_table - Smartreflex n-target value info
79699 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
79700 index 4ea1d37..80f4b33 100644
79701 --- a/include/linux/ppp-comp.h
79702 +++ b/include/linux/ppp-comp.h
79703 @@ -84,7 +84,7 @@ struct compressor {
79704 struct module *owner;
79705 /* Extra skb space needed by the compressor algorithm */
79706 unsigned int comp_extra;
79707 -};
79708 +} __do_const;
79709
79710 /*
79711 * The return value from decompress routine is the length of the
79712 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
79713 index a3d9dc8..8af9922 100644
79714 --- a/include/linux/preempt.h
79715 +++ b/include/linux/preempt.h
79716 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
79717 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
79718 #endif
79719
79720 +#define raw_preempt_count_add(val) __preempt_count_add(val)
79721 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
79722 +
79723 #define __preempt_count_inc() __preempt_count_add(1)
79724 #define __preempt_count_dec() __preempt_count_sub(1)
79725
79726 #define preempt_count_inc() preempt_count_add(1)
79727 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
79728 #define preempt_count_dec() preempt_count_sub(1)
79729 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
79730
79731 #ifdef CONFIG_PREEMPT_COUNT
79732
79733 @@ -41,6 +46,12 @@ do { \
79734 barrier(); \
79735 } while (0)
79736
79737 +#define raw_preempt_disable() \
79738 +do { \
79739 + raw_preempt_count_inc(); \
79740 + barrier(); \
79741 +} while (0)
79742 +
79743 #define sched_preempt_enable_no_resched() \
79744 do { \
79745 barrier(); \
79746 @@ -49,6 +60,12 @@ do { \
79747
79748 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
79749
79750 +#define raw_preempt_enable_no_resched() \
79751 +do { \
79752 + barrier(); \
79753 + raw_preempt_count_dec(); \
79754 +} while (0)
79755 +
79756 #ifdef CONFIG_PREEMPT
79757 #define preempt_enable() \
79758 do { \
79759 @@ -105,8 +122,10 @@ do { \
79760 * region.
79761 */
79762 #define preempt_disable() barrier()
79763 +#define raw_preempt_disable() barrier()
79764 #define sched_preempt_enable_no_resched() barrier()
79765 #define preempt_enable_no_resched() barrier()
79766 +#define raw_preempt_enable_no_resched() barrier()
79767 #define preempt_enable() barrier()
79768 #define preempt_check_resched() do { } while (0)
79769
79770 diff --git a/include/linux/printk.h b/include/linux/printk.h
79771 index 6949258..7c4730e 100644
79772 --- a/include/linux/printk.h
79773 +++ b/include/linux/printk.h
79774 @@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
79775 void early_printk(const char *s, ...) { }
79776 #endif
79777
79778 +extern int kptr_restrict;
79779 +
79780 #ifdef CONFIG_PRINTK
79781 asmlinkage __printf(5, 0)
79782 int vprintk_emit(int facility, int level,
79783 @@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
79784
79785 extern int printk_delay_msec;
79786 extern int dmesg_restrict;
79787 -extern int kptr_restrict;
79788
79789 extern void wake_up_klogd(void);
79790
79791 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
79792 index 608e60a..c26f864 100644
79793 --- a/include/linux/proc_fs.h
79794 +++ b/include/linux/proc_fs.h
79795 @@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
79796 return proc_create_data(name, mode, parent, proc_fops, NULL);
79797 }
79798
79799 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
79800 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
79801 +{
79802 +#ifdef CONFIG_GRKERNSEC_PROC_USER
79803 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
79804 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79805 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
79806 +#else
79807 + return proc_create_data(name, mode, parent, proc_fops, NULL);
79808 +#endif
79809 +}
79810 +
79811 +
79812 extern void proc_set_size(struct proc_dir_entry *, loff_t);
79813 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
79814 extern void *PDE_DATA(const struct inode *);
79815 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
79816 index 34a1e10..70f6bde 100644
79817 --- a/include/linux/proc_ns.h
79818 +++ b/include/linux/proc_ns.h
79819 @@ -14,7 +14,7 @@ struct proc_ns_operations {
79820 void (*put)(void *ns);
79821 int (*install)(struct nsproxy *nsproxy, void *ns);
79822 unsigned int (*inum)(void *ns);
79823 -};
79824 +} __do_const __randomize_layout;
79825
79826 struct proc_ns {
79827 void *ns;
79828 diff --git a/include/linux/quota.h b/include/linux/quota.h
79829 index cc7494a..1e27036 100644
79830 --- a/include/linux/quota.h
79831 +++ b/include/linux/quota.h
79832 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
79833
79834 extern bool qid_eq(struct kqid left, struct kqid right);
79835 extern bool qid_lt(struct kqid left, struct kqid right);
79836 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
79837 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
79838 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
79839 extern bool qid_valid(struct kqid qid);
79840
79841 diff --git a/include/linux/random.h b/include/linux/random.h
79842 index 4002b3d..d5ad855 100644
79843 --- a/include/linux/random.h
79844 +++ b/include/linux/random.h
79845 @@ -10,9 +10,19 @@
79846
79847
79848 extern void add_device_randomness(const void *, unsigned int);
79849 +
79850 +static inline void add_latent_entropy(void)
79851 +{
79852 +
79853 +#ifdef LATENT_ENTROPY_PLUGIN
79854 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
79855 +#endif
79856 +
79857 +}
79858 +
79859 extern void add_input_randomness(unsigned int type, unsigned int code,
79860 - unsigned int value);
79861 -extern void add_interrupt_randomness(int irq, int irq_flags);
79862 + unsigned int value) __latent_entropy;
79863 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
79864
79865 extern void get_random_bytes(void *buf, int nbytes);
79866 extern void get_random_bytes_arch(void *buf, int nbytes);
79867 @@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
79868 extern const struct file_operations random_fops, urandom_fops;
79869 #endif
79870
79871 -unsigned int get_random_int(void);
79872 +unsigned int __intentional_overflow(-1) get_random_int(void);
79873 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
79874
79875 -u32 prandom_u32(void);
79876 +u32 prandom_u32(void) __intentional_overflow(-1);
79877 void prandom_bytes(void *buf, int nbytes);
79878 void prandom_seed(u32 seed);
79879 void prandom_reseed_late(void);
79880 @@ -38,6 +48,11 @@ struct rnd_state {
79881 u32 prandom_u32_state(struct rnd_state *state);
79882 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
79883
79884 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
79885 +{
79886 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
79887 +}
79888 +
79889 /*
79890 * Handle minimum values for seeds
79891 */
79892 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
79893 index fea49b5..2ac22bb 100644
79894 --- a/include/linux/rbtree_augmented.h
79895 +++ b/include/linux/rbtree_augmented.h
79896 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
79897 old->rbaugmented = rbcompute(old); \
79898 } \
79899 rbstatic const struct rb_augment_callbacks rbname = { \
79900 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
79901 + .propagate = rbname ## _propagate, \
79902 + .copy = rbname ## _copy, \
79903 + .rotate = rbname ## _rotate \
79904 };
79905
79906
79907 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
79908 index 45a0a9e..e83788e 100644
79909 --- a/include/linux/rculist.h
79910 +++ b/include/linux/rculist.h
79911 @@ -29,8 +29,8 @@
79912 */
79913 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
79914 {
79915 - ACCESS_ONCE(list->next) = list;
79916 - ACCESS_ONCE(list->prev) = list;
79917 + ACCESS_ONCE_RW(list->next) = list;
79918 + ACCESS_ONCE_RW(list->prev) = list;
79919 }
79920
79921 /*
79922 @@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
79923 struct list_head *prev, struct list_head *next);
79924 #endif
79925
79926 +extern void __pax_list_add_rcu(struct list_head *new,
79927 + struct list_head *prev, struct list_head *next);
79928 +
79929 /**
79930 * list_add_rcu - add a new entry to rcu-protected list
79931 * @new: new entry to be added
79932 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
79933 __list_add_rcu(new, head, head->next);
79934 }
79935
79936 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
79937 +{
79938 + __pax_list_add_rcu(new, head, head->next);
79939 +}
79940 +
79941 /**
79942 * list_add_tail_rcu - add a new entry to rcu-protected list
79943 * @new: new entry to be added
79944 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
79945 __list_add_rcu(new, head->prev, head);
79946 }
79947
79948 +static inline void pax_list_add_tail_rcu(struct list_head *new,
79949 + struct list_head *head)
79950 +{
79951 + __pax_list_add_rcu(new, head->prev, head);
79952 +}
79953 +
79954 /**
79955 * list_del_rcu - deletes entry from list without re-initialization
79956 * @entry: the element to delete from the list.
79957 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
79958 entry->prev = LIST_POISON2;
79959 }
79960
79961 +extern void pax_list_del_rcu(struct list_head *entry);
79962 +
79963 /**
79964 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
79965 * @n: the element to delete from the hash list.
79966 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
79967 index 9e7db9e..7d4fd72 100644
79968 --- a/include/linux/reboot.h
79969 +++ b/include/linux/reboot.h
79970 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
79971 */
79972
79973 extern void migrate_to_reboot_cpu(void);
79974 -extern void machine_restart(char *cmd);
79975 -extern void machine_halt(void);
79976 -extern void machine_power_off(void);
79977 +extern void machine_restart(char *cmd) __noreturn;
79978 +extern void machine_halt(void) __noreturn;
79979 +extern void machine_power_off(void) __noreturn;
79980
79981 extern void machine_shutdown(void);
79982 struct pt_regs;
79983 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
79984 */
79985
79986 extern void kernel_restart_prepare(char *cmd);
79987 -extern void kernel_restart(char *cmd);
79988 -extern void kernel_halt(void);
79989 -extern void kernel_power_off(void);
79990 +extern void kernel_restart(char *cmd) __noreturn;
79991 +extern void kernel_halt(void) __noreturn;
79992 +extern void kernel_power_off(void) __noreturn;
79993
79994 extern int C_A_D; /* for sysctl */
79995 void ctrl_alt_del(void);
79996 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
79997 * Emergency restart, callable from an interrupt handler.
79998 */
79999
80000 -extern void emergency_restart(void);
80001 +extern void emergency_restart(void) __noreturn;
80002 #include <asm/emergency-restart.h>
80003
80004 #endif /* _LINUX_REBOOT_H */
80005 diff --git a/include/linux/regset.h b/include/linux/regset.h
80006 index 8e0c9fe..ac4d221 100644
80007 --- a/include/linux/regset.h
80008 +++ b/include/linux/regset.h
80009 @@ -161,7 +161,8 @@ struct user_regset {
80010 unsigned int align;
80011 unsigned int bias;
80012 unsigned int core_note_type;
80013 -};
80014 +} __do_const;
80015 +typedef struct user_regset __no_const user_regset_no_const;
80016
80017 /**
80018 * struct user_regset_view - available regsets
80019 diff --git a/include/linux/relay.h b/include/linux/relay.h
80020 index d7c8359..818daf5 100644
80021 --- a/include/linux/relay.h
80022 +++ b/include/linux/relay.h
80023 @@ -157,7 +157,7 @@ struct rchan_callbacks
80024 * The callback should return 0 if successful, negative if not.
80025 */
80026 int (*remove_buf_file)(struct dentry *dentry);
80027 -};
80028 +} __no_const;
80029
80030 /*
80031 * CONFIG_RELAY kernel API, kernel/relay.c
80032 diff --git a/include/linux/rio.h b/include/linux/rio.h
80033 index b71d573..2f940bd 100644
80034 --- a/include/linux/rio.h
80035 +++ b/include/linux/rio.h
80036 @@ -355,7 +355,7 @@ struct rio_ops {
80037 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
80038 u64 rstart, u32 size, u32 flags);
80039 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
80040 -};
80041 +} __no_const;
80042
80043 #define RIO_RESOURCE_MEM 0x00000100
80044 #define RIO_RESOURCE_DOORBELL 0x00000200
80045 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
80046 index 6dacb93..6174423 100644
80047 --- a/include/linux/rmap.h
80048 +++ b/include/linux/rmap.h
80049 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
80050 void anon_vma_init(void); /* create anon_vma_cachep */
80051 int anon_vma_prepare(struct vm_area_struct *);
80052 void unlink_anon_vmas(struct vm_area_struct *);
80053 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
80054 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
80055 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
80056 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
80057
80058 static inline void anon_vma_merge(struct vm_area_struct *vma,
80059 struct vm_area_struct *next)
80060 diff --git a/include/linux/sched.h b/include/linux/sched.h
80061 index 53f97eb..1d90705 100644
80062 --- a/include/linux/sched.h
80063 +++ b/include/linux/sched.h
80064 @@ -63,6 +63,7 @@ struct bio_list;
80065 struct fs_struct;
80066 struct perf_event_context;
80067 struct blk_plug;
80068 +struct linux_binprm;
80069
80070 /*
80071 * List of flags we want to share for kernel threads,
80072 @@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
80073 extern int in_sched_functions(unsigned long addr);
80074
80075 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
80076 -extern signed long schedule_timeout(signed long timeout);
80077 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
80078 extern signed long schedule_timeout_interruptible(signed long timeout);
80079 extern signed long schedule_timeout_killable(signed long timeout);
80080 extern signed long schedule_timeout_uninterruptible(signed long timeout);
80081 @@ -315,6 +316,19 @@ struct nsproxy;
80082 struct user_namespace;
80083
80084 #ifdef CONFIG_MMU
80085 +
80086 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80087 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
80088 +#else
80089 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80090 +{
80091 + return 0;
80092 +}
80093 +#endif
80094 +
80095 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
80096 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
80097 +
80098 extern void arch_pick_mmap_layout(struct mm_struct *mm);
80099 extern unsigned long
80100 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
80101 @@ -600,6 +614,17 @@ struct signal_struct {
80102 #ifdef CONFIG_TASKSTATS
80103 struct taskstats *stats;
80104 #endif
80105 +
80106 +#ifdef CONFIG_GRKERNSEC
80107 + u32 curr_ip;
80108 + u32 saved_ip;
80109 + u32 gr_saddr;
80110 + u32 gr_daddr;
80111 + u16 gr_sport;
80112 + u16 gr_dport;
80113 + u8 used_accept:1;
80114 +#endif
80115 +
80116 #ifdef CONFIG_AUDIT
80117 unsigned audit_tty;
80118 unsigned audit_tty_log_passwd;
80119 @@ -626,7 +651,7 @@ struct signal_struct {
80120 struct mutex cred_guard_mutex; /* guard against foreign influences on
80121 * credential calculations
80122 * (notably. ptrace) */
80123 -};
80124 +} __randomize_layout;
80125
80126 /*
80127 * Bits in flags field of signal_struct.
80128 @@ -680,6 +705,14 @@ struct user_struct {
80129 struct key *session_keyring; /* UID's default session keyring */
80130 #endif
80131
80132 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
80133 + unsigned char kernel_banned;
80134 +#endif
80135 +#ifdef CONFIG_GRKERNSEC_BRUTE
80136 + unsigned char suid_banned;
80137 + unsigned long suid_ban_expires;
80138 +#endif
80139 +
80140 /* Hash table maintenance information */
80141 struct hlist_node uidhash_node;
80142 kuid_t uid;
80143 @@ -687,7 +720,7 @@ struct user_struct {
80144 #ifdef CONFIG_PERF_EVENTS
80145 atomic_long_t locked_vm;
80146 #endif
80147 -};
80148 +} __randomize_layout;
80149
80150 extern int uids_sysfs_init(void);
80151
80152 @@ -1162,8 +1195,8 @@ struct task_struct {
80153 struct list_head thread_group;
80154
80155 struct completion *vfork_done; /* for vfork() */
80156 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
80157 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80158 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
80159 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80160
80161 cputime_t utime, stime, utimescaled, stimescaled;
80162 cputime_t gtime;
80163 @@ -1188,11 +1221,6 @@ struct task_struct {
80164 struct task_cputime cputime_expires;
80165 struct list_head cpu_timers[3];
80166
80167 -/* process credentials */
80168 - const struct cred __rcu *real_cred; /* objective and real subjective task
80169 - * credentials (COW) */
80170 - const struct cred __rcu *cred; /* effective (overridable) subjective task
80171 - * credentials (COW) */
80172 char comm[TASK_COMM_LEN]; /* executable name excluding path
80173 - access with [gs]et_task_comm (which lock
80174 it with task_lock())
80175 @@ -1209,6 +1237,10 @@ struct task_struct {
80176 #endif
80177 /* CPU-specific state of this task */
80178 struct thread_struct thread;
80179 +/* thread_info moved to task_struct */
80180 +#ifdef CONFIG_X86
80181 + struct thread_info tinfo;
80182 +#endif
80183 /* filesystem information */
80184 struct fs_struct *fs;
80185 /* open file information */
80186 @@ -1282,6 +1314,10 @@ struct task_struct {
80187 gfp_t lockdep_reclaim_gfp;
80188 #endif
80189
80190 +/* process credentials */
80191 + const struct cred __rcu *real_cred; /* objective and real subjective task
80192 + * credentials (COW) */
80193 +
80194 /* journalling filesystem info */
80195 void *journal_info;
80196
80197 @@ -1320,6 +1356,10 @@ struct task_struct {
80198 /* cg_list protected by css_set_lock and tsk->alloc_lock */
80199 struct list_head cg_list;
80200 #endif
80201 +
80202 + const struct cred __rcu *cred; /* effective (overridable) subjective task
80203 + * credentials (COW) */
80204 +
80205 #ifdef CONFIG_FUTEX
80206 struct robust_list_head __user *robust_list;
80207 #ifdef CONFIG_COMPAT
80208 @@ -1454,7 +1494,78 @@ struct task_struct {
80209 unsigned int sequential_io;
80210 unsigned int sequential_io_avg;
80211 #endif
80212 -};
80213 +
80214 +#ifdef CONFIG_GRKERNSEC
80215 + /* grsecurity */
80216 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80217 + u64 exec_id;
80218 +#endif
80219 +#ifdef CONFIG_GRKERNSEC_SETXID
80220 + const struct cred *delayed_cred;
80221 +#endif
80222 + struct dentry *gr_chroot_dentry;
80223 + struct acl_subject_label *acl;
80224 + struct acl_subject_label *tmpacl;
80225 + struct acl_role_label *role;
80226 + struct file *exec_file;
80227 + unsigned long brute_expires;
80228 + u16 acl_role_id;
80229 + u8 inherited;
80230 + /* is this the task that authenticated to the special role */
80231 + u8 acl_sp_role;
80232 + u8 is_writable;
80233 + u8 brute;
80234 + u8 gr_is_chrooted;
80235 +#endif
80236 +
80237 +} __randomize_layout;
80238 +
80239 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
80240 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
80241 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
80242 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
80243 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
80244 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
80245 +
80246 +#ifdef CONFIG_PAX_SOFTMODE
80247 +extern int pax_softmode;
80248 +#endif
80249 +
80250 +extern int pax_check_flags(unsigned long *);
80251 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
80252 +
80253 +/* if tsk != current then task_lock must be held on it */
80254 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80255 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
80256 +{
80257 + if (likely(tsk->mm))
80258 + return tsk->mm->pax_flags;
80259 + else
80260 + return 0UL;
80261 +}
80262 +
80263 +/* if tsk != current then task_lock must be held on it */
80264 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
80265 +{
80266 + if (likely(tsk->mm)) {
80267 + tsk->mm->pax_flags = flags;
80268 + return 0;
80269 + }
80270 + return -EINVAL;
80271 +}
80272 +#endif
80273 +
80274 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
80275 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
80276 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
80277 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
80278 +#endif
80279 +
80280 +struct path;
80281 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
80282 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
80283 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
80284 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
80285
80286 /* Future-safe accessor for struct task_struct's cpus_allowed. */
80287 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
80288 @@ -1531,7 +1642,7 @@ struct pid_namespace;
80289 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
80290 struct pid_namespace *ns);
80291
80292 -static inline pid_t task_pid_nr(struct task_struct *tsk)
80293 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
80294 {
80295 return tsk->pid;
80296 }
80297 @@ -1981,7 +2092,9 @@ void yield(void);
80298 extern struct exec_domain default_exec_domain;
80299
80300 union thread_union {
80301 +#ifndef CONFIG_X86
80302 struct thread_info thread_info;
80303 +#endif
80304 unsigned long stack[THREAD_SIZE/sizeof(long)];
80305 };
80306
80307 @@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
80308 */
80309
80310 extern struct task_struct *find_task_by_vpid(pid_t nr);
80311 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
80312 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
80313 struct pid_namespace *ns);
80314
80315 @@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
80316 extern void exit_itimers(struct signal_struct *);
80317 extern void flush_itimer_signals(void);
80318
80319 -extern void do_group_exit(int);
80320 +extern __noreturn void do_group_exit(int);
80321
80322 extern int allow_signal(int);
80323 extern int disallow_signal(int);
80324 @@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
80325
80326 #endif
80327
80328 -static inline int object_is_on_stack(void *obj)
80329 +static inline int object_starts_on_stack(void *obj)
80330 {
80331 - void *stack = task_stack_page(current);
80332 + const void *stack = task_stack_page(current);
80333
80334 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
80335 }
80336 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
80337 index 41467f8..1e4253d 100644
80338 --- a/include/linux/sched/sysctl.h
80339 +++ b/include/linux/sched/sysctl.h
80340 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
80341 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
80342
80343 extern int sysctl_max_map_count;
80344 +extern unsigned long sysctl_heap_stack_gap;
80345
80346 extern unsigned int sysctl_sched_latency;
80347 extern unsigned int sysctl_sched_min_granularity;
80348 diff --git a/include/linux/security.h b/include/linux/security.h
80349 index 5623a7f..b352409 100644
80350 --- a/include/linux/security.h
80351 +++ b/include/linux/security.h
80352 @@ -27,6 +27,7 @@
80353 #include <linux/slab.h>
80354 #include <linux/err.h>
80355 #include <linux/string.h>
80356 +#include <linux/grsecurity.h>
80357
80358 struct linux_binprm;
80359 struct cred;
80360 @@ -116,8 +117,6 @@ struct seq_file;
80361
80362 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
80363
80364 -void reset_security_ops(void);
80365 -
80366 #ifdef CONFIG_MMU
80367 extern unsigned long mmap_min_addr;
80368 extern unsigned long dac_mmap_min_addr;
80369 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
80370 index dc368b8..e895209 100644
80371 --- a/include/linux/semaphore.h
80372 +++ b/include/linux/semaphore.h
80373 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
80374 }
80375
80376 extern void down(struct semaphore *sem);
80377 -extern int __must_check down_interruptible(struct semaphore *sem);
80378 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
80379 extern int __must_check down_killable(struct semaphore *sem);
80380 extern int __must_check down_trylock(struct semaphore *sem);
80381 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
80382 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
80383 index 52e0097..09625ef 100644
80384 --- a/include/linux/seq_file.h
80385 +++ b/include/linux/seq_file.h
80386 @@ -27,6 +27,9 @@ struct seq_file {
80387 struct mutex lock;
80388 const struct seq_operations *op;
80389 int poll_event;
80390 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80391 + u64 exec_id;
80392 +#endif
80393 #ifdef CONFIG_USER_NS
80394 struct user_namespace *user_ns;
80395 #endif
80396 @@ -39,6 +42,7 @@ struct seq_operations {
80397 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
80398 int (*show) (struct seq_file *m, void *v);
80399 };
80400 +typedef struct seq_operations __no_const seq_operations_no_const;
80401
80402 #define SEQ_SKIP 1
80403
80404 diff --git a/include/linux/shm.h b/include/linux/shm.h
80405 index 429c199..4d42e38 100644
80406 --- a/include/linux/shm.h
80407 +++ b/include/linux/shm.h
80408 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
80409
80410 /* The task created the shm object. NULL if the task is dead. */
80411 struct task_struct *shm_creator;
80412 +#ifdef CONFIG_GRKERNSEC
80413 + time_t shm_createtime;
80414 + pid_t shm_lapid;
80415 +#endif
80416 };
80417
80418 /* shm_mode upper byte flags */
80419 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
80420 index 6f69b3f..71ac613 100644
80421 --- a/include/linux/skbuff.h
80422 +++ b/include/linux/skbuff.h
80423 @@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
80424 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
80425 int node);
80426 struct sk_buff *build_skb(void *data, unsigned int frag_size);
80427 -static inline struct sk_buff *alloc_skb(unsigned int size,
80428 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
80429 gfp_t priority)
80430 {
80431 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
80432 @@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
80433 */
80434 static inline int skb_queue_empty(const struct sk_buff_head *list)
80435 {
80436 - return list->next == (struct sk_buff *)list;
80437 + return list->next == (const struct sk_buff *)list;
80438 }
80439
80440 /**
80441 @@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
80442 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80443 const struct sk_buff *skb)
80444 {
80445 - return skb->next == (struct sk_buff *)list;
80446 + return skb->next == (const struct sk_buff *)list;
80447 }
80448
80449 /**
80450 @@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80451 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
80452 const struct sk_buff *skb)
80453 {
80454 - return skb->prev == (struct sk_buff *)list;
80455 + return skb->prev == (const struct sk_buff *)list;
80456 }
80457
80458 /**
80459 @@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
80460 return skb->inner_transport_header - skb->inner_network_header;
80461 }
80462
80463 -static inline int skb_network_offset(const struct sk_buff *skb)
80464 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
80465 {
80466 return skb_network_header(skb) - skb->data;
80467 }
80468 @@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
80469 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
80470 */
80471 #ifndef NET_SKB_PAD
80472 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
80473 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
80474 #endif
80475
80476 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
80477 @@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
80478 int *err);
80479 unsigned int datagram_poll(struct file *file, struct socket *sock,
80480 struct poll_table_struct *wait);
80481 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80482 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80483 struct iovec *to, int size);
80484 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
80485 struct iovec *iov);
80486 @@ -2617,6 +2617,9 @@ static inline void nf_reset(struct sk_buff *skb)
80487 nf_bridge_put(skb->nf_bridge);
80488 skb->nf_bridge = NULL;
80489 #endif
80490 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
80491 + skb->nf_trace = 0;
80492 +#endif
80493 }
80494
80495 static inline void nf_reset_trace(struct sk_buff *skb)
80496 diff --git a/include/linux/slab.h b/include/linux/slab.h
80497 index 1e2f4fe..df49ca6 100644
80498 --- a/include/linux/slab.h
80499 +++ b/include/linux/slab.h
80500 @@ -14,15 +14,29 @@
80501 #include <linux/gfp.h>
80502 #include <linux/types.h>
80503 #include <linux/workqueue.h>
80504 -
80505 +#include <linux/err.h>
80506
80507 /*
80508 * Flags to pass to kmem_cache_create().
80509 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
80510 */
80511 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
80512 +
80513 +#ifdef CONFIG_PAX_USERCOPY_SLABS
80514 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
80515 +#else
80516 +#define SLAB_USERCOPY 0x00000000UL
80517 +#endif
80518 +
80519 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
80520 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
80521 +
80522 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
80523 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
80524 +#else
80525 +#define SLAB_NO_SANITIZE 0x00000000UL
80526 +#endif
80527 +
80528 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
80529 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
80530 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
80531 @@ -98,10 +112,13 @@
80532 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
80533 * Both make kfree a no-op.
80534 */
80535 -#define ZERO_SIZE_PTR ((void *)16)
80536 +#define ZERO_SIZE_PTR \
80537 +({ \
80538 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
80539 + (void *)(-MAX_ERRNO-1L); \
80540 +})
80541
80542 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
80543 - (unsigned long)ZERO_SIZE_PTR)
80544 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
80545
80546 #include <linux/kmemleak.h>
80547
80548 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
80549 void kfree(const void *);
80550 void kzfree(const void *);
80551 size_t ksize(const void *);
80552 +const char *check_heap_object(const void *ptr, unsigned long n);
80553 +bool is_usercopy_object(const void *ptr);
80554
80555 /*
80556 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
80557 @@ -174,7 +193,7 @@ struct kmem_cache {
80558 unsigned int align; /* Alignment as calculated */
80559 unsigned long flags; /* Active flags on the slab */
80560 const char *name; /* Slab name for sysfs */
80561 - int refcount; /* Use counter */
80562 + atomic_t refcount; /* Use counter */
80563 void (*ctor)(void *); /* Called on object slot creation */
80564 struct list_head list; /* List of all slab caches on the system */
80565 };
80566 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
80567 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80568 #endif
80569
80570 +#ifdef CONFIG_PAX_USERCOPY_SLABS
80571 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
80572 +#endif
80573 +
80574 /*
80575 * Figure out which kmalloc slab an allocation of a certain size
80576 * belongs to.
80577 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80578 * 2 = 120 .. 192 bytes
80579 * n = 2^(n-1) .. 2^n -1
80580 */
80581 -static __always_inline int kmalloc_index(size_t size)
80582 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
80583 {
80584 if (!size)
80585 return 0;
80586 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
80587 }
80588 #endif /* !CONFIG_SLOB */
80589
80590 -void *__kmalloc(size_t size, gfp_t flags);
80591 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
80592 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
80593
80594 #ifdef CONFIG_NUMA
80595 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
80596 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
80597 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
80598 #else
80599 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
80600 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
80601 index 09bfffb..4fc80fb 100644
80602 --- a/include/linux/slab_def.h
80603 +++ b/include/linux/slab_def.h
80604 @@ -36,7 +36,7 @@ struct kmem_cache {
80605 /* 4) cache creation/removal */
80606 const char *name;
80607 struct list_head list;
80608 - int refcount;
80609 + atomic_t refcount;
80610 int object_size;
80611 int align;
80612
80613 @@ -52,10 +52,14 @@ struct kmem_cache {
80614 unsigned long node_allocs;
80615 unsigned long node_frees;
80616 unsigned long node_overflow;
80617 - atomic_t allochit;
80618 - atomic_t allocmiss;
80619 - atomic_t freehit;
80620 - atomic_t freemiss;
80621 + atomic_unchecked_t allochit;
80622 + atomic_unchecked_t allocmiss;
80623 + atomic_unchecked_t freehit;
80624 + atomic_unchecked_t freemiss;
80625 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
80626 + atomic_unchecked_t sanitized;
80627 + atomic_unchecked_t not_sanitized;
80628 +#endif
80629
80630 /*
80631 * If debugging is enabled, then the allocator can add additional
80632 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
80633 index f56bfa9..8378a26 100644
80634 --- a/include/linux/slub_def.h
80635 +++ b/include/linux/slub_def.h
80636 @@ -74,7 +74,7 @@ struct kmem_cache {
80637 struct kmem_cache_order_objects max;
80638 struct kmem_cache_order_objects min;
80639 gfp_t allocflags; /* gfp flags to use on each alloc */
80640 - int refcount; /* Refcount for slab cache destroy */
80641 + atomic_t refcount; /* Refcount for slab cache destroy */
80642 void (*ctor)(void *);
80643 int inuse; /* Offset to metadata */
80644 int align; /* Alignment */
80645 diff --git a/include/linux/smp.h b/include/linux/smp.h
80646 index 5da22ee..71d8a28 100644
80647 --- a/include/linux/smp.h
80648 +++ b/include/linux/smp.h
80649 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
80650 #endif
80651
80652 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
80653 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
80654 #define put_cpu() preempt_enable()
80655 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
80656
80657 /*
80658 * Callback to arch code if there's nosmp or maxcpus=0 on the
80659 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
80660 index 54f91d3..be2c379 100644
80661 --- a/include/linux/sock_diag.h
80662 +++ b/include/linux/sock_diag.h
80663 @@ -11,7 +11,7 @@ struct sock;
80664 struct sock_diag_handler {
80665 __u8 family;
80666 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
80667 -};
80668 +} __do_const;
80669
80670 int sock_diag_register(const struct sock_diag_handler *h);
80671 void sock_diag_unregister(const struct sock_diag_handler *h);
80672 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
80673 index 680f9a3..f13aeb0 100644
80674 --- a/include/linux/sonet.h
80675 +++ b/include/linux/sonet.h
80676 @@ -7,7 +7,7 @@
80677 #include <uapi/linux/sonet.h>
80678
80679 struct k_sonet_stats {
80680 -#define __HANDLE_ITEM(i) atomic_t i
80681 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80682 __SONET_ITEMS
80683 #undef __HANDLE_ITEM
80684 };
80685 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
80686 index 07d8e53..dc934c9 100644
80687 --- a/include/linux/sunrpc/addr.h
80688 +++ b/include/linux/sunrpc/addr.h
80689 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
80690 {
80691 switch (sap->sa_family) {
80692 case AF_INET:
80693 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
80694 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
80695 case AF_INET6:
80696 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
80697 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
80698 }
80699 return 0;
80700 }
80701 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
80702 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
80703 const struct sockaddr *src)
80704 {
80705 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
80706 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
80707 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
80708
80709 dsin->sin_family = ssin->sin_family;
80710 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
80711 if (sa->sa_family != AF_INET6)
80712 return 0;
80713
80714 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
80715 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
80716 }
80717
80718 #endif /* _LINUX_SUNRPC_ADDR_H */
80719 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
80720 index 8af2804..c7414ef 100644
80721 --- a/include/linux/sunrpc/clnt.h
80722 +++ b/include/linux/sunrpc/clnt.h
80723 @@ -97,7 +97,7 @@ struct rpc_procinfo {
80724 unsigned int p_timer; /* Which RTT timer to use */
80725 u32 p_statidx; /* Which procedure to account */
80726 const char * p_name; /* name of procedure */
80727 -};
80728 +} __do_const;
80729
80730 #ifdef __KERNEL__
80731
80732 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
80733 index 6eecfc2..7ada79d 100644
80734 --- a/include/linux/sunrpc/svc.h
80735 +++ b/include/linux/sunrpc/svc.h
80736 @@ -410,7 +410,7 @@ struct svc_procedure {
80737 unsigned int pc_count; /* call count */
80738 unsigned int pc_cachetype; /* cache info (NFS) */
80739 unsigned int pc_xdrressize; /* maximum size of XDR reply */
80740 -};
80741 +} __do_const;
80742
80743 /*
80744 * Function prototypes.
80745 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
80746 index 0b8e3e6..33e0a01 100644
80747 --- a/include/linux/sunrpc/svc_rdma.h
80748 +++ b/include/linux/sunrpc/svc_rdma.h
80749 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
80750 extern unsigned int svcrdma_max_requests;
80751 extern unsigned int svcrdma_max_req_size;
80752
80753 -extern atomic_t rdma_stat_recv;
80754 -extern atomic_t rdma_stat_read;
80755 -extern atomic_t rdma_stat_write;
80756 -extern atomic_t rdma_stat_sq_starve;
80757 -extern atomic_t rdma_stat_rq_starve;
80758 -extern atomic_t rdma_stat_rq_poll;
80759 -extern atomic_t rdma_stat_rq_prod;
80760 -extern atomic_t rdma_stat_sq_poll;
80761 -extern atomic_t rdma_stat_sq_prod;
80762 +extern atomic_unchecked_t rdma_stat_recv;
80763 +extern atomic_unchecked_t rdma_stat_read;
80764 +extern atomic_unchecked_t rdma_stat_write;
80765 +extern atomic_unchecked_t rdma_stat_sq_starve;
80766 +extern atomic_unchecked_t rdma_stat_rq_starve;
80767 +extern atomic_unchecked_t rdma_stat_rq_poll;
80768 +extern atomic_unchecked_t rdma_stat_rq_prod;
80769 +extern atomic_unchecked_t rdma_stat_sq_poll;
80770 +extern atomic_unchecked_t rdma_stat_sq_prod;
80771
80772 #define RPCRDMA_VERSION 1
80773
80774 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
80775 index 8d71d65..f79586e 100644
80776 --- a/include/linux/sunrpc/svcauth.h
80777 +++ b/include/linux/sunrpc/svcauth.h
80778 @@ -120,7 +120,7 @@ struct auth_ops {
80779 int (*release)(struct svc_rqst *rq);
80780 void (*domain_release)(struct auth_domain *);
80781 int (*set_client)(struct svc_rqst *rq);
80782 -};
80783 +} __do_const;
80784
80785 #define SVC_GARBAGE 1
80786 #define SVC_SYSERR 2
80787 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
80788 index a5ffd32..0935dea 100644
80789 --- a/include/linux/swiotlb.h
80790 +++ b/include/linux/swiotlb.h
80791 @@ -60,7 +60,8 @@ extern void
80792
80793 extern void
80794 swiotlb_free_coherent(struct device *hwdev, size_t size,
80795 - void *vaddr, dma_addr_t dma_handle);
80796 + void *vaddr, dma_addr_t dma_handle,
80797 + struct dma_attrs *attrs);
80798
80799 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
80800 unsigned long offset, size_t size,
80801 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
80802 index 94273bb..c2e05fc 100644
80803 --- a/include/linux/syscalls.h
80804 +++ b/include/linux/syscalls.h
80805 @@ -97,8 +97,14 @@ struct sigaltstack;
80806 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
80807
80808 #define __SC_DECL(t, a) t a
80809 +#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))
80810 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
80811 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
80812 +#define __SC_LONG(t, a) __typeof( \
80813 + __builtin_choose_expr( \
80814 + sizeof(t) > sizeof(int), \
80815 + (t) 0, \
80816 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
80817 + )) a
80818 #define __SC_CAST(t, a) (t) a
80819 #define __SC_ARGS(t, a) a
80820 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
80821 @@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
80822 asmlinkage long sys_fsync(unsigned int fd);
80823 asmlinkage long sys_fdatasync(unsigned int fd);
80824 asmlinkage long sys_bdflush(int func, long data);
80825 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
80826 - char __user *type, unsigned long flags,
80827 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
80828 + const char __user *type, unsigned long flags,
80829 void __user *data);
80830 -asmlinkage long sys_umount(char __user *name, int flags);
80831 -asmlinkage long sys_oldumount(char __user *name);
80832 +asmlinkage long sys_umount(const char __user *name, int flags);
80833 +asmlinkage long sys_oldumount(const char __user *name);
80834 asmlinkage long sys_truncate(const char __user *path, long length);
80835 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
80836 asmlinkage long sys_stat(const char __user *filename,
80837 @@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
80838 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
80839 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
80840 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
80841 - struct sockaddr __user *, int);
80842 + struct sockaddr __user *, int) __intentional_overflow(0);
80843 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
80844 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
80845 unsigned int vlen, unsigned flags);
80846 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
80847 index 27b3b0b..e093dd9 100644
80848 --- a/include/linux/syscore_ops.h
80849 +++ b/include/linux/syscore_ops.h
80850 @@ -16,7 +16,7 @@ struct syscore_ops {
80851 int (*suspend)(void);
80852 void (*resume)(void);
80853 void (*shutdown)(void);
80854 -};
80855 +} __do_const;
80856
80857 extern void register_syscore_ops(struct syscore_ops *ops);
80858 extern void unregister_syscore_ops(struct syscore_ops *ops);
80859 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
80860 index 14a8ff2..fa95f3a 100644
80861 --- a/include/linux/sysctl.h
80862 +++ b/include/linux/sysctl.h
80863 @@ -34,13 +34,13 @@ struct ctl_table_root;
80864 struct ctl_table_header;
80865 struct ctl_dir;
80866
80867 -typedef struct ctl_table ctl_table;
80868 -
80869 typedef int proc_handler (struct ctl_table *ctl, int write,
80870 void __user *buffer, size_t *lenp, loff_t *ppos);
80871
80872 extern int proc_dostring(struct ctl_table *, int,
80873 void __user *, size_t *, loff_t *);
80874 +extern int proc_dostring_modpriv(struct ctl_table *, int,
80875 + void __user *, size_t *, loff_t *);
80876 extern int proc_dointvec(struct ctl_table *, int,
80877 void __user *, size_t *, loff_t *);
80878 extern int proc_dointvec_minmax(struct ctl_table *, int,
80879 @@ -115,7 +115,9 @@ struct ctl_table
80880 struct ctl_table_poll *poll;
80881 void *extra1;
80882 void *extra2;
80883 -};
80884 +} __do_const __randomize_layout;
80885 +typedef struct ctl_table __no_const ctl_table_no_const;
80886 +typedef struct ctl_table ctl_table;
80887
80888 struct ctl_node {
80889 struct rb_node node;
80890 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
80891 index 6695040..3d4192d 100644
80892 --- a/include/linux/sysfs.h
80893 +++ b/include/linux/sysfs.h
80894 @@ -33,7 +33,8 @@ struct attribute {
80895 struct lock_class_key *key;
80896 struct lock_class_key skey;
80897 #endif
80898 -};
80899 +} __do_const;
80900 +typedef struct attribute __no_const attribute_no_const;
80901
80902 /**
80903 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
80904 @@ -62,7 +63,8 @@ struct attribute_group {
80905 struct attribute *, int);
80906 struct attribute **attrs;
80907 struct bin_attribute **bin_attrs;
80908 -};
80909 +} __do_const;
80910 +typedef struct attribute_group __no_const attribute_group_no_const;
80911
80912 /**
80913 * Use these macros to make defining attributes easier. See include/linux/device.h
80914 @@ -126,7 +128,8 @@ struct bin_attribute {
80915 char *, loff_t, size_t);
80916 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
80917 struct vm_area_struct *vma);
80918 -};
80919 +} __do_const;
80920 +typedef struct bin_attribute __no_const bin_attribute_no_const;
80921
80922 /**
80923 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
80924 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
80925 index 387fa7d..3fcde6b 100644
80926 --- a/include/linux/sysrq.h
80927 +++ b/include/linux/sysrq.h
80928 @@ -16,6 +16,7 @@
80929
80930 #include <linux/errno.h>
80931 #include <linux/types.h>
80932 +#include <linux/compiler.h>
80933
80934 /* Possible values of bitmask for enabling sysrq functions */
80935 /* 0x0001 is reserved for enable everything */
80936 @@ -33,7 +34,7 @@ struct sysrq_key_op {
80937 char *help_msg;
80938 char *action_msg;
80939 int enable_mask;
80940 -};
80941 +} __do_const;
80942
80943 #ifdef CONFIG_MAGIC_SYSRQ
80944
80945 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
80946 index fddbe20..0312de8 100644
80947 --- a/include/linux/thread_info.h
80948 +++ b/include/linux/thread_info.h
80949 @@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
80950 #error "no set_restore_sigmask() provided and default one won't work"
80951 #endif
80952
80953 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
80954 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
80955 +{
80956 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
80957 + if (!__builtin_constant_p(n))
80958 +#endif
80959 + __check_object_size(ptr, n, to_user);
80960 +}
80961 +
80962 #endif /* __KERNEL__ */
80963
80964 #endif /* _LINUX_THREAD_INFO_H */
80965 diff --git a/include/linux/tty.h b/include/linux/tty.h
80966 index 97d660e..6356755 100644
80967 --- a/include/linux/tty.h
80968 +++ b/include/linux/tty.h
80969 @@ -196,7 +196,7 @@ struct tty_port {
80970 const struct tty_port_operations *ops; /* Port operations */
80971 spinlock_t lock; /* Lock protecting tty field */
80972 int blocked_open; /* Waiting to open */
80973 - int count; /* Usage count */
80974 + atomic_t count; /* Usage count */
80975 wait_queue_head_t open_wait; /* Open waiters */
80976 wait_queue_head_t close_wait; /* Close waiters */
80977 wait_queue_head_t delta_msr_wait; /* Modem status change */
80978 @@ -278,7 +278,7 @@ struct tty_struct {
80979 /* If the tty has a pending do_SAK, queue it here - akpm */
80980 struct work_struct SAK_work;
80981 struct tty_port *port;
80982 -};
80983 +} __randomize_layout;
80984
80985 /* Each of a tty's open files has private_data pointing to tty_file_private */
80986 struct tty_file_private {
80987 @@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
80988 struct tty_struct *tty, struct file *filp);
80989 static inline int tty_port_users(struct tty_port *port)
80990 {
80991 - return port->count + port->blocked_open;
80992 + return atomic_read(&port->count) + port->blocked_open;
80993 }
80994
80995 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
80996 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
80997 index 756a609..f61242d 100644
80998 --- a/include/linux/tty_driver.h
80999 +++ b/include/linux/tty_driver.h
81000 @@ -285,7 +285,7 @@ struct tty_operations {
81001 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
81002 #endif
81003 const struct file_operations *proc_fops;
81004 -};
81005 +} __do_const;
81006
81007 struct tty_driver {
81008 int magic; /* magic number for this structure */
81009 @@ -319,7 +319,7 @@ struct tty_driver {
81010
81011 const struct tty_operations *ops;
81012 struct list_head tty_drivers;
81013 -};
81014 +} __randomize_layout;
81015
81016 extern struct list_head tty_drivers;
81017
81018 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
81019 index f15c898..207b7d1 100644
81020 --- a/include/linux/tty_ldisc.h
81021 +++ b/include/linux/tty_ldisc.h
81022 @@ -211,7 +211,7 @@ struct tty_ldisc_ops {
81023
81024 struct module *owner;
81025
81026 - int refcount;
81027 + atomic_t refcount;
81028 };
81029
81030 struct tty_ldisc {
81031 diff --git a/include/linux/types.h b/include/linux/types.h
81032 index 4d118ba..c3ee9bf 100644
81033 --- a/include/linux/types.h
81034 +++ b/include/linux/types.h
81035 @@ -176,10 +176,26 @@ typedef struct {
81036 int counter;
81037 } atomic_t;
81038
81039 +#ifdef CONFIG_PAX_REFCOUNT
81040 +typedef struct {
81041 + int counter;
81042 +} atomic_unchecked_t;
81043 +#else
81044 +typedef atomic_t atomic_unchecked_t;
81045 +#endif
81046 +
81047 #ifdef CONFIG_64BIT
81048 typedef struct {
81049 long counter;
81050 } atomic64_t;
81051 +
81052 +#ifdef CONFIG_PAX_REFCOUNT
81053 +typedef struct {
81054 + long counter;
81055 +} atomic64_unchecked_t;
81056 +#else
81057 +typedef atomic64_t atomic64_unchecked_t;
81058 +#endif
81059 #endif
81060
81061 struct list_head {
81062 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
81063 index 9d8cf05..0ed74dd 100644
81064 --- a/include/linux/uaccess.h
81065 +++ b/include/linux/uaccess.h
81066 @@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
81067 long ret; \
81068 mm_segment_t old_fs = get_fs(); \
81069 \
81070 - set_fs(KERNEL_DS); \
81071 pagefault_disable(); \
81072 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
81073 - pagefault_enable(); \
81074 + set_fs(KERNEL_DS); \
81075 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
81076 set_fs(old_fs); \
81077 + pagefault_enable(); \
81078 ret; \
81079 })
81080
81081 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
81082 index 8e522cbc..aa8572d 100644
81083 --- a/include/linux/uidgid.h
81084 +++ b/include/linux/uidgid.h
81085 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
81086
81087 #endif /* CONFIG_USER_NS */
81088
81089 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
81090 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
81091 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
81092 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
81093 +
81094 #endif /* _LINUX_UIDGID_H */
81095 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
81096 index 99c1b4d..562e6f3 100644
81097 --- a/include/linux/unaligned/access_ok.h
81098 +++ b/include/linux/unaligned/access_ok.h
81099 @@ -4,34 +4,34 @@
81100 #include <linux/kernel.h>
81101 #include <asm/byteorder.h>
81102
81103 -static inline u16 get_unaligned_le16(const void *p)
81104 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
81105 {
81106 - return le16_to_cpup((__le16 *)p);
81107 + return le16_to_cpup((const __le16 *)p);
81108 }
81109
81110 -static inline u32 get_unaligned_le32(const void *p)
81111 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
81112 {
81113 - return le32_to_cpup((__le32 *)p);
81114 + return le32_to_cpup((const __le32 *)p);
81115 }
81116
81117 -static inline u64 get_unaligned_le64(const void *p)
81118 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
81119 {
81120 - return le64_to_cpup((__le64 *)p);
81121 + return le64_to_cpup((const __le64 *)p);
81122 }
81123
81124 -static inline u16 get_unaligned_be16(const void *p)
81125 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
81126 {
81127 - return be16_to_cpup((__be16 *)p);
81128 + return be16_to_cpup((const __be16 *)p);
81129 }
81130
81131 -static inline u32 get_unaligned_be32(const void *p)
81132 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
81133 {
81134 - return be32_to_cpup((__be32 *)p);
81135 + return be32_to_cpup((const __be32 *)p);
81136 }
81137
81138 -static inline u64 get_unaligned_be64(const void *p)
81139 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
81140 {
81141 - return be64_to_cpup((__be64 *)p);
81142 + return be64_to_cpup((const __be64 *)p);
81143 }
81144
81145 static inline void put_unaligned_le16(u16 val, void *p)
81146 diff --git a/include/linux/usb.h b/include/linux/usb.h
81147 index 512ab16..f53e1bf 100644
81148 --- a/include/linux/usb.h
81149 +++ b/include/linux/usb.h
81150 @@ -563,7 +563,7 @@ struct usb_device {
81151 int maxchild;
81152
81153 u32 quirks;
81154 - atomic_t urbnum;
81155 + atomic_unchecked_t urbnum;
81156
81157 unsigned long active_duration;
81158
81159 @@ -1643,7 +1643,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
81160
81161 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
81162 __u8 request, __u8 requesttype, __u16 value, __u16 index,
81163 - void *data, __u16 size, int timeout);
81164 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
81165 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
81166 void *data, int len, int *actual_length, int timeout);
81167 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
81168 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
81169 index e452ba6..78f8e80 100644
81170 --- a/include/linux/usb/renesas_usbhs.h
81171 +++ b/include/linux/usb/renesas_usbhs.h
81172 @@ -39,7 +39,7 @@ enum {
81173 */
81174 struct renesas_usbhs_driver_callback {
81175 int (*notify_hotplug)(struct platform_device *pdev);
81176 -};
81177 +} __no_const;
81178
81179 /*
81180 * callback functions for platform
81181 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
81182 index 4836ba3..603f6ee 100644
81183 --- a/include/linux/user_namespace.h
81184 +++ b/include/linux/user_namespace.h
81185 @@ -33,7 +33,7 @@ struct user_namespace {
81186 struct key *persistent_keyring_register;
81187 struct rw_semaphore persistent_keyring_register_sem;
81188 #endif
81189 -};
81190 +} __randomize_layout;
81191
81192 extern struct user_namespace init_user_ns;
81193
81194 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
81195 index 239e277..22a5cf5 100644
81196 --- a/include/linux/utsname.h
81197 +++ b/include/linux/utsname.h
81198 @@ -24,7 +24,7 @@ struct uts_namespace {
81199 struct new_utsname name;
81200 struct user_namespace *user_ns;
81201 unsigned int proc_inum;
81202 -};
81203 +} __randomize_layout;
81204 extern struct uts_namespace init_uts_ns;
81205
81206 #ifdef CONFIG_UTS_NS
81207 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
81208 index 6f8fbcf..e2a0e61 100644
81209 --- a/include/linux/vermagic.h
81210 +++ b/include/linux/vermagic.h
81211 @@ -25,9 +25,41 @@
81212 #define MODULE_ARCH_VERMAGIC ""
81213 #endif
81214
81215 +#ifdef CONFIG_PAX_REFCOUNT
81216 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
81217 +#else
81218 +#define MODULE_PAX_REFCOUNT ""
81219 +#endif
81220 +
81221 +#ifdef CONSTIFY_PLUGIN
81222 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
81223 +#else
81224 +#define MODULE_CONSTIFY_PLUGIN ""
81225 +#endif
81226 +
81227 +#ifdef STACKLEAK_PLUGIN
81228 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
81229 +#else
81230 +#define MODULE_STACKLEAK_PLUGIN ""
81231 +#endif
81232 +
81233 +#ifdef RANDSTRUCT_PLUGIN
81234 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
81235 +#else
81236 +#define MODULE_RANDSTRUCT_PLUGIN
81237 +#endif
81238 +
81239 +#ifdef CONFIG_GRKERNSEC
81240 +#define MODULE_GRSEC "GRSEC "
81241 +#else
81242 +#define MODULE_GRSEC ""
81243 +#endif
81244 +
81245 #define VERMAGIC_STRING \
81246 UTS_RELEASE " " \
81247 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
81248 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
81249 - MODULE_ARCH_VERMAGIC
81250 + MODULE_ARCH_VERMAGIC \
81251 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
81252 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
81253
81254 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
81255 index 502073a..a7de024 100644
81256 --- a/include/linux/vga_switcheroo.h
81257 +++ b/include/linux/vga_switcheroo.h
81258 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
81259
81260 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
81261
81262 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
81263 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
81264 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
81265 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
81266 #else
81267
81268 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
81269 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
81270
81271 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
81272
81273 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81274 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81275 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81276 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81277
81278 #endif
81279 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
81280 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
81281 index 4b8a891..cb8df6e 100644
81282 --- a/include/linux/vmalloc.h
81283 +++ b/include/linux/vmalloc.h
81284 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
81285 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
81286 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
81287 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
81288 +
81289 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
81290 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
81291 +#endif
81292 +
81293 /* bits [20..32] reserved for arch specific ioremap internals */
81294
81295 /*
81296 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
81297
81298 /* for /dev/kmem */
81299 extern long vread(char *buf, char *addr, unsigned long count);
81300 -extern long vwrite(char *buf, char *addr, unsigned long count);
81301 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
81302
81303 /*
81304 * Internals. Dont't use..
81305 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
81306 index e4b9480..5a5f65a 100644
81307 --- a/include/linux/vmstat.h
81308 +++ b/include/linux/vmstat.h
81309 @@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
81310 /*
81311 * Zone based page accounting with per cpu differentials.
81312 */
81313 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81314 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81315
81316 static inline void zone_page_state_add(long x, struct zone *zone,
81317 enum zone_stat_item item)
81318 {
81319 - atomic_long_add(x, &zone->vm_stat[item]);
81320 - atomic_long_add(x, &vm_stat[item]);
81321 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
81322 + atomic_long_add_unchecked(x, &vm_stat[item]);
81323 }
81324
81325 -static inline unsigned long global_page_state(enum zone_stat_item item)
81326 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
81327 {
81328 - long x = atomic_long_read(&vm_stat[item]);
81329 + long x = atomic_long_read_unchecked(&vm_stat[item]);
81330 #ifdef CONFIG_SMP
81331 if (x < 0)
81332 x = 0;
81333 @@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
81334 return x;
81335 }
81336
81337 -static inline unsigned long zone_page_state(struct zone *zone,
81338 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
81339 enum zone_stat_item item)
81340 {
81341 - long x = atomic_long_read(&zone->vm_stat[item]);
81342 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81343 #ifdef CONFIG_SMP
81344 if (x < 0)
81345 x = 0;
81346 @@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
81347 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
81348 enum zone_stat_item item)
81349 {
81350 - long x = atomic_long_read(&zone->vm_stat[item]);
81351 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81352
81353 #ifdef CONFIG_SMP
81354 int cpu;
81355 @@ -220,8 +220,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
81356
81357 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
81358 {
81359 - atomic_long_inc(&zone->vm_stat[item]);
81360 - atomic_long_inc(&vm_stat[item]);
81361 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
81362 + atomic_long_inc_unchecked(&vm_stat[item]);
81363 }
81364
81365 static inline void __inc_zone_page_state(struct page *page,
81366 @@ -232,8 +232,8 @@ static inline void __inc_zone_page_state(struct page *page,
81367
81368 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
81369 {
81370 - atomic_long_dec(&zone->vm_stat[item]);
81371 - atomic_long_dec(&vm_stat[item]);
81372 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
81373 + atomic_long_dec_unchecked(&vm_stat[item]);
81374 }
81375
81376 static inline void __dec_zone_page_state(struct page *page,
81377 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
81378 index 91b0a68..0e9adf6 100644
81379 --- a/include/linux/xattr.h
81380 +++ b/include/linux/xattr.h
81381 @@ -28,7 +28,7 @@ struct xattr_handler {
81382 size_t size, int handler_flags);
81383 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
81384 size_t size, int flags, int handler_flags);
81385 -};
81386 +} __do_const;
81387
81388 struct xattr {
81389 const char *name;
81390 @@ -37,6 +37,9 @@ struct xattr {
81391 };
81392
81393 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
81394 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
81395 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
81396 +#endif
81397 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
81398 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
81399 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
81400 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
81401 index 9c5a6b4..09c9438 100644
81402 --- a/include/linux/zlib.h
81403 +++ b/include/linux/zlib.h
81404 @@ -31,6 +31,7 @@
81405 #define _ZLIB_H
81406
81407 #include <linux/zconf.h>
81408 +#include <linux/compiler.h>
81409
81410 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
81411 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
81412 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
81413
81414 /* basic functions */
81415
81416 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
81417 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
81418 /*
81419 Returns the number of bytes that needs to be allocated for a per-
81420 stream workspace with the specified parameters. A pointer to this
81421 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
81422 index c768c9f..bdcaa5a 100644
81423 --- a/include/media/v4l2-dev.h
81424 +++ b/include/media/v4l2-dev.h
81425 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
81426 int (*mmap) (struct file *, struct vm_area_struct *);
81427 int (*open) (struct file *);
81428 int (*release) (struct file *);
81429 -};
81430 +} __do_const;
81431
81432 /*
81433 * Newer version of video_device, handled by videodev2.c
81434 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
81435 index c9b1593..a572459 100644
81436 --- a/include/media/v4l2-device.h
81437 +++ b/include/media/v4l2-device.h
81438 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
81439 this function returns 0. If the name ends with a digit (e.g. cx18),
81440 then the name will be set to cx18-0 since cx180 looks really odd. */
81441 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
81442 - atomic_t *instance);
81443 + atomic_unchecked_t *instance);
81444
81445 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
81446 Since the parent disappears this ensures that v4l2_dev doesn't have an
81447 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
81448 index 9a36d92..0aafe2a 100644
81449 --- a/include/net/9p/transport.h
81450 +++ b/include/net/9p/transport.h
81451 @@ -60,7 +60,7 @@ struct p9_trans_module {
81452 int (*cancel) (struct p9_client *, struct p9_req_t *req);
81453 int (*zc_request)(struct p9_client *, struct p9_req_t *,
81454 char *, char *, int , int, int, int);
81455 -};
81456 +} __do_const;
81457
81458 void v9fs_register_trans(struct p9_trans_module *m);
81459 void v9fs_unregister_trans(struct p9_trans_module *m);
81460 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
81461 index c853b16d..37fccb7 100644
81462 --- a/include/net/bluetooth/l2cap.h
81463 +++ b/include/net/bluetooth/l2cap.h
81464 @@ -557,7 +557,7 @@ struct l2cap_ops {
81465 long (*get_sndtimeo) (struct l2cap_chan *chan);
81466 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
81467 unsigned long len, int nb);
81468 -};
81469 +} __do_const;
81470
81471 struct l2cap_conn {
81472 struct hci_conn *hcon;
81473 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
81474 index f2ae33d..c457cf0 100644
81475 --- a/include/net/caif/cfctrl.h
81476 +++ b/include/net/caif/cfctrl.h
81477 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
81478 void (*radioset_rsp)(void);
81479 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
81480 struct cflayer *client_layer);
81481 -};
81482 +} __no_const;
81483
81484 /* Link Setup Parameters for CAIF-Links. */
81485 struct cfctrl_link_param {
81486 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
81487 struct cfctrl {
81488 struct cfsrvl serv;
81489 struct cfctrl_rsp res;
81490 - atomic_t req_seq_no;
81491 - atomic_t rsp_seq_no;
81492 + atomic_unchecked_t req_seq_no;
81493 + atomic_unchecked_t rsp_seq_no;
81494 struct list_head list;
81495 /* Protects from simultaneous access to first_req list */
81496 spinlock_t info_list_lock;
81497 diff --git a/include/net/flow.h b/include/net/flow.h
81498 index 65ce471..b7bbe9b 100644
81499 --- a/include/net/flow.h
81500 +++ b/include/net/flow.h
81501 @@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
81502
81503 void flow_cache_flush(void);
81504 void flow_cache_flush_deferred(void);
81505 -extern atomic_t flow_cache_genid;
81506 +extern atomic_unchecked_t flow_cache_genid;
81507
81508 #endif
81509 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
81510 index 1b177ed..a24a138 100644
81511 --- a/include/net/genetlink.h
81512 +++ b/include/net/genetlink.h
81513 @@ -118,7 +118,7 @@ struct genl_ops {
81514 u8 cmd;
81515 u8 internal_flags;
81516 u8 flags;
81517 -};
81518 +} __do_const;
81519
81520 int __genl_register_family(struct genl_family *family);
81521
81522 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
81523 index 734d9b5..48a9a4b 100644
81524 --- a/include/net/gro_cells.h
81525 +++ b/include/net/gro_cells.h
81526 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
81527 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
81528
81529 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
81530 - atomic_long_inc(&dev->rx_dropped);
81531 + atomic_long_inc_unchecked(&dev->rx_dropped);
81532 kfree_skb(skb);
81533 return;
81534 }
81535 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
81536 index c55aeed..b3393f4 100644
81537 --- a/include/net/inet_connection_sock.h
81538 +++ b/include/net/inet_connection_sock.h
81539 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
81540 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
81541 int (*bind_conflict)(const struct sock *sk,
81542 const struct inet_bind_bucket *tb, bool relax);
81543 -};
81544 +} __do_const;
81545
81546 /** inet_connection_sock - INET connection oriented sock
81547 *
81548 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
81549 index f4e127a..c3d5e9c 100644
81550 --- a/include/net/inetpeer.h
81551 +++ b/include/net/inetpeer.h
81552 @@ -47,8 +47,8 @@ struct inet_peer {
81553 */
81554 union {
81555 struct {
81556 - atomic_t rid; /* Frag reception counter */
81557 - atomic_t ip_id_count; /* IP ID for the next packet */
81558 + atomic_unchecked_t rid; /* Frag reception counter */
81559 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
81560 };
81561 struct rcu_head rcu;
81562 struct inet_peer *gc_next;
81563 @@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
81564 /* can be called with or without local BH being disabled */
81565 static inline int inet_getid(struct inet_peer *p, int more)
81566 {
81567 - int old, new;
81568 + int id;
81569 more++;
81570 inet_peer_refcheck(p);
81571 - do {
81572 - old = atomic_read(&p->ip_id_count);
81573 - new = old + more;
81574 - if (!new)
81575 - new = 1;
81576 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
81577 - return new;
81578 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
81579 + if (!id)
81580 + id = atomic_inc_return_unchecked(&p->ip_id_count);
81581 + return id;
81582 }
81583
81584 #endif /* _NET_INETPEER_H */
81585 diff --git a/include/net/ip.h b/include/net/ip.h
81586 index 5a25f36..2e73203 100644
81587 --- a/include/net/ip.h
81588 +++ b/include/net/ip.h
81589 @@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
81590
81591 void inet_get_local_port_range(struct net *net, int *low, int *high);
81592
81593 -extern unsigned long *sysctl_local_reserved_ports;
81594 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
81595 static inline int inet_is_reserved_local_port(int port)
81596 {
81597 return test_bit(port, sysctl_local_reserved_ports);
81598 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
81599 index 9922093..a1755d6 100644
81600 --- a/include/net/ip_fib.h
81601 +++ b/include/net/ip_fib.h
81602 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
81603
81604 #define FIB_RES_SADDR(net, res) \
81605 ((FIB_RES_NH(res).nh_saddr_genid == \
81606 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
81607 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
81608 FIB_RES_NH(res).nh_saddr : \
81609 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
81610 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
81611 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
81612 index 5679d92..2e7a690 100644
81613 --- a/include/net/ip_vs.h
81614 +++ b/include/net/ip_vs.h
81615 @@ -558,7 +558,7 @@ struct ip_vs_conn {
81616 struct ip_vs_conn *control; /* Master control connection */
81617 atomic_t n_control; /* Number of controlled ones */
81618 struct ip_vs_dest *dest; /* real server */
81619 - atomic_t in_pkts; /* incoming packet counter */
81620 + atomic_unchecked_t in_pkts; /* incoming packet counter */
81621
81622 /* packet transmitter for different forwarding methods. If it
81623 mangles the packet, it must return NF_DROP or better NF_STOLEN,
81624 @@ -705,7 +705,7 @@ struct ip_vs_dest {
81625 __be16 port; /* port number of the server */
81626 union nf_inet_addr addr; /* IP address of the server */
81627 volatile unsigned int flags; /* dest status flags */
81628 - atomic_t conn_flags; /* flags to copy to conn */
81629 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
81630 atomic_t weight; /* server weight */
81631
81632 atomic_t refcnt; /* reference counter */
81633 @@ -960,11 +960,11 @@ struct netns_ipvs {
81634 /* ip_vs_lblc */
81635 int sysctl_lblc_expiration;
81636 struct ctl_table_header *lblc_ctl_header;
81637 - struct ctl_table *lblc_ctl_table;
81638 + ctl_table_no_const *lblc_ctl_table;
81639 /* ip_vs_lblcr */
81640 int sysctl_lblcr_expiration;
81641 struct ctl_table_header *lblcr_ctl_header;
81642 - struct ctl_table *lblcr_ctl_table;
81643 + ctl_table_no_const *lblcr_ctl_table;
81644 /* ip_vs_est */
81645 struct list_head est_list; /* estimator list */
81646 spinlock_t est_lock;
81647 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
81648 index 0224402..dafaf94a 100644
81649 --- a/include/net/irda/ircomm_tty.h
81650 +++ b/include/net/irda/ircomm_tty.h
81651 @@ -35,6 +35,7 @@
81652 #include <linux/termios.h>
81653 #include <linux/timer.h>
81654 #include <linux/tty.h> /* struct tty_struct */
81655 +#include <asm/local.h>
81656
81657 #include <net/irda/irias_object.h>
81658 #include <net/irda/ircomm_core.h>
81659 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
81660 index 714cc9a..ea05f3e 100644
81661 --- a/include/net/iucv/af_iucv.h
81662 +++ b/include/net/iucv/af_iucv.h
81663 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
81664 struct iucv_sock_list {
81665 struct hlist_head head;
81666 rwlock_t lock;
81667 - atomic_t autobind_name;
81668 + atomic_unchecked_t autobind_name;
81669 };
81670
81671 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
81672 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
81673 index f3be818..bf46196 100644
81674 --- a/include/net/llc_c_ac.h
81675 +++ b/include/net/llc_c_ac.h
81676 @@ -87,7 +87,7 @@
81677 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
81678 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
81679
81680 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81681 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81682
81683 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
81684 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
81685 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
81686 index 3948cf1..83b28c4 100644
81687 --- a/include/net/llc_c_ev.h
81688 +++ b/include/net/llc_c_ev.h
81689 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
81690 return (struct llc_conn_state_ev *)skb->cb;
81691 }
81692
81693 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81694 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81695 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81696 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81697
81698 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
81699 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
81700 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
81701 index 0e79cfb..f46db31 100644
81702 --- a/include/net/llc_c_st.h
81703 +++ b/include/net/llc_c_st.h
81704 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
81705 u8 next_state;
81706 llc_conn_ev_qfyr_t *ev_qualifiers;
81707 llc_conn_action_t *ev_actions;
81708 -};
81709 +} __do_const;
81710
81711 struct llc_conn_state {
81712 u8 current_state;
81713 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
81714 index a61b98c..aade1eb 100644
81715 --- a/include/net/llc_s_ac.h
81716 +++ b/include/net/llc_s_ac.h
81717 @@ -23,7 +23,7 @@
81718 #define SAP_ACT_TEST_IND 9
81719
81720 /* All action functions must look like this */
81721 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81722 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81723
81724 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
81725 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
81726 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
81727 index 567c681..cd73ac0 100644
81728 --- a/include/net/llc_s_st.h
81729 +++ b/include/net/llc_s_st.h
81730 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
81731 llc_sap_ev_t ev;
81732 u8 next_state;
81733 llc_sap_action_t *ev_actions;
81734 -};
81735 +} __do_const;
81736
81737 struct llc_sap_state {
81738 u8 curr_state;
81739 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
81740 index 7ceed99..d3ffaa2 100644
81741 --- a/include/net/mac80211.h
81742 +++ b/include/net/mac80211.h
81743 @@ -4407,7 +4407,7 @@ struct rate_control_ops {
81744 void (*add_sta_debugfs)(void *priv, void *priv_sta,
81745 struct dentry *dir);
81746 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
81747 -};
81748 +} __do_const;
81749
81750 static inline int rate_supported(struct ieee80211_sta *sta,
81751 enum ieee80211_band band,
81752 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
81753 index 536501a..74ad02bc 100644
81754 --- a/include/net/neighbour.h
81755 +++ b/include/net/neighbour.h
81756 @@ -123,7 +123,7 @@ struct neigh_ops {
81757 void (*error_report)(struct neighbour *, struct sk_buff *);
81758 int (*output)(struct neighbour *, struct sk_buff *);
81759 int (*connected_output)(struct neighbour *, struct sk_buff *);
81760 -};
81761 +} __do_const;
81762
81763 struct pneigh_entry {
81764 struct pneigh_entry *next;
81765 @@ -178,7 +178,7 @@ struct neigh_table {
81766 struct neigh_statistics __percpu *stats;
81767 struct neigh_hash_table __rcu *nht;
81768 struct pneigh_entry **phash_buckets;
81769 -};
81770 +} __randomize_layout;
81771
81772 #define NEIGH_PRIV_ALIGN sizeof(long long)
81773 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
81774 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
81775 index da68c9a..c4a0720 100644
81776 --- a/include/net/net_namespace.h
81777 +++ b/include/net/net_namespace.h
81778 @@ -124,8 +124,8 @@ struct net {
81779 struct netns_ipvs *ipvs;
81780 #endif
81781 struct sock *diag_nlsk;
81782 - atomic_t fnhe_genid;
81783 -};
81784 + atomic_unchecked_t fnhe_genid;
81785 +} __randomize_layout;
81786
81787 /*
81788 * ifindex generation is per-net namespace, and loopback is
81789 @@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
81790 #define __net_init __init
81791 #define __net_exit __exit_refok
81792 #define __net_initdata __initdata
81793 +#ifdef CONSTIFY_PLUGIN
81794 #define __net_initconst __initconst
81795 +#else
81796 +#define __net_initconst __initdata
81797 +#endif
81798 #endif
81799
81800 struct pernet_operations {
81801 @@ -291,7 +295,7 @@ struct pernet_operations {
81802 void (*exit_batch)(struct list_head *net_exit_list);
81803 int *id;
81804 size_t size;
81805 -};
81806 +} __do_const;
81807
81808 /*
81809 * Use these carefully. If you implement a network device and it
81810 @@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
81811
81812 static inline int rt_genid_ipv4(struct net *net)
81813 {
81814 - return atomic_read(&net->ipv4.rt_genid);
81815 + return atomic_read_unchecked(&net->ipv4.rt_genid);
81816 }
81817
81818 static inline void rt_genid_bump_ipv4(struct net *net)
81819 {
81820 - atomic_inc(&net->ipv4.rt_genid);
81821 + atomic_inc_unchecked(&net->ipv4.rt_genid);
81822 }
81823
81824 #if IS_ENABLED(CONFIG_IPV6)
81825 static inline int rt_genid_ipv6(struct net *net)
81826 {
81827 - return atomic_read(&net->ipv6.rt_genid);
81828 + return atomic_read_unchecked(&net->ipv6.rt_genid);
81829 }
81830
81831 static inline void rt_genid_bump_ipv6(struct net *net)
81832 {
81833 - atomic_inc(&net->ipv6.rt_genid);
81834 + atomic_inc_unchecked(&net->ipv6.rt_genid);
81835 }
81836 #else
81837 static inline int rt_genid_ipv6(struct net *net)
81838 @@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
81839
81840 static inline int fnhe_genid(struct net *net)
81841 {
81842 - return atomic_read(&net->fnhe_genid);
81843 + return atomic_read_unchecked(&net->fnhe_genid);
81844 }
81845
81846 static inline void fnhe_genid_bump(struct net *net)
81847 {
81848 - atomic_inc(&net->fnhe_genid);
81849 + atomic_inc_unchecked(&net->fnhe_genid);
81850 }
81851
81852 #endif /* __NET_NET_NAMESPACE_H */
81853 diff --git a/include/net/netdma.h b/include/net/netdma.h
81854 index 8ba8ce2..99b7fff 100644
81855 --- a/include/net/netdma.h
81856 +++ b/include/net/netdma.h
81857 @@ -24,7 +24,7 @@
81858 #include <linux/dmaengine.h>
81859 #include <linux/skbuff.h>
81860
81861 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81862 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81863 struct sk_buff *skb, int offset, struct iovec *to,
81864 size_t len, struct dma_pinned_list *pinned_list);
81865
81866 diff --git a/include/net/netlink.h b/include/net/netlink.h
81867 index 2b47eaa..6d5bcc2 100644
81868 --- a/include/net/netlink.h
81869 +++ b/include/net/netlink.h
81870 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
81871 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
81872 {
81873 if (mark)
81874 - skb_trim(skb, (unsigned char *) mark - skb->data);
81875 + skb_trim(skb, (const unsigned char *) mark - skb->data);
81876 }
81877
81878 /**
81879 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
81880 index c9c0c53..53f24c3 100644
81881 --- a/include/net/netns/conntrack.h
81882 +++ b/include/net/netns/conntrack.h
81883 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
81884 struct nf_proto_net {
81885 #ifdef CONFIG_SYSCTL
81886 struct ctl_table_header *ctl_table_header;
81887 - struct ctl_table *ctl_table;
81888 + ctl_table_no_const *ctl_table;
81889 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
81890 struct ctl_table_header *ctl_compat_header;
81891 - struct ctl_table *ctl_compat_table;
81892 + ctl_table_no_const *ctl_compat_table;
81893 #endif
81894 #endif
81895 unsigned int users;
81896 @@ -58,7 +58,7 @@ struct nf_ip_net {
81897 struct nf_icmp_net icmpv6;
81898 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
81899 struct ctl_table_header *ctl_table_header;
81900 - struct ctl_table *ctl_table;
81901 + ctl_table_no_const *ctl_table;
81902 #endif
81903 };
81904
81905 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
81906 index ee520cb..9a0fd88 100644
81907 --- a/include/net/netns/ipv4.h
81908 +++ b/include/net/netns/ipv4.h
81909 @@ -72,7 +72,7 @@ struct netns_ipv4 {
81910
81911 kgid_t sysctl_ping_group_range[2];
81912
81913 - atomic_t dev_addr_genid;
81914 + atomic_unchecked_t dev_addr_genid;
81915
81916 #ifdef CONFIG_IP_MROUTE
81917 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
81918 @@ -82,6 +82,6 @@ struct netns_ipv4 {
81919 struct fib_rules_ops *mr_rules_ops;
81920 #endif
81921 #endif
81922 - atomic_t rt_genid;
81923 + atomic_unchecked_t rt_genid;
81924 };
81925 #endif
81926 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
81927 index 0fb2401..477d81c 100644
81928 --- a/include/net/netns/ipv6.h
81929 +++ b/include/net/netns/ipv6.h
81930 @@ -71,8 +71,8 @@ struct netns_ipv6 {
81931 struct fib_rules_ops *mr6_rules_ops;
81932 #endif
81933 #endif
81934 - atomic_t dev_addr_genid;
81935 - atomic_t rt_genid;
81936 + atomic_unchecked_t dev_addr_genid;
81937 + atomic_unchecked_t rt_genid;
81938 };
81939
81940 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
81941 diff --git a/include/net/ping.h b/include/net/ping.h
81942 index 90f4841..74446a8 100644
81943 --- a/include/net/ping.h
81944 +++ b/include/net/ping.h
81945 @@ -56,7 +56,7 @@ struct ping_iter_state {
81946 extern struct proto ping_prot;
81947 extern struct ping_table ping_table;
81948 #if IS_ENABLED(CONFIG_IPV6)
81949 -extern struct pingv6_ops pingv6_ops;
81950 +extern struct pingv6_ops *pingv6_ops;
81951 #endif
81952
81953 struct pingfakehdr {
81954 diff --git a/include/net/protocol.h b/include/net/protocol.h
81955 index fbf7676..a5e21c3 100644
81956 --- a/include/net/protocol.h
81957 +++ b/include/net/protocol.h
81958 @@ -44,7 +44,7 @@ struct net_protocol {
81959 void (*err_handler)(struct sk_buff *skb, u32 info);
81960 unsigned int no_policy:1,
81961 netns_ok:1;
81962 -};
81963 +} __do_const;
81964
81965 #if IS_ENABLED(CONFIG_IPV6)
81966 struct inet6_protocol {
81967 @@ -57,7 +57,7 @@ struct inet6_protocol {
81968 u8 type, u8 code, int offset,
81969 __be32 info);
81970 unsigned int flags; /* INET6_PROTO_xxx */
81971 -};
81972 +} __do_const;
81973
81974 #define INET6_PROTO_NOPOLICY 0x1
81975 #define INET6_PROTO_FINAL 0x2
81976 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
81977 index bb13a18..e734116 100644
81978 --- a/include/net/rtnetlink.h
81979 +++ b/include/net/rtnetlink.h
81980 @@ -79,7 +79,7 @@ struct rtnl_link_ops {
81981 const struct net_device *dev);
81982 unsigned int (*get_num_tx_queues)(void);
81983 unsigned int (*get_num_rx_queues)(void);
81984 -};
81985 +} __do_const;
81986
81987 int __rtnl_link_register(struct rtnl_link_ops *ops);
81988 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
81989 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
81990 index 6bd44fe..96f364e 100644
81991 --- a/include/net/sctp/checksum.h
81992 +++ b/include/net/sctp/checksum.h
81993 @@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
81994 unsigned int offset)
81995 {
81996 struct sctphdr *sh = sctp_hdr(skb);
81997 - __le32 ret, old = sh->checksum;
81998 - const struct skb_checksum_ops ops = {
81999 + __le32 ret, old = sh->checksum;
82000 + static const struct skb_checksum_ops ops = {
82001 .update = sctp_csum_update,
82002 .combine = sctp_csum_combine,
82003 };
82004 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
82005 index 4ef75af..5aa073a 100644
82006 --- a/include/net/sctp/sm.h
82007 +++ b/include/net/sctp/sm.h
82008 @@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
82009 typedef struct {
82010 sctp_state_fn_t *fn;
82011 const char *name;
82012 -} sctp_sm_table_entry_t;
82013 +} __do_const sctp_sm_table_entry_t;
82014
82015 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
82016 * currently in use.
82017 @@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
82018 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
82019
82020 /* Extern declarations for major data structures. */
82021 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82022 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82023
82024
82025 /* Get the size of a DATA chunk payload. */
82026 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
82027 index 0a248b3..4dcbe5c 100644
82028 --- a/include/net/sctp/structs.h
82029 +++ b/include/net/sctp/structs.h
82030 @@ -508,7 +508,7 @@ struct sctp_pf {
82031 struct sctp_association *asoc);
82032 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
82033 struct sctp_af *af;
82034 -};
82035 +} __do_const;
82036
82037
82038 /* Structure to track chunk fragments that have been acked, but peer
82039 diff --git a/include/net/sock.h b/include/net/sock.h
82040 index 2ef3c3e..e02013e 100644
82041 --- a/include/net/sock.h
82042 +++ b/include/net/sock.h
82043 @@ -348,7 +348,7 @@ struct sock {
82044 unsigned int sk_napi_id;
82045 unsigned int sk_ll_usec;
82046 #endif
82047 - atomic_t sk_drops;
82048 + atomic_unchecked_t sk_drops;
82049 int sk_rcvbuf;
82050
82051 struct sk_filter __rcu *sk_filter;
82052 @@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
82053 return ret >> PAGE_SHIFT;
82054 }
82055
82056 -static inline long
82057 +static inline long __intentional_overflow(-1)
82058 sk_memory_allocated(const struct sock *sk)
82059 {
82060 struct proto *prot = sk->sk_prot;
82061 @@ -1813,7 +1813,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
82062 }
82063
82064 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
82065 - char __user *from, char *to,
82066 + char __user *from, unsigned char *to,
82067 int copy, int offset)
82068 {
82069 if (skb->ip_summed == CHECKSUM_NONE) {
82070 @@ -2075,7 +2075,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
82071 }
82072 }
82073
82074 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82075 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82076
82077 /**
82078 * sk_page_frag - return an appropriate page_frag
82079 diff --git a/include/net/tcp.h b/include/net/tcp.h
82080 index 70e55d2..c5d8d53 100644
82081 --- a/include/net/tcp.h
82082 +++ b/include/net/tcp.h
82083 @@ -540,7 +540,7 @@ void tcp_retransmit_timer(struct sock *sk);
82084 void tcp_xmit_retransmit_queue(struct sock *);
82085 void tcp_simple_retransmit(struct sock *);
82086 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
82087 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
82088 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
82089
82090 void tcp_send_probe0(struct sock *);
82091 void tcp_send_partial(struct sock *);
82092 @@ -711,8 +711,8 @@ struct tcp_skb_cb {
82093 struct inet6_skb_parm h6;
82094 #endif
82095 } header; /* For incoming frames */
82096 - __u32 seq; /* Starting sequence number */
82097 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
82098 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
82099 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
82100 __u32 when; /* used to compute rtt's */
82101 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
82102
82103 @@ -726,7 +726,7 @@ struct tcp_skb_cb {
82104
82105 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
82106 /* 1 byte hole */
82107 - __u32 ack_seq; /* Sequence number ACK'd */
82108 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
82109 };
82110
82111 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
82112 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
82113 index 6b82fdf..14d74d2 100644
82114 --- a/include/net/xfrm.h
82115 +++ b/include/net/xfrm.h
82116 @@ -287,7 +287,6 @@ struct xfrm_dst;
82117 struct xfrm_policy_afinfo {
82118 unsigned short family;
82119 struct dst_ops *dst_ops;
82120 - void (*garbage_collect)(struct net *net);
82121 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
82122 const xfrm_address_t *saddr,
82123 const xfrm_address_t *daddr);
82124 @@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
82125 struct net_device *dev,
82126 const struct flowi *fl);
82127 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
82128 -};
82129 +} __do_const;
82130
82131 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
82132 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
82133 @@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
82134 int (*transport_finish)(struct sk_buff *skb,
82135 int async);
82136 void (*local_error)(struct sk_buff *skb, u32 mtu);
82137 -};
82138 +} __do_const;
82139
82140 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
82141 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
82142 @@ -429,7 +428,7 @@ struct xfrm_mode {
82143 struct module *owner;
82144 unsigned int encap;
82145 int flags;
82146 -};
82147 +} __do_const;
82148
82149 /* Flags for xfrm_mode. */
82150 enum {
82151 @@ -526,7 +525,7 @@ struct xfrm_policy {
82152 struct timer_list timer;
82153
82154 struct flow_cache_object flo;
82155 - atomic_t genid;
82156 + atomic_unchecked_t genid;
82157 u32 priority;
82158 u32 index;
82159 struct xfrm_mark mark;
82160 @@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
82161 }
82162
82163 void xfrm_garbage_collect(struct net *net);
82164 +void xfrm_garbage_collect_deferred(struct net *net);
82165
82166 #else
82167
82168 @@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
82169 static inline void xfrm_garbage_collect(struct net *net)
82170 {
82171 }
82172 +static inline void xfrm_garbage_collect_deferred(struct net *net)
82173 +{
82174 +}
82175 #endif
82176
82177 static __inline__
82178 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
82179 index 1017e0b..227aa4d 100644
82180 --- a/include/rdma/iw_cm.h
82181 +++ b/include/rdma/iw_cm.h
82182 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
82183 int backlog);
82184
82185 int (*destroy_listen)(struct iw_cm_id *cm_id);
82186 -};
82187 +} __no_const;
82188
82189 /**
82190 * iw_create_cm_id - Create an IW CM identifier.
82191 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
82192 index 52beadf..598734c 100644
82193 --- a/include/scsi/libfc.h
82194 +++ b/include/scsi/libfc.h
82195 @@ -771,6 +771,7 @@ struct libfc_function_template {
82196 */
82197 void (*disc_stop_final) (struct fc_lport *);
82198 };
82199 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
82200
82201 /**
82202 * struct fc_disc - Discovery context
82203 @@ -875,7 +876,7 @@ struct fc_lport {
82204 struct fc_vport *vport;
82205
82206 /* Operational Information */
82207 - struct libfc_function_template tt;
82208 + libfc_function_template_no_const tt;
82209 u8 link_up;
82210 u8 qfull;
82211 enum fc_lport_state state;
82212 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
82213 index d65fbec..f80fef2 100644
82214 --- a/include/scsi/scsi_device.h
82215 +++ b/include/scsi/scsi_device.h
82216 @@ -180,9 +180,9 @@ struct scsi_device {
82217 unsigned int max_device_blocked; /* what device_blocked counts down from */
82218 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
82219
82220 - atomic_t iorequest_cnt;
82221 - atomic_t iodone_cnt;
82222 - atomic_t ioerr_cnt;
82223 + atomic_unchecked_t iorequest_cnt;
82224 + atomic_unchecked_t iodone_cnt;
82225 + atomic_unchecked_t ioerr_cnt;
82226
82227 struct device sdev_gendev,
82228 sdev_dev;
82229 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
82230 index b797e8f..8e2c3aa 100644
82231 --- a/include/scsi/scsi_transport_fc.h
82232 +++ b/include/scsi/scsi_transport_fc.h
82233 @@ -751,7 +751,8 @@ struct fc_function_template {
82234 unsigned long show_host_system_hostname:1;
82235
82236 unsigned long disable_target_scan:1;
82237 -};
82238 +} __do_const;
82239 +typedef struct fc_function_template __no_const fc_function_template_no_const;
82240
82241
82242 /**
82243 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
82244 index ae6c3b8..fd748ac 100644
82245 --- a/include/sound/compress_driver.h
82246 +++ b/include/sound/compress_driver.h
82247 @@ -128,7 +128,7 @@ struct snd_compr_ops {
82248 struct snd_compr_caps *caps);
82249 int (*get_codec_caps) (struct snd_compr_stream *stream,
82250 struct snd_compr_codec_caps *codec);
82251 -};
82252 +} __no_const;
82253
82254 /**
82255 * struct snd_compr: Compressed device
82256 diff --git a/include/sound/soc.h b/include/sound/soc.h
82257 index 1f741cb..8cefc08 100644
82258 --- a/include/sound/soc.h
82259 +++ b/include/sound/soc.h
82260 @@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
82261 /* probe ordering - for components with runtime dependencies */
82262 int probe_order;
82263 int remove_order;
82264 -};
82265 +} __do_const;
82266
82267 /* SoC platform interface */
82268 struct snd_soc_platform_driver {
82269 @@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
82270 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
82271 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
82272 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
82273 -};
82274 +} __do_const;
82275
82276 struct snd_soc_platform {
82277 const char *name;
82278 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
82279 index 321301c..2ae5cb0 100644
82280 --- a/include/target/target_core_base.h
82281 +++ b/include/target/target_core_base.h
82282 @@ -687,7 +687,7 @@ struct se_device {
82283 atomic_long_t write_bytes;
82284 /* Active commands on this virtual SE device */
82285 atomic_t simple_cmds;
82286 - atomic_t dev_ordered_id;
82287 + atomic_unchecked_t dev_ordered_id;
82288 atomic_t dev_ordered_sync;
82289 atomic_t dev_qf_count;
82290 int export_count;
82291 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
82292 new file mode 100644
82293 index 0000000..fb634b7
82294 --- /dev/null
82295 +++ b/include/trace/events/fs.h
82296 @@ -0,0 +1,53 @@
82297 +#undef TRACE_SYSTEM
82298 +#define TRACE_SYSTEM fs
82299 +
82300 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
82301 +#define _TRACE_FS_H
82302 +
82303 +#include <linux/fs.h>
82304 +#include <linux/tracepoint.h>
82305 +
82306 +TRACE_EVENT(do_sys_open,
82307 +
82308 + TP_PROTO(const char *filename, int flags, int mode),
82309 +
82310 + TP_ARGS(filename, flags, mode),
82311 +
82312 + TP_STRUCT__entry(
82313 + __string( filename, filename )
82314 + __field( int, flags )
82315 + __field( int, mode )
82316 + ),
82317 +
82318 + TP_fast_assign(
82319 + __assign_str(filename, filename);
82320 + __entry->flags = flags;
82321 + __entry->mode = mode;
82322 + ),
82323 +
82324 + TP_printk("\"%s\" %x %o",
82325 + __get_str(filename), __entry->flags, __entry->mode)
82326 +);
82327 +
82328 +TRACE_EVENT(open_exec,
82329 +
82330 + TP_PROTO(const char *filename),
82331 +
82332 + TP_ARGS(filename),
82333 +
82334 + TP_STRUCT__entry(
82335 + __string( filename, filename )
82336 + ),
82337 +
82338 + TP_fast_assign(
82339 + __assign_str(filename, filename);
82340 + ),
82341 +
82342 + TP_printk("\"%s\"",
82343 + __get_str(filename))
82344 +);
82345 +
82346 +#endif /* _TRACE_FS_H */
82347 +
82348 +/* This part must be outside protection */
82349 +#include <trace/define_trace.h>
82350 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
82351 index 1c09820..7f5ec79 100644
82352 --- a/include/trace/events/irq.h
82353 +++ b/include/trace/events/irq.h
82354 @@ -36,7 +36,7 @@ struct softirq_action;
82355 */
82356 TRACE_EVENT(irq_handler_entry,
82357
82358 - TP_PROTO(int irq, struct irqaction *action),
82359 + TP_PROTO(int irq, const struct irqaction *action),
82360
82361 TP_ARGS(irq, action),
82362
82363 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
82364 */
82365 TRACE_EVENT(irq_handler_exit,
82366
82367 - TP_PROTO(int irq, struct irqaction *action, int ret),
82368 + TP_PROTO(int irq, const struct irqaction *action, int ret),
82369
82370 TP_ARGS(irq, action, ret),
82371
82372 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
82373 index 7caf44c..23c6f27 100644
82374 --- a/include/uapi/linux/a.out.h
82375 +++ b/include/uapi/linux/a.out.h
82376 @@ -39,6 +39,14 @@ enum machine_type {
82377 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
82378 };
82379
82380 +/* Constants for the N_FLAGS field */
82381 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82382 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
82383 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
82384 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
82385 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82386 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82387 +
82388 #if !defined (N_MAGIC)
82389 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
82390 #endif
82391 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
82392 index d876736..ccce5c0 100644
82393 --- a/include/uapi/linux/byteorder/little_endian.h
82394 +++ b/include/uapi/linux/byteorder/little_endian.h
82395 @@ -42,51 +42,51 @@
82396
82397 static inline __le64 __cpu_to_le64p(const __u64 *p)
82398 {
82399 - return (__force __le64)*p;
82400 + return (__force const __le64)*p;
82401 }
82402 -static inline __u64 __le64_to_cpup(const __le64 *p)
82403 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
82404 {
82405 - return (__force __u64)*p;
82406 + return (__force const __u64)*p;
82407 }
82408 static inline __le32 __cpu_to_le32p(const __u32 *p)
82409 {
82410 - return (__force __le32)*p;
82411 + return (__force const __le32)*p;
82412 }
82413 static inline __u32 __le32_to_cpup(const __le32 *p)
82414 {
82415 - return (__force __u32)*p;
82416 + return (__force const __u32)*p;
82417 }
82418 static inline __le16 __cpu_to_le16p(const __u16 *p)
82419 {
82420 - return (__force __le16)*p;
82421 + return (__force const __le16)*p;
82422 }
82423 static inline __u16 __le16_to_cpup(const __le16 *p)
82424 {
82425 - return (__force __u16)*p;
82426 + return (__force const __u16)*p;
82427 }
82428 static inline __be64 __cpu_to_be64p(const __u64 *p)
82429 {
82430 - return (__force __be64)__swab64p(p);
82431 + return (__force const __be64)__swab64p(p);
82432 }
82433 static inline __u64 __be64_to_cpup(const __be64 *p)
82434 {
82435 - return __swab64p((__u64 *)p);
82436 + return __swab64p((const __u64 *)p);
82437 }
82438 static inline __be32 __cpu_to_be32p(const __u32 *p)
82439 {
82440 - return (__force __be32)__swab32p(p);
82441 + return (__force const __be32)__swab32p(p);
82442 }
82443 -static inline __u32 __be32_to_cpup(const __be32 *p)
82444 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
82445 {
82446 - return __swab32p((__u32 *)p);
82447 + return __swab32p((const __u32 *)p);
82448 }
82449 static inline __be16 __cpu_to_be16p(const __u16 *p)
82450 {
82451 - return (__force __be16)__swab16p(p);
82452 + return (__force const __be16)__swab16p(p);
82453 }
82454 static inline __u16 __be16_to_cpup(const __be16 *p)
82455 {
82456 - return __swab16p((__u16 *)p);
82457 + return __swab16p((const __u16 *)p);
82458 }
82459 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
82460 #define __le64_to_cpus(x) do { (void)(x); } while (0)
82461 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
82462 index ef6103b..d4e65dd 100644
82463 --- a/include/uapi/linux/elf.h
82464 +++ b/include/uapi/linux/elf.h
82465 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
82466 #define PT_GNU_EH_FRAME 0x6474e550
82467
82468 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
82469 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
82470 +
82471 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
82472 +
82473 +/* Constants for the e_flags field */
82474 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82475 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
82476 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
82477 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
82478 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82479 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82480
82481 /*
82482 * Extended Numbering
82483 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
82484 #define DT_DEBUG 21
82485 #define DT_TEXTREL 22
82486 #define DT_JMPREL 23
82487 +#define DT_FLAGS 30
82488 + #define DF_TEXTREL 0x00000004
82489 #define DT_ENCODING 32
82490 #define OLD_DT_LOOS 0x60000000
82491 #define DT_LOOS 0x6000000d
82492 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
82493 #define PF_W 0x2
82494 #define PF_X 0x1
82495
82496 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
82497 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
82498 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
82499 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
82500 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
82501 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
82502 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
82503 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
82504 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
82505 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
82506 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
82507 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
82508 +
82509 typedef struct elf32_phdr{
82510 Elf32_Word p_type;
82511 Elf32_Off p_offset;
82512 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
82513 #define EI_OSABI 7
82514 #define EI_PAD 8
82515
82516 +#define EI_PAX 14
82517 +
82518 #define ELFMAG0 0x7f /* EI_MAG */
82519 #define ELFMAG1 'E'
82520 #define ELFMAG2 'L'
82521 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
82522 index aa169c4..6a2771d 100644
82523 --- a/include/uapi/linux/personality.h
82524 +++ b/include/uapi/linux/personality.h
82525 @@ -30,6 +30,7 @@ enum {
82526 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
82527 ADDR_NO_RANDOMIZE | \
82528 ADDR_COMPAT_LAYOUT | \
82529 + ADDR_LIMIT_3GB | \
82530 MMAP_PAGE_ZERO)
82531
82532 /*
82533 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
82534 index 7530e74..e714828 100644
82535 --- a/include/uapi/linux/screen_info.h
82536 +++ b/include/uapi/linux/screen_info.h
82537 @@ -43,7 +43,8 @@ struct screen_info {
82538 __u16 pages; /* 0x32 */
82539 __u16 vesa_attributes; /* 0x34 */
82540 __u32 capabilities; /* 0x36 */
82541 - __u8 _reserved[6]; /* 0x3a */
82542 + __u16 vesapm_size; /* 0x3a */
82543 + __u8 _reserved[4]; /* 0x3c */
82544 } __attribute__((packed));
82545
82546 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
82547 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
82548 index 0e011eb..82681b1 100644
82549 --- a/include/uapi/linux/swab.h
82550 +++ b/include/uapi/linux/swab.h
82551 @@ -43,7 +43,7 @@
82552 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
82553 */
82554
82555 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
82556 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
82557 {
82558 #ifdef __HAVE_BUILTIN_BSWAP16__
82559 return __builtin_bswap16(val);
82560 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
82561 #endif
82562 }
82563
82564 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
82565 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
82566 {
82567 #ifdef __HAVE_BUILTIN_BSWAP32__
82568 return __builtin_bswap32(val);
82569 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
82570 #endif
82571 }
82572
82573 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
82574 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
82575 {
82576 #ifdef __HAVE_BUILTIN_BSWAP64__
82577 return __builtin_bswap64(val);
82578 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
82579 index 6d67213..552fdd9 100644
82580 --- a/include/uapi/linux/sysctl.h
82581 +++ b/include/uapi/linux/sysctl.h
82582 @@ -155,8 +155,6 @@ enum
82583 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
82584 };
82585
82586 -
82587 -
82588 /* CTL_VM names: */
82589 enum
82590 {
82591 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
82592 index 437f1b0..0eeb38d 100644
82593 --- a/include/uapi/linux/videodev2.h
82594 +++ b/include/uapi/linux/videodev2.h
82595 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
82596 union {
82597 __s32 value;
82598 __s64 value64;
82599 - char *string;
82600 + char __user *string;
82601 };
82602 } __attribute__ ((packed));
82603
82604 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
82605 index e4629b9..6958086 100644
82606 --- a/include/uapi/linux/xattr.h
82607 +++ b/include/uapi/linux/xattr.h
82608 @@ -63,5 +63,9 @@
82609 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
82610 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
82611
82612 +/* User namespace */
82613 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
82614 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
82615 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
82616
82617 #endif /* _UAPI_LINUX_XATTR_H */
82618 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
82619 index f9466fa..f4e2b81 100644
82620 --- a/include/video/udlfb.h
82621 +++ b/include/video/udlfb.h
82622 @@ -53,10 +53,10 @@ struct dlfb_data {
82623 u32 pseudo_palette[256];
82624 int blank_mode; /*one of FB_BLANK_ */
82625 /* blit-only rendering path metrics, exposed through sysfs */
82626 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82627 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
82628 - atomic_t bytes_sent; /* to usb, after compression including overhead */
82629 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
82630 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82631 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
82632 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
82633 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
82634 };
82635
82636 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
82637 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
82638 index 30f5362..8ed8ac9 100644
82639 --- a/include/video/uvesafb.h
82640 +++ b/include/video/uvesafb.h
82641 @@ -122,6 +122,7 @@ struct uvesafb_par {
82642 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
82643 u8 pmi_setpal; /* PMI for palette changes */
82644 u16 *pmi_base; /* protected mode interface location */
82645 + u8 *pmi_code; /* protected mode code location */
82646 void *pmi_start;
82647 void *pmi_pal;
82648 u8 *vbe_state_orig; /*
82649 diff --git a/init/Kconfig b/init/Kconfig
82650 index 4e5d96a..93cd8a1 100644
82651 --- a/init/Kconfig
82652 +++ b/init/Kconfig
82653 @@ -1079,6 +1079,7 @@ endif # CGROUPS
82654
82655 config CHECKPOINT_RESTORE
82656 bool "Checkpoint/restore support" if EXPERT
82657 + depends on !GRKERNSEC
82658 default n
82659 help
82660 Enables additional kernel features in a sake of checkpoint/restore.
82661 @@ -1550,7 +1551,7 @@ config SLUB_DEBUG
82662
82663 config COMPAT_BRK
82664 bool "Disable heap randomization"
82665 - default y
82666 + default n
82667 help
82668 Randomizing heap placement makes heap exploits harder, but it
82669 also breaks ancient binaries (including anything libc5 based).
82670 @@ -1838,7 +1839,7 @@ config INIT_ALL_POSSIBLE
82671 config STOP_MACHINE
82672 bool
82673 default y
82674 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
82675 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
82676 help
82677 Need stop_machine() primitive.
82678
82679 diff --git a/init/Makefile b/init/Makefile
82680 index 7bc47ee..6da2dc7 100644
82681 --- a/init/Makefile
82682 +++ b/init/Makefile
82683 @@ -2,6 +2,9 @@
82684 # Makefile for the linux kernel.
82685 #
82686
82687 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
82688 +asflags-y := $(GCC_PLUGINS_AFLAGS)
82689 +
82690 obj-y := main.o version.o mounts.o
82691 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
82692 obj-y += noinitramfs.o
82693 diff --git a/init/do_mounts.c b/init/do_mounts.c
82694 index 8e5addc..c96ea61 100644
82695 --- a/init/do_mounts.c
82696 +++ b/init/do_mounts.c
82697 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
82698 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
82699 {
82700 struct super_block *s;
82701 - int err = sys_mount(name, "/root", fs, flags, data);
82702 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
82703 if (err)
82704 return err;
82705
82706 - sys_chdir("/root");
82707 + sys_chdir((const char __force_user *)"/root");
82708 s = current->fs->pwd.dentry->d_sb;
82709 ROOT_DEV = s->s_dev;
82710 printk(KERN_INFO
82711 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
82712 va_start(args, fmt);
82713 vsprintf(buf, fmt, args);
82714 va_end(args);
82715 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
82716 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
82717 if (fd >= 0) {
82718 sys_ioctl(fd, FDEJECT, 0);
82719 sys_close(fd);
82720 }
82721 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
82722 - fd = sys_open("/dev/console", O_RDWR, 0);
82723 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
82724 if (fd >= 0) {
82725 sys_ioctl(fd, TCGETS, (long)&termios);
82726 termios.c_lflag &= ~ICANON;
82727 sys_ioctl(fd, TCSETSF, (long)&termios);
82728 - sys_read(fd, &c, 1);
82729 + sys_read(fd, (char __user *)&c, 1);
82730 termios.c_lflag |= ICANON;
82731 sys_ioctl(fd, TCSETSF, (long)&termios);
82732 sys_close(fd);
82733 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
82734 mount_root();
82735 out:
82736 devtmpfs_mount("dev");
82737 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
82738 - sys_chroot(".");
82739 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82740 + sys_chroot((const char __force_user *)".");
82741 }
82742
82743 static bool is_tmpfs;
82744 diff --git a/init/do_mounts.h b/init/do_mounts.h
82745 index f5b978a..69dbfe8 100644
82746 --- a/init/do_mounts.h
82747 +++ b/init/do_mounts.h
82748 @@ -15,15 +15,15 @@ extern int root_mountflags;
82749
82750 static inline int create_dev(char *name, dev_t dev)
82751 {
82752 - sys_unlink(name);
82753 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
82754 + sys_unlink((char __force_user *)name);
82755 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
82756 }
82757
82758 #if BITS_PER_LONG == 32
82759 static inline u32 bstat(char *name)
82760 {
82761 struct stat64 stat;
82762 - if (sys_stat64(name, &stat) != 0)
82763 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
82764 return 0;
82765 if (!S_ISBLK(stat.st_mode))
82766 return 0;
82767 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
82768 static inline u32 bstat(char *name)
82769 {
82770 struct stat stat;
82771 - if (sys_newstat(name, &stat) != 0)
82772 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
82773 return 0;
82774 if (!S_ISBLK(stat.st_mode))
82775 return 0;
82776 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
82777 index 3e0878e..8a9d7a0 100644
82778 --- a/init/do_mounts_initrd.c
82779 +++ b/init/do_mounts_initrd.c
82780 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
82781 {
82782 sys_unshare(CLONE_FS | CLONE_FILES);
82783 /* stdin/stdout/stderr for /linuxrc */
82784 - sys_open("/dev/console", O_RDWR, 0);
82785 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
82786 sys_dup(0);
82787 sys_dup(0);
82788 /* move initrd over / and chdir/chroot in initrd root */
82789 - sys_chdir("/root");
82790 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
82791 - sys_chroot(".");
82792 + sys_chdir((const char __force_user *)"/root");
82793 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82794 + sys_chroot((const char __force_user *)".");
82795 sys_setsid();
82796 return 0;
82797 }
82798 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
82799 create_dev("/dev/root.old", Root_RAM0);
82800 /* mount initrd on rootfs' /root */
82801 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
82802 - sys_mkdir("/old", 0700);
82803 - sys_chdir("/old");
82804 + sys_mkdir((const char __force_user *)"/old", 0700);
82805 + sys_chdir((const char __force_user *)"/old");
82806
82807 /* try loading default modules from initrd */
82808 load_default_modules();
82809 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
82810 current->flags &= ~PF_FREEZER_SKIP;
82811
82812 /* move initrd to rootfs' /old */
82813 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
82814 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
82815 /* switch root and cwd back to / of rootfs */
82816 - sys_chroot("..");
82817 + sys_chroot((const char __force_user *)"..");
82818
82819 if (new_decode_dev(real_root_dev) == Root_RAM0) {
82820 - sys_chdir("/old");
82821 + sys_chdir((const char __force_user *)"/old");
82822 return;
82823 }
82824
82825 - sys_chdir("/");
82826 + sys_chdir((const char __force_user *)"/");
82827 ROOT_DEV = new_decode_dev(real_root_dev);
82828 mount_root();
82829
82830 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
82831 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
82832 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
82833 if (!error)
82834 printk("okay\n");
82835 else {
82836 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
82837 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
82838 if (error == -ENOENT)
82839 printk("/initrd does not exist. Ignored.\n");
82840 else
82841 printk("failed\n");
82842 printk(KERN_NOTICE "Unmounting old root\n");
82843 - sys_umount("/old", MNT_DETACH);
82844 + sys_umount((char __force_user *)"/old", MNT_DETACH);
82845 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
82846 if (fd < 0) {
82847 error = fd;
82848 @@ -127,11 +127,11 @@ int __init initrd_load(void)
82849 * mounted in the normal path.
82850 */
82851 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
82852 - sys_unlink("/initrd.image");
82853 + sys_unlink((const char __force_user *)"/initrd.image");
82854 handle_initrd();
82855 return 1;
82856 }
82857 }
82858 - sys_unlink("/initrd.image");
82859 + sys_unlink((const char __force_user *)"/initrd.image");
82860 return 0;
82861 }
82862 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
82863 index 8cb6db5..d729f50 100644
82864 --- a/init/do_mounts_md.c
82865 +++ b/init/do_mounts_md.c
82866 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
82867 partitioned ? "_d" : "", minor,
82868 md_setup_args[ent].device_names);
82869
82870 - fd = sys_open(name, 0, 0);
82871 + fd = sys_open((char __force_user *)name, 0, 0);
82872 if (fd < 0) {
82873 printk(KERN_ERR "md: open failed - cannot start "
82874 "array %s\n", name);
82875 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
82876 * array without it
82877 */
82878 sys_close(fd);
82879 - fd = sys_open(name, 0, 0);
82880 + fd = sys_open((char __force_user *)name, 0, 0);
82881 sys_ioctl(fd, BLKRRPART, 0);
82882 }
82883 sys_close(fd);
82884 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
82885
82886 wait_for_device_probe();
82887
82888 - fd = sys_open("/dev/md0", 0, 0);
82889 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
82890 if (fd >= 0) {
82891 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
82892 sys_close(fd);
82893 diff --git a/init/init_task.c b/init/init_task.c
82894 index ba0a7f36..2bcf1d5 100644
82895 --- a/init/init_task.c
82896 +++ b/init/init_task.c
82897 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
82898 * Initial thread structure. Alignment of this is handled by a special
82899 * linker map entry.
82900 */
82901 +#ifdef CONFIG_X86
82902 +union thread_union init_thread_union __init_task_data;
82903 +#else
82904 union thread_union init_thread_union __init_task_data =
82905 { INIT_THREAD_INFO(init_task) };
82906 +#endif
82907 diff --git a/init/initramfs.c b/init/initramfs.c
82908 index a67ef9d..2d17ed9 100644
82909 --- a/init/initramfs.c
82910 +++ b/init/initramfs.c
82911 @@ -84,7 +84,7 @@ static void __init free_hash(void)
82912 }
82913 }
82914
82915 -static long __init do_utime(char *filename, time_t mtime)
82916 +static long __init do_utime(char __force_user *filename, time_t mtime)
82917 {
82918 struct timespec t[2];
82919
82920 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
82921 struct dir_entry *de, *tmp;
82922 list_for_each_entry_safe(de, tmp, &dir_list, list) {
82923 list_del(&de->list);
82924 - do_utime(de->name, de->mtime);
82925 + do_utime((char __force_user *)de->name, de->mtime);
82926 kfree(de->name);
82927 kfree(de);
82928 }
82929 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
82930 if (nlink >= 2) {
82931 char *old = find_link(major, minor, ino, mode, collected);
82932 if (old)
82933 - return (sys_link(old, collected) < 0) ? -1 : 1;
82934 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
82935 }
82936 return 0;
82937 }
82938 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
82939 {
82940 struct stat st;
82941
82942 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
82943 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
82944 if (S_ISDIR(st.st_mode))
82945 - sys_rmdir(path);
82946 + sys_rmdir((char __force_user *)path);
82947 else
82948 - sys_unlink(path);
82949 + sys_unlink((char __force_user *)path);
82950 }
82951 }
82952
82953 @@ -315,7 +315,7 @@ static int __init do_name(void)
82954 int openflags = O_WRONLY|O_CREAT;
82955 if (ml != 1)
82956 openflags |= O_TRUNC;
82957 - wfd = sys_open(collected, openflags, mode);
82958 + wfd = sys_open((char __force_user *)collected, openflags, mode);
82959
82960 if (wfd >= 0) {
82961 sys_fchown(wfd, uid, gid);
82962 @@ -327,17 +327,17 @@ static int __init do_name(void)
82963 }
82964 }
82965 } else if (S_ISDIR(mode)) {
82966 - sys_mkdir(collected, mode);
82967 - sys_chown(collected, uid, gid);
82968 - sys_chmod(collected, mode);
82969 + sys_mkdir((char __force_user *)collected, mode);
82970 + sys_chown((char __force_user *)collected, uid, gid);
82971 + sys_chmod((char __force_user *)collected, mode);
82972 dir_add(collected, mtime);
82973 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
82974 S_ISFIFO(mode) || S_ISSOCK(mode)) {
82975 if (maybe_link() == 0) {
82976 - sys_mknod(collected, mode, rdev);
82977 - sys_chown(collected, uid, gid);
82978 - sys_chmod(collected, mode);
82979 - do_utime(collected, mtime);
82980 + sys_mknod((char __force_user *)collected, mode, rdev);
82981 + sys_chown((char __force_user *)collected, uid, gid);
82982 + sys_chmod((char __force_user *)collected, mode);
82983 + do_utime((char __force_user *)collected, mtime);
82984 }
82985 }
82986 return 0;
82987 @@ -346,15 +346,15 @@ static int __init do_name(void)
82988 static int __init do_copy(void)
82989 {
82990 if (count >= body_len) {
82991 - sys_write(wfd, victim, body_len);
82992 + sys_write(wfd, (char __force_user *)victim, body_len);
82993 sys_close(wfd);
82994 - do_utime(vcollected, mtime);
82995 + do_utime((char __force_user *)vcollected, mtime);
82996 kfree(vcollected);
82997 eat(body_len);
82998 state = SkipIt;
82999 return 0;
83000 } else {
83001 - sys_write(wfd, victim, count);
83002 + sys_write(wfd, (char __force_user *)victim, count);
83003 body_len -= count;
83004 eat(count);
83005 return 1;
83006 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
83007 {
83008 collected[N_ALIGN(name_len) + body_len] = '\0';
83009 clean_path(collected, 0);
83010 - sys_symlink(collected + N_ALIGN(name_len), collected);
83011 - sys_lchown(collected, uid, gid);
83012 - do_utime(collected, mtime);
83013 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
83014 + sys_lchown((char __force_user *)collected, uid, gid);
83015 + do_utime((char __force_user *)collected, mtime);
83016 state = SkipIt;
83017 next_state = Reset;
83018 return 0;
83019 @@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
83020 {
83021 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
83022 if (err)
83023 - panic(err); /* Failed to decompress INTERNAL initramfs */
83024 + panic("%s", err); /* Failed to decompress INTERNAL initramfs */
83025 if (initrd_start) {
83026 #ifdef CONFIG_BLK_DEV_RAM
83027 int fd;
83028 diff --git a/init/main.c b/init/main.c
83029 index febc511..f0851763 100644
83030 --- a/init/main.c
83031 +++ b/init/main.c
83032 @@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
83033 extern void tc_init(void);
83034 #endif
83035
83036 +extern void grsecurity_init(void);
83037 +
83038 /*
83039 * Debug helper: via this flag we know that we are in 'early bootup code'
83040 * where only the boot processor is running with IRQ disabled. This means
83041 @@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
83042
83043 __setup("reset_devices", set_reset_devices);
83044
83045 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83046 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
83047 +static int __init setup_grsec_proc_gid(char *str)
83048 +{
83049 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
83050 + return 1;
83051 +}
83052 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
83053 +#endif
83054 +
83055 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
83056 +unsigned long pax_user_shadow_base __read_only;
83057 +EXPORT_SYMBOL(pax_user_shadow_base);
83058 +extern char pax_enter_kernel_user[];
83059 +extern char pax_exit_kernel_user[];
83060 +#endif
83061 +
83062 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
83063 +static int __init setup_pax_nouderef(char *str)
83064 +{
83065 +#ifdef CONFIG_X86_32
83066 + unsigned int cpu;
83067 + struct desc_struct *gdt;
83068 +
83069 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
83070 + gdt = get_cpu_gdt_table(cpu);
83071 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
83072 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
83073 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
83074 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
83075 + }
83076 + loadsegment(ds, __KERNEL_DS);
83077 + loadsegment(es, __KERNEL_DS);
83078 + loadsegment(ss, __KERNEL_DS);
83079 +#else
83080 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
83081 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
83082 + clone_pgd_mask = ~(pgdval_t)0UL;
83083 + pax_user_shadow_base = 0UL;
83084 + setup_clear_cpu_cap(X86_FEATURE_PCID);
83085 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
83086 +#endif
83087 +
83088 + return 0;
83089 +}
83090 +early_param("pax_nouderef", setup_pax_nouderef);
83091 +
83092 +#ifdef CONFIG_X86_64
83093 +static int __init setup_pax_weakuderef(char *str)
83094 +{
83095 + if (clone_pgd_mask != ~(pgdval_t)0UL)
83096 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
83097 + return 1;
83098 +}
83099 +__setup("pax_weakuderef", setup_pax_weakuderef);
83100 +#endif
83101 +#endif
83102 +
83103 +#ifdef CONFIG_PAX_SOFTMODE
83104 +int pax_softmode;
83105 +
83106 +static int __init setup_pax_softmode(char *str)
83107 +{
83108 + get_option(&str, &pax_softmode);
83109 + return 1;
83110 +}
83111 +__setup("pax_softmode=", setup_pax_softmode);
83112 +#endif
83113 +
83114 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
83115 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
83116 static const char *panic_later, *panic_param;
83117 @@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
83118 {
83119 int count = preempt_count();
83120 int ret;
83121 - char msgbuf[64];
83122 + const char *msg1 = "", *msg2 = "";
83123
83124 if (initcall_debug)
83125 ret = do_one_initcall_debug(fn);
83126 else
83127 ret = fn();
83128
83129 - msgbuf[0] = 0;
83130 -
83131 if (preempt_count() != count) {
83132 - sprintf(msgbuf, "preemption imbalance ");
83133 + msg1 = " preemption imbalance";
83134 preempt_count_set(count);
83135 }
83136 if (irqs_disabled()) {
83137 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
83138 + msg2 = " disabled interrupts";
83139 local_irq_enable();
83140 }
83141 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
83142 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
83143
83144 + add_latent_entropy();
83145 return ret;
83146 }
83147
83148 @@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
83149 {
83150 argv_init[0] = init_filename;
83151 return do_execve(init_filename,
83152 - (const char __user *const __user *)argv_init,
83153 - (const char __user *const __user *)envp_init);
83154 + (const char __user *const __force_user *)argv_init,
83155 + (const char __user *const __force_user *)envp_init);
83156 }
83157
83158 static int try_to_run_init_process(const char *init_filename)
83159 @@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
83160 return ret;
83161 }
83162
83163 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83164 +extern int gr_init_ran;
83165 +#endif
83166 +
83167 static noinline void __init kernel_init_freeable(void);
83168
83169 static int __ref kernel_init(void *unused)
83170 @@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
83171 ramdisk_execute_command, ret);
83172 }
83173
83174 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83175 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
83176 + gr_init_ran = 1;
83177 +#endif
83178 +
83179 /*
83180 * We try each of these until one succeeds.
83181 *
83182 @@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
83183 do_basic_setup();
83184
83185 /* Open the /dev/console on the rootfs, this should never fail */
83186 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
83187 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
83188 pr_err("Warning: unable to open an initial console.\n");
83189
83190 (void) sys_dup(0);
83191 @@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
83192 if (!ramdisk_execute_command)
83193 ramdisk_execute_command = "/init";
83194
83195 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
83196 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
83197 ramdisk_execute_command = NULL;
83198 prepare_namespace();
83199 }
83200
83201 + grsecurity_init();
83202 +
83203 /*
83204 * Ok, we have completed the initial bootup, and
83205 * we're essentially up and running. Get rid of the
83206 diff --git a/ipc/compat.c b/ipc/compat.c
83207 index 892f658..e7c6320 100644
83208 --- a/ipc/compat.c
83209 +++ b/ipc/compat.c
83210 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
83211 COMPAT_SHMLBA);
83212 if (err < 0)
83213 return err;
83214 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
83215 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
83216 }
83217 case SHMDT:
83218 return sys_shmdt(compat_ptr(ptr));
83219 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
83220 index b0e99de..09f385c 100644
83221 --- a/ipc/ipc_sysctl.c
83222 +++ b/ipc/ipc_sysctl.c
83223 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
83224 static int proc_ipc_dointvec(ctl_table *table, int write,
83225 void __user *buffer, size_t *lenp, loff_t *ppos)
83226 {
83227 - struct ctl_table ipc_table;
83228 + ctl_table_no_const ipc_table;
83229
83230 memcpy(&ipc_table, table, sizeof(ipc_table));
83231 ipc_table.data = get_ipc(table);
83232 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
83233 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
83234 void __user *buffer, size_t *lenp, loff_t *ppos)
83235 {
83236 - struct ctl_table ipc_table;
83237 + ctl_table_no_const ipc_table;
83238
83239 memcpy(&ipc_table, table, sizeof(ipc_table));
83240 ipc_table.data = get_ipc(table);
83241 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
83242 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83243 void __user *buffer, size_t *lenp, loff_t *ppos)
83244 {
83245 - struct ctl_table ipc_table;
83246 + ctl_table_no_const ipc_table;
83247 size_t lenp_bef = *lenp;
83248 int rc;
83249
83250 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83251 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
83252 void __user *buffer, size_t *lenp, loff_t *ppos)
83253 {
83254 - struct ctl_table ipc_table;
83255 + ctl_table_no_const ipc_table;
83256 memcpy(&ipc_table, table, sizeof(ipc_table));
83257 ipc_table.data = get_ipc(table);
83258
83259 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
83260 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
83261 void __user *buffer, size_t *lenp, loff_t *ppos)
83262 {
83263 - struct ctl_table ipc_table;
83264 + ctl_table_no_const ipc_table;
83265 size_t lenp_bef = *lenp;
83266 int oldval;
83267 int rc;
83268 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
83269 index 383d638..943fdbb 100644
83270 --- a/ipc/mq_sysctl.c
83271 +++ b/ipc/mq_sysctl.c
83272 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
83273 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
83274 void __user *buffer, size_t *lenp, loff_t *ppos)
83275 {
83276 - struct ctl_table mq_table;
83277 + ctl_table_no_const mq_table;
83278 memcpy(&mq_table, table, sizeof(mq_table));
83279 mq_table.data = get_mq(table);
83280
83281 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
83282 index 95827ce..09e6d38 100644
83283 --- a/ipc/mqueue.c
83284 +++ b/ipc/mqueue.c
83285 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
83286 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
83287 info->attr.mq_msgsize);
83288
83289 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
83290 spin_lock(&mq_lock);
83291 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
83292 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
83293 diff --git a/ipc/msg.c b/ipc/msg.c
83294 index 558aa91..359e718 100644
83295 --- a/ipc/msg.c
83296 +++ b/ipc/msg.c
83297 @@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
83298 return security_msg_queue_associate(msq, msgflg);
83299 }
83300
83301 +static struct ipc_ops msg_ops = {
83302 + .getnew = newque,
83303 + .associate = msg_security,
83304 + .more_checks = NULL
83305 +};
83306 +
83307 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
83308 {
83309 struct ipc_namespace *ns;
83310 - struct ipc_ops msg_ops;
83311 struct ipc_params msg_params;
83312
83313 ns = current->nsproxy->ipc_ns;
83314
83315 - msg_ops.getnew = newque;
83316 - msg_ops.associate = msg_security;
83317 - msg_ops.more_checks = NULL;
83318 -
83319 msg_params.key = key;
83320 msg_params.flg = msgflg;
83321
83322 diff --git a/ipc/sem.c b/ipc/sem.c
83323 index db9d241..bc8427c 100644
83324 --- a/ipc/sem.c
83325 +++ b/ipc/sem.c
83326 @@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
83327 return 0;
83328 }
83329
83330 +static struct ipc_ops sem_ops = {
83331 + .getnew = newary,
83332 + .associate = sem_security,
83333 + .more_checks = sem_more_checks
83334 +};
83335 +
83336 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83337 {
83338 struct ipc_namespace *ns;
83339 - struct ipc_ops sem_ops;
83340 struct ipc_params sem_params;
83341
83342 ns = current->nsproxy->ipc_ns;
83343 @@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83344 if (nsems < 0 || nsems > ns->sc_semmsl)
83345 return -EINVAL;
83346
83347 - sem_ops.getnew = newary;
83348 - sem_ops.associate = sem_security;
83349 - sem_ops.more_checks = sem_more_checks;
83350 -
83351 sem_params.key = key;
83352 sem_params.flg = semflg;
83353 sem_params.u.nsems = nsems;
83354 diff --git a/ipc/shm.c b/ipc/shm.c
83355 index 7a51443..3a257d8 100644
83356 --- a/ipc/shm.c
83357 +++ b/ipc/shm.c
83358 @@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
83359 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
83360 #endif
83361
83362 +#ifdef CONFIG_GRKERNSEC
83363 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83364 + const time_t shm_createtime, const kuid_t cuid,
83365 + const int shmid);
83366 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83367 + const time_t shm_createtime);
83368 +#endif
83369 +
83370 void shm_init_ns(struct ipc_namespace *ns)
83371 {
83372 ns->shm_ctlmax = SHMMAX;
83373 @@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
83374 shp->shm_lprid = 0;
83375 shp->shm_atim = shp->shm_dtim = 0;
83376 shp->shm_ctim = get_seconds();
83377 +#ifdef CONFIG_GRKERNSEC
83378 + {
83379 + struct timespec timeval;
83380 + do_posix_clock_monotonic_gettime(&timeval);
83381 +
83382 + shp->shm_createtime = timeval.tv_sec;
83383 + }
83384 +#endif
83385 shp->shm_segsz = size;
83386 shp->shm_nattch = 0;
83387 shp->shm_file = file;
83388 @@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
83389 return 0;
83390 }
83391
83392 +static struct ipc_ops shm_ops = {
83393 + .getnew = newseg,
83394 + .associate = shm_security,
83395 + .more_checks = shm_more_checks
83396 +};
83397 +
83398 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
83399 {
83400 struct ipc_namespace *ns;
83401 - struct ipc_ops shm_ops;
83402 struct ipc_params shm_params;
83403
83404 ns = current->nsproxy->ipc_ns;
83405
83406 - shm_ops.getnew = newseg;
83407 - shm_ops.associate = shm_security;
83408 - shm_ops.more_checks = shm_more_checks;
83409 -
83410 shm_params.key = key;
83411 shm_params.flg = shmflg;
83412 shm_params.u.size = size;
83413 @@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83414 f_mode = FMODE_READ | FMODE_WRITE;
83415 }
83416 if (shmflg & SHM_EXEC) {
83417 +
83418 +#ifdef CONFIG_PAX_MPROTECT
83419 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
83420 + goto out;
83421 +#endif
83422 +
83423 prot |= PROT_EXEC;
83424 acc_mode |= S_IXUGO;
83425 }
83426 @@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83427 if (err)
83428 goto out_unlock;
83429
83430 +#ifdef CONFIG_GRKERNSEC
83431 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
83432 + shp->shm_perm.cuid, shmid) ||
83433 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
83434 + err = -EACCES;
83435 + goto out_unlock;
83436 + }
83437 +#endif
83438 +
83439 ipc_lock_object(&shp->shm_perm);
83440
83441 /* check if shm_destroy() is tearing down shp */
83442 @@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83443 path = shp->shm_file->f_path;
83444 path_get(&path);
83445 shp->shm_nattch++;
83446 +#ifdef CONFIG_GRKERNSEC
83447 + shp->shm_lapid = current->pid;
83448 +#endif
83449 size = i_size_read(path.dentry->d_inode);
83450 ipc_unlock_object(&shp->shm_perm);
83451 rcu_read_unlock();
83452 diff --git a/ipc/util.c b/ipc/util.c
83453 index 3ae17a4..d67c32f 100644
83454 --- a/ipc/util.c
83455 +++ b/ipc/util.c
83456 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
83457 int (*show)(struct seq_file *, void *);
83458 };
83459
83460 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
83461 +
83462 static void ipc_memory_notifier(struct work_struct *work)
83463 {
83464 ipcns_notify(IPCNS_MEMCHANGED);
83465 @@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
83466 granted_mode >>= 6;
83467 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
83468 granted_mode >>= 3;
83469 +
83470 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
83471 + return -1;
83472 +
83473 /* is there some bit set in requested_mode but not in granted_mode? */
83474 if ((requested_mode & ~granted_mode & 0007) &&
83475 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
83476 diff --git a/kernel/acct.c b/kernel/acct.c
83477 index 8d6e145..33e0b1e 100644
83478 --- a/kernel/acct.c
83479 +++ b/kernel/acct.c
83480 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
83481 */
83482 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
83483 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
83484 - file->f_op->write(file, (char *)&ac,
83485 + file->f_op->write(file, (char __force_user *)&ac,
83486 sizeof(acct_t), &file->f_pos);
83487 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
83488 set_fs(fs);
83489 diff --git a/kernel/audit.c b/kernel/audit.c
83490 index 906ae5a0..a7ad0b4 100644
83491 --- a/kernel/audit.c
83492 +++ b/kernel/audit.c
83493 @@ -117,7 +117,7 @@ u32 audit_sig_sid = 0;
83494 3) suppressed due to audit_rate_limit
83495 4) suppressed due to audit_backlog_limit
83496 */
83497 -static atomic_t audit_lost = ATOMIC_INIT(0);
83498 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
83499
83500 /* The netlink socket. */
83501 static struct sock *audit_sock;
83502 @@ -250,7 +250,7 @@ void audit_log_lost(const char *message)
83503 unsigned long now;
83504 int print;
83505
83506 - atomic_inc(&audit_lost);
83507 + atomic_inc_unchecked(&audit_lost);
83508
83509 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
83510
83511 @@ -269,7 +269,7 @@ void audit_log_lost(const char *message)
83512 printk(KERN_WARNING
83513 "audit: audit_lost=%d audit_rate_limit=%d "
83514 "audit_backlog_limit=%d\n",
83515 - atomic_read(&audit_lost),
83516 + atomic_read_unchecked(&audit_lost),
83517 audit_rate_limit,
83518 audit_backlog_limit);
83519 audit_panic(message);
83520 @@ -765,7 +765,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
83521 status_set.pid = audit_pid;
83522 status_set.rate_limit = audit_rate_limit;
83523 status_set.backlog_limit = audit_backlog_limit;
83524 - status_set.lost = atomic_read(&audit_lost);
83525 + status_set.lost = atomic_read_unchecked(&audit_lost);
83526 status_set.backlog = skb_queue_len(&audit_skb_queue);
83527 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
83528 &status_set, sizeof(status_set));
83529 @@ -1356,7 +1356,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
83530 int i, avail, new_len;
83531 unsigned char *ptr;
83532 struct sk_buff *skb;
83533 - static const unsigned char *hex = "0123456789ABCDEF";
83534 + static const unsigned char hex[] = "0123456789ABCDEF";
83535
83536 if (!ab)
83537 return;
83538 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
83539 index 90594c9..abbeed7 100644
83540 --- a/kernel/auditsc.c
83541 +++ b/kernel/auditsc.c
83542 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
83543 }
83544
83545 /* global counter which is incremented every time something logs in */
83546 -static atomic_t session_id = ATOMIC_INIT(0);
83547 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
83548
83549 static int audit_set_loginuid_perm(kuid_t loginuid)
83550 {
83551 @@ -2008,7 +2008,7 @@ int audit_set_loginuid(kuid_t loginuid)
83552
83553 /* are we setting or clearing? */
83554 if (uid_valid(loginuid))
83555 - sessionid = atomic_inc_return(&session_id);
83556 + sessionid = atomic_inc_return_unchecked(&session_id);
83557
83558 task->sessionid = sessionid;
83559 task->loginuid = loginuid;
83560 diff --git a/kernel/capability.c b/kernel/capability.c
83561 index 4e66bf9..cdccecf 100644
83562 --- a/kernel/capability.c
83563 +++ b/kernel/capability.c
83564 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
83565 * before modification is attempted and the application
83566 * fails.
83567 */
83568 + if (tocopy > ARRAY_SIZE(kdata))
83569 + return -EFAULT;
83570 +
83571 if (copy_to_user(dataptr, kdata, tocopy
83572 * sizeof(struct __user_cap_data_struct))) {
83573 return -EFAULT;
83574 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
83575 int ret;
83576
83577 rcu_read_lock();
83578 - ret = security_capable(__task_cred(t), ns, cap);
83579 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
83580 + gr_task_is_capable(t, __task_cred(t), cap);
83581 rcu_read_unlock();
83582
83583 - return (ret == 0);
83584 + return ret;
83585 }
83586
83587 /**
83588 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
83589 int ret;
83590
83591 rcu_read_lock();
83592 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
83593 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
83594 rcu_read_unlock();
83595
83596 - return (ret == 0);
83597 + return ret;
83598 }
83599
83600 /**
83601 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
83602 BUG();
83603 }
83604
83605 - if (security_capable(current_cred(), ns, cap) == 0) {
83606 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
83607 current->flags |= PF_SUPERPRIV;
83608 return true;
83609 }
83610 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
83611 }
83612 EXPORT_SYMBOL(ns_capable);
83613
83614 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
83615 +{
83616 + if (unlikely(!cap_valid(cap))) {
83617 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
83618 + BUG();
83619 + }
83620 +
83621 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
83622 + current->flags |= PF_SUPERPRIV;
83623 + return true;
83624 + }
83625 + return false;
83626 +}
83627 +EXPORT_SYMBOL(ns_capable_nolog);
83628 +
83629 /**
83630 * file_ns_capable - Determine if the file's opener had a capability in effect
83631 * @file: The file we want to check
83632 @@ -432,6 +451,12 @@ bool capable(int cap)
83633 }
83634 EXPORT_SYMBOL(capable);
83635
83636 +bool capable_nolog(int cap)
83637 +{
83638 + return ns_capable_nolog(&init_user_ns, cap);
83639 +}
83640 +EXPORT_SYMBOL(capable_nolog);
83641 +
83642 /**
83643 * inode_capable - Check superior capability over inode
83644 * @inode: The inode in question
83645 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
83646 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83647 }
83648 EXPORT_SYMBOL(inode_capable);
83649 +
83650 +bool inode_capable_nolog(const struct inode *inode, int cap)
83651 +{
83652 + struct user_namespace *ns = current_user_ns();
83653 +
83654 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83655 +}
83656 +EXPORT_SYMBOL(inode_capable_nolog);
83657 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
83658 index bc1dcab..f3a6b42 100644
83659 --- a/kernel/cgroup.c
83660 +++ b/kernel/cgroup.c
83661 @@ -5607,7 +5607,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
83662 struct css_set *cset = link->cset;
83663 struct task_struct *task;
83664 int count = 0;
83665 - seq_printf(seq, "css_set %p\n", cset);
83666 + seq_printf(seq, "css_set %pK\n", cset);
83667 list_for_each_entry(task, &cset->tasks, cg_list) {
83668 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
83669 seq_puts(seq, " ...\n");
83670 diff --git a/kernel/compat.c b/kernel/compat.c
83671 index 0a09e48..b46b3d78 100644
83672 --- a/kernel/compat.c
83673 +++ b/kernel/compat.c
83674 @@ -13,6 +13,7 @@
83675
83676 #include <linux/linkage.h>
83677 #include <linux/compat.h>
83678 +#include <linux/module.h>
83679 #include <linux/errno.h>
83680 #include <linux/time.h>
83681 #include <linux/signal.h>
83682 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
83683 mm_segment_t oldfs;
83684 long ret;
83685
83686 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
83687 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
83688 oldfs = get_fs();
83689 set_fs(KERNEL_DS);
83690 ret = hrtimer_nanosleep_restart(restart);
83691 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
83692 oldfs = get_fs();
83693 set_fs(KERNEL_DS);
83694 ret = hrtimer_nanosleep(&tu,
83695 - rmtp ? (struct timespec __user *)&rmt : NULL,
83696 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
83697 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
83698 set_fs(oldfs);
83699
83700 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
83701 mm_segment_t old_fs = get_fs();
83702
83703 set_fs(KERNEL_DS);
83704 - ret = sys_sigpending((old_sigset_t __user *) &s);
83705 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
83706 set_fs(old_fs);
83707 if (ret == 0)
83708 ret = put_user(s, set);
83709 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
83710 mm_segment_t old_fs = get_fs();
83711
83712 set_fs(KERNEL_DS);
83713 - ret = sys_old_getrlimit(resource, &r);
83714 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
83715 set_fs(old_fs);
83716
83717 if (!ret) {
83718 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
83719 set_fs (KERNEL_DS);
83720 ret = sys_wait4(pid,
83721 (stat_addr ?
83722 - (unsigned int __user *) &status : NULL),
83723 - options, (struct rusage __user *) &r);
83724 + (unsigned int __force_user *) &status : NULL),
83725 + options, (struct rusage __force_user *) &r);
83726 set_fs (old_fs);
83727
83728 if (ret > 0) {
83729 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
83730 memset(&info, 0, sizeof(info));
83731
83732 set_fs(KERNEL_DS);
83733 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
83734 - uru ? (struct rusage __user *)&ru : NULL);
83735 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
83736 + uru ? (struct rusage __force_user *)&ru : NULL);
83737 set_fs(old_fs);
83738
83739 if ((ret < 0) || (info.si_signo == 0))
83740 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
83741 oldfs = get_fs();
83742 set_fs(KERNEL_DS);
83743 err = sys_timer_settime(timer_id, flags,
83744 - (struct itimerspec __user *) &newts,
83745 - (struct itimerspec __user *) &oldts);
83746 + (struct itimerspec __force_user *) &newts,
83747 + (struct itimerspec __force_user *) &oldts);
83748 set_fs(oldfs);
83749 if (!err && old && put_compat_itimerspec(old, &oldts))
83750 return -EFAULT;
83751 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
83752 oldfs = get_fs();
83753 set_fs(KERNEL_DS);
83754 err = sys_timer_gettime(timer_id,
83755 - (struct itimerspec __user *) &ts);
83756 + (struct itimerspec __force_user *) &ts);
83757 set_fs(oldfs);
83758 if (!err && put_compat_itimerspec(setting, &ts))
83759 return -EFAULT;
83760 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
83761 oldfs = get_fs();
83762 set_fs(KERNEL_DS);
83763 err = sys_clock_settime(which_clock,
83764 - (struct timespec __user *) &ts);
83765 + (struct timespec __force_user *) &ts);
83766 set_fs(oldfs);
83767 return err;
83768 }
83769 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
83770 oldfs = get_fs();
83771 set_fs(KERNEL_DS);
83772 err = sys_clock_gettime(which_clock,
83773 - (struct timespec __user *) &ts);
83774 + (struct timespec __force_user *) &ts);
83775 set_fs(oldfs);
83776 if (!err && put_compat_timespec(&ts, tp))
83777 return -EFAULT;
83778 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
83779
83780 oldfs = get_fs();
83781 set_fs(KERNEL_DS);
83782 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
83783 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
83784 set_fs(oldfs);
83785
83786 err = compat_put_timex(utp, &txc);
83787 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
83788 oldfs = get_fs();
83789 set_fs(KERNEL_DS);
83790 err = sys_clock_getres(which_clock,
83791 - (struct timespec __user *) &ts);
83792 + (struct timespec __force_user *) &ts);
83793 set_fs(oldfs);
83794 if (!err && tp && put_compat_timespec(&ts, tp))
83795 return -EFAULT;
83796 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
83797 long err;
83798 mm_segment_t oldfs;
83799 struct timespec tu;
83800 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
83801 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
83802
83803 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
83804 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
83805 oldfs = get_fs();
83806 set_fs(KERNEL_DS);
83807 err = clock_nanosleep_restart(restart);
83808 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
83809 oldfs = get_fs();
83810 set_fs(KERNEL_DS);
83811 err = sys_clock_nanosleep(which_clock, flags,
83812 - (struct timespec __user *) &in,
83813 - (struct timespec __user *) &out);
83814 + (struct timespec __force_user *) &in,
83815 + (struct timespec __force_user *) &out);
83816 set_fs(oldfs);
83817
83818 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
83819 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
83820 mm_segment_t old_fs = get_fs();
83821
83822 set_fs(KERNEL_DS);
83823 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
83824 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
83825 set_fs(old_fs);
83826 if (put_compat_timespec(&t, interval))
83827 return -EFAULT;
83828 diff --git a/kernel/configs.c b/kernel/configs.c
83829 index c18b1f1..b9a0132 100644
83830 --- a/kernel/configs.c
83831 +++ b/kernel/configs.c
83832 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
83833 struct proc_dir_entry *entry;
83834
83835 /* create the current config file */
83836 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
83837 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
83838 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
83839 + &ikconfig_file_ops);
83840 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83841 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
83842 + &ikconfig_file_ops);
83843 +#endif
83844 +#else
83845 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
83846 &ikconfig_file_ops);
83847 +#endif
83848 +
83849 if (!entry)
83850 return -ENOMEM;
83851
83852 diff --git a/kernel/cred.c b/kernel/cred.c
83853 index e0573a4..3874e41 100644
83854 --- a/kernel/cred.c
83855 +++ b/kernel/cred.c
83856 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
83857 validate_creds(cred);
83858 alter_cred_subscribers(cred, -1);
83859 put_cred(cred);
83860 +
83861 +#ifdef CONFIG_GRKERNSEC_SETXID
83862 + cred = (struct cred *) tsk->delayed_cred;
83863 + if (cred != NULL) {
83864 + tsk->delayed_cred = NULL;
83865 + validate_creds(cred);
83866 + alter_cred_subscribers(cred, -1);
83867 + put_cred(cred);
83868 + }
83869 +#endif
83870 }
83871
83872 /**
83873 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
83874 * Always returns 0 thus allowing this function to be tail-called at the end
83875 * of, say, sys_setgid().
83876 */
83877 -int commit_creds(struct cred *new)
83878 +static int __commit_creds(struct cred *new)
83879 {
83880 struct task_struct *task = current;
83881 const struct cred *old = task->real_cred;
83882 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
83883
83884 get_cred(new); /* we will require a ref for the subj creds too */
83885
83886 + gr_set_role_label(task, new->uid, new->gid);
83887 +
83888 /* dumpability changes */
83889 if (!uid_eq(old->euid, new->euid) ||
83890 !gid_eq(old->egid, new->egid) ||
83891 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
83892 put_cred(old);
83893 return 0;
83894 }
83895 +#ifdef CONFIG_GRKERNSEC_SETXID
83896 +extern int set_user(struct cred *new);
83897 +
83898 +void gr_delayed_cred_worker(void)
83899 +{
83900 + const struct cred *new = current->delayed_cred;
83901 + struct cred *ncred;
83902 +
83903 + current->delayed_cred = NULL;
83904 +
83905 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
83906 + // from doing get_cred on it when queueing this
83907 + put_cred(new);
83908 + return;
83909 + } else if (new == NULL)
83910 + return;
83911 +
83912 + ncred = prepare_creds();
83913 + if (!ncred)
83914 + goto die;
83915 + // uids
83916 + ncred->uid = new->uid;
83917 + ncred->euid = new->euid;
83918 + ncred->suid = new->suid;
83919 + ncred->fsuid = new->fsuid;
83920 + // gids
83921 + ncred->gid = new->gid;
83922 + ncred->egid = new->egid;
83923 + ncred->sgid = new->sgid;
83924 + ncred->fsgid = new->fsgid;
83925 + // groups
83926 + if (set_groups(ncred, new->group_info) < 0) {
83927 + abort_creds(ncred);
83928 + goto die;
83929 + }
83930 + // caps
83931 + ncred->securebits = new->securebits;
83932 + ncred->cap_inheritable = new->cap_inheritable;
83933 + ncred->cap_permitted = new->cap_permitted;
83934 + ncred->cap_effective = new->cap_effective;
83935 + ncred->cap_bset = new->cap_bset;
83936 +
83937 + if (set_user(ncred)) {
83938 + abort_creds(ncred);
83939 + goto die;
83940 + }
83941 +
83942 + // from doing get_cred on it when queueing this
83943 + put_cred(new);
83944 +
83945 + __commit_creds(ncred);
83946 + return;
83947 +die:
83948 + // from doing get_cred on it when queueing this
83949 + put_cred(new);
83950 + do_group_exit(SIGKILL);
83951 +}
83952 +#endif
83953 +
83954 +int commit_creds(struct cred *new)
83955 +{
83956 +#ifdef CONFIG_GRKERNSEC_SETXID
83957 + int ret;
83958 + int schedule_it = 0;
83959 + struct task_struct *t;
83960 +
83961 + /* we won't get called with tasklist_lock held for writing
83962 + and interrupts disabled as the cred struct in that case is
83963 + init_cred
83964 + */
83965 + if (grsec_enable_setxid && !current_is_single_threaded() &&
83966 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
83967 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
83968 + schedule_it = 1;
83969 + }
83970 + ret = __commit_creds(new);
83971 + if (schedule_it) {
83972 + rcu_read_lock();
83973 + read_lock(&tasklist_lock);
83974 + for (t = next_thread(current); t != current;
83975 + t = next_thread(t)) {
83976 + if (t->delayed_cred == NULL) {
83977 + t->delayed_cred = get_cred(new);
83978 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
83979 + set_tsk_need_resched(t);
83980 + }
83981 + }
83982 + read_unlock(&tasklist_lock);
83983 + rcu_read_unlock();
83984 + }
83985 + return ret;
83986 +#else
83987 + return __commit_creds(new);
83988 +#endif
83989 +}
83990 +
83991 EXPORT_SYMBOL(commit_creds);
83992
83993 /**
83994 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
83995 index 7d2f35e..1bafcd0 100644
83996 --- a/kernel/debug/debug_core.c
83997 +++ b/kernel/debug/debug_core.c
83998 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
83999 */
84000 static atomic_t masters_in_kgdb;
84001 static atomic_t slaves_in_kgdb;
84002 -static atomic_t kgdb_break_tasklet_var;
84003 +static atomic_unchecked_t kgdb_break_tasklet_var;
84004 atomic_t kgdb_setting_breakpoint;
84005
84006 struct task_struct *kgdb_usethread;
84007 @@ -133,7 +133,7 @@ int kgdb_single_step;
84008 static pid_t kgdb_sstep_pid;
84009
84010 /* to keep track of the CPU which is doing the single stepping*/
84011 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84012 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84013
84014 /*
84015 * If you are debugging a problem where roundup (the collection of
84016 @@ -541,7 +541,7 @@ return_normal:
84017 * kernel will only try for the value of sstep_tries before
84018 * giving up and continuing on.
84019 */
84020 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
84021 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
84022 (kgdb_info[cpu].task &&
84023 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
84024 atomic_set(&kgdb_active, -1);
84025 @@ -639,8 +639,8 @@ cpu_master_loop:
84026 }
84027
84028 kgdb_restore:
84029 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
84030 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
84031 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
84032 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
84033 if (kgdb_info[sstep_cpu].task)
84034 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
84035 else
84036 @@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
84037 static void kgdb_tasklet_bpt(unsigned long ing)
84038 {
84039 kgdb_breakpoint();
84040 - atomic_set(&kgdb_break_tasklet_var, 0);
84041 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
84042 }
84043
84044 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
84045
84046 void kgdb_schedule_breakpoint(void)
84047 {
84048 - if (atomic_read(&kgdb_break_tasklet_var) ||
84049 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
84050 atomic_read(&kgdb_active) != -1 ||
84051 atomic_read(&kgdb_setting_breakpoint))
84052 return;
84053 - atomic_inc(&kgdb_break_tasklet_var);
84054 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
84055 tasklet_schedule(&kgdb_tasklet_breakpoint);
84056 }
84057 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
84058 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
84059 index 0b097c8..11dd5c5 100644
84060 --- a/kernel/debug/kdb/kdb_main.c
84061 +++ b/kernel/debug/kdb/kdb_main.c
84062 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
84063 continue;
84064
84065 kdb_printf("%-20s%8u 0x%p ", mod->name,
84066 - mod->core_size, (void *)mod);
84067 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
84068 #ifdef CONFIG_MODULE_UNLOAD
84069 kdb_printf("%4ld ", module_refcount(mod));
84070 #endif
84071 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
84072 kdb_printf(" (Loading)");
84073 else
84074 kdb_printf(" (Live)");
84075 - kdb_printf(" 0x%p", mod->module_core);
84076 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
84077
84078 #ifdef CONFIG_MODULE_UNLOAD
84079 {
84080 diff --git a/kernel/events/core.c b/kernel/events/core.c
84081 index f574401..11b21f0 100644
84082 --- a/kernel/events/core.c
84083 +++ b/kernel/events/core.c
84084 @@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
84085 * 0 - disallow raw tracepoint access for unpriv
84086 * 1 - disallow cpu events for unpriv
84087 * 2 - disallow kernel profiling for unpriv
84088 + * 3 - disallow all unpriv perf event use
84089 */
84090 -int sysctl_perf_event_paranoid __read_mostly = 1;
84091 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84092 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
84093 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
84094 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
84095 +#else
84096 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
84097 +#endif
84098
84099 /* Minimum for 512 kiB + 1 user control page */
84100 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
84101 @@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
84102
84103 tmp *= sysctl_perf_cpu_time_max_percent;
84104 do_div(tmp, 100);
84105 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
84106 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
84107 }
84108
84109 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
84110 @@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
84111 update_perf_cpu_limits();
84112 }
84113
84114 -static atomic64_t perf_event_id;
84115 +static atomic64_unchecked_t perf_event_id;
84116
84117 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
84118 enum event_type_t event_type);
84119 @@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
84120
84121 static inline u64 perf_event_count(struct perf_event *event)
84122 {
84123 - return local64_read(&event->count) + atomic64_read(&event->child_count);
84124 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
84125 }
84126
84127 static u64 perf_event_read(struct perf_event *event)
84128 @@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
84129 mutex_lock(&event->child_mutex);
84130 total += perf_event_read(event);
84131 *enabled += event->total_time_enabled +
84132 - atomic64_read(&event->child_total_time_enabled);
84133 + atomic64_read_unchecked(&event->child_total_time_enabled);
84134 *running += event->total_time_running +
84135 - atomic64_read(&event->child_total_time_running);
84136 + atomic64_read_unchecked(&event->child_total_time_running);
84137
84138 list_for_each_entry(child, &event->child_list, child_list) {
84139 total += perf_event_read(child);
84140 @@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
84141 userpg->offset -= local64_read(&event->hw.prev_count);
84142
84143 userpg->time_enabled = enabled +
84144 - atomic64_read(&event->child_total_time_enabled);
84145 + atomic64_read_unchecked(&event->child_total_time_enabled);
84146
84147 userpg->time_running = running +
84148 - atomic64_read(&event->child_total_time_running);
84149 + atomic64_read_unchecked(&event->child_total_time_running);
84150
84151 arch_perf_update_userpage(userpg, now);
84152
84153 @@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
84154
84155 /* Data. */
84156 sp = perf_user_stack_pointer(regs);
84157 - rem = __output_copy_user(handle, (void *) sp, dump_size);
84158 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
84159 dyn_size = dump_size - rem;
84160
84161 perf_output_skip(handle, rem);
84162 @@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
84163 values[n++] = perf_event_count(event);
84164 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
84165 values[n++] = enabled +
84166 - atomic64_read(&event->child_total_time_enabled);
84167 + atomic64_read_unchecked(&event->child_total_time_enabled);
84168 }
84169 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
84170 values[n++] = running +
84171 - atomic64_read(&event->child_total_time_running);
84172 + atomic64_read_unchecked(&event->child_total_time_running);
84173 }
84174 if (read_format & PERF_FORMAT_ID)
84175 values[n++] = primary_event_id(event);
84176 @@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
84177 event->parent = parent_event;
84178
84179 event->ns = get_pid_ns(task_active_pid_ns(current));
84180 - event->id = atomic64_inc_return(&perf_event_id);
84181 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
84182
84183 event->state = PERF_EVENT_STATE_INACTIVE;
84184
84185 @@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
84186 if (flags & ~PERF_FLAG_ALL)
84187 return -EINVAL;
84188
84189 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84190 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
84191 + return -EACCES;
84192 +#endif
84193 +
84194 err = perf_copy_attr(attr_uptr, &attr);
84195 if (err)
84196 return err;
84197 @@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
84198 /*
84199 * Add back the child's count to the parent's count:
84200 */
84201 - atomic64_add(child_val, &parent_event->child_count);
84202 - atomic64_add(child_event->total_time_enabled,
84203 + atomic64_add_unchecked(child_val, &parent_event->child_count);
84204 + atomic64_add_unchecked(child_event->total_time_enabled,
84205 &parent_event->child_total_time_enabled);
84206 - atomic64_add(child_event->total_time_running,
84207 + atomic64_add_unchecked(child_event->total_time_running,
84208 &parent_event->child_total_time_running);
84209
84210 /*
84211 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
84212 index 569b2187..19940d9 100644
84213 --- a/kernel/events/internal.h
84214 +++ b/kernel/events/internal.h
84215 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
84216 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
84217 }
84218
84219 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
84220 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
84221 static inline unsigned long \
84222 func_name(struct perf_output_handle *handle, \
84223 - const void *buf, unsigned long len) \
84224 + const void user *buf, unsigned long len) \
84225 { \
84226 unsigned long size, written; \
84227 \
84228 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
84229 return 0;
84230 }
84231
84232 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
84233 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
84234
84235 static inline unsigned long
84236 memcpy_skip(void *dst, const void *src, unsigned long n)
84237 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
84238 return 0;
84239 }
84240
84241 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
84242 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
84243
84244 #ifndef arch_perf_out_copy_user
84245 #define arch_perf_out_copy_user arch_perf_out_copy_user
84246 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
84247 }
84248 #endif
84249
84250 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
84251 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
84252
84253 /* Callchain handling */
84254 extern struct perf_callchain_entry *
84255 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
84256 index 24b7d6c..40cf797 100644
84257 --- a/kernel/events/uprobes.c
84258 +++ b/kernel/events/uprobes.c
84259 @@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
84260 {
84261 struct page *page;
84262 uprobe_opcode_t opcode;
84263 - int result;
84264 + long result;
84265
84266 pagefault_disable();
84267 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
84268 diff --git a/kernel/exit.c b/kernel/exit.c
84269 index a949819..a5f127d 100644
84270 --- a/kernel/exit.c
84271 +++ b/kernel/exit.c
84272 @@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
84273 struct task_struct *leader;
84274 int zap_leader;
84275 repeat:
84276 +#ifdef CONFIG_NET
84277 + gr_del_task_from_ip_table(p);
84278 +#endif
84279 +
84280 /* don't need to get the RCU readlock here - the process is dead and
84281 * can't be modifying its own credentials. But shut RCU-lockdep up */
84282 rcu_read_lock();
84283 @@ -329,7 +333,7 @@ int allow_signal(int sig)
84284 * know it'll be handled, so that they don't get converted to
84285 * SIGKILL or just silently dropped.
84286 */
84287 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
84288 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
84289 recalc_sigpending();
84290 spin_unlock_irq(&current->sighand->siglock);
84291 return 0;
84292 @@ -698,6 +702,8 @@ void do_exit(long code)
84293 struct task_struct *tsk = current;
84294 int group_dead;
84295
84296 + set_fs(USER_DS);
84297 +
84298 profile_task_exit(tsk);
84299
84300 WARN_ON(blk_needs_flush_plug(tsk));
84301 @@ -714,7 +720,6 @@ void do_exit(long code)
84302 * mm_release()->clear_child_tid() from writing to a user-controlled
84303 * kernel address.
84304 */
84305 - set_fs(USER_DS);
84306
84307 ptrace_event(PTRACE_EVENT_EXIT, code);
84308
84309 @@ -773,6 +778,9 @@ void do_exit(long code)
84310 tsk->exit_code = code;
84311 taskstats_exit(tsk, group_dead);
84312
84313 + gr_acl_handle_psacct(tsk, code);
84314 + gr_acl_handle_exit();
84315 +
84316 exit_mm(tsk);
84317
84318 if (group_dead)
84319 @@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
84320 * Take down every thread in the group. This is called by fatal signals
84321 * as well as by sys_exit_group (below).
84322 */
84323 -void
84324 +__noreturn void
84325 do_group_exit(int exit_code)
84326 {
84327 struct signal_struct *sig = current->signal;
84328 diff --git a/kernel/fork.c b/kernel/fork.c
84329 index dfa736c..d170f9b 100644
84330 --- a/kernel/fork.c
84331 +++ b/kernel/fork.c
84332 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
84333 *stackend = STACK_END_MAGIC; /* for overflow detection */
84334
84335 #ifdef CONFIG_CC_STACKPROTECTOR
84336 - tsk->stack_canary = get_random_int();
84337 + tsk->stack_canary = pax_get_random_long();
84338 #endif
84339
84340 /*
84341 @@ -345,12 +345,80 @@ free_tsk:
84342 }
84343
84344 #ifdef CONFIG_MMU
84345 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84346 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
84347 +{
84348 + struct vm_area_struct *tmp;
84349 + unsigned long charge;
84350 + struct file *file;
84351 + int retval;
84352 +
84353 + charge = 0;
84354 + if (mpnt->vm_flags & VM_ACCOUNT) {
84355 + unsigned long len = vma_pages(mpnt);
84356 +
84357 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84358 + goto fail_nomem;
84359 + charge = len;
84360 + }
84361 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84362 + if (!tmp)
84363 + goto fail_nomem;
84364 + *tmp = *mpnt;
84365 + tmp->vm_mm = mm;
84366 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
84367 + retval = vma_dup_policy(mpnt, tmp);
84368 + if (retval)
84369 + goto fail_nomem_policy;
84370 + if (anon_vma_fork(tmp, mpnt))
84371 + goto fail_nomem_anon_vma_fork;
84372 + tmp->vm_flags &= ~VM_LOCKED;
84373 + tmp->vm_next = tmp->vm_prev = NULL;
84374 + tmp->vm_mirror = NULL;
84375 + file = tmp->vm_file;
84376 + if (file) {
84377 + struct inode *inode = file_inode(file);
84378 + struct address_space *mapping = file->f_mapping;
84379 +
84380 + get_file(file);
84381 + if (tmp->vm_flags & VM_DENYWRITE)
84382 + atomic_dec(&inode->i_writecount);
84383 + mutex_lock(&mapping->i_mmap_mutex);
84384 + if (tmp->vm_flags & VM_SHARED)
84385 + mapping->i_mmap_writable++;
84386 + flush_dcache_mmap_lock(mapping);
84387 + /* insert tmp into the share list, just after mpnt */
84388 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84389 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
84390 + else
84391 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
84392 + flush_dcache_mmap_unlock(mapping);
84393 + mutex_unlock(&mapping->i_mmap_mutex);
84394 + }
84395 +
84396 + /*
84397 + * Clear hugetlb-related page reserves for children. This only
84398 + * affects MAP_PRIVATE mappings. Faults generated by the child
84399 + * are not guaranteed to succeed, even if read-only
84400 + */
84401 + if (is_vm_hugetlb_page(tmp))
84402 + reset_vma_resv_huge_pages(tmp);
84403 +
84404 + return tmp;
84405 +
84406 +fail_nomem_anon_vma_fork:
84407 + mpol_put(vma_policy(tmp));
84408 +fail_nomem_policy:
84409 + kmem_cache_free(vm_area_cachep, tmp);
84410 +fail_nomem:
84411 + vm_unacct_memory(charge);
84412 + return NULL;
84413 +}
84414 +
84415 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84416 {
84417 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
84418 struct rb_node **rb_link, *rb_parent;
84419 int retval;
84420 - unsigned long charge;
84421
84422 uprobe_start_dup_mmap();
84423 down_write(&oldmm->mmap_sem);
84424 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84425
84426 prev = NULL;
84427 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
84428 - struct file *file;
84429 -
84430 if (mpnt->vm_flags & VM_DONTCOPY) {
84431 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
84432 -vma_pages(mpnt));
84433 continue;
84434 }
84435 - charge = 0;
84436 - if (mpnt->vm_flags & VM_ACCOUNT) {
84437 - unsigned long len = vma_pages(mpnt);
84438 -
84439 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84440 - goto fail_nomem;
84441 - charge = len;
84442 - }
84443 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84444 - if (!tmp)
84445 - goto fail_nomem;
84446 - *tmp = *mpnt;
84447 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
84448 - retval = vma_dup_policy(mpnt, tmp);
84449 - if (retval)
84450 - goto fail_nomem_policy;
84451 - tmp->vm_mm = mm;
84452 - if (anon_vma_fork(tmp, mpnt))
84453 - goto fail_nomem_anon_vma_fork;
84454 - tmp->vm_flags &= ~VM_LOCKED;
84455 - tmp->vm_next = tmp->vm_prev = NULL;
84456 - file = tmp->vm_file;
84457 - if (file) {
84458 - struct inode *inode = file_inode(file);
84459 - struct address_space *mapping = file->f_mapping;
84460 -
84461 - get_file(file);
84462 - if (tmp->vm_flags & VM_DENYWRITE)
84463 - atomic_dec(&inode->i_writecount);
84464 - mutex_lock(&mapping->i_mmap_mutex);
84465 - if (tmp->vm_flags & VM_SHARED)
84466 - mapping->i_mmap_writable++;
84467 - flush_dcache_mmap_lock(mapping);
84468 - /* insert tmp into the share list, just after mpnt */
84469 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84470 - vma_nonlinear_insert(tmp,
84471 - &mapping->i_mmap_nonlinear);
84472 - else
84473 - vma_interval_tree_insert_after(tmp, mpnt,
84474 - &mapping->i_mmap);
84475 - flush_dcache_mmap_unlock(mapping);
84476 - mutex_unlock(&mapping->i_mmap_mutex);
84477 + tmp = dup_vma(mm, oldmm, mpnt);
84478 + if (!tmp) {
84479 + retval = -ENOMEM;
84480 + goto out;
84481 }
84482
84483 /*
84484 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84485 if (retval)
84486 goto out;
84487 }
84488 +
84489 +#ifdef CONFIG_PAX_SEGMEXEC
84490 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
84491 + struct vm_area_struct *mpnt_m;
84492 +
84493 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
84494 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
84495 +
84496 + if (!mpnt->vm_mirror)
84497 + continue;
84498 +
84499 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
84500 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
84501 + mpnt->vm_mirror = mpnt_m;
84502 + } else {
84503 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
84504 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
84505 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
84506 + mpnt->vm_mirror->vm_mirror = mpnt;
84507 + }
84508 + }
84509 + BUG_ON(mpnt_m);
84510 + }
84511 +#endif
84512 +
84513 /* a new mm has just been created */
84514 arch_dup_mmap(oldmm, mm);
84515 retval = 0;
84516 @@ -468,14 +521,6 @@ out:
84517 up_write(&oldmm->mmap_sem);
84518 uprobe_end_dup_mmap();
84519 return retval;
84520 -fail_nomem_anon_vma_fork:
84521 - mpol_put(vma_policy(tmp));
84522 -fail_nomem_policy:
84523 - kmem_cache_free(vm_area_cachep, tmp);
84524 -fail_nomem:
84525 - retval = -ENOMEM;
84526 - vm_unacct_memory(charge);
84527 - goto out;
84528 }
84529
84530 static inline int mm_alloc_pgd(struct mm_struct *mm)
84531 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
84532 return ERR_PTR(err);
84533
84534 mm = get_task_mm(task);
84535 - if (mm && mm != current->mm &&
84536 - !ptrace_may_access(task, mode)) {
84537 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
84538 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
84539 mmput(mm);
84540 mm = ERR_PTR(-EACCES);
84541 }
84542 @@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
84543 spin_unlock(&fs->lock);
84544 return -EAGAIN;
84545 }
84546 - fs->users++;
84547 + atomic_inc(&fs->users);
84548 spin_unlock(&fs->lock);
84549 return 0;
84550 }
84551 tsk->fs = copy_fs_struct(fs);
84552 if (!tsk->fs)
84553 return -ENOMEM;
84554 + /* Carry through gr_chroot_dentry and is_chrooted instead
84555 + of recomputing it here. Already copied when the task struct
84556 + is duplicated. This allows pivot_root to not be treated as
84557 + a chroot
84558 + */
84559 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
84560 +
84561 return 0;
84562 }
84563
84564 @@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
84565 * parts of the process environment (as per the clone
84566 * flags). The actual kick-off is left to the caller.
84567 */
84568 -static struct task_struct *copy_process(unsigned long clone_flags,
84569 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
84570 unsigned long stack_start,
84571 unsigned long stack_size,
84572 int __user *child_tidptr,
84573 @@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84574 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
84575 #endif
84576 retval = -EAGAIN;
84577 +
84578 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
84579 +
84580 if (atomic_read(&p->real_cred->user->processes) >=
84581 task_rlimit(p, RLIMIT_NPROC)) {
84582 if (p->real_cred->user != INIT_USER &&
84583 @@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84584 goto bad_fork_free_pid;
84585 }
84586
84587 + /* synchronizes with gr_set_acls()
84588 + we need to call this past the point of no return for fork()
84589 + */
84590 + gr_copy_label(p);
84591 +
84592 if (likely(p->pid)) {
84593 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
84594
84595 @@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
84596 bad_fork_free:
84597 free_task(p);
84598 fork_out:
84599 + gr_log_forkfail(retval);
84600 +
84601 return ERR_PTR(retval);
84602 }
84603
84604 @@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
84605
84606 p = copy_process(clone_flags, stack_start, stack_size,
84607 child_tidptr, NULL, trace);
84608 + add_latent_entropy();
84609 /*
84610 * Do this prior waking up the new thread - the thread pointer
84611 * might get invalid after that point, if the thread exits quickly.
84612 @@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
84613 if (clone_flags & CLONE_PARENT_SETTID)
84614 put_user(nr, parent_tidptr);
84615
84616 + gr_handle_brute_check();
84617 +
84618 if (clone_flags & CLONE_VFORK) {
84619 p->vfork_done = &vfork;
84620 init_completion(&vfork);
84621 @@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
84622 mm_cachep = kmem_cache_create("mm_struct",
84623 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
84624 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
84625 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
84626 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
84627 mmap_init();
84628 nsproxy_cache_init();
84629 }
84630 @@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
84631 return 0;
84632
84633 /* don't need lock here; in the worst case we'll do useless copy */
84634 - if (fs->users == 1)
84635 + if (atomic_read(&fs->users) == 1)
84636 return 0;
84637
84638 *new_fsp = copy_fs_struct(fs);
84639 @@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
84640 fs = current->fs;
84641 spin_lock(&fs->lock);
84642 current->fs = new_fs;
84643 - if (--fs->users)
84644 + gr_set_chroot_entries(current, &current->fs->root);
84645 + if (atomic_dec_return(&fs->users))
84646 new_fs = NULL;
84647 else
84648 new_fs = fs;
84649 diff --git a/kernel/futex.c b/kernel/futex.c
84650 index f6ff019..ac53307 100644
84651 --- a/kernel/futex.c
84652 +++ b/kernel/futex.c
84653 @@ -54,6 +54,7 @@
84654 #include <linux/mount.h>
84655 #include <linux/pagemap.h>
84656 #include <linux/syscalls.h>
84657 +#include <linux/ptrace.h>
84658 #include <linux/signal.h>
84659 #include <linux/export.h>
84660 #include <linux/magic.h>
84661 @@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
84662 struct page *page, *page_head;
84663 int err, ro = 0;
84664
84665 +#ifdef CONFIG_PAX_SEGMEXEC
84666 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
84667 + return -EFAULT;
84668 +#endif
84669 +
84670 /*
84671 * The futex address must be "naturally" aligned.
84672 */
84673 @@ -442,7 +448,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
84674
84675 static int get_futex_value_locked(u32 *dest, u32 __user *from)
84676 {
84677 - int ret;
84678 + unsigned long ret;
84679
84680 pagefault_disable();
84681 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
84682 @@ -2735,6 +2741,7 @@ static int __init futex_init(void)
84683 {
84684 u32 curval;
84685 int i;
84686 + mm_segment_t oldfs;
84687
84688 /*
84689 * This will fail and we want it. Some arch implementations do
84690 @@ -2746,8 +2753,11 @@ static int __init futex_init(void)
84691 * implementation, the non-functional ones will return
84692 * -ENOSYS.
84693 */
84694 + oldfs = get_fs();
84695 + set_fs(USER_DS);
84696 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
84697 futex_cmpxchg_enabled = 1;
84698 + set_fs(oldfs);
84699
84700 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
84701 plist_head_init(&futex_queues[i].chain);
84702 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
84703 index f9f44fd..29885e4 100644
84704 --- a/kernel/futex_compat.c
84705 +++ b/kernel/futex_compat.c
84706 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
84707 return 0;
84708 }
84709
84710 -static void __user *futex_uaddr(struct robust_list __user *entry,
84711 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
84712 compat_long_t futex_offset)
84713 {
84714 compat_uptr_t base = ptr_to_compat(entry);
84715 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
84716 index f45b75b..bfac6d5 100644
84717 --- a/kernel/gcov/base.c
84718 +++ b/kernel/gcov/base.c
84719 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
84720 }
84721
84722 #ifdef CONFIG_MODULES
84723 -static inline int within(void *addr, void *start, unsigned long size)
84724 -{
84725 - return ((addr >= start) && (addr < start + size));
84726 -}
84727 -
84728 /* Update list and generate events when modules are unloaded. */
84729 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84730 void *data)
84731 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84732
84733 /* Remove entries located in module from linked list. */
84734 while ((info = gcov_info_next(info))) {
84735 - if (within(info, mod->module_core, mod->core_size)) {
84736 + if (within_module_core_rw((unsigned long)info, mod)) {
84737 gcov_info_unlink(prev, info);
84738 if (gcov_events_enabled)
84739 gcov_event(GCOV_REMOVE, info);
84740 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
84741 index 383319b..56ebb13 100644
84742 --- a/kernel/hrtimer.c
84743 +++ b/kernel/hrtimer.c
84744 @@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
84745 local_irq_restore(flags);
84746 }
84747
84748 -static void run_hrtimer_softirq(struct softirq_action *h)
84749 +static __latent_entropy void run_hrtimer_softirq(void)
84750 {
84751 hrtimer_peek_ahead_timers();
84752 }
84753 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
84754 index 55fcce6..0e4cf34 100644
84755 --- a/kernel/irq_work.c
84756 +++ b/kernel/irq_work.c
84757 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
84758 return NOTIFY_OK;
84759 }
84760
84761 -static struct notifier_block cpu_notify;
84762 +static struct notifier_block cpu_notify = {
84763 + .notifier_call = irq_work_cpu_notify,
84764 + .priority = 0,
84765 +};
84766
84767 static __init int irq_work_init_cpu_notifier(void)
84768 {
84769 - cpu_notify.notifier_call = irq_work_cpu_notify;
84770 - cpu_notify.priority = 0;
84771 register_cpu_notifier(&cpu_notify);
84772 return 0;
84773 }
84774 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
84775 index 9019f15..9a3c42e 100644
84776 --- a/kernel/jump_label.c
84777 +++ b/kernel/jump_label.c
84778 @@ -14,6 +14,7 @@
84779 #include <linux/err.h>
84780 #include <linux/static_key.h>
84781 #include <linux/jump_label_ratelimit.h>
84782 +#include <linux/mm.h>
84783
84784 #ifdef HAVE_JUMP_LABEL
84785
84786 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
84787
84788 size = (((unsigned long)stop - (unsigned long)start)
84789 / sizeof(struct jump_entry));
84790 + pax_open_kernel();
84791 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
84792 + pax_close_kernel();
84793 }
84794
84795 static void jump_label_update(struct static_key *key, int enable);
84796 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
84797 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
84798 struct jump_entry *iter;
84799
84800 + pax_open_kernel();
84801 for (iter = iter_start; iter < iter_stop; iter++) {
84802 if (within_module_init(iter->code, mod))
84803 iter->code = 0;
84804 }
84805 + pax_close_kernel();
84806 }
84807
84808 static int
84809 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
84810 index 3127ad5..159d880 100644
84811 --- a/kernel/kallsyms.c
84812 +++ b/kernel/kallsyms.c
84813 @@ -11,6 +11,9 @@
84814 * Changed the compression method from stem compression to "table lookup"
84815 * compression (see scripts/kallsyms.c for a more complete description)
84816 */
84817 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84818 +#define __INCLUDED_BY_HIDESYM 1
84819 +#endif
84820 #include <linux/kallsyms.h>
84821 #include <linux/module.h>
84822 #include <linux/init.h>
84823 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
84824
84825 static inline int is_kernel_inittext(unsigned long addr)
84826 {
84827 + if (system_state != SYSTEM_BOOTING)
84828 + return 0;
84829 +
84830 if (addr >= (unsigned long)_sinittext
84831 && addr <= (unsigned long)_einittext)
84832 return 1;
84833 return 0;
84834 }
84835
84836 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84837 +#ifdef CONFIG_MODULES
84838 +static inline int is_module_text(unsigned long addr)
84839 +{
84840 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
84841 + return 1;
84842 +
84843 + addr = ktla_ktva(addr);
84844 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
84845 +}
84846 +#else
84847 +static inline int is_module_text(unsigned long addr)
84848 +{
84849 + return 0;
84850 +}
84851 +#endif
84852 +#endif
84853 +
84854 static inline int is_kernel_text(unsigned long addr)
84855 {
84856 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
84857 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
84858
84859 static inline int is_kernel(unsigned long addr)
84860 {
84861 +
84862 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84863 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
84864 + return 1;
84865 +
84866 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
84867 +#else
84868 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
84869 +#endif
84870 +
84871 return 1;
84872 return in_gate_area_no_mm(addr);
84873 }
84874
84875 static int is_ksym_addr(unsigned long addr)
84876 {
84877 +
84878 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84879 + if (is_module_text(addr))
84880 + return 0;
84881 +#endif
84882 +
84883 if (all_var)
84884 return is_kernel(addr);
84885
84886 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
84887
84888 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
84889 {
84890 - iter->name[0] = '\0';
84891 iter->nameoff = get_symbol_offset(new_pos);
84892 iter->pos = new_pos;
84893 }
84894 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
84895 {
84896 struct kallsym_iter *iter = m->private;
84897
84898 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84899 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
84900 + return 0;
84901 +#endif
84902 +
84903 /* Some debugging symbols have no name. Ignore them. */
84904 if (!iter->name[0])
84905 return 0;
84906 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
84907 */
84908 type = iter->exported ? toupper(iter->type) :
84909 tolower(iter->type);
84910 +
84911 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
84912 type, iter->name, iter->module_name);
84913 } else
84914 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
84915 struct kallsym_iter *iter;
84916 int ret;
84917
84918 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
84919 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
84920 if (!iter)
84921 return -ENOMEM;
84922 reset_iter(iter, 0);
84923 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
84924 index e30ac0f..3528cac 100644
84925 --- a/kernel/kcmp.c
84926 +++ b/kernel/kcmp.c
84927 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
84928 struct task_struct *task1, *task2;
84929 int ret;
84930
84931 +#ifdef CONFIG_GRKERNSEC
84932 + return -ENOSYS;
84933 +#endif
84934 +
84935 rcu_read_lock();
84936
84937 /*
84938 diff --git a/kernel/kexec.c b/kernel/kexec.c
84939 index 9c97016..df438f8 100644
84940 --- a/kernel/kexec.c
84941 +++ b/kernel/kexec.c
84942 @@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
84943 unsigned long flags)
84944 {
84945 struct compat_kexec_segment in;
84946 - struct kexec_segment out, __user *ksegments;
84947 + struct kexec_segment out;
84948 + struct kexec_segment __user *ksegments;
84949 unsigned long i, result;
84950
84951 /* Don't allow clients that don't understand the native
84952 diff --git a/kernel/kmod.c b/kernel/kmod.c
84953 index b086006..655e2aa 100644
84954 --- a/kernel/kmod.c
84955 +++ b/kernel/kmod.c
84956 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
84957 kfree(info->argv);
84958 }
84959
84960 -static int call_modprobe(char *module_name, int wait)
84961 +static int call_modprobe(char *module_name, char *module_param, int wait)
84962 {
84963 struct subprocess_info *info;
84964 static char *envp[] = {
84965 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
84966 NULL
84967 };
84968
84969 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
84970 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
84971 if (!argv)
84972 goto out;
84973
84974 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
84975 argv[1] = "-q";
84976 argv[2] = "--";
84977 argv[3] = module_name; /* check free_modprobe_argv() */
84978 - argv[4] = NULL;
84979 + argv[4] = module_param;
84980 + argv[5] = NULL;
84981
84982 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
84983 NULL, free_modprobe_argv, NULL);
84984 @@ -129,9 +130,8 @@ out:
84985 * If module auto-loading support is disabled then this function
84986 * becomes a no-operation.
84987 */
84988 -int __request_module(bool wait, const char *fmt, ...)
84989 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
84990 {
84991 - va_list args;
84992 char module_name[MODULE_NAME_LEN];
84993 unsigned int max_modprobes;
84994 int ret;
84995 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
84996 if (!modprobe_path[0])
84997 return 0;
84998
84999 - va_start(args, fmt);
85000 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
85001 - va_end(args);
85002 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
85003 if (ret >= MODULE_NAME_LEN)
85004 return -ENAMETOOLONG;
85005
85006 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
85007 if (ret)
85008 return ret;
85009
85010 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85011 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85012 + /* hack to workaround consolekit/udisks stupidity */
85013 + read_lock(&tasklist_lock);
85014 + if (!strcmp(current->comm, "mount") &&
85015 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
85016 + read_unlock(&tasklist_lock);
85017 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
85018 + return -EPERM;
85019 + }
85020 + read_unlock(&tasklist_lock);
85021 + }
85022 +#endif
85023 +
85024 /* If modprobe needs a service that is in a module, we get a recursive
85025 * loop. Limit the number of running kmod threads to max_threads/2 or
85026 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
85027 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
85028
85029 trace_module_request(module_name, wait, _RET_IP_);
85030
85031 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85032 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85033
85034 atomic_dec(&kmod_concurrent);
85035 return ret;
85036 }
85037 +
85038 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
85039 +{
85040 + va_list args;
85041 + int ret;
85042 +
85043 + va_start(args, fmt);
85044 + ret = ____request_module(wait, module_param, fmt, args);
85045 + va_end(args);
85046 +
85047 + return ret;
85048 +}
85049 +
85050 +int __request_module(bool wait, const char *fmt, ...)
85051 +{
85052 + va_list args;
85053 + int ret;
85054 +
85055 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85056 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85057 + char module_param[MODULE_NAME_LEN];
85058 +
85059 + memset(module_param, 0, sizeof(module_param));
85060 +
85061 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
85062 +
85063 + va_start(args, fmt);
85064 + ret = ____request_module(wait, module_param, fmt, args);
85065 + va_end(args);
85066 +
85067 + return ret;
85068 + }
85069 +#endif
85070 +
85071 + va_start(args, fmt);
85072 + ret = ____request_module(wait, NULL, fmt, args);
85073 + va_end(args);
85074 +
85075 + return ret;
85076 +}
85077 +
85078 EXPORT_SYMBOL(__request_module);
85079 #endif /* CONFIG_MODULES */
85080
85081 @@ -218,6 +271,19 @@ static int ____call_usermodehelper(void *data)
85082 */
85083 set_user_nice(current, 0);
85084
85085 +#ifdef CONFIG_GRKERNSEC
85086 + /* this is race-free as far as userland is concerned as we copied
85087 + out the path to be used prior to this point and are now operating
85088 + on that copy
85089 + */
85090 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
85091 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7)) || strstr(sub_info->path, "..")) {
85092 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
85093 + retval = -EPERM;
85094 + goto fail;
85095 + }
85096 +#endif
85097 +
85098 retval = -ENOMEM;
85099 new = prepare_kernel_cred(current);
85100 if (!new)
85101 @@ -240,8 +306,8 @@ static int ____call_usermodehelper(void *data)
85102 commit_creds(new);
85103
85104 retval = do_execve(sub_info->path,
85105 - (const char __user *const __user *)sub_info->argv,
85106 - (const char __user *const __user *)sub_info->envp);
85107 + (const char __user *const __force_user *)sub_info->argv,
85108 + (const char __user *const __force_user *)sub_info->envp);
85109 if (!retval)
85110 return 0;
85111
85112 @@ -260,6 +326,10 @@ static int call_helper(void *data)
85113
85114 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
85115 {
85116 +#ifdef CONFIG_GRKERNSEC
85117 + kfree(info->path);
85118 + info->path = info->origpath;
85119 +#endif
85120 if (info->cleanup)
85121 (*info->cleanup)(info);
85122 kfree(info);
85123 @@ -303,7 +373,7 @@ static int wait_for_helper(void *data)
85124 *
85125 * Thus the __user pointer cast is valid here.
85126 */
85127 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
85128 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
85129
85130 /*
85131 * If ret is 0, either ____call_usermodehelper failed and the
85132 @@ -542,7 +612,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
85133 goto out;
85134
85135 INIT_WORK(&sub_info->work, __call_usermodehelper);
85136 +#ifdef CONFIG_GRKERNSEC
85137 + sub_info->origpath = path;
85138 + sub_info->path = kstrdup(path, gfp_mask);
85139 +#else
85140 sub_info->path = path;
85141 +#endif
85142 sub_info->argv = argv;
85143 sub_info->envp = envp;
85144
85145 @@ -650,7 +725,7 @@ EXPORT_SYMBOL(call_usermodehelper);
85146 static int proc_cap_handler(struct ctl_table *table, int write,
85147 void __user *buffer, size_t *lenp, loff_t *ppos)
85148 {
85149 - struct ctl_table t;
85150 + ctl_table_no_const t;
85151 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
85152 kernel_cap_t new_cap;
85153 int err, i;
85154 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
85155 index ceeadfc..11c18b6 100644
85156 --- a/kernel/kprobes.c
85157 +++ b/kernel/kprobes.c
85158 @@ -31,6 +31,9 @@
85159 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
85160 * <prasanna@in.ibm.com> added function-return probes.
85161 */
85162 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85163 +#define __INCLUDED_BY_HIDESYM 1
85164 +#endif
85165 #include <linux/kprobes.h>
85166 #include <linux/hash.h>
85167 #include <linux/init.h>
85168 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
85169
85170 static void *alloc_insn_page(void)
85171 {
85172 - return module_alloc(PAGE_SIZE);
85173 + return module_alloc_exec(PAGE_SIZE);
85174 }
85175
85176 static void free_insn_page(void *page)
85177 {
85178 - module_free(NULL, page);
85179 + module_free_exec(NULL, page);
85180 }
85181
85182 struct kprobe_insn_cache kprobe_insn_slots = {
85183 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
85184 kprobe_type = "k";
85185
85186 if (sym)
85187 - seq_printf(pi, "%p %s %s+0x%x %s ",
85188 + seq_printf(pi, "%pK %s %s+0x%x %s ",
85189 p->addr, kprobe_type, sym, offset,
85190 (modname ? modname : " "));
85191 else
85192 - seq_printf(pi, "%p %s %p ",
85193 + seq_printf(pi, "%pK %s %pK ",
85194 p->addr, kprobe_type, p->addr);
85195
85196 if (!pp)
85197 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
85198 index 9659d38..bffd520 100644
85199 --- a/kernel/ksysfs.c
85200 +++ b/kernel/ksysfs.c
85201 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
85202 {
85203 if (count+1 > UEVENT_HELPER_PATH_LEN)
85204 return -ENOENT;
85205 + if (!capable(CAP_SYS_ADMIN))
85206 + return -EPERM;
85207 memcpy(uevent_helper, buf, count);
85208 uevent_helper[count] = '\0';
85209 if (count && uevent_helper[count-1] == '\n')
85210 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
85211 return count;
85212 }
85213
85214 -static struct bin_attribute notes_attr = {
85215 +static bin_attribute_no_const notes_attr __read_only = {
85216 .attr = {
85217 .name = "notes",
85218 .mode = S_IRUGO,
85219 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
85220 index 576ba75..7c256e4 100644
85221 --- a/kernel/locking/lockdep.c
85222 +++ b/kernel/locking/lockdep.c
85223 @@ -596,6 +596,10 @@ static int static_obj(void *obj)
85224 end = (unsigned long) &_end,
85225 addr = (unsigned long) obj;
85226
85227 +#ifdef CONFIG_PAX_KERNEXEC
85228 + start = ktla_ktva(start);
85229 +#endif
85230 +
85231 /*
85232 * static variable?
85233 */
85234 @@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
85235 if (!static_obj(lock->key)) {
85236 debug_locks_off();
85237 printk("INFO: trying to register non-static key.\n");
85238 + printk("lock:%pS key:%pS.\n", lock, lock->key);
85239 printk("the code is fine but needs lockdep annotation.\n");
85240 printk("turning off the locking correctness validator.\n");
85241 dump_stack();
85242 @@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
85243 if (!class)
85244 return 0;
85245 }
85246 - atomic_inc((atomic_t *)&class->ops);
85247 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
85248 if (very_verbose(class)) {
85249 printk("\nacquire class [%p] %s", class->key, class->name);
85250 if (class->name_version > 1)
85251 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
85252 index ef43ac4..2720dfa 100644
85253 --- a/kernel/locking/lockdep_proc.c
85254 +++ b/kernel/locking/lockdep_proc.c
85255 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
85256 return 0;
85257 }
85258
85259 - seq_printf(m, "%p", class->key);
85260 + seq_printf(m, "%pK", class->key);
85261 #ifdef CONFIG_DEBUG_LOCKDEP
85262 seq_printf(m, " OPS:%8ld", class->ops);
85263 #endif
85264 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
85265
85266 list_for_each_entry(entry, &class->locks_after, entry) {
85267 if (entry->distance == 1) {
85268 - seq_printf(m, " -> [%p] ", entry->class->key);
85269 + seq_printf(m, " -> [%pK] ", entry->class->key);
85270 print_name(m, entry->class);
85271 seq_puts(m, "\n");
85272 }
85273 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
85274 if (!class->key)
85275 continue;
85276
85277 - seq_printf(m, "[%p] ", class->key);
85278 + seq_printf(m, "[%pK] ", class->key);
85279 print_name(m, class);
85280 seq_puts(m, "\n");
85281 }
85282 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85283 if (!i)
85284 seq_line(m, '-', 40-namelen, namelen);
85285
85286 - snprintf(ip, sizeof(ip), "[<%p>]",
85287 + snprintf(ip, sizeof(ip), "[<%pK>]",
85288 (void *)class->contention_point[i]);
85289 seq_printf(m, "%40s %14lu %29s %pS\n",
85290 name, stats->contention_point[i],
85291 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85292 if (!i)
85293 seq_line(m, '-', 40-namelen, namelen);
85294
85295 - snprintf(ip, sizeof(ip), "[<%p>]",
85296 + snprintf(ip, sizeof(ip), "[<%pK>]",
85297 (void *)class->contending_point[i]);
85298 seq_printf(m, "%40s %14lu %29s %pS\n",
85299 name, stats->contending_point[i],
85300 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
85301 index 7e3443f..b2a1e6b 100644
85302 --- a/kernel/locking/mutex-debug.c
85303 +++ b/kernel/locking/mutex-debug.c
85304 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
85305 }
85306
85307 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85308 - struct thread_info *ti)
85309 + struct task_struct *task)
85310 {
85311 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
85312
85313 /* Mark the current thread as blocked on the lock: */
85314 - ti->task->blocked_on = waiter;
85315 + task->blocked_on = waiter;
85316 }
85317
85318 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85319 - struct thread_info *ti)
85320 + struct task_struct *task)
85321 {
85322 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
85323 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
85324 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
85325 - ti->task->blocked_on = NULL;
85326 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
85327 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
85328 + task->blocked_on = NULL;
85329
85330 list_del_init(&waiter->list);
85331 waiter->task = NULL;
85332 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
85333 index 0799fd3..d06ae3b 100644
85334 --- a/kernel/locking/mutex-debug.h
85335 +++ b/kernel/locking/mutex-debug.h
85336 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
85337 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
85338 extern void debug_mutex_add_waiter(struct mutex *lock,
85339 struct mutex_waiter *waiter,
85340 - struct thread_info *ti);
85341 + struct task_struct *task);
85342 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85343 - struct thread_info *ti);
85344 + struct task_struct *task);
85345 extern void debug_mutex_unlock(struct mutex *lock);
85346 extern void debug_mutex_init(struct mutex *lock, const char *name,
85347 struct lock_class_key *key);
85348 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
85349 index 4dd6e4c..df52693 100644
85350 --- a/kernel/locking/mutex.c
85351 +++ b/kernel/locking/mutex.c
85352 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
85353 node->locked = 1;
85354 return;
85355 }
85356 - ACCESS_ONCE(prev->next) = node;
85357 + ACCESS_ONCE_RW(prev->next) = node;
85358 smp_wmb();
85359 /* Wait until the lock holder passes the lock down */
85360 while (!ACCESS_ONCE(node->locked))
85361 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
85362 while (!(next = ACCESS_ONCE(node->next)))
85363 arch_mutex_cpu_relax();
85364 }
85365 - ACCESS_ONCE(next->locked) = 1;
85366 + ACCESS_ONCE_RW(next->locked) = 1;
85367 smp_wmb();
85368 }
85369
85370 @@ -520,7 +520,7 @@ slowpath:
85371 goto skip_wait;
85372
85373 debug_mutex_lock_common(lock, &waiter);
85374 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
85375 + debug_mutex_add_waiter(lock, &waiter, task);
85376
85377 /* add waiting tasks to the end of the waitqueue (FIFO): */
85378 list_add_tail(&waiter.list, &lock->wait_list);
85379 @@ -564,7 +564,7 @@ slowpath:
85380 schedule_preempt_disabled();
85381 spin_lock_mutex(&lock->wait_lock, flags);
85382 }
85383 - mutex_remove_waiter(lock, &waiter, current_thread_info());
85384 + mutex_remove_waiter(lock, &waiter, task);
85385 /* set it to 0 if there are no waiters left: */
85386 if (likely(list_empty(&lock->wait_list)))
85387 atomic_set(&lock->count, 0);
85388 @@ -601,7 +601,7 @@ skip_wait:
85389 return 0;
85390
85391 err:
85392 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
85393 + mutex_remove_waiter(lock, &waiter, task);
85394 spin_unlock_mutex(&lock->wait_lock, flags);
85395 debug_mutex_free_waiter(&waiter);
85396 mutex_release(&lock->dep_map, 1, ip);
85397 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
85398 index 1d96dd0..994ff19 100644
85399 --- a/kernel/locking/rtmutex-tester.c
85400 +++ b/kernel/locking/rtmutex-tester.c
85401 @@ -22,7 +22,7 @@
85402 #define MAX_RT_TEST_MUTEXES 8
85403
85404 static spinlock_t rttest_lock;
85405 -static atomic_t rttest_event;
85406 +static atomic_unchecked_t rttest_event;
85407
85408 struct test_thread_data {
85409 int opcode;
85410 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85411
85412 case RTTEST_LOCKCONT:
85413 td->mutexes[td->opdata] = 1;
85414 - td->event = atomic_add_return(1, &rttest_event);
85415 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85416 return 0;
85417
85418 case RTTEST_RESET:
85419 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85420 return 0;
85421
85422 case RTTEST_RESETEVENT:
85423 - atomic_set(&rttest_event, 0);
85424 + atomic_set_unchecked(&rttest_event, 0);
85425 return 0;
85426
85427 default:
85428 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85429 return ret;
85430
85431 td->mutexes[id] = 1;
85432 - td->event = atomic_add_return(1, &rttest_event);
85433 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85434 rt_mutex_lock(&mutexes[id]);
85435 - td->event = atomic_add_return(1, &rttest_event);
85436 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85437 td->mutexes[id] = 4;
85438 return 0;
85439
85440 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85441 return ret;
85442
85443 td->mutexes[id] = 1;
85444 - td->event = atomic_add_return(1, &rttest_event);
85445 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85446 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
85447 - td->event = atomic_add_return(1, &rttest_event);
85448 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85449 td->mutexes[id] = ret ? 0 : 4;
85450 return ret ? -EINTR : 0;
85451
85452 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85453 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
85454 return ret;
85455
85456 - td->event = atomic_add_return(1, &rttest_event);
85457 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85458 rt_mutex_unlock(&mutexes[id]);
85459 - td->event = atomic_add_return(1, &rttest_event);
85460 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85461 td->mutexes[id] = 0;
85462 return 0;
85463
85464 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85465 break;
85466
85467 td->mutexes[dat] = 2;
85468 - td->event = atomic_add_return(1, &rttest_event);
85469 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85470 break;
85471
85472 default:
85473 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85474 return;
85475
85476 td->mutexes[dat] = 3;
85477 - td->event = atomic_add_return(1, &rttest_event);
85478 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85479 break;
85480
85481 case RTTEST_LOCKNOWAIT:
85482 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85483 return;
85484
85485 td->mutexes[dat] = 1;
85486 - td->event = atomic_add_return(1, &rttest_event);
85487 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85488 return;
85489
85490 default:
85491 diff --git a/kernel/module.c b/kernel/module.c
85492 index f5a3b1e..1f5578b 100644
85493 --- a/kernel/module.c
85494 +++ b/kernel/module.c
85495 @@ -61,6 +61,7 @@
85496 #include <linux/pfn.h>
85497 #include <linux/bsearch.h>
85498 #include <linux/fips.h>
85499 +#include <linux/grsecurity.h>
85500 #include <uapi/linux/module.h>
85501 #include "module-internal.h"
85502
85503 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
85504
85505 /* Bounds of module allocation, for speeding __module_address.
85506 * Protected by module_mutex. */
85507 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
85508 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
85509 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
85510
85511 int register_module_notifier(struct notifier_block * nb)
85512 {
85513 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85514 return true;
85515
85516 list_for_each_entry_rcu(mod, &modules, list) {
85517 - struct symsearch arr[] = {
85518 + struct symsearch modarr[] = {
85519 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
85520 NOT_GPL_ONLY, false },
85521 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
85522 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85523 if (mod->state == MODULE_STATE_UNFORMED)
85524 continue;
85525
85526 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
85527 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
85528 return true;
85529 }
85530 return false;
85531 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
85532 if (!pcpusec->sh_size)
85533 return 0;
85534
85535 - if (align > PAGE_SIZE) {
85536 + if (align-1 >= PAGE_SIZE) {
85537 pr_warn("%s: per-cpu alignment %li > %li\n",
85538 mod->name, align, PAGE_SIZE);
85539 align = PAGE_SIZE;
85540 @@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
85541 static ssize_t show_coresize(struct module_attribute *mattr,
85542 struct module_kobject *mk, char *buffer)
85543 {
85544 - return sprintf(buffer, "%u\n", mk->mod->core_size);
85545 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
85546 }
85547
85548 static struct module_attribute modinfo_coresize =
85549 @@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
85550 static ssize_t show_initsize(struct module_attribute *mattr,
85551 struct module_kobject *mk, char *buffer)
85552 {
85553 - return sprintf(buffer, "%u\n", mk->mod->init_size);
85554 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
85555 }
85556
85557 static struct module_attribute modinfo_initsize =
85558 @@ -1286,7 +1288,7 @@ resolve_symbol_wait(struct module *mod,
85559 */
85560 #ifdef CONFIG_SYSFS
85561
85562 -#ifdef CONFIG_KALLSYMS
85563 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
85564 static inline bool sect_empty(const Elf_Shdr *sect)
85565 {
85566 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
85567 @@ -1426,7 +1428,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
85568 {
85569 unsigned int notes, loaded, i;
85570 struct module_notes_attrs *notes_attrs;
85571 - struct bin_attribute *nattr;
85572 + bin_attribute_no_const *nattr;
85573
85574 /* failed to create section attributes, so can't create notes */
85575 if (!mod->sect_attrs)
85576 @@ -1538,7 +1540,7 @@ static void del_usage_links(struct module *mod)
85577 static int module_add_modinfo_attrs(struct module *mod)
85578 {
85579 struct module_attribute *attr;
85580 - struct module_attribute *temp_attr;
85581 + module_attribute_no_const *temp_attr;
85582 int error = 0;
85583 int i;
85584
85585 @@ -1759,21 +1761,21 @@ static void set_section_ro_nx(void *base,
85586
85587 static void unset_module_core_ro_nx(struct module *mod)
85588 {
85589 - set_page_attributes(mod->module_core + mod->core_text_size,
85590 - mod->module_core + mod->core_size,
85591 + set_page_attributes(mod->module_core_rw,
85592 + mod->module_core_rw + mod->core_size_rw,
85593 set_memory_x);
85594 - set_page_attributes(mod->module_core,
85595 - mod->module_core + mod->core_ro_size,
85596 + set_page_attributes(mod->module_core_rx,
85597 + mod->module_core_rx + mod->core_size_rx,
85598 set_memory_rw);
85599 }
85600
85601 static void unset_module_init_ro_nx(struct module *mod)
85602 {
85603 - set_page_attributes(mod->module_init + mod->init_text_size,
85604 - mod->module_init + mod->init_size,
85605 + set_page_attributes(mod->module_init_rw,
85606 + mod->module_init_rw + mod->init_size_rw,
85607 set_memory_x);
85608 - set_page_attributes(mod->module_init,
85609 - mod->module_init + mod->init_ro_size,
85610 + set_page_attributes(mod->module_init_rx,
85611 + mod->module_init_rx + mod->init_size_rx,
85612 set_memory_rw);
85613 }
85614
85615 @@ -1786,14 +1788,14 @@ void set_all_modules_text_rw(void)
85616 list_for_each_entry_rcu(mod, &modules, list) {
85617 if (mod->state == MODULE_STATE_UNFORMED)
85618 continue;
85619 - if ((mod->module_core) && (mod->core_text_size)) {
85620 - set_page_attributes(mod->module_core,
85621 - mod->module_core + mod->core_text_size,
85622 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
85623 + set_page_attributes(mod->module_core_rx,
85624 + mod->module_core_rx + mod->core_size_rx,
85625 set_memory_rw);
85626 }
85627 - if ((mod->module_init) && (mod->init_text_size)) {
85628 - set_page_attributes(mod->module_init,
85629 - mod->module_init + mod->init_text_size,
85630 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
85631 + set_page_attributes(mod->module_init_rx,
85632 + mod->module_init_rx + mod->init_size_rx,
85633 set_memory_rw);
85634 }
85635 }
85636 @@ -1809,14 +1811,14 @@ void set_all_modules_text_ro(void)
85637 list_for_each_entry_rcu(mod, &modules, list) {
85638 if (mod->state == MODULE_STATE_UNFORMED)
85639 continue;
85640 - if ((mod->module_core) && (mod->core_text_size)) {
85641 - set_page_attributes(mod->module_core,
85642 - mod->module_core + mod->core_text_size,
85643 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
85644 + set_page_attributes(mod->module_core_rx,
85645 + mod->module_core_rx + mod->core_size_rx,
85646 set_memory_ro);
85647 }
85648 - if ((mod->module_init) && (mod->init_text_size)) {
85649 - set_page_attributes(mod->module_init,
85650 - mod->module_init + mod->init_text_size,
85651 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
85652 + set_page_attributes(mod->module_init_rx,
85653 + mod->module_init_rx + mod->init_size_rx,
85654 set_memory_ro);
85655 }
85656 }
85657 @@ -1867,16 +1869,19 @@ static void free_module(struct module *mod)
85658
85659 /* This may be NULL, but that's OK */
85660 unset_module_init_ro_nx(mod);
85661 - module_free(mod, mod->module_init);
85662 + module_free(mod, mod->module_init_rw);
85663 + module_free_exec(mod, mod->module_init_rx);
85664 kfree(mod->args);
85665 percpu_modfree(mod);
85666
85667 /* Free lock-classes: */
85668 - lockdep_free_key_range(mod->module_core, mod->core_size);
85669 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
85670 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
85671
85672 /* Finally, free the core (containing the module structure) */
85673 unset_module_core_ro_nx(mod);
85674 - module_free(mod, mod->module_core);
85675 + module_free_exec(mod, mod->module_core_rx);
85676 + module_free(mod, mod->module_core_rw);
85677
85678 #ifdef CONFIG_MPU
85679 update_protections(current->mm);
85680 @@ -1945,9 +1950,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85681 int ret = 0;
85682 const struct kernel_symbol *ksym;
85683
85684 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85685 + int is_fs_load = 0;
85686 + int register_filesystem_found = 0;
85687 + char *p;
85688 +
85689 + p = strstr(mod->args, "grsec_modharden_fs");
85690 + if (p) {
85691 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
85692 + /* copy \0 as well */
85693 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
85694 + is_fs_load = 1;
85695 + }
85696 +#endif
85697 +
85698 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
85699 const char *name = info->strtab + sym[i].st_name;
85700
85701 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85702 + /* it's a real shame this will never get ripped and copied
85703 + upstream! ;(
85704 + */
85705 + if (is_fs_load && !strcmp(name, "register_filesystem"))
85706 + register_filesystem_found = 1;
85707 +#endif
85708 +
85709 switch (sym[i].st_shndx) {
85710 case SHN_COMMON:
85711 /* We compiled with -fno-common. These are not
85712 @@ -1968,7 +1995,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85713 ksym = resolve_symbol_wait(mod, info, name);
85714 /* Ok if resolved. */
85715 if (ksym && !IS_ERR(ksym)) {
85716 + pax_open_kernel();
85717 sym[i].st_value = ksym->value;
85718 + pax_close_kernel();
85719 break;
85720 }
85721
85722 @@ -1987,11 +2016,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85723 secbase = (unsigned long)mod_percpu(mod);
85724 else
85725 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
85726 + pax_open_kernel();
85727 sym[i].st_value += secbase;
85728 + pax_close_kernel();
85729 break;
85730 }
85731 }
85732
85733 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85734 + if (is_fs_load && !register_filesystem_found) {
85735 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
85736 + ret = -EPERM;
85737 + }
85738 +#endif
85739 +
85740 return ret;
85741 }
85742
85743 @@ -2075,22 +2113,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
85744 || s->sh_entsize != ~0UL
85745 || strstarts(sname, ".init"))
85746 continue;
85747 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
85748 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85749 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
85750 + else
85751 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
85752 pr_debug("\t%s\n", sname);
85753 }
85754 - switch (m) {
85755 - case 0: /* executable */
85756 - mod->core_size = debug_align(mod->core_size);
85757 - mod->core_text_size = mod->core_size;
85758 - break;
85759 - case 1: /* RO: text and ro-data */
85760 - mod->core_size = debug_align(mod->core_size);
85761 - mod->core_ro_size = mod->core_size;
85762 - break;
85763 - case 3: /* whole core */
85764 - mod->core_size = debug_align(mod->core_size);
85765 - break;
85766 - }
85767 }
85768
85769 pr_debug("Init section allocation order:\n");
85770 @@ -2104,23 +2132,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
85771 || s->sh_entsize != ~0UL
85772 || !strstarts(sname, ".init"))
85773 continue;
85774 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
85775 - | INIT_OFFSET_MASK);
85776 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85777 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
85778 + else
85779 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
85780 + s->sh_entsize |= INIT_OFFSET_MASK;
85781 pr_debug("\t%s\n", sname);
85782 }
85783 - switch (m) {
85784 - case 0: /* executable */
85785 - mod->init_size = debug_align(mod->init_size);
85786 - mod->init_text_size = mod->init_size;
85787 - break;
85788 - case 1: /* RO: text and ro-data */
85789 - mod->init_size = debug_align(mod->init_size);
85790 - mod->init_ro_size = mod->init_size;
85791 - break;
85792 - case 3: /* whole init */
85793 - mod->init_size = debug_align(mod->init_size);
85794 - break;
85795 - }
85796 }
85797 }
85798
85799 @@ -2293,7 +2311,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85800
85801 /* Put symbol section at end of init part of module. */
85802 symsect->sh_flags |= SHF_ALLOC;
85803 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
85804 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
85805 info->index.sym) | INIT_OFFSET_MASK;
85806 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
85807
85808 @@ -2310,13 +2328,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85809 }
85810
85811 /* Append room for core symbols at end of core part. */
85812 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
85813 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
85814 - mod->core_size += strtab_size;
85815 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
85816 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
85817 + mod->core_size_rx += strtab_size;
85818
85819 /* Put string table section at end of init part of module. */
85820 strsect->sh_flags |= SHF_ALLOC;
85821 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
85822 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
85823 info->index.str) | INIT_OFFSET_MASK;
85824 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
85825 }
85826 @@ -2334,12 +2352,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85827 /* Make sure we get permanent strtab: don't use info->strtab. */
85828 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
85829
85830 + pax_open_kernel();
85831 +
85832 /* Set types up while we still have access to sections. */
85833 for (i = 0; i < mod->num_symtab; i++)
85834 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
85835
85836 - mod->core_symtab = dst = mod->module_core + info->symoffs;
85837 - mod->core_strtab = s = mod->module_core + info->stroffs;
85838 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
85839 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
85840 src = mod->symtab;
85841 for (ndst = i = 0; i < mod->num_symtab; i++) {
85842 if (i == 0 ||
85843 @@ -2351,6 +2371,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85844 }
85845 }
85846 mod->core_num_syms = ndst;
85847 +
85848 + pax_close_kernel();
85849 }
85850 #else
85851 static inline void layout_symtab(struct module *mod, struct load_info *info)
85852 @@ -2384,17 +2406,33 @@ void * __weak module_alloc(unsigned long size)
85853 return vmalloc_exec(size);
85854 }
85855
85856 -static void *module_alloc_update_bounds(unsigned long size)
85857 +static void *module_alloc_update_bounds_rw(unsigned long size)
85858 {
85859 void *ret = module_alloc(size);
85860
85861 if (ret) {
85862 mutex_lock(&module_mutex);
85863 /* Update module bounds. */
85864 - if ((unsigned long)ret < module_addr_min)
85865 - module_addr_min = (unsigned long)ret;
85866 - if ((unsigned long)ret + size > module_addr_max)
85867 - module_addr_max = (unsigned long)ret + size;
85868 + if ((unsigned long)ret < module_addr_min_rw)
85869 + module_addr_min_rw = (unsigned long)ret;
85870 + if ((unsigned long)ret + size > module_addr_max_rw)
85871 + module_addr_max_rw = (unsigned long)ret + size;
85872 + mutex_unlock(&module_mutex);
85873 + }
85874 + return ret;
85875 +}
85876 +
85877 +static void *module_alloc_update_bounds_rx(unsigned long size)
85878 +{
85879 + void *ret = module_alloc_exec(size);
85880 +
85881 + if (ret) {
85882 + mutex_lock(&module_mutex);
85883 + /* Update module bounds. */
85884 + if ((unsigned long)ret < module_addr_min_rx)
85885 + module_addr_min_rx = (unsigned long)ret;
85886 + if ((unsigned long)ret + size > module_addr_max_rx)
85887 + module_addr_max_rx = (unsigned long)ret + size;
85888 mutex_unlock(&module_mutex);
85889 }
85890 return ret;
85891 @@ -2667,8 +2705,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
85892 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
85893 {
85894 const char *modmagic = get_modinfo(info, "vermagic");
85895 + const char *license = get_modinfo(info, "license");
85896 int err;
85897
85898 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
85899 + if (!license || !license_is_gpl_compatible(license))
85900 + return -ENOEXEC;
85901 +#endif
85902 +
85903 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
85904 modmagic = NULL;
85905
85906 @@ -2693,7 +2737,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
85907 }
85908
85909 /* Set up license info based on the info section */
85910 - set_license(mod, get_modinfo(info, "license"));
85911 + set_license(mod, license);
85912
85913 return 0;
85914 }
85915 @@ -2787,7 +2831,7 @@ static int move_module(struct module *mod, struct load_info *info)
85916 void *ptr;
85917
85918 /* Do the allocs. */
85919 - ptr = module_alloc_update_bounds(mod->core_size);
85920 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
85921 /*
85922 * The pointer to this block is stored in the module structure
85923 * which is inside the block. Just mark it as not being a
85924 @@ -2797,11 +2841,11 @@ static int move_module(struct module *mod, struct load_info *info)
85925 if (!ptr)
85926 return -ENOMEM;
85927
85928 - memset(ptr, 0, mod->core_size);
85929 - mod->module_core = ptr;
85930 + memset(ptr, 0, mod->core_size_rw);
85931 + mod->module_core_rw = ptr;
85932
85933 - if (mod->init_size) {
85934 - ptr = module_alloc_update_bounds(mod->init_size);
85935 + if (mod->init_size_rw) {
85936 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
85937 /*
85938 * The pointer to this block is stored in the module structure
85939 * which is inside the block. This block doesn't need to be
85940 @@ -2810,13 +2854,45 @@ static int move_module(struct module *mod, struct load_info *info)
85941 */
85942 kmemleak_ignore(ptr);
85943 if (!ptr) {
85944 - module_free(mod, mod->module_core);
85945 + module_free(mod, mod->module_core_rw);
85946 return -ENOMEM;
85947 }
85948 - memset(ptr, 0, mod->init_size);
85949 - mod->module_init = ptr;
85950 + memset(ptr, 0, mod->init_size_rw);
85951 + mod->module_init_rw = ptr;
85952 } else
85953 - mod->module_init = NULL;
85954 + mod->module_init_rw = NULL;
85955 +
85956 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
85957 + kmemleak_not_leak(ptr);
85958 + if (!ptr) {
85959 + if (mod->module_init_rw)
85960 + module_free(mod, mod->module_init_rw);
85961 + module_free(mod, mod->module_core_rw);
85962 + return -ENOMEM;
85963 + }
85964 +
85965 + pax_open_kernel();
85966 + memset(ptr, 0, mod->core_size_rx);
85967 + pax_close_kernel();
85968 + mod->module_core_rx = ptr;
85969 +
85970 + if (mod->init_size_rx) {
85971 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
85972 + kmemleak_ignore(ptr);
85973 + if (!ptr && mod->init_size_rx) {
85974 + module_free_exec(mod, mod->module_core_rx);
85975 + if (mod->module_init_rw)
85976 + module_free(mod, mod->module_init_rw);
85977 + module_free(mod, mod->module_core_rw);
85978 + return -ENOMEM;
85979 + }
85980 +
85981 + pax_open_kernel();
85982 + memset(ptr, 0, mod->init_size_rx);
85983 + pax_close_kernel();
85984 + mod->module_init_rx = ptr;
85985 + } else
85986 + mod->module_init_rx = NULL;
85987
85988 /* Transfer each section which specifies SHF_ALLOC */
85989 pr_debug("final section addresses:\n");
85990 @@ -2827,16 +2903,45 @@ static int move_module(struct module *mod, struct load_info *info)
85991 if (!(shdr->sh_flags & SHF_ALLOC))
85992 continue;
85993
85994 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
85995 - dest = mod->module_init
85996 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
85997 - else
85998 - dest = mod->module_core + shdr->sh_entsize;
85999 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
86000 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86001 + dest = mod->module_init_rw
86002 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86003 + else
86004 + dest = mod->module_init_rx
86005 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86006 + } else {
86007 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86008 + dest = mod->module_core_rw + shdr->sh_entsize;
86009 + else
86010 + dest = mod->module_core_rx + shdr->sh_entsize;
86011 + }
86012 +
86013 + if (shdr->sh_type != SHT_NOBITS) {
86014 +
86015 +#ifdef CONFIG_PAX_KERNEXEC
86016 +#ifdef CONFIG_X86_64
86017 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
86018 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
86019 +#endif
86020 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
86021 + pax_open_kernel();
86022 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86023 + pax_close_kernel();
86024 + } else
86025 +#endif
86026
86027 - if (shdr->sh_type != SHT_NOBITS)
86028 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86029 + }
86030 /* Update sh_addr to point to copy in image. */
86031 - shdr->sh_addr = (unsigned long)dest;
86032 +
86033 +#ifdef CONFIG_PAX_KERNEXEC
86034 + if (shdr->sh_flags & SHF_EXECINSTR)
86035 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
86036 + else
86037 +#endif
86038 +
86039 + shdr->sh_addr = (unsigned long)dest;
86040 pr_debug("\t0x%lx %s\n",
86041 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
86042 }
86043 @@ -2893,12 +2998,12 @@ static void flush_module_icache(const struct module *mod)
86044 * Do it before processing of module parameters, so the module
86045 * can provide parameter accessor functions of its own.
86046 */
86047 - if (mod->module_init)
86048 - flush_icache_range((unsigned long)mod->module_init,
86049 - (unsigned long)mod->module_init
86050 - + mod->init_size);
86051 - flush_icache_range((unsigned long)mod->module_core,
86052 - (unsigned long)mod->module_core + mod->core_size);
86053 + if (mod->module_init_rx)
86054 + flush_icache_range((unsigned long)mod->module_init_rx,
86055 + (unsigned long)mod->module_init_rx
86056 + + mod->init_size_rx);
86057 + flush_icache_range((unsigned long)mod->module_core_rx,
86058 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
86059
86060 set_fs(old_fs);
86061 }
86062 @@ -2955,8 +3060,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
86063 static void module_deallocate(struct module *mod, struct load_info *info)
86064 {
86065 percpu_modfree(mod);
86066 - module_free(mod, mod->module_init);
86067 - module_free(mod, mod->module_core);
86068 + module_free_exec(mod, mod->module_init_rx);
86069 + module_free_exec(mod, mod->module_core_rx);
86070 + module_free(mod, mod->module_init_rw);
86071 + module_free(mod, mod->module_core_rw);
86072 }
86073
86074 int __weak module_finalize(const Elf_Ehdr *hdr,
86075 @@ -2969,7 +3076,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
86076 static int post_relocation(struct module *mod, const struct load_info *info)
86077 {
86078 /* Sort exception table now relocations are done. */
86079 + pax_open_kernel();
86080 sort_extable(mod->extable, mod->extable + mod->num_exentries);
86081 + pax_close_kernel();
86082
86083 /* Copy relocated percpu area over. */
86084 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
86085 @@ -3023,16 +3132,16 @@ static int do_init_module(struct module *mod)
86086 MODULE_STATE_COMING, mod);
86087
86088 /* Set RO and NX regions for core */
86089 - set_section_ro_nx(mod->module_core,
86090 - mod->core_text_size,
86091 - mod->core_ro_size,
86092 - mod->core_size);
86093 + set_section_ro_nx(mod->module_core_rx,
86094 + mod->core_size_rx,
86095 + mod->core_size_rx,
86096 + mod->core_size_rx);
86097
86098 /* Set RO and NX regions for init */
86099 - set_section_ro_nx(mod->module_init,
86100 - mod->init_text_size,
86101 - mod->init_ro_size,
86102 - mod->init_size);
86103 + set_section_ro_nx(mod->module_init_rx,
86104 + mod->init_size_rx,
86105 + mod->init_size_rx,
86106 + mod->init_size_rx);
86107
86108 do_mod_ctors(mod);
86109 /* Start the module */
86110 @@ -3093,11 +3202,12 @@ static int do_init_module(struct module *mod)
86111 mod->strtab = mod->core_strtab;
86112 #endif
86113 unset_module_init_ro_nx(mod);
86114 - module_free(mod, mod->module_init);
86115 - mod->module_init = NULL;
86116 - mod->init_size = 0;
86117 - mod->init_ro_size = 0;
86118 - mod->init_text_size = 0;
86119 + module_free(mod, mod->module_init_rw);
86120 + module_free_exec(mod, mod->module_init_rx);
86121 + mod->module_init_rw = NULL;
86122 + mod->module_init_rx = NULL;
86123 + mod->init_size_rw = 0;
86124 + mod->init_size_rx = 0;
86125 mutex_unlock(&module_mutex);
86126 wake_up_all(&module_wq);
86127
86128 @@ -3240,9 +3350,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
86129 if (err)
86130 goto free_unload;
86131
86132 + /* Now copy in args */
86133 + mod->args = strndup_user(uargs, ~0UL >> 1);
86134 + if (IS_ERR(mod->args)) {
86135 + err = PTR_ERR(mod->args);
86136 + goto free_unload;
86137 + }
86138 +
86139 /* Set up MODINFO_ATTR fields */
86140 setup_modinfo(mod, info);
86141
86142 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86143 + {
86144 + char *p, *p2;
86145 +
86146 + if (strstr(mod->args, "grsec_modharden_netdev")) {
86147 + 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);
86148 + err = -EPERM;
86149 + goto free_modinfo;
86150 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
86151 + p += sizeof("grsec_modharden_normal") - 1;
86152 + p2 = strstr(p, "_");
86153 + if (p2) {
86154 + *p2 = '\0';
86155 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
86156 + *p2 = '_';
86157 + }
86158 + err = -EPERM;
86159 + goto free_modinfo;
86160 + }
86161 + }
86162 +#endif
86163 +
86164 /* Fix up syms, so that st_value is a pointer to location. */
86165 err = simplify_symbols(mod, info);
86166 if (err < 0)
86167 @@ -3258,13 +3397,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
86168
86169 flush_module_icache(mod);
86170
86171 - /* Now copy in args */
86172 - mod->args = strndup_user(uargs, ~0UL >> 1);
86173 - if (IS_ERR(mod->args)) {
86174 - err = PTR_ERR(mod->args);
86175 - goto free_arch_cleanup;
86176 - }
86177 -
86178 dynamic_debug_setup(info->debug, info->num_debug);
86179
86180 /* Finally it's fully formed, ready to start executing. */
86181 @@ -3299,11 +3431,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
86182 ddebug_cleanup:
86183 dynamic_debug_remove(info->debug);
86184 synchronize_sched();
86185 - kfree(mod->args);
86186 - free_arch_cleanup:
86187 module_arch_cleanup(mod);
86188 free_modinfo:
86189 free_modinfo(mod);
86190 + kfree(mod->args);
86191 free_unload:
86192 module_unload_free(mod);
86193 unlink_mod:
86194 @@ -3386,10 +3517,16 @@ static const char *get_ksymbol(struct module *mod,
86195 unsigned long nextval;
86196
86197 /* At worse, next value is at end of module */
86198 - if (within_module_init(addr, mod))
86199 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
86200 + if (within_module_init_rx(addr, mod))
86201 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
86202 + else if (within_module_init_rw(addr, mod))
86203 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
86204 + else if (within_module_core_rx(addr, mod))
86205 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
86206 + else if (within_module_core_rw(addr, mod))
86207 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
86208 else
86209 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
86210 + return NULL;
86211
86212 /* Scan for closest preceding symbol, and next symbol. (ELF
86213 starts real symbols at 1). */
86214 @@ -3640,7 +3777,7 @@ static int m_show(struct seq_file *m, void *p)
86215 return 0;
86216
86217 seq_printf(m, "%s %u",
86218 - mod->name, mod->init_size + mod->core_size);
86219 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
86220 print_unload_info(m, mod);
86221
86222 /* Informative for users. */
86223 @@ -3649,7 +3786,7 @@ static int m_show(struct seq_file *m, void *p)
86224 mod->state == MODULE_STATE_COMING ? "Loading":
86225 "Live");
86226 /* Used by oprofile and other similar tools. */
86227 - seq_printf(m, " 0x%pK", mod->module_core);
86228 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
86229
86230 /* Taints info */
86231 if (mod->taints)
86232 @@ -3685,7 +3822,17 @@ static const struct file_operations proc_modules_operations = {
86233
86234 static int __init proc_modules_init(void)
86235 {
86236 +#ifndef CONFIG_GRKERNSEC_HIDESYM
86237 +#ifdef CONFIG_GRKERNSEC_PROC_USER
86238 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86239 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86240 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
86241 +#else
86242 proc_create("modules", 0, NULL, &proc_modules_operations);
86243 +#endif
86244 +#else
86245 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86246 +#endif
86247 return 0;
86248 }
86249 module_init(proc_modules_init);
86250 @@ -3746,14 +3893,14 @@ struct module *__module_address(unsigned long addr)
86251 {
86252 struct module *mod;
86253
86254 - if (addr < module_addr_min || addr > module_addr_max)
86255 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
86256 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
86257 return NULL;
86258
86259 list_for_each_entry_rcu(mod, &modules, list) {
86260 if (mod->state == MODULE_STATE_UNFORMED)
86261 continue;
86262 - if (within_module_core(addr, mod)
86263 - || within_module_init(addr, mod))
86264 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
86265 return mod;
86266 }
86267 return NULL;
86268 @@ -3788,11 +3935,20 @@ bool is_module_text_address(unsigned long addr)
86269 */
86270 struct module *__module_text_address(unsigned long addr)
86271 {
86272 - struct module *mod = __module_address(addr);
86273 + struct module *mod;
86274 +
86275 +#ifdef CONFIG_X86_32
86276 + addr = ktla_ktva(addr);
86277 +#endif
86278 +
86279 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
86280 + return NULL;
86281 +
86282 + mod = __module_address(addr);
86283 +
86284 if (mod) {
86285 /* Make sure it's within the text section. */
86286 - if (!within(addr, mod->module_init, mod->init_text_size)
86287 - && !within(addr, mod->module_core, mod->core_text_size))
86288 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
86289 mod = NULL;
86290 }
86291 return mod;
86292 diff --git a/kernel/notifier.c b/kernel/notifier.c
86293 index 2d5cc4c..d9ea600 100644
86294 --- a/kernel/notifier.c
86295 +++ b/kernel/notifier.c
86296 @@ -5,6 +5,7 @@
86297 #include <linux/rcupdate.h>
86298 #include <linux/vmalloc.h>
86299 #include <linux/reboot.h>
86300 +#include <linux/mm.h>
86301
86302 /*
86303 * Notifier list for kernel code which wants to be called
86304 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
86305 while ((*nl) != NULL) {
86306 if (n->priority > (*nl)->priority)
86307 break;
86308 - nl = &((*nl)->next);
86309 + nl = (struct notifier_block **)&((*nl)->next);
86310 }
86311 - n->next = *nl;
86312 + pax_open_kernel();
86313 + *(const void **)&n->next = *nl;
86314 rcu_assign_pointer(*nl, n);
86315 + pax_close_kernel();
86316 return 0;
86317 }
86318
86319 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
86320 return 0;
86321 if (n->priority > (*nl)->priority)
86322 break;
86323 - nl = &((*nl)->next);
86324 + nl = (struct notifier_block **)&((*nl)->next);
86325 }
86326 - n->next = *nl;
86327 + pax_open_kernel();
86328 + *(const void **)&n->next = *nl;
86329 rcu_assign_pointer(*nl, n);
86330 + pax_close_kernel();
86331 return 0;
86332 }
86333
86334 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
86335 {
86336 while ((*nl) != NULL) {
86337 if ((*nl) == n) {
86338 + pax_open_kernel();
86339 rcu_assign_pointer(*nl, n->next);
86340 + pax_close_kernel();
86341 return 0;
86342 }
86343 - nl = &((*nl)->next);
86344 + nl = (struct notifier_block **)&((*nl)->next);
86345 }
86346 return -ENOENT;
86347 }
86348 diff --git a/kernel/padata.c b/kernel/padata.c
86349 index 2abd25d..02c4faa 100644
86350 --- a/kernel/padata.c
86351 +++ b/kernel/padata.c
86352 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
86353 * seq_nr mod. number of cpus in use.
86354 */
86355
86356 - seq_nr = atomic_inc_return(&pd->seq_nr);
86357 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
86358 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
86359
86360 return padata_index_to_cpu(pd, cpu_index);
86361 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
86362 padata_init_pqueues(pd);
86363 padata_init_squeues(pd);
86364 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
86365 - atomic_set(&pd->seq_nr, -1);
86366 + atomic_set_unchecked(&pd->seq_nr, -1);
86367 atomic_set(&pd->reorder_objects, 0);
86368 atomic_set(&pd->refcnt, 0);
86369 pd->pinst = pinst;
86370 diff --git a/kernel/panic.c b/kernel/panic.c
86371 index c00b4ce..a846117 100644
86372 --- a/kernel/panic.c
86373 +++ b/kernel/panic.c
86374 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
86375 disable_trace_on_warning();
86376
86377 pr_warn("------------[ cut here ]------------\n");
86378 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
86379 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
86380 raw_smp_processor_id(), current->pid, file, line, caller);
86381
86382 if (args)
86383 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
86384 */
86385 void __stack_chk_fail(void)
86386 {
86387 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
86388 + dump_stack();
86389 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
86390 __builtin_return_address(0));
86391 }
86392 EXPORT_SYMBOL(__stack_chk_fail);
86393 diff --git a/kernel/pid.c b/kernel/pid.c
86394 index 9b9a266..c20ef80 100644
86395 --- a/kernel/pid.c
86396 +++ b/kernel/pid.c
86397 @@ -33,6 +33,7 @@
86398 #include <linux/rculist.h>
86399 #include <linux/bootmem.h>
86400 #include <linux/hash.h>
86401 +#include <linux/security.h>
86402 #include <linux/pid_namespace.h>
86403 #include <linux/init_task.h>
86404 #include <linux/syscalls.h>
86405 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
86406
86407 int pid_max = PID_MAX_DEFAULT;
86408
86409 -#define RESERVED_PIDS 300
86410 +#define RESERVED_PIDS 500
86411
86412 int pid_max_min = RESERVED_PIDS + 1;
86413 int pid_max_max = PID_MAX_LIMIT;
86414 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
86415 */
86416 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
86417 {
86418 + struct task_struct *task;
86419 +
86420 rcu_lockdep_assert(rcu_read_lock_held(),
86421 "find_task_by_pid_ns() needs rcu_read_lock()"
86422 " protection");
86423 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86424 +
86425 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86426 +
86427 + if (gr_pid_is_chrooted(task))
86428 + return NULL;
86429 +
86430 + return task;
86431 }
86432
86433 struct task_struct *find_task_by_vpid(pid_t vnr)
86434 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
86435 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
86436 }
86437
86438 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
86439 +{
86440 + rcu_lockdep_assert(rcu_read_lock_held(),
86441 + "find_task_by_pid_ns() needs rcu_read_lock()"
86442 + " protection");
86443 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
86444 +}
86445 +
86446 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
86447 {
86448 struct pid *pid;
86449 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
86450 index 06c62de..b08cc6c 100644
86451 --- a/kernel/pid_namespace.c
86452 +++ b/kernel/pid_namespace.c
86453 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
86454 void __user *buffer, size_t *lenp, loff_t *ppos)
86455 {
86456 struct pid_namespace *pid_ns = task_active_pid_ns(current);
86457 - struct ctl_table tmp = *table;
86458 + ctl_table_no_const tmp = *table;
86459
86460 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
86461 return -EPERM;
86462 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
86463 index c7f31aa..2b44977 100644
86464 --- a/kernel/posix-cpu-timers.c
86465 +++ b/kernel/posix-cpu-timers.c
86466 @@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
86467
86468 static __init int init_posix_cpu_timers(void)
86469 {
86470 - struct k_clock process = {
86471 + static struct k_clock process = {
86472 .clock_getres = process_cpu_clock_getres,
86473 .clock_get = process_cpu_clock_get,
86474 .timer_create = process_cpu_timer_create,
86475 .nsleep = process_cpu_nsleep,
86476 .nsleep_restart = process_cpu_nsleep_restart,
86477 };
86478 - struct k_clock thread = {
86479 + static struct k_clock thread = {
86480 .clock_getres = thread_cpu_clock_getres,
86481 .clock_get = thread_cpu_clock_get,
86482 .timer_create = thread_cpu_timer_create,
86483 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
86484 index 424c2d4..679242f 100644
86485 --- a/kernel/posix-timers.c
86486 +++ b/kernel/posix-timers.c
86487 @@ -43,6 +43,7 @@
86488 #include <linux/hash.h>
86489 #include <linux/posix-clock.h>
86490 #include <linux/posix-timers.h>
86491 +#include <linux/grsecurity.h>
86492 #include <linux/syscalls.h>
86493 #include <linux/wait.h>
86494 #include <linux/workqueue.h>
86495 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
86496 * which we beg off on and pass to do_sys_settimeofday().
86497 */
86498
86499 -static struct k_clock posix_clocks[MAX_CLOCKS];
86500 +static struct k_clock *posix_clocks[MAX_CLOCKS];
86501
86502 /*
86503 * These ones are defined below.
86504 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
86505 */
86506 static __init int init_posix_timers(void)
86507 {
86508 - struct k_clock clock_realtime = {
86509 + static struct k_clock clock_realtime = {
86510 .clock_getres = hrtimer_get_res,
86511 .clock_get = posix_clock_realtime_get,
86512 .clock_set = posix_clock_realtime_set,
86513 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
86514 .timer_get = common_timer_get,
86515 .timer_del = common_timer_del,
86516 };
86517 - struct k_clock clock_monotonic = {
86518 + static struct k_clock clock_monotonic = {
86519 .clock_getres = hrtimer_get_res,
86520 .clock_get = posix_ktime_get_ts,
86521 .nsleep = common_nsleep,
86522 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
86523 .timer_get = common_timer_get,
86524 .timer_del = common_timer_del,
86525 };
86526 - struct k_clock clock_monotonic_raw = {
86527 + static struct k_clock clock_monotonic_raw = {
86528 .clock_getres = hrtimer_get_res,
86529 .clock_get = posix_get_monotonic_raw,
86530 };
86531 - struct k_clock clock_realtime_coarse = {
86532 + static struct k_clock clock_realtime_coarse = {
86533 .clock_getres = posix_get_coarse_res,
86534 .clock_get = posix_get_realtime_coarse,
86535 };
86536 - struct k_clock clock_monotonic_coarse = {
86537 + static struct k_clock clock_monotonic_coarse = {
86538 .clock_getres = posix_get_coarse_res,
86539 .clock_get = posix_get_monotonic_coarse,
86540 };
86541 - struct k_clock clock_tai = {
86542 + static struct k_clock clock_tai = {
86543 .clock_getres = hrtimer_get_res,
86544 .clock_get = posix_get_tai,
86545 .nsleep = common_nsleep,
86546 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
86547 .timer_get = common_timer_get,
86548 .timer_del = common_timer_del,
86549 };
86550 - struct k_clock clock_boottime = {
86551 + static struct k_clock clock_boottime = {
86552 .clock_getres = hrtimer_get_res,
86553 .clock_get = posix_get_boottime,
86554 .nsleep = common_nsleep,
86555 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
86556 return;
86557 }
86558
86559 - posix_clocks[clock_id] = *new_clock;
86560 + posix_clocks[clock_id] = new_clock;
86561 }
86562 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
86563
86564 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
86565 return (id & CLOCKFD_MASK) == CLOCKFD ?
86566 &clock_posix_dynamic : &clock_posix_cpu;
86567
86568 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
86569 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
86570 return NULL;
86571 - return &posix_clocks[id];
86572 + return posix_clocks[id];
86573 }
86574
86575 static int common_timer_create(struct k_itimer *new_timer)
86576 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
86577 struct k_clock *kc = clockid_to_kclock(which_clock);
86578 struct k_itimer *new_timer;
86579 int error, new_timer_id;
86580 - sigevent_t event;
86581 + sigevent_t event = { };
86582 int it_id_set = IT_ID_NOT_SET;
86583
86584 if (!kc)
86585 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
86586 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
86587 return -EFAULT;
86588
86589 + /* only the CLOCK_REALTIME clock can be set, all other clocks
86590 + have their clock_set fptr set to a nosettime dummy function
86591 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
86592 + call common_clock_set, which calls do_sys_settimeofday, which
86593 + we hook
86594 + */
86595 +
86596 return kc->clock_set(which_clock, &new_tp);
86597 }
86598
86599 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
86600 index 2fac9cc..56fef29 100644
86601 --- a/kernel/power/Kconfig
86602 +++ b/kernel/power/Kconfig
86603 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
86604 config HIBERNATION
86605 bool "Hibernation (aka 'suspend to disk')"
86606 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
86607 + depends on !GRKERNSEC_KMEM
86608 + depends on !PAX_MEMORY_SANITIZE
86609 select HIBERNATE_CALLBACKS
86610 select LZO_COMPRESS
86611 select LZO_DECOMPRESS
86612 diff --git a/kernel/power/process.c b/kernel/power/process.c
86613 index 06ec886..9dba35e 100644
86614 --- a/kernel/power/process.c
86615 +++ b/kernel/power/process.c
86616 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
86617 unsigned int elapsed_msecs;
86618 bool wakeup = false;
86619 int sleep_usecs = USEC_PER_MSEC;
86620 + bool timedout = false;
86621
86622 do_gettimeofday(&start);
86623
86624 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
86625
86626 while (true) {
86627 todo = 0;
86628 + if (time_after(jiffies, end_time))
86629 + timedout = true;
86630 read_lock(&tasklist_lock);
86631 do_each_thread(g, p) {
86632 if (p == current || !freeze_task(p))
86633 continue;
86634
86635 - if (!freezer_should_skip(p))
86636 + if (!freezer_should_skip(p)) {
86637 todo++;
86638 + if (timedout) {
86639 + printk(KERN_ERR "Task refusing to freeze:\n");
86640 + sched_show_task(p);
86641 + }
86642 + }
86643 } while_each_thread(g, p);
86644 read_unlock(&tasklist_lock);
86645
86646 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
86647 todo += wq_busy;
86648 }
86649
86650 - if (!todo || time_after(jiffies, end_time))
86651 + if (!todo || timedout)
86652 break;
86653
86654 if (pm_wakeup_pending()) {
86655 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
86656 index be7c86b..c741464 100644
86657 --- a/kernel/printk/printk.c
86658 +++ b/kernel/printk/printk.c
86659 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
86660 if (from_file && type != SYSLOG_ACTION_OPEN)
86661 return 0;
86662
86663 +#ifdef CONFIG_GRKERNSEC_DMESG
86664 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
86665 + return -EPERM;
86666 +#endif
86667 +
86668 if (syslog_action_restricted(type)) {
86669 if (capable(CAP_SYSLOG))
86670 return 0;
86671 diff --git a/kernel/profile.c b/kernel/profile.c
86672 index 6631e1e..310c266 100644
86673 --- a/kernel/profile.c
86674 +++ b/kernel/profile.c
86675 @@ -37,7 +37,7 @@ struct profile_hit {
86676 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
86677 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
86678
86679 -static atomic_t *prof_buffer;
86680 +static atomic_unchecked_t *prof_buffer;
86681 static unsigned long prof_len, prof_shift;
86682
86683 int prof_on __read_mostly;
86684 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
86685 hits[i].pc = 0;
86686 continue;
86687 }
86688 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86689 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86690 hits[i].hits = hits[i].pc = 0;
86691 }
86692 }
86693 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86694 * Add the current hit(s) and flush the write-queue out
86695 * to the global buffer:
86696 */
86697 - atomic_add(nr_hits, &prof_buffer[pc]);
86698 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
86699 for (i = 0; i < NR_PROFILE_HIT; ++i) {
86700 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86701 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86702 hits[i].pc = hits[i].hits = 0;
86703 }
86704 out:
86705 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86706 {
86707 unsigned long pc;
86708 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
86709 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86710 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86711 }
86712 #endif /* !CONFIG_SMP */
86713
86714 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
86715 return -EFAULT;
86716 buf++; p++; count--; read++;
86717 }
86718 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
86719 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
86720 if (copy_to_user(buf, (void *)pnt, count))
86721 return -EFAULT;
86722 read += count;
86723 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
86724 }
86725 #endif
86726 profile_discard_flip_buffers();
86727 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
86728 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
86729 return count;
86730 }
86731
86732 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
86733 index 1f4bcb3..99cf7ab 100644
86734 --- a/kernel/ptrace.c
86735 +++ b/kernel/ptrace.c
86736 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
86737 if (seize)
86738 flags |= PT_SEIZED;
86739 rcu_read_lock();
86740 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86741 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86742 flags |= PT_PTRACE_CAP;
86743 rcu_read_unlock();
86744 task->ptrace = flags;
86745 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
86746 break;
86747 return -EIO;
86748 }
86749 - if (copy_to_user(dst, buf, retval))
86750 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
86751 return -EFAULT;
86752 copied += retval;
86753 src += retval;
86754 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
86755 bool seized = child->ptrace & PT_SEIZED;
86756 int ret = -EIO;
86757 siginfo_t siginfo, *si;
86758 - void __user *datavp = (void __user *) data;
86759 + void __user *datavp = (__force void __user *) data;
86760 unsigned long __user *datalp = datavp;
86761 unsigned long flags;
86762
86763 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
86764 goto out;
86765 }
86766
86767 + if (gr_handle_ptrace(child, request)) {
86768 + ret = -EPERM;
86769 + goto out_put_task_struct;
86770 + }
86771 +
86772 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86773 ret = ptrace_attach(child, request, addr, data);
86774 /*
86775 * Some architectures need to do book-keeping after
86776 * a ptrace attach.
86777 */
86778 - if (!ret)
86779 + if (!ret) {
86780 arch_ptrace_attach(child);
86781 + gr_audit_ptrace(child);
86782 + }
86783 goto out_put_task_struct;
86784 }
86785
86786 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
86787 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
86788 if (copied != sizeof(tmp))
86789 return -EIO;
86790 - return put_user(tmp, (unsigned long __user *)data);
86791 + return put_user(tmp, (__force unsigned long __user *)data);
86792 }
86793
86794 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
86795 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
86796 }
86797
86798 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86799 - compat_long_t addr, compat_long_t data)
86800 + compat_ulong_t addr, compat_ulong_t data)
86801 {
86802 struct task_struct *child;
86803 long ret;
86804 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86805 goto out;
86806 }
86807
86808 + if (gr_handle_ptrace(child, request)) {
86809 + ret = -EPERM;
86810 + goto out_put_task_struct;
86811 + }
86812 +
86813 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86814 ret = ptrace_attach(child, request, addr, data);
86815 /*
86816 * Some architectures need to do book-keeping after
86817 * a ptrace attach.
86818 */
86819 - if (!ret)
86820 + if (!ret) {
86821 arch_ptrace_attach(child);
86822 + gr_audit_ptrace(child);
86823 + }
86824 goto out_put_task_struct;
86825 }
86826
86827 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
86828 index 01d5ccb..cdcbee6 100644
86829 --- a/kernel/rcu/srcu.c
86830 +++ b/kernel/rcu/srcu.c
86831 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
86832
86833 idx = ACCESS_ONCE(sp->completed) & 0x1;
86834 preempt_disable();
86835 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
86836 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
86837 smp_mb(); /* B */ /* Avoid leaking the critical section. */
86838 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
86839 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
86840 preempt_enable();
86841 return idx;
86842 }
86843 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
86844 index 1254f31..16258dc 100644
86845 --- a/kernel/rcu/tiny.c
86846 +++ b/kernel/rcu/tiny.c
86847 @@ -46,7 +46,7 @@
86848 /* Forward declarations for tiny_plugin.h. */
86849 struct rcu_ctrlblk;
86850 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
86851 -static void rcu_process_callbacks(struct softirq_action *unused);
86852 +static void rcu_process_callbacks(void);
86853 static void __call_rcu(struct rcu_head *head,
86854 void (*func)(struct rcu_head *rcu),
86855 struct rcu_ctrlblk *rcp);
86856 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
86857 false));
86858 }
86859
86860 -static void rcu_process_callbacks(struct softirq_action *unused)
86861 +static __latent_entropy void rcu_process_callbacks(void)
86862 {
86863 __rcu_process_callbacks(&rcu_sched_ctrlblk);
86864 __rcu_process_callbacks(&rcu_bh_ctrlblk);
86865 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
86866 index 3929cd4..421624d 100644
86867 --- a/kernel/rcu/torture.c
86868 +++ b/kernel/rcu/torture.c
86869 @@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
86870 { 0 };
86871 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
86872 { 0 };
86873 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
86874 -static atomic_t n_rcu_torture_alloc;
86875 -static atomic_t n_rcu_torture_alloc_fail;
86876 -static atomic_t n_rcu_torture_free;
86877 -static atomic_t n_rcu_torture_mberror;
86878 -static atomic_t n_rcu_torture_error;
86879 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
86880 +static atomic_unchecked_t n_rcu_torture_alloc;
86881 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
86882 +static atomic_unchecked_t n_rcu_torture_free;
86883 +static atomic_unchecked_t n_rcu_torture_mberror;
86884 +static atomic_unchecked_t n_rcu_torture_error;
86885 static long n_rcu_torture_barrier_error;
86886 static long n_rcu_torture_boost_ktrerror;
86887 static long n_rcu_torture_boost_rterror;
86888 @@ -299,11 +299,11 @@ rcu_torture_alloc(void)
86889
86890 spin_lock_bh(&rcu_torture_lock);
86891 if (list_empty(&rcu_torture_freelist)) {
86892 - atomic_inc(&n_rcu_torture_alloc_fail);
86893 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
86894 spin_unlock_bh(&rcu_torture_lock);
86895 return NULL;
86896 }
86897 - atomic_inc(&n_rcu_torture_alloc);
86898 + atomic_inc_unchecked(&n_rcu_torture_alloc);
86899 p = rcu_torture_freelist.next;
86900 list_del_init(p);
86901 spin_unlock_bh(&rcu_torture_lock);
86902 @@ -316,7 +316,7 @@ rcu_torture_alloc(void)
86903 static void
86904 rcu_torture_free(struct rcu_torture *p)
86905 {
86906 - atomic_inc(&n_rcu_torture_free);
86907 + atomic_inc_unchecked(&n_rcu_torture_free);
86908 spin_lock_bh(&rcu_torture_lock);
86909 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
86910 spin_unlock_bh(&rcu_torture_lock);
86911 @@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
86912 i = rp->rtort_pipe_count;
86913 if (i > RCU_TORTURE_PIPE_LEN)
86914 i = RCU_TORTURE_PIPE_LEN;
86915 - atomic_inc(&rcu_torture_wcount[i]);
86916 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
86917 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
86918 rp->rtort_mbtest = 0;
86919 rcu_torture_free(rp);
86920 @@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
86921 i = old_rp->rtort_pipe_count;
86922 if (i > RCU_TORTURE_PIPE_LEN)
86923 i = RCU_TORTURE_PIPE_LEN;
86924 - atomic_inc(&rcu_torture_wcount[i]);
86925 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
86926 old_rp->rtort_pipe_count++;
86927 if (gp_normal == gp_exp)
86928 exp = !!(rcu_random(&rand) & 0x80);
86929 @@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
86930 i = rp->rtort_pipe_count;
86931 if (i > RCU_TORTURE_PIPE_LEN)
86932 i = RCU_TORTURE_PIPE_LEN;
86933 - atomic_inc(&rcu_torture_wcount[i]);
86934 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
86935 if (++rp->rtort_pipe_count >=
86936 RCU_TORTURE_PIPE_LEN) {
86937 rp->rtort_mbtest = 0;
86938 @@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
86939 return;
86940 }
86941 if (p->rtort_mbtest == 0)
86942 - atomic_inc(&n_rcu_torture_mberror);
86943 + atomic_inc_unchecked(&n_rcu_torture_mberror);
86944 spin_lock(&rand_lock);
86945 cur_ops->read_delay(&rand);
86946 n_rcu_torture_timers++;
86947 @@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
86948 continue;
86949 }
86950 if (p->rtort_mbtest == 0)
86951 - atomic_inc(&n_rcu_torture_mberror);
86952 + atomic_inc_unchecked(&n_rcu_torture_mberror);
86953 cur_ops->read_delay(&rand);
86954 preempt_disable();
86955 pipe_count = p->rtort_pipe_count;
86956 @@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
86957 rcu_torture_current,
86958 rcu_torture_current_version,
86959 list_empty(&rcu_torture_freelist),
86960 - atomic_read(&n_rcu_torture_alloc),
86961 - atomic_read(&n_rcu_torture_alloc_fail),
86962 - atomic_read(&n_rcu_torture_free));
86963 + atomic_read_unchecked(&n_rcu_torture_alloc),
86964 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
86965 + atomic_read_unchecked(&n_rcu_torture_free));
86966 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
86967 - atomic_read(&n_rcu_torture_mberror),
86968 + atomic_read_unchecked(&n_rcu_torture_mberror),
86969 n_rcu_torture_boost_ktrerror,
86970 n_rcu_torture_boost_rterror);
86971 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
86972 @@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
86973 n_barrier_attempts,
86974 n_rcu_torture_barrier_error);
86975 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
86976 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
86977 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
86978 n_rcu_torture_barrier_error != 0 ||
86979 n_rcu_torture_boost_ktrerror != 0 ||
86980 n_rcu_torture_boost_rterror != 0 ||
86981 n_rcu_torture_boost_failure != 0 ||
86982 i > 1) {
86983 cnt += sprintf(&page[cnt], "!!! ");
86984 - atomic_inc(&n_rcu_torture_error);
86985 + atomic_inc_unchecked(&n_rcu_torture_error);
86986 WARN_ON_ONCE(1);
86987 }
86988 cnt += sprintf(&page[cnt], "Reader Pipe: ");
86989 @@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
86990 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
86991 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
86992 cnt += sprintf(&page[cnt], " %d",
86993 - atomic_read(&rcu_torture_wcount[i]));
86994 + atomic_read_unchecked(&rcu_torture_wcount[i]));
86995 }
86996 cnt += sprintf(&page[cnt], "\n");
86997 if (cur_ops->stats)
86998 @@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
86999
87000 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
87001
87002 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87003 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87004 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
87005 else if (n_online_successes != n_online_attempts ||
87006 n_offline_successes != n_offline_attempts)
87007 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
87008
87009 rcu_torture_current = NULL;
87010 rcu_torture_current_version = 0;
87011 - atomic_set(&n_rcu_torture_alloc, 0);
87012 - atomic_set(&n_rcu_torture_alloc_fail, 0);
87013 - atomic_set(&n_rcu_torture_free, 0);
87014 - atomic_set(&n_rcu_torture_mberror, 0);
87015 - atomic_set(&n_rcu_torture_error, 0);
87016 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
87017 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
87018 + atomic_set_unchecked(&n_rcu_torture_free, 0);
87019 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
87020 + atomic_set_unchecked(&n_rcu_torture_error, 0);
87021 n_rcu_torture_barrier_error = 0;
87022 n_rcu_torture_boost_ktrerror = 0;
87023 n_rcu_torture_boost_rterror = 0;
87024 n_rcu_torture_boost_failure = 0;
87025 n_rcu_torture_boosts = 0;
87026 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
87027 - atomic_set(&rcu_torture_wcount[i], 0);
87028 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
87029 for_each_possible_cpu(cpu) {
87030 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
87031 per_cpu(rcu_torture_count, cpu)[i] = 0;
87032 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
87033 index dd08198..5ccccbe 100644
87034 --- a/kernel/rcu/tree.c
87035 +++ b/kernel/rcu/tree.c
87036 @@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
87037 rcu_prepare_for_idle(smp_processor_id());
87038 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
87039 smp_mb__before_atomic_inc(); /* See above. */
87040 - atomic_inc(&rdtp->dynticks);
87041 + atomic_inc_unchecked(&rdtp->dynticks);
87042 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
87043 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
87044 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
87045
87046 /*
87047 * It is illegal to enter an extended quiescent state while
87048 @@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
87049 int user)
87050 {
87051 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
87052 - atomic_inc(&rdtp->dynticks);
87053 + atomic_inc_unchecked(&rdtp->dynticks);
87054 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
87055 smp_mb__after_atomic_inc(); /* See above. */
87056 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
87057 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
87058 rcu_cleanup_after_idle(smp_processor_id());
87059 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
87060 if (!user && !is_idle_task(current)) {
87061 @@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
87062 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
87063
87064 if (rdtp->dynticks_nmi_nesting == 0 &&
87065 - (atomic_read(&rdtp->dynticks) & 0x1))
87066 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
87067 return;
87068 rdtp->dynticks_nmi_nesting++;
87069 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
87070 - atomic_inc(&rdtp->dynticks);
87071 + atomic_inc_unchecked(&rdtp->dynticks);
87072 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
87073 smp_mb__after_atomic_inc(); /* See above. */
87074 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
87075 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
87076 }
87077
87078 /**
87079 @@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
87080 return;
87081 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
87082 smp_mb__before_atomic_inc(); /* See above. */
87083 - atomic_inc(&rdtp->dynticks);
87084 + atomic_inc_unchecked(&rdtp->dynticks);
87085 smp_mb__after_atomic_inc(); /* Force delay to next write. */
87086 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
87087 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
87088 }
87089
87090 /**
87091 @@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
87092 */
87093 bool notrace __rcu_is_watching(void)
87094 {
87095 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
87096 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
87097 }
87098
87099 /**
87100 @@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
87101 static int dyntick_save_progress_counter(struct rcu_data *rdp,
87102 bool *isidle, unsigned long *maxj)
87103 {
87104 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
87105 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87106 rcu_sysidle_check_cpu(rdp, isidle, maxj);
87107 return (rdp->dynticks_snap & 0x1) == 0;
87108 }
87109 @@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
87110 unsigned int curr;
87111 unsigned int snap;
87112
87113 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
87114 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87115 snap = (unsigned int)rdp->dynticks_snap;
87116
87117 /*
87118 @@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
87119 rdp = this_cpu_ptr(rsp->rda);
87120 rcu_preempt_check_blocked_tasks(rnp);
87121 rnp->qsmask = rnp->qsmaskinit;
87122 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
87123 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
87124 WARN_ON_ONCE(rnp->completed != rsp->completed);
87125 - ACCESS_ONCE(rnp->completed) = rsp->completed;
87126 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
87127 if (rnp == rdp->mynode)
87128 __note_gp_changes(rsp, rnp, rdp);
87129 rcu_preempt_boost_start_gp(rnp);
87130 @@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
87131 */
87132 rcu_for_each_node_breadth_first(rsp, rnp) {
87133 raw_spin_lock_irq(&rnp->lock);
87134 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
87135 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
87136 rdp = this_cpu_ptr(rsp->rda);
87137 if (rnp == rdp->mynode)
87138 __note_gp_changes(rsp, rnp, rdp);
87139 @@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
87140 rsp->qlen += rdp->qlen;
87141 rdp->n_cbs_orphaned += rdp->qlen;
87142 rdp->qlen_lazy = 0;
87143 - ACCESS_ONCE(rdp->qlen) = 0;
87144 + ACCESS_ONCE_RW(rdp->qlen) = 0;
87145 }
87146
87147 /*
87148 @@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
87149 }
87150 smp_mb(); /* List handling before counting for rcu_barrier(). */
87151 rdp->qlen_lazy -= count_lazy;
87152 - ACCESS_ONCE(rdp->qlen) -= count;
87153 + ACCESS_ONCE_RW(rdp->qlen) -= count;
87154 rdp->n_cbs_invoked += count;
87155
87156 /* Reinstate batch limit if we have worked down the excess. */
87157 @@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
87158 /*
87159 * Do RCU core processing for the current CPU.
87160 */
87161 -static void rcu_process_callbacks(struct softirq_action *unused)
87162 +static void rcu_process_callbacks(void)
87163 {
87164 struct rcu_state *rsp;
87165
87166 @@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87167 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
87168 if (debug_rcu_head_queue(head)) {
87169 /* Probable double call_rcu(), so leak the callback. */
87170 - ACCESS_ONCE(head->func) = rcu_leak_callback;
87171 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
87172 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
87173 return;
87174 }
87175 @@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87176 local_irq_restore(flags);
87177 return;
87178 }
87179 - ACCESS_ONCE(rdp->qlen)++;
87180 + ACCESS_ONCE_RW(rdp->qlen)++;
87181 if (lazy)
87182 rdp->qlen_lazy++;
87183 else
87184 @@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
87185 * counter wrap on a 32-bit system. Quite a few more CPUs would of
87186 * course be required on a 64-bit system.
87187 */
87188 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
87189 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
87190 (ulong)atomic_long_read(&rsp->expedited_done) +
87191 ULONG_MAX / 8)) {
87192 synchronize_sched();
87193 - atomic_long_inc(&rsp->expedited_wrap);
87194 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
87195 return;
87196 }
87197
87198 @@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
87199 * Take a ticket. Note that atomic_inc_return() implies a
87200 * full memory barrier.
87201 */
87202 - snap = atomic_long_inc_return(&rsp->expedited_start);
87203 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
87204 firstsnap = snap;
87205 get_online_cpus();
87206 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
87207 @@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
87208 synchronize_sched_expedited_cpu_stop,
87209 NULL) == -EAGAIN) {
87210 put_online_cpus();
87211 - atomic_long_inc(&rsp->expedited_tryfail);
87212 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
87213
87214 /* Check to see if someone else did our work for us. */
87215 s = atomic_long_read(&rsp->expedited_done);
87216 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87217 /* ensure test happens before caller kfree */
87218 smp_mb__before_atomic_inc(); /* ^^^ */
87219 - atomic_long_inc(&rsp->expedited_workdone1);
87220 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
87221 return;
87222 }
87223
87224 @@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
87225 udelay(trycount * num_online_cpus());
87226 } else {
87227 wait_rcu_gp(call_rcu_sched);
87228 - atomic_long_inc(&rsp->expedited_normal);
87229 + atomic_long_inc_unchecked(&rsp->expedited_normal);
87230 return;
87231 }
87232
87233 @@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
87234 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87235 /* ensure test happens before caller kfree */
87236 smp_mb__before_atomic_inc(); /* ^^^ */
87237 - atomic_long_inc(&rsp->expedited_workdone2);
87238 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
87239 return;
87240 }
87241
87242 @@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
87243 * period works for us.
87244 */
87245 get_online_cpus();
87246 - snap = atomic_long_read(&rsp->expedited_start);
87247 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
87248 smp_mb(); /* ensure read is before try_stop_cpus(). */
87249 }
87250 - atomic_long_inc(&rsp->expedited_stoppedcpus);
87251 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
87252
87253 /*
87254 * Everyone up to our most recent fetch is covered by our grace
87255 @@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
87256 * than we did already did their update.
87257 */
87258 do {
87259 - atomic_long_inc(&rsp->expedited_done_tries);
87260 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
87261 s = atomic_long_read(&rsp->expedited_done);
87262 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
87263 /* ensure test happens before caller kfree */
87264 smp_mb__before_atomic_inc(); /* ^^^ */
87265 - atomic_long_inc(&rsp->expedited_done_lost);
87266 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
87267 break;
87268 }
87269 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
87270 - atomic_long_inc(&rsp->expedited_done_exit);
87271 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
87272
87273 put_online_cpus();
87274 }
87275 @@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87276 * ACCESS_ONCE() to prevent the compiler from speculating
87277 * the increment to precede the early-exit check.
87278 */
87279 - ACCESS_ONCE(rsp->n_barrier_done)++;
87280 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87281 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
87282 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
87283 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
87284 @@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87285
87286 /* Increment ->n_barrier_done to prevent duplicate work. */
87287 smp_mb(); /* Keep increment after above mechanism. */
87288 - ACCESS_ONCE(rsp->n_barrier_done)++;
87289 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87290 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
87291 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
87292 smp_mb(); /* Keep increment before caller's subsequent code. */
87293 @@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
87294 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
87295 init_callback_list(rdp);
87296 rdp->qlen_lazy = 0;
87297 - ACCESS_ONCE(rdp->qlen) = 0;
87298 + ACCESS_ONCE_RW(rdp->qlen) = 0;
87299 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
87300 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
87301 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
87302 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
87303 rdp->cpu = cpu;
87304 rdp->rsp = rsp;
87305 rcu_boot_init_nocb_percpu_data(rdp);
87306 @@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
87307 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
87308 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
87309 rcu_sysidle_init_percpu_data(rdp->dynticks);
87310 - atomic_set(&rdp->dynticks->dynticks,
87311 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
87312 + atomic_set_unchecked(&rdp->dynticks->dynticks,
87313 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
87314 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
87315
87316 /* Add CPU to rcu_node bitmasks. */
87317 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
87318 index 52be957..365ded3 100644
87319 --- a/kernel/rcu/tree.h
87320 +++ b/kernel/rcu/tree.h
87321 @@ -87,11 +87,11 @@ struct rcu_dynticks {
87322 long long dynticks_nesting; /* Track irq/process nesting level. */
87323 /* Process level is worth LLONG_MAX/2. */
87324 int dynticks_nmi_nesting; /* Track NMI nesting level. */
87325 - atomic_t dynticks; /* Even value for idle, else odd. */
87326 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
87327 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
87328 long long dynticks_idle_nesting;
87329 /* irq/process nesting level from idle. */
87330 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
87331 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
87332 /* "Idle" excludes userspace execution. */
87333 unsigned long dynticks_idle_jiffies;
87334 /* End of last non-NMI non-idle period. */
87335 @@ -429,17 +429,17 @@ struct rcu_state {
87336 /* _rcu_barrier(). */
87337 /* End of fields guarded by barrier_mutex. */
87338
87339 - atomic_long_t expedited_start; /* Starting ticket. */
87340 - atomic_long_t expedited_done; /* Done ticket. */
87341 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
87342 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
87343 - atomic_long_t expedited_workdone1; /* # done by others #1. */
87344 - atomic_long_t expedited_workdone2; /* # done by others #2. */
87345 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
87346 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
87347 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
87348 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
87349 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
87350 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
87351 + atomic_long_t expedited_done; /* Done ticket. */
87352 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
87353 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
87354 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
87355 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
87356 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
87357 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
87358 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
87359 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
87360 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
87361
87362 unsigned long jiffies_force_qs; /* Time at which to invoke */
87363 /* force_quiescent_state(). */
87364 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
87365 index 08a7652..3598c7e 100644
87366 --- a/kernel/rcu/tree_plugin.h
87367 +++ b/kernel/rcu/tree_plugin.h
87368 @@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
87369 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
87370 {
87371 return !rcu_preempted_readers_exp(rnp) &&
87372 - ACCESS_ONCE(rnp->expmask) == 0;
87373 + ACCESS_ONCE_RW(rnp->expmask) == 0;
87374 }
87375
87376 /*
87377 @@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
87378
87379 /* Clean up and exit. */
87380 smp_mb(); /* ensure expedited GP seen before counter increment. */
87381 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
87382 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
87383 unlock_mb_ret:
87384 mutex_unlock(&sync_rcu_preempt_exp_mutex);
87385 mb_ret:
87386 @@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
87387 free_cpumask_var(cm);
87388 }
87389
87390 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
87391 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
87392 .store = &rcu_cpu_kthread_task,
87393 .thread_should_run = rcu_cpu_kthread_should_run,
87394 .thread_fn = rcu_cpu_kthread,
87395 @@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
87396 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
87397 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
87398 cpu, ticks_value, ticks_title,
87399 - atomic_read(&rdtp->dynticks) & 0xfff,
87400 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
87401 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
87402 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
87403 fast_no_hz);
87404 @@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
87405
87406 /* Enqueue the callback on the nocb list and update counts. */
87407 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
87408 - ACCESS_ONCE(*old_rhpp) = rhp;
87409 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
87410 atomic_long_add(rhcount, &rdp->nocb_q_count);
87411 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
87412
87413 @@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
87414 * Extract queued callbacks, update counts, and wait
87415 * for a grace period to elapse.
87416 */
87417 - ACCESS_ONCE(rdp->nocb_head) = NULL;
87418 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
87419 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
87420 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
87421 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
87422 - ACCESS_ONCE(rdp->nocb_p_count) += c;
87423 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
87424 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
87425 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
87426 rcu_nocb_wait_gp(rdp);
87427
87428 /* Each pass through the following loop invokes a callback. */
87429 @@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
87430 list = next;
87431 }
87432 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
87433 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
87434 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
87435 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
87436 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
87437 rdp->n_nocbs_invoked += c;
87438 }
87439 return 0;
87440 @@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
87441 t = kthread_run(rcu_nocb_kthread, rdp,
87442 "rcuo%c/%d", rsp->abbr, cpu);
87443 BUG_ON(IS_ERR(t));
87444 - ACCESS_ONCE(rdp->nocb_kthread) = t;
87445 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
87446 }
87447 }
87448
87449 @@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
87450
87451 /* Record start of fully idle period. */
87452 j = jiffies;
87453 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
87454 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
87455 smp_mb__before_atomic_inc();
87456 - atomic_inc(&rdtp->dynticks_idle);
87457 + atomic_inc_unchecked(&rdtp->dynticks_idle);
87458 smp_mb__after_atomic_inc();
87459 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
87460 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
87461 }
87462
87463 /*
87464 @@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
87465
87466 /* Record end of idle period. */
87467 smp_mb__before_atomic_inc();
87468 - atomic_inc(&rdtp->dynticks_idle);
87469 + atomic_inc_unchecked(&rdtp->dynticks_idle);
87470 smp_mb__after_atomic_inc();
87471 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
87472 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
87473
87474 /*
87475 * If we are the timekeeping CPU, we are permitted to be non-idle
87476 @@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
87477 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
87478
87479 /* Pick up current idle and NMI-nesting counter and check. */
87480 - cur = atomic_read(&rdtp->dynticks_idle);
87481 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
87482 if (cur & 0x1) {
87483 *isidle = false; /* We are not idle! */
87484 return;
87485 @@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
87486 case RCU_SYSIDLE_NOT:
87487
87488 /* First time all are idle, so note a short idle period. */
87489 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87490 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87491 break;
87492
87493 case RCU_SYSIDLE_SHORT:
87494 @@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
87495 static void rcu_sysidle_cancel(void)
87496 {
87497 smp_mb();
87498 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
87499 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
87500 }
87501
87502 /*
87503 @@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
87504 smp_mb(); /* grace period precedes setting inuse. */
87505
87506 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
87507 - ACCESS_ONCE(rshp->inuse) = 0;
87508 + ACCESS_ONCE_RW(rshp->inuse) = 0;
87509 }
87510
87511 /*
87512 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
87513 index 3596797..f78391c 100644
87514 --- a/kernel/rcu/tree_trace.c
87515 +++ b/kernel/rcu/tree_trace.c
87516 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
87517 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
87518 rdp->passed_quiesce, rdp->qs_pending);
87519 seq_printf(m, " dt=%d/%llx/%d df=%lu",
87520 - atomic_read(&rdp->dynticks->dynticks),
87521 + atomic_read_unchecked(&rdp->dynticks->dynticks),
87522 rdp->dynticks->dynticks_nesting,
87523 rdp->dynticks->dynticks_nmi_nesting,
87524 rdp->dynticks_fqs);
87525 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
87526 struct rcu_state *rsp = (struct rcu_state *)m->private;
87527
87528 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",
87529 - atomic_long_read(&rsp->expedited_start),
87530 + atomic_long_read_unchecked(&rsp->expedited_start),
87531 atomic_long_read(&rsp->expedited_done),
87532 - atomic_long_read(&rsp->expedited_wrap),
87533 - atomic_long_read(&rsp->expedited_tryfail),
87534 - atomic_long_read(&rsp->expedited_workdone1),
87535 - atomic_long_read(&rsp->expedited_workdone2),
87536 - atomic_long_read(&rsp->expedited_normal),
87537 - atomic_long_read(&rsp->expedited_stoppedcpus),
87538 - atomic_long_read(&rsp->expedited_done_tries),
87539 - atomic_long_read(&rsp->expedited_done_lost),
87540 - atomic_long_read(&rsp->expedited_done_exit));
87541 + atomic_long_read_unchecked(&rsp->expedited_wrap),
87542 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
87543 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
87544 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
87545 + atomic_long_read_unchecked(&rsp->expedited_normal),
87546 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
87547 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
87548 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
87549 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
87550 return 0;
87551 }
87552
87553 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
87554 index 6cb3dff..dc5710f 100644
87555 --- a/kernel/rcu/update.c
87556 +++ b/kernel/rcu/update.c
87557 @@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
87558 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
87559 */
87560 if (till_stall_check < 3) {
87561 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
87562 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
87563 till_stall_check = 3;
87564 } else if (till_stall_check > 300) {
87565 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
87566 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
87567 till_stall_check = 300;
87568 }
87569 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
87570 diff --git a/kernel/resource.c b/kernel/resource.c
87571 index 3f285dc..5755f62 100644
87572 --- a/kernel/resource.c
87573 +++ b/kernel/resource.c
87574 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
87575
87576 static int __init ioresources_init(void)
87577 {
87578 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
87579 +#ifdef CONFIG_GRKERNSEC_PROC_USER
87580 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
87581 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
87582 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87583 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
87584 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
87585 +#endif
87586 +#else
87587 proc_create("ioports", 0, NULL, &proc_ioports_operations);
87588 proc_create("iomem", 0, NULL, &proc_iomem_operations);
87589 +#endif
87590 return 0;
87591 }
87592 __initcall(ioresources_init);
87593 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
87594 index 4a07353..66b5291 100644
87595 --- a/kernel/sched/auto_group.c
87596 +++ b/kernel/sched/auto_group.c
87597 @@ -11,7 +11,7 @@
87598
87599 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
87600 static struct autogroup autogroup_default;
87601 -static atomic_t autogroup_seq_nr;
87602 +static atomic_unchecked_t autogroup_seq_nr;
87603
87604 void __init autogroup_init(struct task_struct *init_task)
87605 {
87606 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
87607
87608 kref_init(&ag->kref);
87609 init_rwsem(&ag->lock);
87610 - ag->id = atomic_inc_return(&autogroup_seq_nr);
87611 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
87612 ag->tg = tg;
87613 #ifdef CONFIG_RT_GROUP_SCHED
87614 /*
87615 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
87616 index a63f4dc..349bbb0 100644
87617 --- a/kernel/sched/completion.c
87618 +++ b/kernel/sched/completion.c
87619 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
87620 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87621 * or number of jiffies left till timeout) if completed.
87622 */
87623 -long __sched
87624 +long __sched __intentional_overflow(-1)
87625 wait_for_completion_interruptible_timeout(struct completion *x,
87626 unsigned long timeout)
87627 {
87628 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
87629 *
87630 * Return: -ERESTARTSYS if interrupted, 0 if completed.
87631 */
87632 -int __sched wait_for_completion_killable(struct completion *x)
87633 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
87634 {
87635 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
87636 if (t == -ERESTARTSYS)
87637 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
87638 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87639 * or number of jiffies left till timeout) if completed.
87640 */
87641 -long __sched
87642 +long __sched __intentional_overflow(-1)
87643 wait_for_completion_killable_timeout(struct completion *x,
87644 unsigned long timeout)
87645 {
87646 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
87647 index a88f4a4..9d57ac9 100644
87648 --- a/kernel/sched/core.c
87649 +++ b/kernel/sched/core.c
87650 @@ -2871,6 +2871,8 @@ int can_nice(const struct task_struct *p, const int nice)
87651 /* convert nice value [19,-20] to rlimit style value [1,40] */
87652 int nice_rlim = 20 - nice;
87653
87654 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
87655 +
87656 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
87657 capable(CAP_SYS_NICE));
87658 }
87659 @@ -2904,7 +2906,8 @@ SYSCALL_DEFINE1(nice, int, increment)
87660 if (nice > 19)
87661 nice = 19;
87662
87663 - if (increment < 0 && !can_nice(current, nice))
87664 + if (increment < 0 && (!can_nice(current, nice) ||
87665 + gr_handle_chroot_nice()))
87666 return -EPERM;
87667
87668 retval = security_task_setnice(current, nice);
87669 @@ -3066,6 +3069,7 @@ recheck:
87670 unsigned long rlim_rtprio =
87671 task_rlimit(p, RLIMIT_RTPRIO);
87672
87673 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
87674 /* can't set/change the rt policy */
87675 if (policy != p->policy && !rlim_rtprio)
87676 return -EPERM;
87677 @@ -4232,7 +4236,7 @@ static void migrate_tasks(unsigned int dead_cpu)
87678
87679 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
87680
87681 -static struct ctl_table sd_ctl_dir[] = {
87682 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
87683 {
87684 .procname = "sched_domain",
87685 .mode = 0555,
87686 @@ -4249,17 +4253,17 @@ static struct ctl_table sd_ctl_root[] = {
87687 {}
87688 };
87689
87690 -static struct ctl_table *sd_alloc_ctl_entry(int n)
87691 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
87692 {
87693 - struct ctl_table *entry =
87694 + ctl_table_no_const *entry =
87695 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
87696
87697 return entry;
87698 }
87699
87700 -static void sd_free_ctl_entry(struct ctl_table **tablep)
87701 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
87702 {
87703 - struct ctl_table *entry;
87704 + ctl_table_no_const *entry;
87705
87706 /*
87707 * In the intermediate directories, both the child directory and
87708 @@ -4267,22 +4271,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
87709 * will always be set. In the lowest directory the names are
87710 * static strings and all have proc handlers.
87711 */
87712 - for (entry = *tablep; entry->mode; entry++) {
87713 - if (entry->child)
87714 - sd_free_ctl_entry(&entry->child);
87715 + for (entry = tablep; entry->mode; entry++) {
87716 + if (entry->child) {
87717 + sd_free_ctl_entry(entry->child);
87718 + pax_open_kernel();
87719 + entry->child = NULL;
87720 + pax_close_kernel();
87721 + }
87722 if (entry->proc_handler == NULL)
87723 kfree(entry->procname);
87724 }
87725
87726 - kfree(*tablep);
87727 - *tablep = NULL;
87728 + kfree(tablep);
87729 }
87730
87731 static int min_load_idx = 0;
87732 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
87733
87734 static void
87735 -set_table_entry(struct ctl_table *entry,
87736 +set_table_entry(ctl_table_no_const *entry,
87737 const char *procname, void *data, int maxlen,
87738 umode_t mode, proc_handler *proc_handler,
87739 bool load_idx)
87740 @@ -4302,7 +4309,7 @@ set_table_entry(struct ctl_table *entry,
87741 static struct ctl_table *
87742 sd_alloc_ctl_domain_table(struct sched_domain *sd)
87743 {
87744 - struct ctl_table *table = sd_alloc_ctl_entry(13);
87745 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
87746
87747 if (table == NULL)
87748 return NULL;
87749 @@ -4337,9 +4344,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
87750 return table;
87751 }
87752
87753 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
87754 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
87755 {
87756 - struct ctl_table *entry, *table;
87757 + ctl_table_no_const *entry, *table;
87758 struct sched_domain *sd;
87759 int domain_num = 0, i;
87760 char buf[32];
87761 @@ -4366,11 +4373,13 @@ static struct ctl_table_header *sd_sysctl_header;
87762 static void register_sched_domain_sysctl(void)
87763 {
87764 int i, cpu_num = num_possible_cpus();
87765 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
87766 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
87767 char buf[32];
87768
87769 WARN_ON(sd_ctl_dir[0].child);
87770 + pax_open_kernel();
87771 sd_ctl_dir[0].child = entry;
87772 + pax_close_kernel();
87773
87774 if (entry == NULL)
87775 return;
87776 @@ -4393,8 +4402,12 @@ static void unregister_sched_domain_sysctl(void)
87777 if (sd_sysctl_header)
87778 unregister_sysctl_table(sd_sysctl_header);
87779 sd_sysctl_header = NULL;
87780 - if (sd_ctl_dir[0].child)
87781 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
87782 + if (sd_ctl_dir[0].child) {
87783 + sd_free_ctl_entry(sd_ctl_dir[0].child);
87784 + pax_open_kernel();
87785 + sd_ctl_dir[0].child = NULL;
87786 + pax_close_kernel();
87787 + }
87788 }
87789 #else
87790 static void register_sched_domain_sysctl(void)
87791 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
87792 index e64b079..a46bd34 100644
87793 --- a/kernel/sched/fair.c
87794 +++ b/kernel/sched/fair.c
87795 @@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
87796
87797 static void reset_ptenuma_scan(struct task_struct *p)
87798 {
87799 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
87800 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
87801 p->mm->numa_scan_offset = 0;
87802 }
87803
87804 @@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
87805 * run_rebalance_domains is triggered when needed from the scheduler tick.
87806 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
87807 */
87808 -static void run_rebalance_domains(struct softirq_action *h)
87809 +static __latent_entropy void run_rebalance_domains(void)
87810 {
87811 int this_cpu = smp_processor_id();
87812 struct rq *this_rq = cpu_rq(this_cpu);
87813 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
87814 index 88c85b2..a1dec86 100644
87815 --- a/kernel/sched/sched.h
87816 +++ b/kernel/sched/sched.h
87817 @@ -1035,7 +1035,7 @@ struct sched_class {
87818 #ifdef CONFIG_FAIR_GROUP_SCHED
87819 void (*task_move_group) (struct task_struct *p, int on_rq);
87820 #endif
87821 -};
87822 +} __do_const;
87823
87824 #define sched_class_highest (&stop_sched_class)
87825 #define for_each_class(class) \
87826 diff --git a/kernel/signal.c b/kernel/signal.c
87827 index 940b30e..7fd6041 100644
87828 --- a/kernel/signal.c
87829 +++ b/kernel/signal.c
87830 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
87831
87832 int print_fatal_signals __read_mostly;
87833
87834 -static void __user *sig_handler(struct task_struct *t, int sig)
87835 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
87836 {
87837 return t->sighand->action[sig - 1].sa.sa_handler;
87838 }
87839
87840 -static int sig_handler_ignored(void __user *handler, int sig)
87841 +static int sig_handler_ignored(__sighandler_t handler, int sig)
87842 {
87843 /* Is it explicitly or implicitly ignored? */
87844 return handler == SIG_IGN ||
87845 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
87846
87847 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
87848 {
87849 - void __user *handler;
87850 + __sighandler_t handler;
87851
87852 handler = sig_handler(t, sig);
87853
87854 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
87855 atomic_inc(&user->sigpending);
87856 rcu_read_unlock();
87857
87858 + if (!override_rlimit)
87859 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
87860 +
87861 if (override_rlimit ||
87862 atomic_read(&user->sigpending) <=
87863 task_rlimit(t, RLIMIT_SIGPENDING)) {
87864 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
87865
87866 int unhandled_signal(struct task_struct *tsk, int sig)
87867 {
87868 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
87869 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
87870 if (is_global_init(tsk))
87871 return 1;
87872 if (handler != SIG_IGN && handler != SIG_DFL)
87873 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
87874 }
87875 }
87876
87877 + /* allow glibc communication via tgkill to other threads in our
87878 + thread group */
87879 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
87880 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
87881 + && gr_handle_signal(t, sig))
87882 + return -EPERM;
87883 +
87884 return security_task_kill(t, info, sig, 0);
87885 }
87886
87887 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
87888 return send_signal(sig, info, p, 1);
87889 }
87890
87891 -static int
87892 +int
87893 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87894 {
87895 return send_signal(sig, info, t, 0);
87896 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87897 unsigned long int flags;
87898 int ret, blocked, ignored;
87899 struct k_sigaction *action;
87900 + int is_unhandled = 0;
87901
87902 spin_lock_irqsave(&t->sighand->siglock, flags);
87903 action = &t->sighand->action[sig-1];
87904 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
87905 }
87906 if (action->sa.sa_handler == SIG_DFL)
87907 t->signal->flags &= ~SIGNAL_UNKILLABLE;
87908 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
87909 + is_unhandled = 1;
87910 ret = specific_send_sig_info(sig, info, t);
87911 spin_unlock_irqrestore(&t->sighand->siglock, flags);
87912
87913 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
87914 + normal operation */
87915 + if (is_unhandled) {
87916 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
87917 + gr_handle_crash(t, sig);
87918 + }
87919 +
87920 return ret;
87921 }
87922
87923 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
87924 ret = check_kill_permission(sig, info, p);
87925 rcu_read_unlock();
87926
87927 - if (!ret && sig)
87928 + if (!ret && sig) {
87929 ret = do_send_sig_info(sig, info, p, true);
87930 + if (!ret)
87931 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
87932 + }
87933
87934 return ret;
87935 }
87936 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
87937 int error = -ESRCH;
87938
87939 rcu_read_lock();
87940 - p = find_task_by_vpid(pid);
87941 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
87942 + /* allow glibc communication via tgkill to other threads in our
87943 + thread group */
87944 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
87945 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
87946 + p = find_task_by_vpid_unrestricted(pid);
87947 + else
87948 +#endif
87949 + p = find_task_by_vpid(pid);
87950 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
87951 error = check_kill_permission(sig, info, p);
87952 /*
87953 @@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
87954 }
87955 seg = get_fs();
87956 set_fs(KERNEL_DS);
87957 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
87958 - (stack_t __force __user *) &uoss,
87959 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
87960 + (stack_t __force_user *) &uoss,
87961 compat_user_stack_pointer());
87962 set_fs(seg);
87963 if (ret >= 0 && uoss_ptr) {
87964 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
87965 index eb89e18..a4e6792 100644
87966 --- a/kernel/smpboot.c
87967 +++ b/kernel/smpboot.c
87968 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
87969 }
87970 smpboot_unpark_thread(plug_thread, cpu);
87971 }
87972 - list_add(&plug_thread->list, &hotplug_threads);
87973 + pax_list_add(&plug_thread->list, &hotplug_threads);
87974 out:
87975 mutex_unlock(&smpboot_threads_lock);
87976 return ret;
87977 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
87978 {
87979 get_online_cpus();
87980 mutex_lock(&smpboot_threads_lock);
87981 - list_del(&plug_thread->list);
87982 + pax_list_del(&plug_thread->list);
87983 smpboot_destroy_threads(plug_thread);
87984 mutex_unlock(&smpboot_threads_lock);
87985 put_online_cpus();
87986 diff --git a/kernel/softirq.c b/kernel/softirq.c
87987 index 11025cc..bc0e4dc 100644
87988 --- a/kernel/softirq.c
87989 +++ b/kernel/softirq.c
87990 @@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
87991 EXPORT_SYMBOL(irq_stat);
87992 #endif
87993
87994 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
87995 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
87996
87997 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
87998
87999 -char *softirq_to_name[NR_SOFTIRQS] = {
88000 +const char * const softirq_to_name[NR_SOFTIRQS] = {
88001 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
88002 "TASKLET", "SCHED", "HRTIMER", "RCU"
88003 };
88004 @@ -250,7 +250,7 @@ restart:
88005 kstat_incr_softirqs_this_cpu(vec_nr);
88006
88007 trace_softirq_entry(vec_nr);
88008 - h->action(h);
88009 + h->action();
88010 trace_softirq_exit(vec_nr);
88011 if (unlikely(prev_count != preempt_count())) {
88012 printk(KERN_ERR "huh, entered softirq %u %s %p"
88013 @@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
88014 or_softirq_pending(1UL << nr);
88015 }
88016
88017 -void open_softirq(int nr, void (*action)(struct softirq_action *))
88018 +void __init open_softirq(int nr, void (*action)(void))
88019 {
88020 softirq_vec[nr].action = action;
88021 }
88022 @@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
88023
88024 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
88025
88026 -static void tasklet_action(struct softirq_action *a)
88027 +static __latent_entropy void tasklet_action(void)
88028 {
88029 struct tasklet_struct *list;
88030
88031 @@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
88032 }
88033 }
88034
88035 -static void tasklet_hi_action(struct softirq_action *a)
88036 +static __latent_entropy void tasklet_hi_action(void)
88037 {
88038 struct tasklet_struct *list;
88039
88040 @@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
88041 .notifier_call = cpu_callback
88042 };
88043
88044 -static struct smp_hotplug_thread softirq_threads = {
88045 +static struct smp_hotplug_thread softirq_threads __read_only = {
88046 .store = &ksoftirqd,
88047 .thread_should_run = ksoftirqd_should_run,
88048 .thread_fn = run_ksoftirqd,
88049 diff --git a/kernel/sys.c b/kernel/sys.c
88050 index c723113..46bf922 100644
88051 --- a/kernel/sys.c
88052 +++ b/kernel/sys.c
88053 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
88054 error = -EACCES;
88055 goto out;
88056 }
88057 +
88058 + if (gr_handle_chroot_setpriority(p, niceval)) {
88059 + error = -EACCES;
88060 + goto out;
88061 + }
88062 +
88063 no_nice = security_task_setnice(p, niceval);
88064 if (no_nice) {
88065 error = no_nice;
88066 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
88067 goto error;
88068 }
88069
88070 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
88071 + goto error;
88072 +
88073 if (rgid != (gid_t) -1 ||
88074 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
88075 new->sgid = new->egid;
88076 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
88077 old = current_cred();
88078
88079 retval = -EPERM;
88080 +
88081 + if (gr_check_group_change(kgid, kgid, kgid))
88082 + goto error;
88083 +
88084 if (ns_capable(old->user_ns, CAP_SETGID))
88085 new->gid = new->egid = new->sgid = new->fsgid = kgid;
88086 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
88087 @@ -403,7 +416,7 @@ error:
88088 /*
88089 * change the user struct in a credentials set to match the new UID
88090 */
88091 -static int set_user(struct cred *new)
88092 +int set_user(struct cred *new)
88093 {
88094 struct user_struct *new_user;
88095
88096 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
88097 goto error;
88098 }
88099
88100 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
88101 + goto error;
88102 +
88103 if (!uid_eq(new->uid, old->uid)) {
88104 retval = set_user(new);
88105 if (retval < 0)
88106 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
88107 old = current_cred();
88108
88109 retval = -EPERM;
88110 +
88111 + if (gr_check_crash_uid(kuid))
88112 + goto error;
88113 + if (gr_check_user_change(kuid, kuid, kuid))
88114 + goto error;
88115 +
88116 if (ns_capable(old->user_ns, CAP_SETUID)) {
88117 new->suid = new->uid = kuid;
88118 if (!uid_eq(kuid, old->uid)) {
88119 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
88120 goto error;
88121 }
88122
88123 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
88124 + goto error;
88125 +
88126 if (ruid != (uid_t) -1) {
88127 new->uid = kruid;
88128 if (!uid_eq(kruid, old->uid)) {
88129 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
88130 goto error;
88131 }
88132
88133 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
88134 + goto error;
88135 +
88136 if (rgid != (gid_t) -1)
88137 new->gid = krgid;
88138 if (egid != (gid_t) -1)
88139 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
88140 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
88141 ns_capable(old->user_ns, CAP_SETUID)) {
88142 if (!uid_eq(kuid, old->fsuid)) {
88143 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
88144 + goto error;
88145 +
88146 new->fsuid = kuid;
88147 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
88148 goto change_okay;
88149 }
88150 }
88151
88152 +error:
88153 abort_creds(new);
88154 return old_fsuid;
88155
88156 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
88157 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
88158 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
88159 ns_capable(old->user_ns, CAP_SETGID)) {
88160 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
88161 + goto error;
88162 +
88163 if (!gid_eq(kgid, old->fsgid)) {
88164 new->fsgid = kgid;
88165 goto change_okay;
88166 }
88167 }
88168
88169 +error:
88170 abort_creds(new);
88171 return old_fsgid;
88172
88173 @@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
88174 return -EFAULT;
88175
88176 down_read(&uts_sem);
88177 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
88178 + error = __copy_to_user(name->sysname, &utsname()->sysname,
88179 __OLD_UTS_LEN);
88180 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
88181 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
88182 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
88183 __OLD_UTS_LEN);
88184 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
88185 - error |= __copy_to_user(&name->release, &utsname()->release,
88186 + error |= __copy_to_user(name->release, &utsname()->release,
88187 __OLD_UTS_LEN);
88188 error |= __put_user(0, name->release + __OLD_UTS_LEN);
88189 - error |= __copy_to_user(&name->version, &utsname()->version,
88190 + error |= __copy_to_user(name->version, &utsname()->version,
88191 __OLD_UTS_LEN);
88192 error |= __put_user(0, name->version + __OLD_UTS_LEN);
88193 - error |= __copy_to_user(&name->machine, &utsname()->machine,
88194 + error |= __copy_to_user(name->machine, &utsname()->machine,
88195 __OLD_UTS_LEN);
88196 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
88197 up_read(&uts_sem);
88198 @@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
88199 */
88200 new_rlim->rlim_cur = 1;
88201 }
88202 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
88203 + is changed to a lower value. Since tasks can be created by the same
88204 + user in between this limit change and an execve by this task, force
88205 + a recheck only for this task by setting PF_NPROC_EXCEEDED
88206 + */
88207 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
88208 + tsk->flags |= PF_NPROC_EXCEEDED;
88209 }
88210 if (!retval) {
88211 if (old_rlim)
88212 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
88213 index 34a6047..5665aa7 100644
88214 --- a/kernel/sysctl.c
88215 +++ b/kernel/sysctl.c
88216 @@ -93,7 +93,6 @@
88217
88218
88219 #if defined(CONFIG_SYSCTL)
88220 -
88221 /* External variables not in a header file. */
88222 extern int sysctl_overcommit_memory;
88223 extern int sysctl_overcommit_ratio;
88224 @@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
88225
88226 /* Constants used for minimum and maximum */
88227 #ifdef CONFIG_LOCKUP_DETECTOR
88228 -static int sixty = 60;
88229 +static int sixty __read_only = 60;
88230 #endif
88231
88232 -static int zero;
88233 -static int __maybe_unused one = 1;
88234 -static int __maybe_unused two = 2;
88235 -static int __maybe_unused three = 3;
88236 -static unsigned long one_ul = 1;
88237 -static int one_hundred = 100;
88238 +static int neg_one __read_only = -1;
88239 +static int zero __read_only = 0;
88240 +static int __maybe_unused one __read_only = 1;
88241 +static int __maybe_unused two __read_only = 2;
88242 +static int __maybe_unused three __read_only = 3;
88243 +static unsigned long one_ul __read_only = 1;
88244 +static int one_hundred __read_only = 100;
88245 #ifdef CONFIG_PRINTK
88246 -static int ten_thousand = 10000;
88247 +static int ten_thousand __read_only = 10000;
88248 #endif
88249
88250 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
88251 @@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
88252 void __user *buffer, size_t *lenp, loff_t *ppos);
88253 #endif
88254
88255 -#ifdef CONFIG_PRINTK
88256 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88257 void __user *buffer, size_t *lenp, loff_t *ppos);
88258 -#endif
88259
88260 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
88261 void __user *buffer, size_t *lenp, loff_t *ppos);
88262 @@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
88263
88264 #endif
88265
88266 +extern struct ctl_table grsecurity_table[];
88267 +
88268 static struct ctl_table kern_table[];
88269 static struct ctl_table vm_table[];
88270 static struct ctl_table fs_table[];
88271 @@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
88272 int sysctl_legacy_va_layout;
88273 #endif
88274
88275 +#ifdef CONFIG_PAX_SOFTMODE
88276 +static ctl_table pax_table[] = {
88277 + {
88278 + .procname = "softmode",
88279 + .data = &pax_softmode,
88280 + .maxlen = sizeof(unsigned int),
88281 + .mode = 0600,
88282 + .proc_handler = &proc_dointvec,
88283 + },
88284 +
88285 + { }
88286 +};
88287 +#endif
88288 +
88289 /* The default sysctl tables: */
88290
88291 static struct ctl_table sysctl_base_table[] = {
88292 @@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
88293 #endif
88294
88295 static struct ctl_table kern_table[] = {
88296 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
88297 + {
88298 + .procname = "grsecurity",
88299 + .mode = 0500,
88300 + .child = grsecurity_table,
88301 + },
88302 +#endif
88303 +
88304 +#ifdef CONFIG_PAX_SOFTMODE
88305 + {
88306 + .procname = "pax",
88307 + .mode = 0500,
88308 + .child = pax_table,
88309 + },
88310 +#endif
88311 +
88312 {
88313 .procname = "sched_child_runs_first",
88314 .data = &sysctl_sched_child_runs_first,
88315 @@ -620,7 +650,7 @@ static struct ctl_table kern_table[] = {
88316 .data = &modprobe_path,
88317 .maxlen = KMOD_PATH_LEN,
88318 .mode = 0644,
88319 - .proc_handler = proc_dostring,
88320 + .proc_handler = proc_dostring_modpriv,
88321 },
88322 {
88323 .procname = "modules_disabled",
88324 @@ -787,16 +817,20 @@ static struct ctl_table kern_table[] = {
88325 .extra1 = &zero,
88326 .extra2 = &one,
88327 },
88328 +#endif
88329 {
88330 .procname = "kptr_restrict",
88331 .data = &kptr_restrict,
88332 .maxlen = sizeof(int),
88333 .mode = 0644,
88334 .proc_handler = proc_dointvec_minmax_sysadmin,
88335 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88336 + .extra1 = &two,
88337 +#else
88338 .extra1 = &zero,
88339 +#endif
88340 .extra2 = &two,
88341 },
88342 -#endif
88343 {
88344 .procname = "ngroups_max",
88345 .data = &ngroups_max,
88346 @@ -1039,10 +1073,17 @@ static struct ctl_table kern_table[] = {
88347 */
88348 {
88349 .procname = "perf_event_paranoid",
88350 - .data = &sysctl_perf_event_paranoid,
88351 - .maxlen = sizeof(sysctl_perf_event_paranoid),
88352 + .data = &sysctl_perf_event_legitimately_concerned,
88353 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
88354 .mode = 0644,
88355 - .proc_handler = proc_dointvec,
88356 + /* go ahead, be a hero */
88357 + .proc_handler = proc_dointvec_minmax_sysadmin,
88358 + .extra1 = &neg_one,
88359 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88360 + .extra2 = &three,
88361 +#else
88362 + .extra2 = &two,
88363 +#endif
88364 },
88365 {
88366 .procname = "perf_event_mlock_kb",
88367 @@ -1306,6 +1347,13 @@ static struct ctl_table vm_table[] = {
88368 .proc_handler = proc_dointvec_minmax,
88369 .extra1 = &zero,
88370 },
88371 + {
88372 + .procname = "heap_stack_gap",
88373 + .data = &sysctl_heap_stack_gap,
88374 + .maxlen = sizeof(sysctl_heap_stack_gap),
88375 + .mode = 0644,
88376 + .proc_handler = proc_doulongvec_minmax,
88377 + },
88378 #else
88379 {
88380 .procname = "nr_trim_pages",
88381 @@ -1770,6 +1818,16 @@ int proc_dostring(struct ctl_table *table, int write,
88382 buffer, lenp, ppos);
88383 }
88384
88385 +int proc_dostring_modpriv(struct ctl_table *table, int write,
88386 + void __user *buffer, size_t *lenp, loff_t *ppos)
88387 +{
88388 + if (write && !capable(CAP_SYS_MODULE))
88389 + return -EPERM;
88390 +
88391 + return _proc_do_string(table->data, table->maxlen, write,
88392 + buffer, lenp, ppos);
88393 +}
88394 +
88395 static size_t proc_skip_spaces(char **buf)
88396 {
88397 size_t ret;
88398 @@ -1875,6 +1933,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
88399 len = strlen(tmp);
88400 if (len > *size)
88401 len = *size;
88402 + if (len > sizeof(tmp))
88403 + len = sizeof(tmp);
88404 if (copy_to_user(*buf, tmp, len))
88405 return -EFAULT;
88406 *size -= len;
88407 @@ -2039,7 +2099,7 @@ int proc_dointvec(struct ctl_table *table, int write,
88408 static int proc_taint(struct ctl_table *table, int write,
88409 void __user *buffer, size_t *lenp, loff_t *ppos)
88410 {
88411 - struct ctl_table t;
88412 + ctl_table_no_const t;
88413 unsigned long tmptaint = get_taint();
88414 int err;
88415
88416 @@ -2067,7 +2127,6 @@ static int proc_taint(struct ctl_table *table, int write,
88417 return err;
88418 }
88419
88420 -#ifdef CONFIG_PRINTK
88421 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88422 void __user *buffer, size_t *lenp, loff_t *ppos)
88423 {
88424 @@ -2076,7 +2135,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88425
88426 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
88427 }
88428 -#endif
88429
88430 struct do_proc_dointvec_minmax_conv_param {
88431 int *min;
88432 @@ -2623,6 +2681,12 @@ int proc_dostring(struct ctl_table *table, int write,
88433 return -ENOSYS;
88434 }
88435
88436 +int proc_dostring_modpriv(struct ctl_table *table, int write,
88437 + void __user *buffer, size_t *lenp, loff_t *ppos)
88438 +{
88439 + return -ENOSYS;
88440 +}
88441 +
88442 int proc_dointvec(struct ctl_table *table, int write,
88443 void __user *buffer, size_t *lenp, loff_t *ppos)
88444 {
88445 @@ -2679,5 +2743,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
88446 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
88447 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
88448 EXPORT_SYMBOL(proc_dostring);
88449 +EXPORT_SYMBOL(proc_dostring_modpriv);
88450 EXPORT_SYMBOL(proc_doulongvec_minmax);
88451 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
88452 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
88453 index 13d2f7c..c93d0b0 100644
88454 --- a/kernel/taskstats.c
88455 +++ b/kernel/taskstats.c
88456 @@ -28,9 +28,12 @@
88457 #include <linux/fs.h>
88458 #include <linux/file.h>
88459 #include <linux/pid_namespace.h>
88460 +#include <linux/grsecurity.h>
88461 #include <net/genetlink.h>
88462 #include <linux/atomic.h>
88463
88464 +extern int gr_is_taskstats_denied(int pid);
88465 +
88466 /*
88467 * Maximum length of a cpumask that can be specified in
88468 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
88469 @@ -576,6 +579,9 @@ err:
88470
88471 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
88472 {
88473 + if (gr_is_taskstats_denied(current->pid))
88474 + return -EACCES;
88475 +
88476 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
88477 return cmd_attr_register_cpumask(info);
88478 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
88479 diff --git a/kernel/time.c b/kernel/time.c
88480 index 7c7964c..2a0d412 100644
88481 --- a/kernel/time.c
88482 +++ b/kernel/time.c
88483 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
88484 return error;
88485
88486 if (tz) {
88487 + /* we log in do_settimeofday called below, so don't log twice
88488 + */
88489 + if (!tv)
88490 + gr_log_timechange();
88491 +
88492 sys_tz = *tz;
88493 update_vsyscall_tz();
88494 if (firsttime) {
88495 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
88496 index 88c9c65..7497ebc 100644
88497 --- a/kernel/time/alarmtimer.c
88498 +++ b/kernel/time/alarmtimer.c
88499 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
88500 struct platform_device *pdev;
88501 int error = 0;
88502 int i;
88503 - struct k_clock alarm_clock = {
88504 + static struct k_clock alarm_clock = {
88505 .clock_getres = alarm_clock_getres,
88506 .clock_get = alarm_clock_get,
88507 .timer_create = alarm_timer_create,
88508 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
88509 index 87b4f00..b7f77a7 100644
88510 --- a/kernel/time/timekeeping.c
88511 +++ b/kernel/time/timekeeping.c
88512 @@ -15,6 +15,7 @@
88513 #include <linux/init.h>
88514 #include <linux/mm.h>
88515 #include <linux/sched.h>
88516 +#include <linux/grsecurity.h>
88517 #include <linux/syscore_ops.h>
88518 #include <linux/clocksource.h>
88519 #include <linux/jiffies.h>
88520 @@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
88521 if (!timespec_valid_strict(tv))
88522 return -EINVAL;
88523
88524 + gr_log_timechange();
88525 +
88526 raw_spin_lock_irqsave(&timekeeper_lock, flags);
88527 write_seqcount_begin(&timekeeper_seq);
88528
88529 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
88530 index 61ed862..3b52c65 100644
88531 --- a/kernel/time/timer_list.c
88532 +++ b/kernel/time/timer_list.c
88533 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
88534
88535 static void print_name_offset(struct seq_file *m, void *sym)
88536 {
88537 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88538 + SEQ_printf(m, "<%p>", NULL);
88539 +#else
88540 char symname[KSYM_NAME_LEN];
88541
88542 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
88543 SEQ_printf(m, "<%pK>", sym);
88544 else
88545 SEQ_printf(m, "%s", symname);
88546 +#endif
88547 }
88548
88549 static void
88550 @@ -119,7 +123,11 @@ next_one:
88551 static void
88552 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
88553 {
88554 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88555 + SEQ_printf(m, " .base: %p\n", NULL);
88556 +#else
88557 SEQ_printf(m, " .base: %pK\n", base);
88558 +#endif
88559 SEQ_printf(m, " .index: %d\n",
88560 base->index);
88561 SEQ_printf(m, " .resolution: %Lu nsecs\n",
88562 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
88563 {
88564 struct proc_dir_entry *pe;
88565
88566 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88567 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
88568 +#else
88569 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
88570 +#endif
88571 if (!pe)
88572 return -ENOMEM;
88573 return 0;
88574 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
88575 index 1fb08f2..ca4bb1e 100644
88576 --- a/kernel/time/timer_stats.c
88577 +++ b/kernel/time/timer_stats.c
88578 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
88579 static unsigned long nr_entries;
88580 static struct entry entries[MAX_ENTRIES];
88581
88582 -static atomic_t overflow_count;
88583 +static atomic_unchecked_t overflow_count;
88584
88585 /*
88586 * The entries are in a hash-table, for fast lookup:
88587 @@ -140,7 +140,7 @@ static void reset_entries(void)
88588 nr_entries = 0;
88589 memset(entries, 0, sizeof(entries));
88590 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
88591 - atomic_set(&overflow_count, 0);
88592 + atomic_set_unchecked(&overflow_count, 0);
88593 }
88594
88595 static struct entry *alloc_entry(void)
88596 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88597 if (likely(entry))
88598 entry->count++;
88599 else
88600 - atomic_inc(&overflow_count);
88601 + atomic_inc_unchecked(&overflow_count);
88602
88603 out_unlock:
88604 raw_spin_unlock_irqrestore(lock, flags);
88605 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88606
88607 static void print_name_offset(struct seq_file *m, unsigned long addr)
88608 {
88609 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88610 + seq_printf(m, "<%p>", NULL);
88611 +#else
88612 char symname[KSYM_NAME_LEN];
88613
88614 if (lookup_symbol_name(addr, symname) < 0)
88615 - seq_printf(m, "<%p>", (void *)addr);
88616 + seq_printf(m, "<%pK>", (void *)addr);
88617 else
88618 seq_printf(m, "%s", symname);
88619 +#endif
88620 }
88621
88622 static int tstats_show(struct seq_file *m, void *v)
88623 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
88624
88625 seq_puts(m, "Timer Stats Version: v0.3\n");
88626 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
88627 - if (atomic_read(&overflow_count))
88628 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
88629 + if (atomic_read_unchecked(&overflow_count))
88630 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
88631 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
88632
88633 for (i = 0; i < nr_entries; i++) {
88634 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
88635 {
88636 struct proc_dir_entry *pe;
88637
88638 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88639 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
88640 +#else
88641 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
88642 +#endif
88643 if (!pe)
88644 return -ENOMEM;
88645 return 0;
88646 diff --git a/kernel/timer.c b/kernel/timer.c
88647 index accfd24..e00f0c0 100644
88648 --- a/kernel/timer.c
88649 +++ b/kernel/timer.c
88650 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
88651 /*
88652 * This function runs timers and the timer-tq in bottom half context.
88653 */
88654 -static void run_timer_softirq(struct softirq_action *h)
88655 +static __latent_entropy void run_timer_softirq(void)
88656 {
88657 struct tvec_base *base = __this_cpu_read(tvec_bases);
88658
88659 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
88660 *
88661 * In all cases the return value is guaranteed to be non-negative.
88662 */
88663 -signed long __sched schedule_timeout(signed long timeout)
88664 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
88665 {
88666 struct timer_list timer;
88667 unsigned long expire;
88668 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
88669 index f785aef..59f1b18 100644
88670 --- a/kernel/trace/blktrace.c
88671 +++ b/kernel/trace/blktrace.c
88672 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
88673 struct blk_trace *bt = filp->private_data;
88674 char buf[16];
88675
88676 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
88677 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
88678
88679 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
88680 }
88681 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
88682 return 1;
88683
88684 bt = buf->chan->private_data;
88685 - atomic_inc(&bt->dropped);
88686 + atomic_inc_unchecked(&bt->dropped);
88687 return 0;
88688 }
88689
88690 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
88691
88692 bt->dir = dir;
88693 bt->dev = dev;
88694 - atomic_set(&bt->dropped, 0);
88695 + atomic_set_unchecked(&bt->dropped, 0);
88696 INIT_LIST_HEAD(&bt->running_list);
88697
88698 ret = -EIO;
88699 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
88700 index 72a0f81..0bbfd090 100644
88701 --- a/kernel/trace/ftrace.c
88702 +++ b/kernel/trace/ftrace.c
88703 @@ -1944,12 +1944,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
88704 if (unlikely(ftrace_disabled))
88705 return 0;
88706
88707 + ret = ftrace_arch_code_modify_prepare();
88708 + FTRACE_WARN_ON(ret);
88709 + if (ret)
88710 + return 0;
88711 +
88712 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
88713 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
88714 if (ret) {
88715 ftrace_bug(ret, ip);
88716 - return 0;
88717 }
88718 - return 1;
88719 + return ret ? 0 : 1;
88720 }
88721
88722 /*
88723 @@ -4119,8 +4124,10 @@ static int ftrace_process_locs(struct module *mod,
88724 if (!count)
88725 return 0;
88726
88727 + pax_open_kernel();
88728 sort(start, count, sizeof(*start),
88729 ftrace_cmp_ips, ftrace_swap_ips);
88730 + pax_close_kernel();
88731
88732 start_pg = ftrace_allocate_pages(count);
88733 if (!start_pg)
88734 @@ -4851,8 +4858,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
88735 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
88736
88737 static int ftrace_graph_active;
88738 -static struct notifier_block ftrace_suspend_notifier;
88739 -
88740 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
88741 {
88742 return 0;
88743 @@ -5003,6 +5008,10 @@ static struct ftrace_ops fgraph_ops __read_mostly = {
88744 FTRACE_OPS_FL_RECURSION_SAFE,
88745 };
88746
88747 +static struct notifier_block ftrace_suspend_notifier = {
88748 + .notifier_call = ftrace_suspend_notifier_call
88749 +};
88750 +
88751 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88752 trace_func_graph_ent_t entryfunc)
88753 {
88754 @@ -5016,7 +5025,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88755 goto out;
88756 }
88757
88758 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
88759 register_pm_notifier(&ftrace_suspend_notifier);
88760
88761 ftrace_graph_active++;
88762 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
88763 index cc2f66f..05edd54 100644
88764 --- a/kernel/trace/ring_buffer.c
88765 +++ b/kernel/trace/ring_buffer.c
88766 @@ -352,9 +352,9 @@ struct buffer_data_page {
88767 */
88768 struct buffer_page {
88769 struct list_head list; /* list of buffer pages */
88770 - local_t write; /* index for next write */
88771 + local_unchecked_t write; /* index for next write */
88772 unsigned read; /* index for next read */
88773 - local_t entries; /* entries on this page */
88774 + local_unchecked_t entries; /* entries on this page */
88775 unsigned long real_end; /* real end of data */
88776 struct buffer_data_page *page; /* Actual data page */
88777 };
88778 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
88779 unsigned long last_overrun;
88780 local_t entries_bytes;
88781 local_t entries;
88782 - local_t overrun;
88783 - local_t commit_overrun;
88784 + local_unchecked_t overrun;
88785 + local_unchecked_t commit_overrun;
88786 local_t dropped_events;
88787 local_t committing;
88788 local_t commits;
88789 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88790 *
88791 * We add a counter to the write field to denote this.
88792 */
88793 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
88794 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
88795 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
88796 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
88797
88798 /*
88799 * Just make sure we have seen our old_write and synchronize
88800 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88801 * cmpxchg to only update if an interrupt did not already
88802 * do it for us. If the cmpxchg fails, we don't care.
88803 */
88804 - (void)local_cmpxchg(&next_page->write, old_write, val);
88805 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
88806 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
88807 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
88808
88809 /*
88810 * No need to worry about races with clearing out the commit.
88811 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
88812
88813 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
88814 {
88815 - return local_read(&bpage->entries) & RB_WRITE_MASK;
88816 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
88817 }
88818
88819 static inline unsigned long rb_page_write(struct buffer_page *bpage)
88820 {
88821 - return local_read(&bpage->write) & RB_WRITE_MASK;
88822 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
88823 }
88824
88825 static int
88826 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
88827 * bytes consumed in ring buffer from here.
88828 * Increment overrun to account for the lost events.
88829 */
88830 - local_add(page_entries, &cpu_buffer->overrun);
88831 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
88832 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
88833 }
88834
88835 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
88836 * it is our responsibility to update
88837 * the counters.
88838 */
88839 - local_add(entries, &cpu_buffer->overrun);
88840 + local_add_unchecked(entries, &cpu_buffer->overrun);
88841 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
88842
88843 /*
88844 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88845 if (tail == BUF_PAGE_SIZE)
88846 tail_page->real_end = 0;
88847
88848 - local_sub(length, &tail_page->write);
88849 + local_sub_unchecked(length, &tail_page->write);
88850 return;
88851 }
88852
88853 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88854 rb_event_set_padding(event);
88855
88856 /* Set the write back to the previous setting */
88857 - local_sub(length, &tail_page->write);
88858 + local_sub_unchecked(length, &tail_page->write);
88859 return;
88860 }
88861
88862 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
88863
88864 /* Set write to end of buffer */
88865 length = (tail + length) - BUF_PAGE_SIZE;
88866 - local_sub(length, &tail_page->write);
88867 + local_sub_unchecked(length, &tail_page->write);
88868 }
88869
88870 /*
88871 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
88872 * about it.
88873 */
88874 if (unlikely(next_page == commit_page)) {
88875 - local_inc(&cpu_buffer->commit_overrun);
88876 + local_inc_unchecked(&cpu_buffer->commit_overrun);
88877 goto out_reset;
88878 }
88879
88880 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
88881 cpu_buffer->tail_page) &&
88882 (cpu_buffer->commit_page ==
88883 cpu_buffer->reader_page))) {
88884 - local_inc(&cpu_buffer->commit_overrun);
88885 + local_inc_unchecked(&cpu_buffer->commit_overrun);
88886 goto out_reset;
88887 }
88888 }
88889 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
88890 length += RB_LEN_TIME_EXTEND;
88891
88892 tail_page = cpu_buffer->tail_page;
88893 - write = local_add_return(length, &tail_page->write);
88894 + write = local_add_return_unchecked(length, &tail_page->write);
88895
88896 /* set write to only the index of the write */
88897 write &= RB_WRITE_MASK;
88898 @@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
88899 kmemcheck_annotate_bitfield(event, bitfield);
88900 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
88901
88902 - local_inc(&tail_page->entries);
88903 + local_inc_unchecked(&tail_page->entries);
88904
88905 /*
88906 * If this is the first commit on the page, then update
88907 @@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
88908
88909 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
88910 unsigned long write_mask =
88911 - local_read(&bpage->write) & ~RB_WRITE_MASK;
88912 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
88913 unsigned long event_length = rb_event_length(event);
88914 /*
88915 * This is on the tail page. It is possible that
88916 @@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
88917 */
88918 old_index += write_mask;
88919 new_index += write_mask;
88920 - index = local_cmpxchg(&bpage->write, old_index, new_index);
88921 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
88922 if (index == old_index) {
88923 /* update counters */
88924 local_sub(event_length, &cpu_buffer->entries_bytes);
88925 @@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
88926
88927 /* Do the likely case first */
88928 if (likely(bpage->page == (void *)addr)) {
88929 - local_dec(&bpage->entries);
88930 + local_dec_unchecked(&bpage->entries);
88931 return;
88932 }
88933
88934 @@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
88935 start = bpage;
88936 do {
88937 if (bpage->page == (void *)addr) {
88938 - local_dec(&bpage->entries);
88939 + local_dec_unchecked(&bpage->entries);
88940 return;
88941 }
88942 rb_inc_page(cpu_buffer, &bpage);
88943 @@ -3139,7 +3139,7 @@ static inline unsigned long
88944 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
88945 {
88946 return local_read(&cpu_buffer->entries) -
88947 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
88948 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
88949 }
88950
88951 /**
88952 @@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
88953 return 0;
88954
88955 cpu_buffer = buffer->buffers[cpu];
88956 - ret = local_read(&cpu_buffer->overrun);
88957 + ret = local_read_unchecked(&cpu_buffer->overrun);
88958
88959 return ret;
88960 }
88961 @@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
88962 return 0;
88963
88964 cpu_buffer = buffer->buffers[cpu];
88965 - ret = local_read(&cpu_buffer->commit_overrun);
88966 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
88967
88968 return ret;
88969 }
88970 @@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
88971 /* if you care about this being correct, lock the buffer */
88972 for_each_buffer_cpu(buffer, cpu) {
88973 cpu_buffer = buffer->buffers[cpu];
88974 - overruns += local_read(&cpu_buffer->overrun);
88975 + overruns += local_read_unchecked(&cpu_buffer->overrun);
88976 }
88977
88978 return overruns;
88979 @@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
88980 /*
88981 * Reset the reader page to size zero.
88982 */
88983 - local_set(&cpu_buffer->reader_page->write, 0);
88984 - local_set(&cpu_buffer->reader_page->entries, 0);
88985 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
88986 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
88987 local_set(&cpu_buffer->reader_page->page->commit, 0);
88988 cpu_buffer->reader_page->real_end = 0;
88989
88990 @@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
88991 * want to compare with the last_overrun.
88992 */
88993 smp_mb();
88994 - overwrite = local_read(&(cpu_buffer->overrun));
88995 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
88996
88997 /*
88998 * Here's the tricky part.
88999 @@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
89000
89001 cpu_buffer->head_page
89002 = list_entry(cpu_buffer->pages, struct buffer_page, list);
89003 - local_set(&cpu_buffer->head_page->write, 0);
89004 - local_set(&cpu_buffer->head_page->entries, 0);
89005 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
89006 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
89007 local_set(&cpu_buffer->head_page->page->commit, 0);
89008
89009 cpu_buffer->head_page->read = 0;
89010 @@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
89011
89012 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
89013 INIT_LIST_HEAD(&cpu_buffer->new_pages);
89014 - local_set(&cpu_buffer->reader_page->write, 0);
89015 - local_set(&cpu_buffer->reader_page->entries, 0);
89016 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
89017 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
89018 local_set(&cpu_buffer->reader_page->page->commit, 0);
89019 cpu_buffer->reader_page->read = 0;
89020
89021 local_set(&cpu_buffer->entries_bytes, 0);
89022 - local_set(&cpu_buffer->overrun, 0);
89023 - local_set(&cpu_buffer->commit_overrun, 0);
89024 + local_set_unchecked(&cpu_buffer->overrun, 0);
89025 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
89026 local_set(&cpu_buffer->dropped_events, 0);
89027 local_set(&cpu_buffer->entries, 0);
89028 local_set(&cpu_buffer->committing, 0);
89029 @@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
89030 rb_init_page(bpage);
89031 bpage = reader->page;
89032 reader->page = *data_page;
89033 - local_set(&reader->write, 0);
89034 - local_set(&reader->entries, 0);
89035 + local_set_unchecked(&reader->write, 0);
89036 + local_set_unchecked(&reader->entries, 0);
89037 reader->read = 0;
89038 *data_page = bpage;
89039
89040 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
89041 index 9d20cd9..221d816 100644
89042 --- a/kernel/trace/trace.c
89043 +++ b/kernel/trace/trace.c
89044 @@ -3346,7 +3346,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
89045 return 0;
89046 }
89047
89048 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
89049 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
89050 {
89051 /* do nothing if flag is already set */
89052 if (!!(trace_flags & mask) == !!enabled)
89053 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
89054 index ea189e0..a5b48c4 100644
89055 --- a/kernel/trace/trace.h
89056 +++ b/kernel/trace/trace.h
89057 @@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
89058 void trace_printk_init_buffers(void);
89059 void trace_printk_start_comm(void);
89060 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
89061 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
89062 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
89063
89064 /*
89065 * Normal trace_printk() and friends allocates special buffers
89066 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
89067 index 26dc348..8708ca7 100644
89068 --- a/kernel/trace/trace_clock.c
89069 +++ b/kernel/trace/trace_clock.c
89070 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
89071 return now;
89072 }
89073
89074 -static atomic64_t trace_counter;
89075 +static atomic64_unchecked_t trace_counter;
89076
89077 /*
89078 * trace_clock_counter(): simply an atomic counter.
89079 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
89080 */
89081 u64 notrace trace_clock_counter(void)
89082 {
89083 - return atomic64_add_return(1, &trace_counter);
89084 + return atomic64_inc_return_unchecked(&trace_counter);
89085 }
89086 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
89087 index a11800a..3dafde5 100644
89088 --- a/kernel/trace/trace_events.c
89089 +++ b/kernel/trace/trace_events.c
89090 @@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
89091 return 0;
89092 }
89093
89094 -struct ftrace_module_file_ops;
89095 static void __add_event_to_tracers(struct ftrace_event_call *call);
89096
89097 /* Add an additional event_call dynamically */
89098 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
89099 index 0abd9b8..6a663a2 100644
89100 --- a/kernel/trace/trace_mmiotrace.c
89101 +++ b/kernel/trace/trace_mmiotrace.c
89102 @@ -24,7 +24,7 @@ struct header_iter {
89103 static struct trace_array *mmio_trace_array;
89104 static bool overrun_detected;
89105 static unsigned long prev_overruns;
89106 -static atomic_t dropped_count;
89107 +static atomic_unchecked_t dropped_count;
89108
89109 static void mmio_reset_data(struct trace_array *tr)
89110 {
89111 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
89112
89113 static unsigned long count_overruns(struct trace_iterator *iter)
89114 {
89115 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
89116 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
89117 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
89118
89119 if (over > prev_overruns)
89120 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
89121 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
89122 sizeof(*entry), 0, pc);
89123 if (!event) {
89124 - atomic_inc(&dropped_count);
89125 + atomic_inc_unchecked(&dropped_count);
89126 return;
89127 }
89128 entry = ring_buffer_event_data(event);
89129 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
89130 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
89131 sizeof(*entry), 0, pc);
89132 if (!event) {
89133 - atomic_inc(&dropped_count);
89134 + atomic_inc_unchecked(&dropped_count);
89135 return;
89136 }
89137 entry = ring_buffer_event_data(event);
89138 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
89139 index ed32284..884d6c3 100644
89140 --- a/kernel/trace/trace_output.c
89141 +++ b/kernel/trace/trace_output.c
89142 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
89143
89144 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
89145 if (!IS_ERR(p)) {
89146 - p = mangle_path(s->buffer + s->len, p, "\n");
89147 + p = mangle_path(s->buffer + s->len, p, "\n\\");
89148 if (p) {
89149 s->len = p - s->buffer;
89150 return 1;
89151 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
89152 goto out;
89153 }
89154
89155 + pax_open_kernel();
89156 if (event->funcs->trace == NULL)
89157 - event->funcs->trace = trace_nop_print;
89158 + *(void **)&event->funcs->trace = trace_nop_print;
89159 if (event->funcs->raw == NULL)
89160 - event->funcs->raw = trace_nop_print;
89161 + *(void **)&event->funcs->raw = trace_nop_print;
89162 if (event->funcs->hex == NULL)
89163 - event->funcs->hex = trace_nop_print;
89164 + *(void **)&event->funcs->hex = trace_nop_print;
89165 if (event->funcs->binary == NULL)
89166 - event->funcs->binary = trace_nop_print;
89167 + *(void **)&event->funcs->binary = trace_nop_print;
89168 + pax_close_kernel();
89169
89170 key = event->type & (EVENT_HASHSIZE - 1);
89171
89172 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
89173 index b20428c..4845a10 100644
89174 --- a/kernel/trace/trace_stack.c
89175 +++ b/kernel/trace/trace_stack.c
89176 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
89177 return;
89178
89179 /* we do not handle interrupt stacks yet */
89180 - if (!object_is_on_stack(stack))
89181 + if (!object_starts_on_stack(stack))
89182 return;
89183
89184 local_irq_save(flags);
89185 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
89186 index 240fb62..583473e 100644
89187 --- a/kernel/user_namespace.c
89188 +++ b/kernel/user_namespace.c
89189 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
89190 !kgid_has_mapping(parent_ns, group))
89191 return -EPERM;
89192
89193 +#ifdef CONFIG_GRKERNSEC
89194 + /*
89195 + * This doesn't really inspire confidence:
89196 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
89197 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
89198 + * Increases kernel attack surface in areas developers
89199 + * previously cared little about ("low importance due
89200 + * to requiring "root" capability")
89201 + * To be removed when this code receives *proper* review
89202 + */
89203 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
89204 + !capable(CAP_SETGID))
89205 + return -EPERM;
89206 +#endif
89207 +
89208 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
89209 if (!ns)
89210 return -ENOMEM;
89211 @@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
89212 if (atomic_read(&current->mm->mm_users) > 1)
89213 return -EINVAL;
89214
89215 - if (current->fs->users != 1)
89216 + if (atomic_read(&current->fs->users) != 1)
89217 return -EINVAL;
89218
89219 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
89220 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
89221 index 4f69f9a..7c6f8f8 100644
89222 --- a/kernel/utsname_sysctl.c
89223 +++ b/kernel/utsname_sysctl.c
89224 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
89225 static int proc_do_uts_string(ctl_table *table, int write,
89226 void __user *buffer, size_t *lenp, loff_t *ppos)
89227 {
89228 - struct ctl_table uts_table;
89229 + ctl_table_no_const uts_table;
89230 int r;
89231 memcpy(&uts_table, table, sizeof(uts_table));
89232 uts_table.data = get_uts(table, write);
89233 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
89234 index 4431610..4265616 100644
89235 --- a/kernel/watchdog.c
89236 +++ b/kernel/watchdog.c
89237 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
89238 static void watchdog_nmi_disable(unsigned int cpu) { return; }
89239 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
89240
89241 -static struct smp_hotplug_thread watchdog_threads = {
89242 +static struct smp_hotplug_thread watchdog_threads __read_only = {
89243 .store = &softlockup_watchdog,
89244 .thread_should_run = watchdog_should_run,
89245 .thread_fn = watchdog,
89246 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
89247 index b010eac..e4bda78 100644
89248 --- a/kernel/workqueue.c
89249 +++ b/kernel/workqueue.c
89250 @@ -4671,7 +4671,7 @@ static void rebind_workers(struct worker_pool *pool)
89251 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
89252 worker_flags |= WORKER_REBOUND;
89253 worker_flags &= ~WORKER_UNBOUND;
89254 - ACCESS_ONCE(worker->flags) = worker_flags;
89255 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
89256 }
89257
89258 spin_unlock_irq(&pool->lock);
89259 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
89260 index db25707..8b16430 100644
89261 --- a/lib/Kconfig.debug
89262 +++ b/lib/Kconfig.debug
89263 @@ -845,7 +845,7 @@ config DEBUG_MUTEXES
89264
89265 config DEBUG_WW_MUTEX_SLOWPATH
89266 bool "Wait/wound mutex debugging: Slowpath testing"
89267 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89268 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89269 select DEBUG_LOCK_ALLOC
89270 select DEBUG_SPINLOCK
89271 select DEBUG_MUTEXES
89272 @@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
89273
89274 config DEBUG_LOCK_ALLOC
89275 bool "Lock debugging: detect incorrect freeing of live locks"
89276 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89277 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89278 select DEBUG_SPINLOCK
89279 select DEBUG_MUTEXES
89280 select LOCKDEP
89281 @@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
89282
89283 config PROVE_LOCKING
89284 bool "Lock debugging: prove locking correctness"
89285 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89286 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89287 select LOCKDEP
89288 select DEBUG_SPINLOCK
89289 select DEBUG_MUTEXES
89290 @@ -923,7 +923,7 @@ config LOCKDEP
89291
89292 config LOCK_STAT
89293 bool "Lock usage statistics"
89294 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89295 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89296 select LOCKDEP
89297 select DEBUG_SPINLOCK
89298 select DEBUG_MUTEXES
89299 @@ -1385,6 +1385,7 @@ config LATENCYTOP
89300 depends on DEBUG_KERNEL
89301 depends on STACKTRACE_SUPPORT
89302 depends on PROC_FS
89303 + depends on !GRKERNSEC_HIDESYM
89304 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
89305 select KALLSYMS
89306 select KALLSYMS_ALL
89307 @@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89308 config DEBUG_STRICT_USER_COPY_CHECKS
89309 bool "Strict user copy size checks"
89310 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89311 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
89312 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
89313 help
89314 Enabling this option turns a certain set of sanity checks for user
89315 copy operations into compile time failures.
89316 @@ -1520,7 +1521,7 @@ endmenu # runtime tests
89317
89318 config PROVIDE_OHCI1394_DMA_INIT
89319 bool "Remote debugging over FireWire early on boot"
89320 - depends on PCI && X86
89321 + depends on PCI && X86 && !GRKERNSEC
89322 help
89323 If you want to debug problems which hang or crash the kernel early
89324 on boot and the crashing machine has a FireWire port, you can use
89325 @@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
89326
89327 config FIREWIRE_OHCI_REMOTE_DMA
89328 bool "Remote debugging over FireWire with firewire-ohci"
89329 - depends on FIREWIRE_OHCI
89330 + depends on FIREWIRE_OHCI && !GRKERNSEC
89331 help
89332 This option lets you use the FireWire bus for remote debugging
89333 with help of the firewire-ohci driver. It enables unfiltered
89334 diff --git a/lib/Makefile b/lib/Makefile
89335 index a459c31..3320e82 100644
89336 --- a/lib/Makefile
89337 +++ b/lib/Makefile
89338 @@ -49,7 +49,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
89339 obj-$(CONFIG_BTREE) += btree.o
89340 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
89341 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
89342 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
89343 +obj-y += list_debug.o
89344 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
89345
89346 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
89347 diff --git a/lib/bitmap.c b/lib/bitmap.c
89348 index 06f7e4f..f3cf2b0 100644
89349 --- a/lib/bitmap.c
89350 +++ b/lib/bitmap.c
89351 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
89352 {
89353 int c, old_c, totaldigits, ndigits, nchunks, nbits;
89354 u32 chunk;
89355 - const char __user __force *ubuf = (const char __user __force *)buf;
89356 + const char __user *ubuf = (const char __force_user *)buf;
89357
89358 bitmap_zero(maskp, nmaskbits);
89359
89360 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
89361 {
89362 if (!access_ok(VERIFY_READ, ubuf, ulen))
89363 return -EFAULT;
89364 - return __bitmap_parse((const char __force *)ubuf,
89365 + return __bitmap_parse((const char __force_kernel *)ubuf,
89366 ulen, 1, maskp, nmaskbits);
89367
89368 }
89369 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
89370 {
89371 unsigned a, b;
89372 int c, old_c, totaldigits;
89373 - const char __user __force *ubuf = (const char __user __force *)buf;
89374 + const char __user *ubuf = (const char __force_user *)buf;
89375 int exp_digit, in_range;
89376
89377 totaldigits = c = 0;
89378 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
89379 {
89380 if (!access_ok(VERIFY_READ, ubuf, ulen))
89381 return -EFAULT;
89382 - return __bitmap_parselist((const char __force *)ubuf,
89383 + return __bitmap_parselist((const char __force_kernel *)ubuf,
89384 ulen, 1, maskp, nmaskbits);
89385 }
89386 EXPORT_SYMBOL(bitmap_parselist_user);
89387 diff --git a/lib/bug.c b/lib/bug.c
89388 index 1686034..a9c00c8 100644
89389 --- a/lib/bug.c
89390 +++ b/lib/bug.c
89391 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
89392 return BUG_TRAP_TYPE_NONE;
89393
89394 bug = find_bug(bugaddr);
89395 + if (!bug)
89396 + return BUG_TRAP_TYPE_NONE;
89397
89398 file = NULL;
89399 line = 0;
89400 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
89401 index e0731c3..ad66444 100644
89402 --- a/lib/debugobjects.c
89403 +++ b/lib/debugobjects.c
89404 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
89405 if (limit > 4)
89406 return;
89407
89408 - is_on_stack = object_is_on_stack(addr);
89409 + is_on_stack = object_starts_on_stack(addr);
89410 if (is_on_stack == onstack)
89411 return;
89412
89413 diff --git a/lib/devres.c b/lib/devres.c
89414 index 8235331..5881053 100644
89415 --- a/lib/devres.c
89416 +++ b/lib/devres.c
89417 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
89418 void devm_iounmap(struct device *dev, void __iomem *addr)
89419 {
89420 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
89421 - (void *)addr));
89422 + (void __force *)addr));
89423 iounmap(addr);
89424 }
89425 EXPORT_SYMBOL(devm_iounmap);
89426 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
89427 {
89428 ioport_unmap(addr);
89429 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
89430 - devm_ioport_map_match, (void *)addr));
89431 + devm_ioport_map_match, (void __force *)addr));
89432 }
89433 EXPORT_SYMBOL(devm_ioport_unmap);
89434 #endif /* CONFIG_HAS_IOPORT */
89435 diff --git a/lib/div64.c b/lib/div64.c
89436 index 4382ad7..08aa558 100644
89437 --- a/lib/div64.c
89438 +++ b/lib/div64.c
89439 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
89440 EXPORT_SYMBOL(__div64_32);
89441
89442 #ifndef div_s64_rem
89443 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89444 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89445 {
89446 u64 quotient;
89447
89448 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
89449 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
89450 */
89451 #ifndef div64_u64
89452 -u64 div64_u64(u64 dividend, u64 divisor)
89453 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
89454 {
89455 u32 high = divisor >> 32;
89456 u64 quot;
89457 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
89458 index d87a17a..ac0d79a 100644
89459 --- a/lib/dma-debug.c
89460 +++ b/lib/dma-debug.c
89461 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
89462
89463 void dma_debug_add_bus(struct bus_type *bus)
89464 {
89465 - struct notifier_block *nb;
89466 + notifier_block_no_const *nb;
89467
89468 if (global_disable)
89469 return;
89470 @@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
89471
89472 static void check_for_stack(struct device *dev, void *addr)
89473 {
89474 - if (object_is_on_stack(addr))
89475 + if (object_starts_on_stack(addr))
89476 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
89477 "stack [addr=%p]\n", addr);
89478 }
89479 diff --git a/lib/inflate.c b/lib/inflate.c
89480 index 013a761..c28f3fc 100644
89481 --- a/lib/inflate.c
89482 +++ b/lib/inflate.c
89483 @@ -269,7 +269,7 @@ static void free(void *where)
89484 malloc_ptr = free_mem_ptr;
89485 }
89486 #else
89487 -#define malloc(a) kmalloc(a, GFP_KERNEL)
89488 +#define malloc(a) kmalloc((a), GFP_KERNEL)
89489 #define free(a) kfree(a)
89490 #endif
89491
89492 diff --git a/lib/ioremap.c b/lib/ioremap.c
89493 index 0c9216c..863bd89 100644
89494 --- a/lib/ioremap.c
89495 +++ b/lib/ioremap.c
89496 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
89497 unsigned long next;
89498
89499 phys_addr -= addr;
89500 - pmd = pmd_alloc(&init_mm, pud, addr);
89501 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
89502 if (!pmd)
89503 return -ENOMEM;
89504 do {
89505 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
89506 unsigned long next;
89507
89508 phys_addr -= addr;
89509 - pud = pud_alloc(&init_mm, pgd, addr);
89510 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
89511 if (!pud)
89512 return -ENOMEM;
89513 do {
89514 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
89515 index bd2bea9..6b3c95e 100644
89516 --- a/lib/is_single_threaded.c
89517 +++ b/lib/is_single_threaded.c
89518 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
89519 struct task_struct *p, *t;
89520 bool ret;
89521
89522 + if (!mm)
89523 + return true;
89524 +
89525 if (atomic_read(&task->signal->live) != 1)
89526 return false;
89527
89528 diff --git a/lib/kobject.c b/lib/kobject.c
89529 index 5b4b888..c2950f7 100644
89530 --- a/lib/kobject.c
89531 +++ b/lib/kobject.c
89532 @@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
89533
89534
89535 static DEFINE_SPINLOCK(kobj_ns_type_lock);
89536 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
89537 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
89538
89539 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89540 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89541 {
89542 enum kobj_ns_type type = ops->type;
89543 int error;
89544 diff --git a/lib/list_debug.c b/lib/list_debug.c
89545 index c24c2f7..f0296f4 100644
89546 --- a/lib/list_debug.c
89547 +++ b/lib/list_debug.c
89548 @@ -11,7 +11,9 @@
89549 #include <linux/bug.h>
89550 #include <linux/kernel.h>
89551 #include <linux/rculist.h>
89552 +#include <linux/mm.h>
89553
89554 +#ifdef CONFIG_DEBUG_LIST
89555 /*
89556 * Insert a new entry between two known consecutive entries.
89557 *
89558 @@ -19,21 +21,40 @@
89559 * the prev/next entries already!
89560 */
89561
89562 +static bool __list_add_debug(struct list_head *new,
89563 + struct list_head *prev,
89564 + struct list_head *next)
89565 +{
89566 + if (unlikely(next->prev != prev)) {
89567 + printk(KERN_ERR "list_add corruption. next->prev should be "
89568 + "prev (%p), but was %p. (next=%p).\n",
89569 + prev, next->prev, next);
89570 + BUG();
89571 + return false;
89572 + }
89573 + if (unlikely(prev->next != next)) {
89574 + printk(KERN_ERR "list_add corruption. prev->next should be "
89575 + "next (%p), but was %p. (prev=%p).\n",
89576 + next, prev->next, prev);
89577 + BUG();
89578 + return false;
89579 + }
89580 + if (unlikely(new == prev || new == next)) {
89581 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
89582 + new, prev, next);
89583 + BUG();
89584 + return false;
89585 + }
89586 + return true;
89587 +}
89588 +
89589 void __list_add(struct list_head *new,
89590 - struct list_head *prev,
89591 - struct list_head *next)
89592 + struct list_head *prev,
89593 + struct list_head *next)
89594 {
89595 - WARN(next->prev != prev,
89596 - "list_add corruption. next->prev should be "
89597 - "prev (%p), but was %p. (next=%p).\n",
89598 - prev, next->prev, next);
89599 - WARN(prev->next != next,
89600 - "list_add corruption. prev->next should be "
89601 - "next (%p), but was %p. (prev=%p).\n",
89602 - next, prev->next, prev);
89603 - WARN(new == prev || new == next,
89604 - "list_add double add: new=%p, prev=%p, next=%p.\n",
89605 - new, prev, next);
89606 + if (!__list_add_debug(new, prev, next))
89607 + return;
89608 +
89609 next->prev = new;
89610 new->next = next;
89611 new->prev = prev;
89612 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
89613 }
89614 EXPORT_SYMBOL(__list_add);
89615
89616 -void __list_del_entry(struct list_head *entry)
89617 +static bool __list_del_entry_debug(struct list_head *entry)
89618 {
89619 struct list_head *prev, *next;
89620
89621 prev = entry->prev;
89622 next = entry->next;
89623
89624 - if (WARN(next == LIST_POISON1,
89625 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89626 - entry, LIST_POISON1) ||
89627 - WARN(prev == LIST_POISON2,
89628 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89629 - entry, LIST_POISON2) ||
89630 - WARN(prev->next != entry,
89631 - "list_del corruption. prev->next should be %p, "
89632 - "but was %p\n", entry, prev->next) ||
89633 - WARN(next->prev != entry,
89634 - "list_del corruption. next->prev should be %p, "
89635 - "but was %p\n", entry, next->prev))
89636 + if (unlikely(next == LIST_POISON1)) {
89637 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89638 + entry, LIST_POISON1);
89639 + BUG();
89640 + return false;
89641 + }
89642 + if (unlikely(prev == LIST_POISON2)) {
89643 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89644 + entry, LIST_POISON2);
89645 + BUG();
89646 + return false;
89647 + }
89648 + if (unlikely(entry->prev->next != entry)) {
89649 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
89650 + "but was %p\n", entry, prev->next);
89651 + BUG();
89652 + return false;
89653 + }
89654 + if (unlikely(entry->next->prev != entry)) {
89655 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
89656 + "but was %p\n", entry, next->prev);
89657 + BUG();
89658 + return false;
89659 + }
89660 + return true;
89661 +}
89662 +
89663 +void __list_del_entry(struct list_head *entry)
89664 +{
89665 + if (!__list_del_entry_debug(entry))
89666 return;
89667
89668 - __list_del(prev, next);
89669 + __list_del(entry->prev, entry->next);
89670 }
89671 EXPORT_SYMBOL(__list_del_entry);
89672
89673 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
89674 void __list_add_rcu(struct list_head *new,
89675 struct list_head *prev, struct list_head *next)
89676 {
89677 - WARN(next->prev != prev,
89678 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
89679 - prev, next->prev, next);
89680 - WARN(prev->next != next,
89681 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
89682 - next, prev->next, prev);
89683 + if (!__list_add_debug(new, prev, next))
89684 + return;
89685 +
89686 new->next = next;
89687 new->prev = prev;
89688 rcu_assign_pointer(list_next_rcu(prev), new);
89689 next->prev = new;
89690 }
89691 EXPORT_SYMBOL(__list_add_rcu);
89692 +#endif
89693 +
89694 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
89695 +{
89696 +#ifdef CONFIG_DEBUG_LIST
89697 + if (!__list_add_debug(new, prev, next))
89698 + return;
89699 +#endif
89700 +
89701 + pax_open_kernel();
89702 + next->prev = new;
89703 + new->next = next;
89704 + new->prev = prev;
89705 + prev->next = new;
89706 + pax_close_kernel();
89707 +}
89708 +EXPORT_SYMBOL(__pax_list_add);
89709 +
89710 +void pax_list_del(struct list_head *entry)
89711 +{
89712 +#ifdef CONFIG_DEBUG_LIST
89713 + if (!__list_del_entry_debug(entry))
89714 + return;
89715 +#endif
89716 +
89717 + pax_open_kernel();
89718 + __list_del(entry->prev, entry->next);
89719 + entry->next = LIST_POISON1;
89720 + entry->prev = LIST_POISON2;
89721 + pax_close_kernel();
89722 +}
89723 +EXPORT_SYMBOL(pax_list_del);
89724 +
89725 +void pax_list_del_init(struct list_head *entry)
89726 +{
89727 + pax_open_kernel();
89728 + __list_del(entry->prev, entry->next);
89729 + INIT_LIST_HEAD(entry);
89730 + pax_close_kernel();
89731 +}
89732 +EXPORT_SYMBOL(pax_list_del_init);
89733 +
89734 +void __pax_list_add_rcu(struct list_head *new,
89735 + struct list_head *prev, struct list_head *next)
89736 +{
89737 +#ifdef CONFIG_DEBUG_LIST
89738 + if (!__list_add_debug(new, prev, next))
89739 + return;
89740 +#endif
89741 +
89742 + pax_open_kernel();
89743 + new->next = next;
89744 + new->prev = prev;
89745 + rcu_assign_pointer(list_next_rcu(prev), new);
89746 + next->prev = new;
89747 + pax_close_kernel();
89748 +}
89749 +EXPORT_SYMBOL(__pax_list_add_rcu);
89750 +
89751 +void pax_list_del_rcu(struct list_head *entry)
89752 +{
89753 +#ifdef CONFIG_DEBUG_LIST
89754 + if (!__list_del_entry_debug(entry))
89755 + return;
89756 +#endif
89757 +
89758 + pax_open_kernel();
89759 + __list_del(entry->prev, entry->next);
89760 + entry->next = LIST_POISON1;
89761 + entry->prev = LIST_POISON2;
89762 + pax_close_kernel();
89763 +}
89764 +EXPORT_SYMBOL(pax_list_del_rcu);
89765 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
89766 index 1a53d49..ace934c 100644
89767 --- a/lib/percpu-refcount.c
89768 +++ b/lib/percpu-refcount.c
89769 @@ -29,7 +29,7 @@
89770 * can't hit 0 before we've added up all the percpu refs.
89771 */
89772
89773 -#define PCPU_COUNT_BIAS (1U << 31)
89774 +#define PCPU_COUNT_BIAS (1U << 30)
89775
89776 /**
89777 * percpu_ref_init - initialize a percpu refcount
89778 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
89779 index 7811ed3..f80ca19 100644
89780 --- a/lib/radix-tree.c
89781 +++ b/lib/radix-tree.c
89782 @@ -93,7 +93,7 @@ struct radix_tree_preload {
89783 int nr;
89784 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
89785 };
89786 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
89787 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
89788
89789 static inline void *ptr_to_indirect(void *ptr)
89790 {
89791 diff --git a/lib/rbtree.c b/lib/rbtree.c
89792 index 65f4eff..2cfa167 100644
89793 --- a/lib/rbtree.c
89794 +++ b/lib/rbtree.c
89795 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
89796 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
89797
89798 static const struct rb_augment_callbacks dummy_callbacks = {
89799 - dummy_propagate, dummy_copy, dummy_rotate
89800 + .propagate = dummy_propagate,
89801 + .copy = dummy_copy,
89802 + .rotate = dummy_rotate
89803 };
89804
89805 void rb_insert_color(struct rb_node *node, struct rb_root *root)
89806 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
89807 index bb2b201..46abaf9 100644
89808 --- a/lib/strncpy_from_user.c
89809 +++ b/lib/strncpy_from_user.c
89810 @@ -21,7 +21,7 @@
89811 */
89812 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
89813 {
89814 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89815 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89816 long res = 0;
89817
89818 /*
89819 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
89820 index a28df52..3d55877 100644
89821 --- a/lib/strnlen_user.c
89822 +++ b/lib/strnlen_user.c
89823 @@ -26,7 +26,7 @@
89824 */
89825 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
89826 {
89827 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89828 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89829 long align, res = 0;
89830 unsigned long c;
89831
89832 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
89833 index e4399fa..5e8b214 100644
89834 --- a/lib/swiotlb.c
89835 +++ b/lib/swiotlb.c
89836 @@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
89837
89838 void
89839 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
89840 - dma_addr_t dev_addr)
89841 + dma_addr_t dev_addr, struct dma_attrs *attrs)
89842 {
89843 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
89844
89845 diff --git a/lib/usercopy.c b/lib/usercopy.c
89846 index 4f5b1dd..7cab418 100644
89847 --- a/lib/usercopy.c
89848 +++ b/lib/usercopy.c
89849 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
89850 WARN(1, "Buffer overflow detected!\n");
89851 }
89852 EXPORT_SYMBOL(copy_from_user_overflow);
89853 +
89854 +void copy_to_user_overflow(void)
89855 +{
89856 + WARN(1, "Buffer overflow detected!\n");
89857 +}
89858 +EXPORT_SYMBOL(copy_to_user_overflow);
89859 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
89860 index 10909c5..653e1b8 100644
89861 --- a/lib/vsprintf.c
89862 +++ b/lib/vsprintf.c
89863 @@ -16,6 +16,9 @@
89864 * - scnprintf and vscnprintf
89865 */
89866
89867 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89868 +#define __INCLUDED_BY_HIDESYM 1
89869 +#endif
89870 #include <stdarg.h>
89871 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
89872 #include <linux/types.h>
89873 @@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
89874 return number(buf, end, *(const netdev_features_t *)addr, spec);
89875 }
89876
89877 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89878 +int kptr_restrict __read_mostly = 2;
89879 +#else
89880 int kptr_restrict __read_mostly;
89881 +#endif
89882
89883 /*
89884 * Show a '%p' thing. A kernel extension is that the '%p' is followed
89885 @@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
89886 * - 'f' For simple symbolic function names without offset
89887 * - 'S' For symbolic direct pointers with offset
89888 * - 's' For symbolic direct pointers without offset
89889 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
89890 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
89891 * - 'B' For backtraced symbolic direct pointers with offset
89892 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
89893 @@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89894
89895 if (!ptr && *fmt != 'K') {
89896 /*
89897 - * Print (null) with the same width as a pointer so it makes
89898 + * Print (nil) with the same width as a pointer so it makes
89899 * tabular output look nice.
89900 */
89901 if (spec.field_width == -1)
89902 spec.field_width = default_width;
89903 - return string(buf, end, "(null)", spec);
89904 + return string(buf, end, "(nil)", spec);
89905 }
89906
89907 switch (*fmt) {
89908 @@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89909 /* Fallthrough */
89910 case 'S':
89911 case 's':
89912 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89913 + break;
89914 +#else
89915 + return symbol_string(buf, end, ptr, spec, fmt);
89916 +#endif
89917 + case 'A':
89918 case 'B':
89919 return symbol_string(buf, end, ptr, spec, fmt);
89920 case 'R':
89921 @@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89922 va_end(va);
89923 return buf;
89924 }
89925 + case 'P':
89926 + break;
89927 case 'K':
89928 /*
89929 * %pK cannot be used in IRQ context because its test
89930 @@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
89931 ((const struct file *)ptr)->f_path.dentry,
89932 spec, fmt);
89933 }
89934 +
89935 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89936 + /* 'P' = approved pointers to copy to userland,
89937 + as in the /proc/kallsyms case, as we make it display nothing
89938 + for non-root users, and the real contents for root users
89939 + Also ignore 'K' pointers, since we force their NULLing for non-root users
89940 + above
89941 + */
89942 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
89943 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
89944 + dump_stack();
89945 + ptr = NULL;
89946 + }
89947 +#endif
89948 +
89949 spec.flags |= SMALL;
89950 if (spec.field_width == -1) {
89951 spec.field_width = default_width;
89952 @@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
89953 typeof(type) value; \
89954 if (sizeof(type) == 8) { \
89955 args = PTR_ALIGN(args, sizeof(u32)); \
89956 - *(u32 *)&value = *(u32 *)args; \
89957 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
89958 + *(u32 *)&value = *(const u32 *)args; \
89959 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
89960 } else { \
89961 args = PTR_ALIGN(args, sizeof(type)); \
89962 - value = *(typeof(type) *)args; \
89963 + value = *(const typeof(type) *)args; \
89964 } \
89965 args += sizeof(type); \
89966 value; \
89967 @@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
89968 case FORMAT_TYPE_STR: {
89969 const char *str_arg = args;
89970 args += strlen(str_arg) + 1;
89971 - str = string(str, end, (char *)str_arg, spec);
89972 + str = string(str, end, str_arg, spec);
89973 break;
89974 }
89975
89976 diff --git a/localversion-grsec b/localversion-grsec
89977 new file mode 100644
89978 index 0000000..7cd6065
89979 --- /dev/null
89980 +++ b/localversion-grsec
89981 @@ -0,0 +1 @@
89982 +-grsec
89983 diff --git a/mm/Kconfig b/mm/Kconfig
89984 index 723bbe0..ea624b1 100644
89985 --- a/mm/Kconfig
89986 +++ b/mm/Kconfig
89987 @@ -326,10 +326,11 @@ config KSM
89988 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
89989
89990 config DEFAULT_MMAP_MIN_ADDR
89991 - int "Low address space to protect from user allocation"
89992 + int "Low address space to protect from user allocation"
89993 depends on MMU
89994 - default 4096
89995 - help
89996 + default 32768 if ALPHA || ARM || PARISC || SPARC32
89997 + default 65536
89998 + help
89999 This is the portion of low virtual memory which should be protected
90000 from userspace allocation. Keeping a user from writing to low pages
90001 can help reduce the impact of kernel NULL pointer bugs.
90002 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
90003
90004 config HWPOISON_INJECT
90005 tristate "HWPoison pages injector"
90006 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
90007 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
90008 select PROC_PAGE_MONITOR
90009
90010 config NOMMU_INITIAL_TRIM_EXCESS
90011 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
90012 index ce682f7..1fb54f9 100644
90013 --- a/mm/backing-dev.c
90014 +++ b/mm/backing-dev.c
90015 @@ -12,7 +12,7 @@
90016 #include <linux/device.h>
90017 #include <trace/events/writeback.h>
90018
90019 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
90020 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
90021
90022 struct backing_dev_info default_backing_dev_info = {
90023 .name = "default",
90024 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
90025 return err;
90026
90027 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
90028 - atomic_long_inc_return(&bdi_seq));
90029 + atomic_long_inc_return_unchecked(&bdi_seq));
90030 if (err) {
90031 bdi_destroy(bdi);
90032 return err;
90033 diff --git a/mm/filemap.c b/mm/filemap.c
90034 index b7749a9..50d1123 100644
90035 --- a/mm/filemap.c
90036 +++ b/mm/filemap.c
90037 @@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
90038 struct address_space *mapping = file->f_mapping;
90039
90040 if (!mapping->a_ops->readpage)
90041 - return -ENOEXEC;
90042 + return -ENODEV;
90043 file_accessed(file);
90044 vma->vm_ops = &generic_file_vm_ops;
90045 return 0;
90046 @@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
90047
90048 while (bytes) {
90049 char __user *buf = iov->iov_base + base;
90050 - int copy = min(bytes, iov->iov_len - base);
90051 + size_t copy = min(bytes, iov->iov_len - base);
90052
90053 base = 0;
90054 left = __copy_from_user_inatomic(vaddr, buf, copy);
90055 @@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
90056 BUG_ON(!in_atomic());
90057 kaddr = kmap_atomic(page);
90058 if (likely(i->nr_segs == 1)) {
90059 - int left;
90060 + size_t left;
90061 char __user *buf = i->iov->iov_base + i->iov_offset;
90062 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
90063 copied = bytes - left;
90064 @@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
90065
90066 kaddr = kmap(page);
90067 if (likely(i->nr_segs == 1)) {
90068 - int left;
90069 + size_t left;
90070 char __user *buf = i->iov->iov_base + i->iov_offset;
90071 left = __copy_from_user(kaddr + offset, buf, bytes);
90072 copied = bytes - left;
90073 @@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
90074 * zero-length segments (without overruning the iovec).
90075 */
90076 while (bytes || unlikely(i->count && !iov->iov_len)) {
90077 - int copy;
90078 + size_t copy;
90079
90080 copy = min(bytes, iov->iov_len - base);
90081 BUG_ON(!i->count || i->count < copy);
90082 @@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
90083 *pos = i_size_read(inode);
90084
90085 if (limit != RLIM_INFINITY) {
90086 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
90087 if (*pos >= limit) {
90088 send_sig(SIGXFSZ, current, 0);
90089 return -EFBIG;
90090 diff --git a/mm/fremap.c b/mm/fremap.c
90091 index bbc4d66..117b798 100644
90092 --- a/mm/fremap.c
90093 +++ b/mm/fremap.c
90094 @@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
90095 retry:
90096 vma = find_vma(mm, start);
90097
90098 +#ifdef CONFIG_PAX_SEGMEXEC
90099 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
90100 + goto out;
90101 +#endif
90102 +
90103 /*
90104 * Make sure the vma is shared, that it supports prefaulting,
90105 * and that the remapped range is valid and fully within
90106 diff --git a/mm/highmem.c b/mm/highmem.c
90107 index b32b70c..e512eb0 100644
90108 --- a/mm/highmem.c
90109 +++ b/mm/highmem.c
90110 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
90111 * So no dangers, even with speculative execution.
90112 */
90113 page = pte_page(pkmap_page_table[i]);
90114 + pax_open_kernel();
90115 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
90116 -
90117 + pax_close_kernel();
90118 set_page_address(page, NULL);
90119 need_flush = 1;
90120 }
90121 @@ -198,9 +199,11 @@ start:
90122 }
90123 }
90124 vaddr = PKMAP_ADDR(last_pkmap_nr);
90125 +
90126 + pax_open_kernel();
90127 set_pte_at(&init_mm, vaddr,
90128 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
90129 -
90130 + pax_close_kernel();
90131 pkmap_count[last_pkmap_nr] = 1;
90132 set_page_address(page, (void *)vaddr);
90133
90134 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
90135 index dee6cf4..52b94f7 100644
90136 --- a/mm/hugetlb.c
90137 +++ b/mm/hugetlb.c
90138 @@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
90139 struct hstate *h = &default_hstate;
90140 unsigned long tmp;
90141 int ret;
90142 + ctl_table_no_const hugetlb_table;
90143
90144 tmp = h->max_huge_pages;
90145
90146 if (write && h->order >= MAX_ORDER)
90147 return -EINVAL;
90148
90149 - table->data = &tmp;
90150 - table->maxlen = sizeof(unsigned long);
90151 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90152 + hugetlb_table = *table;
90153 + hugetlb_table.data = &tmp;
90154 + hugetlb_table.maxlen = sizeof(unsigned long);
90155 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90156 if (ret)
90157 goto out;
90158
90159 @@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
90160 struct hstate *h = &default_hstate;
90161 unsigned long tmp;
90162 int ret;
90163 + ctl_table_no_const hugetlb_table;
90164
90165 tmp = h->nr_overcommit_huge_pages;
90166
90167 if (write && h->order >= MAX_ORDER)
90168 return -EINVAL;
90169
90170 - table->data = &tmp;
90171 - table->maxlen = sizeof(unsigned long);
90172 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90173 + hugetlb_table = *table;
90174 + hugetlb_table.data = &tmp;
90175 + hugetlb_table.maxlen = sizeof(unsigned long);
90176 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90177 if (ret)
90178 goto out;
90179
90180 @@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
90181 return 1;
90182 }
90183
90184 +#ifdef CONFIG_PAX_SEGMEXEC
90185 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
90186 +{
90187 + struct mm_struct *mm = vma->vm_mm;
90188 + struct vm_area_struct *vma_m;
90189 + unsigned long address_m;
90190 + pte_t *ptep_m;
90191 +
90192 + vma_m = pax_find_mirror_vma(vma);
90193 + if (!vma_m)
90194 + return;
90195 +
90196 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90197 + address_m = address + SEGMEXEC_TASK_SIZE;
90198 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
90199 + get_page(page_m);
90200 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
90201 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
90202 +}
90203 +#endif
90204 +
90205 /*
90206 * Hugetlb_cow() should be called with page lock of the original hugepage held.
90207 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
90208 @@ -2712,6 +2737,11 @@ retry_avoidcopy:
90209 make_huge_pte(vma, new_page, 1));
90210 page_remove_rmap(old_page);
90211 hugepage_add_new_anon_rmap(new_page, vma, address);
90212 +
90213 +#ifdef CONFIG_PAX_SEGMEXEC
90214 + pax_mirror_huge_pte(vma, address, new_page);
90215 +#endif
90216 +
90217 /* Make the old page be freed below */
90218 new_page = old_page;
90219 }
90220 @@ -2876,6 +2906,10 @@ retry:
90221 && (vma->vm_flags & VM_SHARED)));
90222 set_huge_pte_at(mm, address, ptep, new_pte);
90223
90224 +#ifdef CONFIG_PAX_SEGMEXEC
90225 + pax_mirror_huge_pte(vma, address, page);
90226 +#endif
90227 +
90228 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
90229 /* Optimization, do the COW without a second fault */
90230 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
90231 @@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90232 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
90233 struct hstate *h = hstate_vma(vma);
90234
90235 +#ifdef CONFIG_PAX_SEGMEXEC
90236 + struct vm_area_struct *vma_m;
90237 +#endif
90238 +
90239 address &= huge_page_mask(h);
90240
90241 ptep = huge_pte_offset(mm, address);
90242 @@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90243 VM_FAULT_SET_HINDEX(hstate_index(h));
90244 }
90245
90246 +#ifdef CONFIG_PAX_SEGMEXEC
90247 + vma_m = pax_find_mirror_vma(vma);
90248 + if (vma_m) {
90249 + unsigned long address_m;
90250 +
90251 + if (vma->vm_start > vma_m->vm_start) {
90252 + address_m = address;
90253 + address -= SEGMEXEC_TASK_SIZE;
90254 + vma = vma_m;
90255 + h = hstate_vma(vma);
90256 + } else
90257 + address_m = address + SEGMEXEC_TASK_SIZE;
90258 +
90259 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
90260 + return VM_FAULT_OOM;
90261 + address_m &= HPAGE_MASK;
90262 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
90263 + }
90264 +#endif
90265 +
90266 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
90267 if (!ptep)
90268 return VM_FAULT_OOM;
90269 diff --git a/mm/internal.h b/mm/internal.h
90270 index 684f7aa..9eb9edc 100644
90271 --- a/mm/internal.h
90272 +++ b/mm/internal.h
90273 @@ -97,6 +97,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
90274 * in mm/page_alloc.c
90275 */
90276 extern void __free_pages_bootmem(struct page *page, unsigned int order);
90277 +extern void free_compound_page(struct page *page);
90278 extern void prep_compound_page(struct page *page, unsigned long order);
90279 #ifdef CONFIG_MEMORY_FAILURE
90280 extern bool is_free_buddy_page(struct page *page);
90281 @@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
90282
90283 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
90284 unsigned long, unsigned long,
90285 - unsigned long, unsigned long);
90286 + unsigned long, unsigned long) __intentional_overflow(-1);
90287
90288 extern void set_pageblock_order(void);
90289 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
90290 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
90291 index 31f01c5..7015178 100644
90292 --- a/mm/kmemleak.c
90293 +++ b/mm/kmemleak.c
90294 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
90295
90296 for (i = 0; i < object->trace_len; i++) {
90297 void *ptr = (void *)object->trace[i];
90298 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
90299 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
90300 }
90301 }
90302
90303 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
90304 return -ENOMEM;
90305 }
90306
90307 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
90308 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
90309 &kmemleak_fops);
90310 if (!dentry)
90311 pr_warning("Failed to create the debugfs kmemleak file\n");
90312 diff --git a/mm/maccess.c b/mm/maccess.c
90313 index d53adf9..03a24bf 100644
90314 --- a/mm/maccess.c
90315 +++ b/mm/maccess.c
90316 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
90317 set_fs(KERNEL_DS);
90318 pagefault_disable();
90319 ret = __copy_from_user_inatomic(dst,
90320 - (__force const void __user *)src, size);
90321 + (const void __force_user *)src, size);
90322 pagefault_enable();
90323 set_fs(old_fs);
90324
90325 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
90326
90327 set_fs(KERNEL_DS);
90328 pagefault_disable();
90329 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
90330 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
90331 pagefault_enable();
90332 set_fs(old_fs);
90333
90334 diff --git a/mm/madvise.c b/mm/madvise.c
90335 index 539eeb9..e24a987 100644
90336 --- a/mm/madvise.c
90337 +++ b/mm/madvise.c
90338 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
90339 pgoff_t pgoff;
90340 unsigned long new_flags = vma->vm_flags;
90341
90342 +#ifdef CONFIG_PAX_SEGMEXEC
90343 + struct vm_area_struct *vma_m;
90344 +#endif
90345 +
90346 switch (behavior) {
90347 case MADV_NORMAL:
90348 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
90349 @@ -126,6 +130,13 @@ success:
90350 /*
90351 * vm_flags is protected by the mmap_sem held in write mode.
90352 */
90353 +
90354 +#ifdef CONFIG_PAX_SEGMEXEC
90355 + vma_m = pax_find_mirror_vma(vma);
90356 + if (vma_m)
90357 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
90358 +#endif
90359 +
90360 vma->vm_flags = new_flags;
90361
90362 out:
90363 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90364 struct vm_area_struct **prev,
90365 unsigned long start, unsigned long end)
90366 {
90367 +
90368 +#ifdef CONFIG_PAX_SEGMEXEC
90369 + struct vm_area_struct *vma_m;
90370 +#endif
90371 +
90372 *prev = vma;
90373 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
90374 return -EINVAL;
90375 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90376 zap_page_range(vma, start, end - start, &details);
90377 } else
90378 zap_page_range(vma, start, end - start, NULL);
90379 +
90380 +#ifdef CONFIG_PAX_SEGMEXEC
90381 + vma_m = pax_find_mirror_vma(vma);
90382 + if (vma_m) {
90383 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
90384 + struct zap_details details = {
90385 + .nonlinear_vma = vma_m,
90386 + .last_index = ULONG_MAX,
90387 + };
90388 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
90389 + } else
90390 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
90391 + }
90392 +#endif
90393 +
90394 return 0;
90395 }
90396
90397 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
90398 if (end < start)
90399 return error;
90400
90401 +#ifdef CONFIG_PAX_SEGMEXEC
90402 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90403 + if (end > SEGMEXEC_TASK_SIZE)
90404 + return error;
90405 + } else
90406 +#endif
90407 +
90408 + if (end > TASK_SIZE)
90409 + return error;
90410 +
90411 error = 0;
90412 if (end == start)
90413 return error;
90414 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
90415 index fabe550..f31b51c 100644
90416 --- a/mm/memory-failure.c
90417 +++ b/mm/memory-failure.c
90418 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
90419
90420 int sysctl_memory_failure_recovery __read_mostly = 1;
90421
90422 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90423 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90424
90425 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
90426
90427 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
90428 pfn, t->comm, t->pid);
90429 si.si_signo = SIGBUS;
90430 si.si_errno = 0;
90431 - si.si_addr = (void *)addr;
90432 + si.si_addr = (void __user *)addr;
90433 #ifdef __ARCH_SI_TRAPNO
90434 si.si_trapno = trapno;
90435 #endif
90436 @@ -762,7 +762,7 @@ static struct page_state {
90437 unsigned long res;
90438 char *msg;
90439 int (*action)(struct page *p, unsigned long pfn);
90440 -} error_states[] = {
90441 +} __do_const error_states[] = {
90442 { reserved, reserved, "reserved kernel", me_kernel },
90443 /*
90444 * free pages are specially detected outside this table:
90445 @@ -1063,7 +1063,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90446 nr_pages = 1 << compound_order(hpage);
90447 else /* normal page or thp */
90448 nr_pages = 1;
90449 - atomic_long_add(nr_pages, &num_poisoned_pages);
90450 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
90451
90452 /*
90453 * We need/can do nothing about count=0 pages.
90454 @@ -1093,7 +1093,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90455 if (!PageHWPoison(hpage)
90456 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
90457 || (p != hpage && TestSetPageHWPoison(hpage))) {
90458 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90459 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90460 return 0;
90461 }
90462 set_page_hwpoison_huge_page(hpage);
90463 @@ -1162,7 +1162,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90464 }
90465 if (hwpoison_filter(p)) {
90466 if (TestClearPageHWPoison(p))
90467 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90468 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90469 unlock_page(hpage);
90470 put_page(hpage);
90471 return 0;
90472 @@ -1380,7 +1380,7 @@ int unpoison_memory(unsigned long pfn)
90473 return 0;
90474 }
90475 if (TestClearPageHWPoison(p))
90476 - atomic_long_dec(&num_poisoned_pages);
90477 + atomic_long_dec_unchecked(&num_poisoned_pages);
90478 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
90479 return 0;
90480 }
90481 @@ -1394,7 +1394,7 @@ int unpoison_memory(unsigned long pfn)
90482 */
90483 if (TestClearPageHWPoison(page)) {
90484 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
90485 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90486 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90487 freeit = 1;
90488 if (PageHuge(page))
90489 clear_page_hwpoison_huge_page(page);
90490 @@ -1519,11 +1519,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
90491 if (PageHuge(page)) {
90492 set_page_hwpoison_huge_page(hpage);
90493 dequeue_hwpoisoned_huge_page(hpage);
90494 - atomic_long_add(1 << compound_order(hpage),
90495 + atomic_long_add_unchecked(1 << compound_order(hpage),
90496 &num_poisoned_pages);
90497 } else {
90498 SetPageHWPoison(page);
90499 - atomic_long_inc(&num_poisoned_pages);
90500 + atomic_long_inc_unchecked(&num_poisoned_pages);
90501 }
90502 }
90503 return ret;
90504 @@ -1562,7 +1562,7 @@ static int __soft_offline_page(struct page *page, int flags)
90505 put_page(page);
90506 pr_info("soft_offline: %#lx: invalidated\n", pfn);
90507 SetPageHWPoison(page);
90508 - atomic_long_inc(&num_poisoned_pages);
90509 + atomic_long_inc_unchecked(&num_poisoned_pages);
90510 return 0;
90511 }
90512
90513 @@ -1607,7 +1607,7 @@ static int __soft_offline_page(struct page *page, int flags)
90514 if (!is_free_buddy_page(page))
90515 pr_info("soft offline: %#lx: page leaked\n",
90516 pfn);
90517 - atomic_long_inc(&num_poisoned_pages);
90518 + atomic_long_inc_unchecked(&num_poisoned_pages);
90519 }
90520 } else {
90521 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
90522 @@ -1681,11 +1681,11 @@ int soft_offline_page(struct page *page, int flags)
90523 if (PageHuge(page)) {
90524 set_page_hwpoison_huge_page(hpage);
90525 dequeue_hwpoisoned_huge_page(hpage);
90526 - atomic_long_add(1 << compound_order(hpage),
90527 + atomic_long_add_unchecked(1 << compound_order(hpage),
90528 &num_poisoned_pages);
90529 } else {
90530 SetPageHWPoison(page);
90531 - atomic_long_inc(&num_poisoned_pages);
90532 + atomic_long_inc_unchecked(&num_poisoned_pages);
90533 }
90534 }
90535 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
90536 diff --git a/mm/memory.c b/mm/memory.c
90537 index 6768ce9..4c41d69 100644
90538 --- a/mm/memory.c
90539 +++ b/mm/memory.c
90540 @@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90541 free_pte_range(tlb, pmd, addr);
90542 } while (pmd++, addr = next, addr != end);
90543
90544 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
90545 start &= PUD_MASK;
90546 if (start < floor)
90547 return;
90548 @@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90549 pmd = pmd_offset(pud, start);
90550 pud_clear(pud);
90551 pmd_free_tlb(tlb, pmd, start);
90552 +#endif
90553 +
90554 }
90555
90556 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90557 @@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90558 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
90559 } while (pud++, addr = next, addr != end);
90560
90561 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
90562 start &= PGDIR_MASK;
90563 if (start < floor)
90564 return;
90565 @@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90566 pud = pud_offset(pgd, start);
90567 pgd_clear(pgd);
90568 pud_free_tlb(tlb, pud, start);
90569 +#endif
90570 +
90571 }
90572
90573 /*
90574 @@ -1635,12 +1641,6 @@ no_page_table:
90575 return page;
90576 }
90577
90578 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
90579 -{
90580 - return stack_guard_page_start(vma, addr) ||
90581 - stack_guard_page_end(vma, addr+PAGE_SIZE);
90582 -}
90583 -
90584 /**
90585 * __get_user_pages() - pin user pages in memory
90586 * @tsk: task_struct of target task
90587 @@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90588
90589 i = 0;
90590
90591 - do {
90592 + while (nr_pages) {
90593 struct vm_area_struct *vma;
90594
90595 - vma = find_extend_vma(mm, start);
90596 + vma = find_vma(mm, start);
90597 if (!vma && in_gate_area(mm, start)) {
90598 unsigned long pg = start & PAGE_MASK;
90599 pgd_t *pgd;
90600 @@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90601 goto next_page;
90602 }
90603
90604 - if (!vma ||
90605 + if (!vma || start < vma->vm_start ||
90606 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
90607 !(vm_flags & vma->vm_flags))
90608 return i ? : -EFAULT;
90609 @@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90610 int ret;
90611 unsigned int fault_flags = 0;
90612
90613 - /* For mlock, just skip the stack guard page. */
90614 - if (foll_flags & FOLL_MLOCK) {
90615 - if (stack_guard_page(vma, start))
90616 - goto next_page;
90617 - }
90618 if (foll_flags & FOLL_WRITE)
90619 fault_flags |= FAULT_FLAG_WRITE;
90620 if (nonblocking)
90621 @@ -1892,7 +1887,7 @@ next_page:
90622 start += page_increm * PAGE_SIZE;
90623 nr_pages -= page_increm;
90624 } while (nr_pages && start < vma->vm_end);
90625 - } while (nr_pages);
90626 + }
90627 return i;
90628 }
90629 EXPORT_SYMBOL(__get_user_pages);
90630 @@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
90631 page_add_file_rmap(page);
90632 set_pte_at(mm, addr, pte, mk_pte(page, prot));
90633
90634 +#ifdef CONFIG_PAX_SEGMEXEC
90635 + pax_mirror_file_pte(vma, addr, page, ptl);
90636 +#endif
90637 +
90638 retval = 0;
90639 pte_unmap_unlock(pte, ptl);
90640 return retval;
90641 @@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
90642 if (!page_count(page))
90643 return -EINVAL;
90644 if (!(vma->vm_flags & VM_MIXEDMAP)) {
90645 +
90646 +#ifdef CONFIG_PAX_SEGMEXEC
90647 + struct vm_area_struct *vma_m;
90648 +#endif
90649 +
90650 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
90651 BUG_ON(vma->vm_flags & VM_PFNMAP);
90652 vma->vm_flags |= VM_MIXEDMAP;
90653 +
90654 +#ifdef CONFIG_PAX_SEGMEXEC
90655 + vma_m = pax_find_mirror_vma(vma);
90656 + if (vma_m)
90657 + vma_m->vm_flags |= VM_MIXEDMAP;
90658 +#endif
90659 +
90660 }
90661 return insert_page(vma, addr, page, vma->vm_page_prot);
90662 }
90663 @@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
90664 unsigned long pfn)
90665 {
90666 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
90667 + BUG_ON(vma->vm_mirror);
90668
90669 if (addr < vma->vm_start || addr >= vma->vm_end)
90670 return -EFAULT;
90671 @@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
90672
90673 BUG_ON(pud_huge(*pud));
90674
90675 - pmd = pmd_alloc(mm, pud, addr);
90676 + pmd = (mm == &init_mm) ?
90677 + pmd_alloc_kernel(mm, pud, addr) :
90678 + pmd_alloc(mm, pud, addr);
90679 if (!pmd)
90680 return -ENOMEM;
90681 do {
90682 @@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
90683 unsigned long next;
90684 int err;
90685
90686 - pud = pud_alloc(mm, pgd, addr);
90687 + pud = (mm == &init_mm) ?
90688 + pud_alloc_kernel(mm, pgd, addr) :
90689 + pud_alloc(mm, pgd, addr);
90690 if (!pud)
90691 return -ENOMEM;
90692 do {
90693 @@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
90694 copy_user_highpage(dst, src, va, vma);
90695 }
90696
90697 +#ifdef CONFIG_PAX_SEGMEXEC
90698 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
90699 +{
90700 + struct mm_struct *mm = vma->vm_mm;
90701 + spinlock_t *ptl;
90702 + pte_t *pte, entry;
90703 +
90704 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
90705 + entry = *pte;
90706 + if (!pte_present(entry)) {
90707 + if (!pte_none(entry)) {
90708 + BUG_ON(pte_file(entry));
90709 + free_swap_and_cache(pte_to_swp_entry(entry));
90710 + pte_clear_not_present_full(mm, address, pte, 0);
90711 + }
90712 + } else {
90713 + struct page *page;
90714 +
90715 + flush_cache_page(vma, address, pte_pfn(entry));
90716 + entry = ptep_clear_flush(vma, address, pte);
90717 + BUG_ON(pte_dirty(entry));
90718 + page = vm_normal_page(vma, address, entry);
90719 + if (page) {
90720 + update_hiwater_rss(mm);
90721 + if (PageAnon(page))
90722 + dec_mm_counter_fast(mm, MM_ANONPAGES);
90723 + else
90724 + dec_mm_counter_fast(mm, MM_FILEPAGES);
90725 + page_remove_rmap(page);
90726 + page_cache_release(page);
90727 + }
90728 + }
90729 + pte_unmap_unlock(pte, ptl);
90730 +}
90731 +
90732 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
90733 + *
90734 + * the ptl of the lower mapped page is held on entry and is not released on exit
90735 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
90736 + */
90737 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90738 +{
90739 + struct mm_struct *mm = vma->vm_mm;
90740 + unsigned long address_m;
90741 + spinlock_t *ptl_m;
90742 + struct vm_area_struct *vma_m;
90743 + pmd_t *pmd_m;
90744 + pte_t *pte_m, entry_m;
90745 +
90746 + BUG_ON(!page_m || !PageAnon(page_m));
90747 +
90748 + vma_m = pax_find_mirror_vma(vma);
90749 + if (!vma_m)
90750 + return;
90751 +
90752 + BUG_ON(!PageLocked(page_m));
90753 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90754 + address_m = address + SEGMEXEC_TASK_SIZE;
90755 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90756 + pte_m = pte_offset_map(pmd_m, address_m);
90757 + ptl_m = pte_lockptr(mm, pmd_m);
90758 + if (ptl != ptl_m) {
90759 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90760 + if (!pte_none(*pte_m))
90761 + goto out;
90762 + }
90763 +
90764 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90765 + page_cache_get(page_m);
90766 + page_add_anon_rmap(page_m, vma_m, address_m);
90767 + inc_mm_counter_fast(mm, MM_ANONPAGES);
90768 + set_pte_at(mm, address_m, pte_m, entry_m);
90769 + update_mmu_cache(vma_m, address_m, pte_m);
90770 +out:
90771 + if (ptl != ptl_m)
90772 + spin_unlock(ptl_m);
90773 + pte_unmap(pte_m);
90774 + unlock_page(page_m);
90775 +}
90776 +
90777 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90778 +{
90779 + struct mm_struct *mm = vma->vm_mm;
90780 + unsigned long address_m;
90781 + spinlock_t *ptl_m;
90782 + struct vm_area_struct *vma_m;
90783 + pmd_t *pmd_m;
90784 + pte_t *pte_m, entry_m;
90785 +
90786 + BUG_ON(!page_m || PageAnon(page_m));
90787 +
90788 + vma_m = pax_find_mirror_vma(vma);
90789 + if (!vma_m)
90790 + return;
90791 +
90792 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90793 + address_m = address + SEGMEXEC_TASK_SIZE;
90794 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90795 + pte_m = pte_offset_map(pmd_m, address_m);
90796 + ptl_m = pte_lockptr(mm, pmd_m);
90797 + if (ptl != ptl_m) {
90798 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90799 + if (!pte_none(*pte_m))
90800 + goto out;
90801 + }
90802 +
90803 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90804 + page_cache_get(page_m);
90805 + page_add_file_rmap(page_m);
90806 + inc_mm_counter_fast(mm, MM_FILEPAGES);
90807 + set_pte_at(mm, address_m, pte_m, entry_m);
90808 + update_mmu_cache(vma_m, address_m, pte_m);
90809 +out:
90810 + if (ptl != ptl_m)
90811 + spin_unlock(ptl_m);
90812 + pte_unmap(pte_m);
90813 +}
90814 +
90815 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
90816 +{
90817 + struct mm_struct *mm = vma->vm_mm;
90818 + unsigned long address_m;
90819 + spinlock_t *ptl_m;
90820 + struct vm_area_struct *vma_m;
90821 + pmd_t *pmd_m;
90822 + pte_t *pte_m, entry_m;
90823 +
90824 + vma_m = pax_find_mirror_vma(vma);
90825 + if (!vma_m)
90826 + return;
90827 +
90828 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90829 + address_m = address + SEGMEXEC_TASK_SIZE;
90830 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90831 + pte_m = pte_offset_map(pmd_m, address_m);
90832 + ptl_m = pte_lockptr(mm, pmd_m);
90833 + if (ptl != ptl_m) {
90834 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90835 + if (!pte_none(*pte_m))
90836 + goto out;
90837 + }
90838 +
90839 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
90840 + set_pte_at(mm, address_m, pte_m, entry_m);
90841 +out:
90842 + if (ptl != ptl_m)
90843 + spin_unlock(ptl_m);
90844 + pte_unmap(pte_m);
90845 +}
90846 +
90847 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
90848 +{
90849 + struct page *page_m;
90850 + pte_t entry;
90851 +
90852 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
90853 + goto out;
90854 +
90855 + entry = *pte;
90856 + page_m = vm_normal_page(vma, address, entry);
90857 + if (!page_m)
90858 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
90859 + else if (PageAnon(page_m)) {
90860 + if (pax_find_mirror_vma(vma)) {
90861 + pte_unmap_unlock(pte, ptl);
90862 + lock_page(page_m);
90863 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
90864 + if (pte_same(entry, *pte))
90865 + pax_mirror_anon_pte(vma, address, page_m, ptl);
90866 + else
90867 + unlock_page(page_m);
90868 + }
90869 + } else
90870 + pax_mirror_file_pte(vma, address, page_m, ptl);
90871 +
90872 +out:
90873 + pte_unmap_unlock(pte, ptl);
90874 +}
90875 +#endif
90876 +
90877 /*
90878 * This routine handles present pages, when users try to write
90879 * to a shared page. It is done by copying the page to a new address
90880 @@ -2807,6 +3003,12 @@ gotten:
90881 */
90882 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
90883 if (likely(pte_same(*page_table, orig_pte))) {
90884 +
90885 +#ifdef CONFIG_PAX_SEGMEXEC
90886 + if (pax_find_mirror_vma(vma))
90887 + BUG_ON(!trylock_page(new_page));
90888 +#endif
90889 +
90890 if (old_page) {
90891 if (!PageAnon(old_page)) {
90892 dec_mm_counter_fast(mm, MM_FILEPAGES);
90893 @@ -2858,6 +3060,10 @@ gotten:
90894 page_remove_rmap(old_page);
90895 }
90896
90897 +#ifdef CONFIG_PAX_SEGMEXEC
90898 + pax_mirror_anon_pte(vma, address, new_page, ptl);
90899 +#endif
90900 +
90901 /* Free the old page.. */
90902 new_page = old_page;
90903 ret |= VM_FAULT_WRITE;
90904 @@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
90905 swap_free(entry);
90906 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
90907 try_to_free_swap(page);
90908 +
90909 +#ifdef CONFIG_PAX_SEGMEXEC
90910 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
90911 +#endif
90912 +
90913 unlock_page(page);
90914 if (page != swapcache) {
90915 /*
90916 @@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
90917
90918 /* No need to invalidate - it was non-present before */
90919 update_mmu_cache(vma, address, page_table);
90920 +
90921 +#ifdef CONFIG_PAX_SEGMEXEC
90922 + pax_mirror_anon_pte(vma, address, page, ptl);
90923 +#endif
90924 +
90925 unlock:
90926 pte_unmap_unlock(page_table, ptl);
90927 out:
90928 @@ -3177,40 +3393,6 @@ out_release:
90929 }
90930
90931 /*
90932 - * This is like a special single-page "expand_{down|up}wards()",
90933 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
90934 - * doesn't hit another vma.
90935 - */
90936 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
90937 -{
90938 - address &= PAGE_MASK;
90939 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
90940 - struct vm_area_struct *prev = vma->vm_prev;
90941 -
90942 - /*
90943 - * Is there a mapping abutting this one below?
90944 - *
90945 - * That's only ok if it's the same stack mapping
90946 - * that has gotten split..
90947 - */
90948 - if (prev && prev->vm_end == address)
90949 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
90950 -
90951 - expand_downwards(vma, address - PAGE_SIZE);
90952 - }
90953 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
90954 - struct vm_area_struct *next = vma->vm_next;
90955 -
90956 - /* As VM_GROWSDOWN but s/below/above/ */
90957 - if (next && next->vm_start == address + PAGE_SIZE)
90958 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
90959 -
90960 - expand_upwards(vma, address + PAGE_SIZE);
90961 - }
90962 - return 0;
90963 -}
90964 -
90965 -/*
90966 * We enter with non-exclusive mmap_sem (to exclude vma changes,
90967 * but allow concurrent faults), and pte mapped but not yet locked.
90968 * We return with mmap_sem still held, but pte unmapped and unlocked.
90969 @@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
90970 unsigned long address, pte_t *page_table, pmd_t *pmd,
90971 unsigned int flags)
90972 {
90973 - struct page *page;
90974 + struct page *page = NULL;
90975 spinlock_t *ptl;
90976 pte_t entry;
90977
90978 - pte_unmap(page_table);
90979 -
90980 - /* Check if we need to add a guard page to the stack */
90981 - if (check_stack_guard_page(vma, address) < 0)
90982 - return VM_FAULT_SIGBUS;
90983 -
90984 - /* Use the zero-page for reads */
90985 if (!(flags & FAULT_FLAG_WRITE)) {
90986 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
90987 vma->vm_page_prot));
90988 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
90989 + ptl = pte_lockptr(mm, pmd);
90990 + spin_lock(ptl);
90991 if (!pte_none(*page_table))
90992 goto unlock;
90993 goto setpte;
90994 }
90995
90996 /* Allocate our own private page. */
90997 + pte_unmap(page_table);
90998 +
90999 if (unlikely(anon_vma_prepare(vma)))
91000 goto oom;
91001 page = alloc_zeroed_user_highpage_movable(vma, address);
91002 @@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
91003 if (!pte_none(*page_table))
91004 goto release;
91005
91006 +#ifdef CONFIG_PAX_SEGMEXEC
91007 + if (pax_find_mirror_vma(vma))
91008 + BUG_ON(!trylock_page(page));
91009 +#endif
91010 +
91011 inc_mm_counter_fast(mm, MM_ANONPAGES);
91012 page_add_new_anon_rmap(page, vma, address);
91013 setpte:
91014 @@ -3270,6 +3453,12 @@ setpte:
91015
91016 /* No need to invalidate - it was non-present before */
91017 update_mmu_cache(vma, address, page_table);
91018 +
91019 +#ifdef CONFIG_PAX_SEGMEXEC
91020 + if (page)
91021 + pax_mirror_anon_pte(vma, address, page, ptl);
91022 +#endif
91023 +
91024 unlock:
91025 pte_unmap_unlock(page_table, ptl);
91026 return 0;
91027 @@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91028 */
91029 /* Only go through if we didn't race with anybody else... */
91030 if (likely(pte_same(*page_table, orig_pte))) {
91031 +
91032 +#ifdef CONFIG_PAX_SEGMEXEC
91033 + if (anon && pax_find_mirror_vma(vma))
91034 + BUG_ON(!trylock_page(page));
91035 +#endif
91036 +
91037 flush_icache_page(vma, page);
91038 entry = mk_pte(page, vma->vm_page_prot);
91039 if (flags & FAULT_FLAG_WRITE)
91040 @@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91041
91042 /* no need to invalidate: a not-present page won't be cached */
91043 update_mmu_cache(vma, address, page_table);
91044 +
91045 +#ifdef CONFIG_PAX_SEGMEXEC
91046 + if (anon)
91047 + pax_mirror_anon_pte(vma, address, page, ptl);
91048 + else
91049 + pax_mirror_file_pte(vma, address, page, ptl);
91050 +#endif
91051 +
91052 } else {
91053 if (cow_page)
91054 mem_cgroup_uncharge_page(cow_page);
91055 @@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
91056 if (flags & FAULT_FLAG_WRITE)
91057 flush_tlb_fix_spurious_fault(vma, address);
91058 }
91059 +
91060 +#ifdef CONFIG_PAX_SEGMEXEC
91061 + pax_mirror_pte(vma, address, pte, pmd, ptl);
91062 + return 0;
91063 +#endif
91064 +
91065 unlock:
91066 pte_unmap_unlock(pte, ptl);
91067 return 0;
91068 @@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91069 pmd_t *pmd;
91070 pte_t *pte;
91071
91072 +#ifdef CONFIG_PAX_SEGMEXEC
91073 + struct vm_area_struct *vma_m;
91074 +#endif
91075 +
91076 if (unlikely(is_vm_hugetlb_page(vma)))
91077 return hugetlb_fault(mm, vma, address, flags);
91078
91079 +#ifdef CONFIG_PAX_SEGMEXEC
91080 + vma_m = pax_find_mirror_vma(vma);
91081 + if (vma_m) {
91082 + unsigned long address_m;
91083 + pgd_t *pgd_m;
91084 + pud_t *pud_m;
91085 + pmd_t *pmd_m;
91086 +
91087 + if (vma->vm_start > vma_m->vm_start) {
91088 + address_m = address;
91089 + address -= SEGMEXEC_TASK_SIZE;
91090 + vma = vma_m;
91091 + } else
91092 + address_m = address + SEGMEXEC_TASK_SIZE;
91093 +
91094 + pgd_m = pgd_offset(mm, address_m);
91095 + pud_m = pud_alloc(mm, pgd_m, address_m);
91096 + if (!pud_m)
91097 + return VM_FAULT_OOM;
91098 + pmd_m = pmd_alloc(mm, pud_m, address_m);
91099 + if (!pmd_m)
91100 + return VM_FAULT_OOM;
91101 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
91102 + return VM_FAULT_OOM;
91103 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
91104 + }
91105 +#endif
91106 +
91107 retry:
91108 pgd = pgd_offset(mm, address);
91109 pud = pud_alloc(mm, pgd, address);
91110 @@ -3838,6 +4079,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91111 spin_unlock(&mm->page_table_lock);
91112 return 0;
91113 }
91114 +
91115 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91116 +{
91117 + pud_t *new = pud_alloc_one(mm, address);
91118 + if (!new)
91119 + return -ENOMEM;
91120 +
91121 + smp_wmb(); /* See comment in __pte_alloc */
91122 +
91123 + spin_lock(&mm->page_table_lock);
91124 + if (pgd_present(*pgd)) /* Another has populated it */
91125 + pud_free(mm, new);
91126 + else
91127 + pgd_populate_kernel(mm, pgd, new);
91128 + spin_unlock(&mm->page_table_lock);
91129 + return 0;
91130 +}
91131 #endif /* __PAGETABLE_PUD_FOLDED */
91132
91133 #ifndef __PAGETABLE_PMD_FOLDED
91134 @@ -3868,6 +4126,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
91135 spin_unlock(&mm->page_table_lock);
91136 return 0;
91137 }
91138 +
91139 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
91140 +{
91141 + pmd_t *new = pmd_alloc_one(mm, address);
91142 + if (!new)
91143 + return -ENOMEM;
91144 +
91145 + smp_wmb(); /* See comment in __pte_alloc */
91146 +
91147 + spin_lock(&mm->page_table_lock);
91148 +#ifndef __ARCH_HAS_4LEVEL_HACK
91149 + if (pud_present(*pud)) /* Another has populated it */
91150 + pmd_free(mm, new);
91151 + else
91152 + pud_populate_kernel(mm, pud, new);
91153 +#else
91154 + if (pgd_present(*pud)) /* Another has populated it */
91155 + pmd_free(mm, new);
91156 + else
91157 + pgd_populate_kernel(mm, pud, new);
91158 +#endif /* __ARCH_HAS_4LEVEL_HACK */
91159 + spin_unlock(&mm->page_table_lock);
91160 + return 0;
91161 +}
91162 #endif /* __PAGETABLE_PMD_FOLDED */
91163
91164 #if !defined(__HAVE_ARCH_GATE_AREA)
91165 @@ -3881,7 +4163,7 @@ static int __init gate_vma_init(void)
91166 gate_vma.vm_start = FIXADDR_USER_START;
91167 gate_vma.vm_end = FIXADDR_USER_END;
91168 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
91169 - gate_vma.vm_page_prot = __P101;
91170 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
91171
91172 return 0;
91173 }
91174 @@ -4015,8 +4297,8 @@ out:
91175 return ret;
91176 }
91177
91178 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91179 - void *buf, int len, int write)
91180 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91181 + void *buf, size_t len, int write)
91182 {
91183 resource_size_t phys_addr;
91184 unsigned long prot = 0;
91185 @@ -4042,8 +4324,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
91186 * Access another process' address space as given in mm. If non-NULL, use the
91187 * given task for page fault accounting.
91188 */
91189 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91190 - unsigned long addr, void *buf, int len, int write)
91191 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91192 + unsigned long addr, void *buf, size_t len, int write)
91193 {
91194 struct vm_area_struct *vma;
91195 void *old_buf = buf;
91196 @@ -4051,7 +4333,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91197 down_read(&mm->mmap_sem);
91198 /* ignore errors, just check how much was successfully transferred */
91199 while (len) {
91200 - int bytes, ret, offset;
91201 + ssize_t bytes, ret, offset;
91202 void *maddr;
91203 struct page *page = NULL;
91204
91205 @@ -4110,8 +4392,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91206 *
91207 * The caller must hold a reference on @mm.
91208 */
91209 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91210 - void *buf, int len, int write)
91211 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
91212 + void *buf, size_t len, int write)
91213 {
91214 return __access_remote_vm(NULL, mm, addr, buf, len, write);
91215 }
91216 @@ -4121,11 +4403,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91217 * Source/target buffer must be kernel space,
91218 * Do not walk the page table directly, use get_user_pages
91219 */
91220 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
91221 - void *buf, int len, int write)
91222 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
91223 + void *buf, size_t len, int write)
91224 {
91225 struct mm_struct *mm;
91226 - int ret;
91227 + ssize_t ret;
91228
91229 mm = get_task_mm(tsk);
91230 if (!mm)
91231 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
91232 index 0cd2c4d..9558c83 100644
91233 --- a/mm/mempolicy.c
91234 +++ b/mm/mempolicy.c
91235 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91236 unsigned long vmstart;
91237 unsigned long vmend;
91238
91239 +#ifdef CONFIG_PAX_SEGMEXEC
91240 + struct vm_area_struct *vma_m;
91241 +#endif
91242 +
91243 vma = find_vma(mm, start);
91244 if (!vma || vma->vm_start > start)
91245 return -EFAULT;
91246 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91247 err = vma_replace_policy(vma, new_pol);
91248 if (err)
91249 goto out;
91250 +
91251 +#ifdef CONFIG_PAX_SEGMEXEC
91252 + vma_m = pax_find_mirror_vma(vma);
91253 + if (vma_m) {
91254 + err = vma_replace_policy(vma_m, new_pol);
91255 + if (err)
91256 + goto out;
91257 + }
91258 +#endif
91259 +
91260 }
91261
91262 out:
91263 @@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
91264
91265 if (end < start)
91266 return -EINVAL;
91267 +
91268 +#ifdef CONFIG_PAX_SEGMEXEC
91269 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
91270 + if (end > SEGMEXEC_TASK_SIZE)
91271 + return -EINVAL;
91272 + } else
91273 +#endif
91274 +
91275 + if (end > TASK_SIZE)
91276 + return -EINVAL;
91277 +
91278 if (end == start)
91279 return 0;
91280
91281 @@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91282 */
91283 tcred = __task_cred(task);
91284 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91285 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91286 - !capable(CAP_SYS_NICE)) {
91287 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91288 rcu_read_unlock();
91289 err = -EPERM;
91290 goto out_put;
91291 @@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91292 goto out;
91293 }
91294
91295 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
91296 + if (mm != current->mm &&
91297 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
91298 + mmput(mm);
91299 + err = -EPERM;
91300 + goto out;
91301 + }
91302 +#endif
91303 +
91304 err = do_migrate_pages(mm, old, new,
91305 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
91306
91307 diff --git a/mm/migrate.c b/mm/migrate.c
91308 index 9194375..75c81e2 100644
91309 --- a/mm/migrate.c
91310 +++ b/mm/migrate.c
91311 @@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
91312 */
91313 tcred = __task_cred(task);
91314 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91315 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91316 - !capable(CAP_SYS_NICE)) {
91317 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91318 rcu_read_unlock();
91319 err = -EPERM;
91320 goto out;
91321 diff --git a/mm/mlock.c b/mm/mlock.c
91322 index 192e6ee..b044449 100644
91323 --- a/mm/mlock.c
91324 +++ b/mm/mlock.c
91325 @@ -14,6 +14,7 @@
91326 #include <linux/pagevec.h>
91327 #include <linux/mempolicy.h>
91328 #include <linux/syscalls.h>
91329 +#include <linux/security.h>
91330 #include <linux/sched.h>
91331 #include <linux/export.h>
91332 #include <linux/rmap.h>
91333 @@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
91334 {
91335 unsigned long nstart, end, tmp;
91336 struct vm_area_struct * vma, * prev;
91337 - int error;
91338 + int error = 0;
91339
91340 VM_BUG_ON(start & ~PAGE_MASK);
91341 VM_BUG_ON(len != PAGE_ALIGN(len));
91342 @@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
91343 return -EINVAL;
91344 if (end == start)
91345 return 0;
91346 + if (end > TASK_SIZE)
91347 + return -EINVAL;
91348 +
91349 vma = find_vma(current->mm, start);
91350 if (!vma || vma->vm_start > start)
91351 return -ENOMEM;
91352 @@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
91353 for (nstart = start ; ; ) {
91354 vm_flags_t newflags;
91355
91356 +#ifdef CONFIG_PAX_SEGMEXEC
91357 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91358 + break;
91359 +#endif
91360 +
91361 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
91362
91363 newflags = vma->vm_flags & ~VM_LOCKED;
91364 @@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
91365 lock_limit >>= PAGE_SHIFT;
91366
91367 /* check against resource limits */
91368 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
91369 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
91370 error = do_mlock(start, len, 1);
91371 up_write(&current->mm->mmap_sem);
91372 @@ -754,6 +764,11 @@ static int do_mlockall(int flags)
91373 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
91374 vm_flags_t newflags;
91375
91376 +#ifdef CONFIG_PAX_SEGMEXEC
91377 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91378 + break;
91379 +#endif
91380 +
91381 newflags = vma->vm_flags & ~VM_LOCKED;
91382 if (flags & MCL_CURRENT)
91383 newflags |= VM_LOCKED;
91384 @@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
91385 lock_limit >>= PAGE_SHIFT;
91386
91387 ret = -ENOMEM;
91388 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
91389 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
91390 capable(CAP_IPC_LOCK))
91391 ret = do_mlockall(flags);
91392 diff --git a/mm/mmap.c b/mm/mmap.c
91393 index 834b2d7..650d1b9 100644
91394 --- a/mm/mmap.c
91395 +++ b/mm/mmap.c
91396 @@ -36,6 +36,7 @@
91397 #include <linux/sched/sysctl.h>
91398 #include <linux/notifier.h>
91399 #include <linux/memory.h>
91400 +#include <linux/random.h>
91401
91402 #include <asm/uaccess.h>
91403 #include <asm/cacheflush.h>
91404 @@ -52,6 +53,16 @@
91405 #define arch_rebalance_pgtables(addr, len) (addr)
91406 #endif
91407
91408 +static inline void verify_mm_writelocked(struct mm_struct *mm)
91409 +{
91410 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
91411 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
91412 + up_read(&mm->mmap_sem);
91413 + BUG();
91414 + }
91415 +#endif
91416 +}
91417 +
91418 static void unmap_region(struct mm_struct *mm,
91419 struct vm_area_struct *vma, struct vm_area_struct *prev,
91420 unsigned long start, unsigned long end);
91421 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
91422 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
91423 *
91424 */
91425 -pgprot_t protection_map[16] = {
91426 +pgprot_t protection_map[16] __read_only = {
91427 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
91428 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
91429 };
91430
91431 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
91432 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
91433 {
91434 - return __pgprot(pgprot_val(protection_map[vm_flags &
91435 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
91436 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
91437 pgprot_val(arch_vm_get_page_prot(vm_flags)));
91438 +
91439 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91440 + if (!(__supported_pte_mask & _PAGE_NX) &&
91441 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
91442 + (vm_flags & (VM_READ | VM_WRITE)))
91443 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
91444 +#endif
91445 +
91446 + return prot;
91447 }
91448 EXPORT_SYMBOL(vm_get_page_prot);
91449
91450 @@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
91451 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
91452 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
91453 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
91454 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
91455 /*
91456 * Make sure vm_committed_as in one cacheline and not cacheline shared with
91457 * other variables. It can be updated by several CPUs frequently.
91458 @@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
91459 struct vm_area_struct *next = vma->vm_next;
91460
91461 might_sleep();
91462 + BUG_ON(vma->vm_mirror);
91463 if (vma->vm_ops && vma->vm_ops->close)
91464 vma->vm_ops->close(vma);
91465 if (vma->vm_file)
91466 @@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
91467 * not page aligned -Ram Gupta
91468 */
91469 rlim = rlimit(RLIMIT_DATA);
91470 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
91471 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
91472 (mm->end_data - mm->start_data) > rlim)
91473 goto out;
91474 @@ -893,7 +916,15 @@ again: remove_next = 1 + (end > next->vm_end);
91475 static inline int is_mergeable_vma(struct vm_area_struct *vma,
91476 struct file *file, unsigned long vm_flags)
91477 {
91478 - if (vma->vm_flags ^ vm_flags)
91479 + /*
91480 + * VM_SOFTDIRTY should not prevent from VMA merging, if we
91481 + * match the flags but dirty bit -- the caller should mark
91482 + * merged VMA as dirty. If dirty bit won't be excluded from
91483 + * comparison, we increase pressue on the memory system forcing
91484 + * the kernel to generate new VMAs when old one could be
91485 + * extended instead.
91486 + */
91487 + if ((vma->vm_flags ^ vm_flags) & ~VM_SOFTDIRTY)
91488 return 0;
91489 if (vma->vm_file != file)
91490 return 0;
91491 @@ -931,6 +962,12 @@ static int
91492 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
91493 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91494 {
91495 +
91496 +#ifdef CONFIG_PAX_SEGMEXEC
91497 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
91498 + return 0;
91499 +#endif
91500 +
91501 if (is_mergeable_vma(vma, file, vm_flags) &&
91502 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91503 if (vma->vm_pgoff == vm_pgoff)
91504 @@ -950,6 +987,12 @@ static int
91505 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91506 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91507 {
91508 +
91509 +#ifdef CONFIG_PAX_SEGMEXEC
91510 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
91511 + return 0;
91512 +#endif
91513 +
91514 if (is_mergeable_vma(vma, file, vm_flags) &&
91515 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91516 pgoff_t vm_pglen;
91517 @@ -992,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91518 struct vm_area_struct *vma_merge(struct mm_struct *mm,
91519 struct vm_area_struct *prev, unsigned long addr,
91520 unsigned long end, unsigned long vm_flags,
91521 - struct anon_vma *anon_vma, struct file *file,
91522 + struct anon_vma *anon_vma, struct file *file,
91523 pgoff_t pgoff, struct mempolicy *policy)
91524 {
91525 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
91526 struct vm_area_struct *area, *next;
91527 int err;
91528
91529 +#ifdef CONFIG_PAX_SEGMEXEC
91530 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
91531 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
91532 +
91533 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
91534 +#endif
91535 +
91536 /*
91537 * We later require that vma->vm_flags == vm_flags,
91538 * so this tests vma->vm_flags & VM_SPECIAL, too.
91539 @@ -1014,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91540 if (next && next->vm_end == end) /* cases 6, 7, 8 */
91541 next = next->vm_next;
91542
91543 +#ifdef CONFIG_PAX_SEGMEXEC
91544 + if (prev)
91545 + prev_m = pax_find_mirror_vma(prev);
91546 + if (area)
91547 + area_m = pax_find_mirror_vma(area);
91548 + if (next)
91549 + next_m = pax_find_mirror_vma(next);
91550 +#endif
91551 +
91552 /*
91553 * Can it merge with the predecessor?
91554 */
91555 @@ -1033,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91556 /* cases 1, 6 */
91557 err = vma_adjust(prev, prev->vm_start,
91558 next->vm_end, prev->vm_pgoff, NULL);
91559 - } else /* cases 2, 5, 7 */
91560 +
91561 +#ifdef CONFIG_PAX_SEGMEXEC
91562 + if (!err && prev_m)
91563 + err = vma_adjust(prev_m, prev_m->vm_start,
91564 + next_m->vm_end, prev_m->vm_pgoff, NULL);
91565 +#endif
91566 +
91567 + } else { /* cases 2, 5, 7 */
91568 err = vma_adjust(prev, prev->vm_start,
91569 end, prev->vm_pgoff, NULL);
91570 +
91571 +#ifdef CONFIG_PAX_SEGMEXEC
91572 + if (!err && prev_m)
91573 + err = vma_adjust(prev_m, prev_m->vm_start,
91574 + end_m, prev_m->vm_pgoff, NULL);
91575 +#endif
91576 +
91577 + }
91578 if (err)
91579 return NULL;
91580 khugepaged_enter_vma_merge(prev);
91581 @@ -1049,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91582 mpol_equal(policy, vma_policy(next)) &&
91583 can_vma_merge_before(next, vm_flags,
91584 anon_vma, file, pgoff+pglen)) {
91585 - if (prev && addr < prev->vm_end) /* case 4 */
91586 + if (prev && addr < prev->vm_end) { /* case 4 */
91587 err = vma_adjust(prev, prev->vm_start,
91588 addr, prev->vm_pgoff, NULL);
91589 - else /* cases 3, 8 */
91590 +
91591 +#ifdef CONFIG_PAX_SEGMEXEC
91592 + if (!err && prev_m)
91593 + err = vma_adjust(prev_m, prev_m->vm_start,
91594 + addr_m, prev_m->vm_pgoff, NULL);
91595 +#endif
91596 +
91597 + } else { /* cases 3, 8 */
91598 err = vma_adjust(area, addr, next->vm_end,
91599 next->vm_pgoff - pglen, NULL);
91600 +
91601 +#ifdef CONFIG_PAX_SEGMEXEC
91602 + if (!err && area_m)
91603 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
91604 + next_m->vm_pgoff - pglen, NULL);
91605 +#endif
91606 +
91607 + }
91608 if (err)
91609 return NULL;
91610 khugepaged_enter_vma_merge(area);
91611 @@ -1082,7 +1171,7 @@ static int anon_vma_compatible(struct vm_area_struct *a, struct vm_area_struct *
91612 return a->vm_end == b->vm_start &&
91613 mpol_equal(vma_policy(a), vma_policy(b)) &&
91614 a->vm_file == b->vm_file &&
91615 - !((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC)) &&
91616 + !((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC|VM_SOFTDIRTY)) &&
91617 b->vm_pgoff == a->vm_pgoff + ((b->vm_start - a->vm_start) >> PAGE_SHIFT);
91618 }
91619
91620 @@ -1163,8 +1252,10 @@ none:
91621 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91622 struct file *file, long pages)
91623 {
91624 - const unsigned long stack_flags
91625 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
91626 +
91627 +#ifdef CONFIG_PAX_RANDMMAP
91628 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91629 +#endif
91630
91631 mm->total_vm += pages;
91632
91633 @@ -1172,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91634 mm->shared_vm += pages;
91635 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
91636 mm->exec_vm += pages;
91637 - } else if (flags & stack_flags)
91638 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
91639 mm->stack_vm += pages;
91640 }
91641 #endif /* CONFIG_PROC_FS */
91642 @@ -1210,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91643 * (the exception is when the underlying filesystem is noexec
91644 * mounted, in which case we dont add PROT_EXEC.)
91645 */
91646 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
91647 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
91648 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
91649 prot |= PROT_EXEC;
91650
91651 @@ -1236,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91652 /* Obtain the address to map to. we verify (or select) it and ensure
91653 * that it represents a valid section of the address space.
91654 */
91655 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
91656 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
91657 if (addr & ~PAGE_MASK)
91658 return addr;
91659
91660 @@ -1247,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91661 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
91662 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
91663
91664 +#ifdef CONFIG_PAX_MPROTECT
91665 + if (mm->pax_flags & MF_PAX_MPROTECT) {
91666 +
91667 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
91668 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
91669 + mm->binfmt->handle_mmap)
91670 + mm->binfmt->handle_mmap(file);
91671 +#endif
91672 +
91673 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
91674 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
91675 + gr_log_rwxmmap(file);
91676 +
91677 +#ifdef CONFIG_PAX_EMUPLT
91678 + vm_flags &= ~VM_EXEC;
91679 +#else
91680 + return -EPERM;
91681 +#endif
91682 +
91683 + }
91684 +
91685 + if (!(vm_flags & VM_EXEC))
91686 + vm_flags &= ~VM_MAYEXEC;
91687 +#else
91688 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
91689 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
91690 +#endif
91691 + else
91692 + vm_flags &= ~VM_MAYWRITE;
91693 + }
91694 +#endif
91695 +
91696 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91697 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
91698 + vm_flags &= ~VM_PAGEEXEC;
91699 +#endif
91700 +
91701 if (flags & MAP_LOCKED)
91702 if (!can_do_mlock())
91703 return -EPERM;
91704 @@ -1258,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91705 locked += mm->locked_vm;
91706 lock_limit = rlimit(RLIMIT_MEMLOCK);
91707 lock_limit >>= PAGE_SHIFT;
91708 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
91709 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
91710 return -EAGAIN;
91711 }
91712 @@ -1342,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91713 vm_flags |= VM_NORESERVE;
91714 }
91715
91716 + if (!gr_acl_handle_mmap(file, prot))
91717 + return -EACCES;
91718 +
91719 addr = mmap_region(file, addr, len, vm_flags, pgoff);
91720 if (!IS_ERR_VALUE(addr) &&
91721 ((vm_flags & VM_LOCKED) ||
91722 @@ -1435,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
91723 vm_flags_t vm_flags = vma->vm_flags;
91724
91725 /* If it was private or non-writable, the write bit is already clear */
91726 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
91727 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
91728 return 0;
91729
91730 /* The backer wishes to know when pages are first written to? */
91731 @@ -1481,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91732 struct rb_node **rb_link, *rb_parent;
91733 unsigned long charged = 0;
91734
91735 +#ifdef CONFIG_PAX_SEGMEXEC
91736 + struct vm_area_struct *vma_m = NULL;
91737 +#endif
91738 +
91739 + /*
91740 + * mm->mmap_sem is required to protect against another thread
91741 + * changing the mappings in case we sleep.
91742 + */
91743 + verify_mm_writelocked(mm);
91744 +
91745 /* Check against address space limit. */
91746 +
91747 +#ifdef CONFIG_PAX_RANDMMAP
91748 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91749 +#endif
91750 +
91751 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
91752 unsigned long nr_pages;
91753
91754 @@ -1500,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91755
91756 /* Clear old maps */
91757 error = -ENOMEM;
91758 -munmap_back:
91759 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
91760 if (do_munmap(mm, addr, len))
91761 return -ENOMEM;
91762 - goto munmap_back;
91763 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
91764 }
91765
91766 /*
91767 @@ -1535,6 +1681,16 @@ munmap_back:
91768 goto unacct_error;
91769 }
91770
91771 +#ifdef CONFIG_PAX_SEGMEXEC
91772 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
91773 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
91774 + if (!vma_m) {
91775 + error = -ENOMEM;
91776 + goto free_vma;
91777 + }
91778 + }
91779 +#endif
91780 +
91781 vma->vm_mm = mm;
91782 vma->vm_start = addr;
91783 vma->vm_end = addr + len;
91784 @@ -1554,6 +1710,13 @@ munmap_back:
91785 if (error)
91786 goto unmap_and_free_vma;
91787
91788 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91789 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
91790 + vma->vm_flags |= VM_PAGEEXEC;
91791 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
91792 + }
91793 +#endif
91794 +
91795 /* Can addr have changed??
91796 *
91797 * Answer: Yes, several device drivers can do it in their
91798 @@ -1587,6 +1750,12 @@ munmap_back:
91799 }
91800
91801 vma_link(mm, vma, prev, rb_link, rb_parent);
91802 +
91803 +#ifdef CONFIG_PAX_SEGMEXEC
91804 + if (vma_m)
91805 + BUG_ON(pax_mirror_vma(vma_m, vma));
91806 +#endif
91807 +
91808 /* Once vma denies write, undo our temporary denial count */
91809 if (vm_flags & VM_DENYWRITE)
91810 allow_write_access(file);
91811 @@ -1595,6 +1764,7 @@ out:
91812 perf_event_mmap(vma);
91813
91814 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
91815 + track_exec_limit(mm, addr, addr + len, vm_flags);
91816 if (vm_flags & VM_LOCKED) {
91817 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
91818 vma == get_gate_vma(current->mm)))
91819 @@ -1627,6 +1797,12 @@ unmap_and_free_vma:
91820 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
91821 charged = 0;
91822 free_vma:
91823 +
91824 +#ifdef CONFIG_PAX_SEGMEXEC
91825 + if (vma_m)
91826 + kmem_cache_free(vm_area_cachep, vma_m);
91827 +#endif
91828 +
91829 kmem_cache_free(vm_area_cachep, vma);
91830 unacct_error:
91831 if (charged)
91832 @@ -1634,7 +1810,63 @@ unacct_error:
91833 return error;
91834 }
91835
91836 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
91837 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
91838 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
91839 +{
91840 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
91841 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
91842 +
91843 + return 0;
91844 +}
91845 +#endif
91846 +
91847 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
91848 +{
91849 + if (!vma) {
91850 +#ifdef CONFIG_STACK_GROWSUP
91851 + if (addr > sysctl_heap_stack_gap)
91852 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
91853 + else
91854 + vma = find_vma(current->mm, 0);
91855 + if (vma && (vma->vm_flags & VM_GROWSUP))
91856 + return false;
91857 +#endif
91858 + return true;
91859 + }
91860 +
91861 + if (addr + len > vma->vm_start)
91862 + return false;
91863 +
91864 + if (vma->vm_flags & VM_GROWSDOWN)
91865 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
91866 +#ifdef CONFIG_STACK_GROWSUP
91867 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
91868 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
91869 +#endif
91870 + else if (offset)
91871 + return offset <= vma->vm_start - addr - len;
91872 +
91873 + return true;
91874 +}
91875 +
91876 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
91877 +{
91878 + if (vma->vm_start < len)
91879 + return -ENOMEM;
91880 +
91881 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
91882 + if (offset <= vma->vm_start - len)
91883 + return vma->vm_start - len - offset;
91884 + else
91885 + return -ENOMEM;
91886 + }
91887 +
91888 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
91889 + return vma->vm_start - len - sysctl_heap_stack_gap;
91890 + return -ENOMEM;
91891 +}
91892 +
91893 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
91894 {
91895 /*
91896 * We implement the search by looking for an rbtree node that
91897 @@ -1682,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
91898 }
91899 }
91900
91901 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
91902 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
91903 check_current:
91904 /* Check if current node has a suitable gap */
91905 if (gap_start > high_limit)
91906 return -ENOMEM;
91907 +
91908 + if (gap_end - gap_start > info->threadstack_offset)
91909 + gap_start += info->threadstack_offset;
91910 + else
91911 + gap_start = gap_end;
91912 +
91913 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
91914 + if (gap_end - gap_start > sysctl_heap_stack_gap)
91915 + gap_start += sysctl_heap_stack_gap;
91916 + else
91917 + gap_start = gap_end;
91918 + }
91919 + if (vma->vm_flags & VM_GROWSDOWN) {
91920 + if (gap_end - gap_start > sysctl_heap_stack_gap)
91921 + gap_end -= sysctl_heap_stack_gap;
91922 + else
91923 + gap_end = gap_start;
91924 + }
91925 if (gap_end >= low_limit && gap_end - gap_start >= length)
91926 goto found;
91927
91928 @@ -1736,7 +1986,7 @@ found:
91929 return gap_start;
91930 }
91931
91932 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
91933 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
91934 {
91935 struct mm_struct *mm = current->mm;
91936 struct vm_area_struct *vma;
91937 @@ -1790,6 +2040,24 @@ check_current:
91938 gap_end = vma->vm_start;
91939 if (gap_end < low_limit)
91940 return -ENOMEM;
91941 +
91942 + if (gap_end - gap_start > info->threadstack_offset)
91943 + gap_end -= info->threadstack_offset;
91944 + else
91945 + gap_end = gap_start;
91946 +
91947 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
91948 + if (gap_end - gap_start > sysctl_heap_stack_gap)
91949 + gap_start += sysctl_heap_stack_gap;
91950 + else
91951 + gap_start = gap_end;
91952 + }
91953 + if (vma->vm_flags & VM_GROWSDOWN) {
91954 + if (gap_end - gap_start > sysctl_heap_stack_gap)
91955 + gap_end -= sysctl_heap_stack_gap;
91956 + else
91957 + gap_end = gap_start;
91958 + }
91959 if (gap_start <= high_limit && gap_end - gap_start >= length)
91960 goto found;
91961
91962 @@ -1853,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
91963 struct mm_struct *mm = current->mm;
91964 struct vm_area_struct *vma;
91965 struct vm_unmapped_area_info info;
91966 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
91967
91968 if (len > TASK_SIZE - mmap_min_addr)
91969 return -ENOMEM;
91970 @@ -1860,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
91971 if (flags & MAP_FIXED)
91972 return addr;
91973
91974 +#ifdef CONFIG_PAX_RANDMMAP
91975 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
91976 +#endif
91977 +
91978 if (addr) {
91979 addr = PAGE_ALIGN(addr);
91980 vma = find_vma(mm, addr);
91981 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
91982 - (!vma || addr + len <= vma->vm_start))
91983 + check_heap_stack_gap(vma, addr, len, offset))
91984 return addr;
91985 }
91986
91987 @@ -1873,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
91988 info.low_limit = mm->mmap_base;
91989 info.high_limit = TASK_SIZE;
91990 info.align_mask = 0;
91991 + info.threadstack_offset = offset;
91992 return vm_unmapped_area(&info);
91993 }
91994 #endif
91995 @@ -1891,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
91996 struct mm_struct *mm = current->mm;
91997 unsigned long addr = addr0;
91998 struct vm_unmapped_area_info info;
91999 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
92000
92001 /* requested length too big for entire address space */
92002 if (len > TASK_SIZE - mmap_min_addr)
92003 @@ -1899,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92004 if (flags & MAP_FIXED)
92005 return addr;
92006
92007 +#ifdef CONFIG_PAX_RANDMMAP
92008 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
92009 +#endif
92010 +
92011 /* requesting a specific address */
92012 if (addr) {
92013 addr = PAGE_ALIGN(addr);
92014 vma = find_vma(mm, addr);
92015 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
92016 - (!vma || addr + len <= vma->vm_start))
92017 + check_heap_stack_gap(vma, addr, len, offset))
92018 return addr;
92019 }
92020
92021 @@ -1913,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92022 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
92023 info.high_limit = mm->mmap_base;
92024 info.align_mask = 0;
92025 + info.threadstack_offset = offset;
92026 addr = vm_unmapped_area(&info);
92027
92028 /*
92029 @@ -1925,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92030 VM_BUG_ON(addr != -ENOMEM);
92031 info.flags = 0;
92032 info.low_limit = TASK_UNMAPPED_BASE;
92033 +
92034 +#ifdef CONFIG_PAX_RANDMMAP
92035 + if (mm->pax_flags & MF_PAX_RANDMMAP)
92036 + info.low_limit += mm->delta_mmap;
92037 +#endif
92038 +
92039 info.high_limit = TASK_SIZE;
92040 addr = vm_unmapped_area(&info);
92041 }
92042 @@ -2026,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
92043 return vma;
92044 }
92045
92046 +#ifdef CONFIG_PAX_SEGMEXEC
92047 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
92048 +{
92049 + struct vm_area_struct *vma_m;
92050 +
92051 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
92052 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
92053 + BUG_ON(vma->vm_mirror);
92054 + return NULL;
92055 + }
92056 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
92057 + vma_m = vma->vm_mirror;
92058 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
92059 + BUG_ON(vma->vm_file != vma_m->vm_file);
92060 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
92061 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
92062 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
92063 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
92064 + return vma_m;
92065 +}
92066 +#endif
92067 +
92068 /*
92069 * Verify that the stack growth is acceptable and
92070 * update accounting. This is shared with both the
92071 @@ -2042,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92072 return -ENOMEM;
92073
92074 /* Stack limit test */
92075 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
92076 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
92077 return -ENOMEM;
92078
92079 @@ -2052,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92080 locked = mm->locked_vm + grow;
92081 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
92082 limit >>= PAGE_SHIFT;
92083 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92084 if (locked > limit && !capable(CAP_IPC_LOCK))
92085 return -ENOMEM;
92086 }
92087 @@ -2081,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92088 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
92089 * vma is the last one with address > vma->vm_end. Have to extend vma.
92090 */
92091 +#ifndef CONFIG_IA64
92092 +static
92093 +#endif
92094 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92095 {
92096 int error;
92097 + bool locknext;
92098
92099 if (!(vma->vm_flags & VM_GROWSUP))
92100 return -EFAULT;
92101
92102 + /* Also guard against wrapping around to address 0. */
92103 + if (address < PAGE_ALIGN(address+1))
92104 + address = PAGE_ALIGN(address+1);
92105 + else
92106 + return -ENOMEM;
92107 +
92108 /*
92109 * We must make sure the anon_vma is allocated
92110 * so that the anon_vma locking is not a noop.
92111 */
92112 if (unlikely(anon_vma_prepare(vma)))
92113 return -ENOMEM;
92114 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
92115 + if (locknext && anon_vma_prepare(vma->vm_next))
92116 + return -ENOMEM;
92117 vma_lock_anon_vma(vma);
92118 + if (locknext)
92119 + vma_lock_anon_vma(vma->vm_next);
92120
92121 /*
92122 * vma->vm_start/vm_end cannot change under us because the caller
92123 * is required to hold the mmap_sem in read mode. We need the
92124 - * anon_vma lock to serialize against concurrent expand_stacks.
92125 - * Also guard against wrapping around to address 0.
92126 + * anon_vma locks to serialize against concurrent expand_stacks
92127 + * and expand_upwards.
92128 */
92129 - if (address < PAGE_ALIGN(address+4))
92130 - address = PAGE_ALIGN(address+4);
92131 - else {
92132 - vma_unlock_anon_vma(vma);
92133 - return -ENOMEM;
92134 - }
92135 error = 0;
92136
92137 /* Somebody else might have raced and expanded it already */
92138 - if (address > vma->vm_end) {
92139 + 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)
92140 + error = -ENOMEM;
92141 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
92142 unsigned long size, grow;
92143
92144 size = address - vma->vm_start;
92145 @@ -2146,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92146 }
92147 }
92148 }
92149 + if (locknext)
92150 + vma_unlock_anon_vma(vma->vm_next);
92151 vma_unlock_anon_vma(vma);
92152 khugepaged_enter_vma_merge(vma);
92153 validate_mm(vma->vm_mm);
92154 @@ -2160,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
92155 unsigned long address)
92156 {
92157 int error;
92158 + bool lockprev = false;
92159 + struct vm_area_struct *prev;
92160
92161 /*
92162 * We must make sure the anon_vma is allocated
92163 @@ -2173,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
92164 if (error)
92165 return error;
92166
92167 + prev = vma->vm_prev;
92168 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
92169 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
92170 +#endif
92171 + if (lockprev && anon_vma_prepare(prev))
92172 + return -ENOMEM;
92173 + if (lockprev)
92174 + vma_lock_anon_vma(prev);
92175 +
92176 vma_lock_anon_vma(vma);
92177
92178 /*
92179 @@ -2182,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
92180 */
92181
92182 /* Somebody else might have raced and expanded it already */
92183 - if (address < vma->vm_start) {
92184 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
92185 + error = -ENOMEM;
92186 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
92187 unsigned long size, grow;
92188
92189 +#ifdef CONFIG_PAX_SEGMEXEC
92190 + struct vm_area_struct *vma_m;
92191 +
92192 + vma_m = pax_find_mirror_vma(vma);
92193 +#endif
92194 +
92195 size = vma->vm_end - address;
92196 grow = (vma->vm_start - address) >> PAGE_SHIFT;
92197
92198 @@ -2209,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
92199 vma->vm_pgoff -= grow;
92200 anon_vma_interval_tree_post_update_vma(vma);
92201 vma_gap_update(vma);
92202 +
92203 +#ifdef CONFIG_PAX_SEGMEXEC
92204 + if (vma_m) {
92205 + anon_vma_interval_tree_pre_update_vma(vma_m);
92206 + vma_m->vm_start -= grow << PAGE_SHIFT;
92207 + vma_m->vm_pgoff -= grow;
92208 + anon_vma_interval_tree_post_update_vma(vma_m);
92209 + vma_gap_update(vma_m);
92210 + }
92211 +#endif
92212 +
92213 spin_unlock(&vma->vm_mm->page_table_lock);
92214
92215 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
92216 perf_event_mmap(vma);
92217 }
92218 }
92219 }
92220 vma_unlock_anon_vma(vma);
92221 + if (lockprev)
92222 + vma_unlock_anon_vma(prev);
92223 khugepaged_enter_vma_merge(vma);
92224 validate_mm(vma->vm_mm);
92225 return error;
92226 @@ -2313,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
92227 do {
92228 long nrpages = vma_pages(vma);
92229
92230 +#ifdef CONFIG_PAX_SEGMEXEC
92231 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
92232 + vma = remove_vma(vma);
92233 + continue;
92234 + }
92235 +#endif
92236 +
92237 if (vma->vm_flags & VM_ACCOUNT)
92238 nr_accounted += nrpages;
92239 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
92240 @@ -2357,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
92241 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
92242 vma->vm_prev = NULL;
92243 do {
92244 +
92245 +#ifdef CONFIG_PAX_SEGMEXEC
92246 + if (vma->vm_mirror) {
92247 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
92248 + vma->vm_mirror->vm_mirror = NULL;
92249 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
92250 + vma->vm_mirror = NULL;
92251 + }
92252 +#endif
92253 +
92254 vma_rb_erase(vma, &mm->mm_rb);
92255 mm->map_count--;
92256 tail_vma = vma;
92257 @@ -2382,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92258 struct vm_area_struct *new;
92259 int err = -ENOMEM;
92260
92261 +#ifdef CONFIG_PAX_SEGMEXEC
92262 + struct vm_area_struct *vma_m, *new_m = NULL;
92263 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
92264 +#endif
92265 +
92266 if (is_vm_hugetlb_page(vma) && (addr &
92267 ~(huge_page_mask(hstate_vma(vma)))))
92268 return -EINVAL;
92269
92270 +#ifdef CONFIG_PAX_SEGMEXEC
92271 + vma_m = pax_find_mirror_vma(vma);
92272 +#endif
92273 +
92274 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92275 if (!new)
92276 goto out_err;
92277
92278 +#ifdef CONFIG_PAX_SEGMEXEC
92279 + if (vma_m) {
92280 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92281 + if (!new_m) {
92282 + kmem_cache_free(vm_area_cachep, new);
92283 + goto out_err;
92284 + }
92285 + }
92286 +#endif
92287 +
92288 /* most fields are the same, copy all, and then fixup */
92289 *new = *vma;
92290
92291 @@ -2402,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92292 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
92293 }
92294
92295 +#ifdef CONFIG_PAX_SEGMEXEC
92296 + if (vma_m) {
92297 + *new_m = *vma_m;
92298 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
92299 + new_m->vm_mirror = new;
92300 + new->vm_mirror = new_m;
92301 +
92302 + if (new_below)
92303 + new_m->vm_end = addr_m;
92304 + else {
92305 + new_m->vm_start = addr_m;
92306 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
92307 + }
92308 + }
92309 +#endif
92310 +
92311 err = vma_dup_policy(vma, new);
92312 if (err)
92313 goto out_free_vma;
92314 @@ -2421,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92315 else
92316 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
92317
92318 +#ifdef CONFIG_PAX_SEGMEXEC
92319 + if (!err && vma_m) {
92320 + struct mempolicy *pol = vma_policy(new);
92321 +
92322 + if (anon_vma_clone(new_m, vma_m))
92323 + goto out_free_mpol;
92324 +
92325 + mpol_get(pol);
92326 + set_vma_policy(new_m, pol);
92327 +
92328 + if (new_m->vm_file)
92329 + get_file(new_m->vm_file);
92330 +
92331 + if (new_m->vm_ops && new_m->vm_ops->open)
92332 + new_m->vm_ops->open(new_m);
92333 +
92334 + if (new_below)
92335 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
92336 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
92337 + else
92338 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
92339 +
92340 + if (err) {
92341 + if (new_m->vm_ops && new_m->vm_ops->close)
92342 + new_m->vm_ops->close(new_m);
92343 + if (new_m->vm_file)
92344 + fput(new_m->vm_file);
92345 + mpol_put(pol);
92346 + }
92347 + }
92348 +#endif
92349 +
92350 /* Success. */
92351 if (!err)
92352 return 0;
92353 @@ -2430,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92354 new->vm_ops->close(new);
92355 if (new->vm_file)
92356 fput(new->vm_file);
92357 - unlink_anon_vmas(new);
92358 out_free_mpol:
92359 mpol_put(vma_policy(new));
92360 out_free_vma:
92361 +
92362 +#ifdef CONFIG_PAX_SEGMEXEC
92363 + if (new_m) {
92364 + unlink_anon_vmas(new_m);
92365 + kmem_cache_free(vm_area_cachep, new_m);
92366 + }
92367 +#endif
92368 +
92369 + unlink_anon_vmas(new);
92370 kmem_cache_free(vm_area_cachep, new);
92371 out_err:
92372 return err;
92373 @@ -2446,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92374 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92375 unsigned long addr, int new_below)
92376 {
92377 +
92378 +#ifdef CONFIG_PAX_SEGMEXEC
92379 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92380 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
92381 + if (mm->map_count >= sysctl_max_map_count-1)
92382 + return -ENOMEM;
92383 + } else
92384 +#endif
92385 +
92386 if (mm->map_count >= sysctl_max_map_count)
92387 return -ENOMEM;
92388
92389 @@ -2457,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92390 * work. This now handles partial unmappings.
92391 * Jeremy Fitzhardinge <jeremy@goop.org>
92392 */
92393 +#ifdef CONFIG_PAX_SEGMEXEC
92394 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92395 {
92396 + int ret = __do_munmap(mm, start, len);
92397 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
92398 + return ret;
92399 +
92400 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
92401 +}
92402 +
92403 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92404 +#else
92405 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92406 +#endif
92407 +{
92408 unsigned long end;
92409 struct vm_area_struct *vma, *prev, *last;
92410
92411 + /*
92412 + * mm->mmap_sem is required to protect against another thread
92413 + * changing the mappings in case we sleep.
92414 + */
92415 + verify_mm_writelocked(mm);
92416 +
92417 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
92418 return -EINVAL;
92419
92420 @@ -2536,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92421 /* Fix up all other VM information */
92422 remove_vma_list(mm, vma);
92423
92424 + track_exec_limit(mm, start, end, 0UL);
92425 +
92426 return 0;
92427 }
92428
92429 @@ -2544,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
92430 int ret;
92431 struct mm_struct *mm = current->mm;
92432
92433 +
92434 +#ifdef CONFIG_PAX_SEGMEXEC
92435 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
92436 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
92437 + return -EINVAL;
92438 +#endif
92439 +
92440 down_write(&mm->mmap_sem);
92441 ret = do_munmap(mm, start, len);
92442 up_write(&mm->mmap_sem);
92443 @@ -2557,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
92444 return vm_munmap(addr, len);
92445 }
92446
92447 -static inline void verify_mm_writelocked(struct mm_struct *mm)
92448 -{
92449 -#ifdef CONFIG_DEBUG_VM
92450 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92451 - WARN_ON(1);
92452 - up_read(&mm->mmap_sem);
92453 - }
92454 -#endif
92455 -}
92456 -
92457 /*
92458 * this is really a simplified "do_mmap". it only handles
92459 * anonymous maps. eventually we may be able to do some
92460 @@ -2580,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92461 struct rb_node ** rb_link, * rb_parent;
92462 pgoff_t pgoff = addr >> PAGE_SHIFT;
92463 int error;
92464 + unsigned long charged;
92465
92466 len = PAGE_ALIGN(len);
92467 if (!len)
92468 @@ -2587,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92469
92470 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
92471
92472 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
92473 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
92474 + flags &= ~VM_EXEC;
92475 +
92476 +#ifdef CONFIG_PAX_MPROTECT
92477 + if (mm->pax_flags & MF_PAX_MPROTECT)
92478 + flags &= ~VM_MAYEXEC;
92479 +#endif
92480 +
92481 + }
92482 +#endif
92483 +
92484 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
92485 if (error & ~PAGE_MASK)
92486 return error;
92487
92488 + charged = len >> PAGE_SHIFT;
92489 +
92490 /*
92491 * mlock MCL_FUTURE?
92492 */
92493 if (mm->def_flags & VM_LOCKED) {
92494 unsigned long locked, lock_limit;
92495 - locked = len >> PAGE_SHIFT;
92496 + locked = charged;
92497 locked += mm->locked_vm;
92498 lock_limit = rlimit(RLIMIT_MEMLOCK);
92499 lock_limit >>= PAGE_SHIFT;
92500 @@ -2613,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92501 /*
92502 * Clear old maps. this also does some error checking for us
92503 */
92504 - munmap_back:
92505 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92506 if (do_munmap(mm, addr, len))
92507 return -ENOMEM;
92508 - goto munmap_back;
92509 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92510 }
92511
92512 /* Check against address space limits *after* clearing old maps... */
92513 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
92514 + if (!may_expand_vm(mm, charged))
92515 return -ENOMEM;
92516
92517 if (mm->map_count > sysctl_max_map_count)
92518 return -ENOMEM;
92519
92520 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
92521 + if (security_vm_enough_memory_mm(mm, charged))
92522 return -ENOMEM;
92523
92524 /* Can we just expand an old private anonymous mapping? */
92525 @@ -2641,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92526 */
92527 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92528 if (!vma) {
92529 - vm_unacct_memory(len >> PAGE_SHIFT);
92530 + vm_unacct_memory(charged);
92531 return -ENOMEM;
92532 }
92533
92534 @@ -2655,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92535 vma_link(mm, vma, prev, rb_link, rb_parent);
92536 out:
92537 perf_event_mmap(vma);
92538 - mm->total_vm += len >> PAGE_SHIFT;
92539 + mm->total_vm += charged;
92540 if (flags & VM_LOCKED)
92541 - mm->locked_vm += (len >> PAGE_SHIFT);
92542 + mm->locked_vm += charged;
92543 vma->vm_flags |= VM_SOFTDIRTY;
92544 + track_exec_limit(mm, addr, addr + len, flags);
92545 return addr;
92546 }
92547
92548 @@ -2720,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
92549 while (vma) {
92550 if (vma->vm_flags & VM_ACCOUNT)
92551 nr_accounted += vma_pages(vma);
92552 + vma->vm_mirror = NULL;
92553 vma = remove_vma(vma);
92554 }
92555 vm_unacct_memory(nr_accounted);
92556 @@ -2737,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92557 struct vm_area_struct *prev;
92558 struct rb_node **rb_link, *rb_parent;
92559
92560 +#ifdef CONFIG_PAX_SEGMEXEC
92561 + struct vm_area_struct *vma_m = NULL;
92562 +#endif
92563 +
92564 + if (security_mmap_addr(vma->vm_start))
92565 + return -EPERM;
92566 +
92567 /*
92568 * The vm_pgoff of a purely anonymous vma should be irrelevant
92569 * until its first write fault, when page's anon_vma and index
92570 @@ -2760,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92571 security_vm_enough_memory_mm(mm, vma_pages(vma)))
92572 return -ENOMEM;
92573
92574 +#ifdef CONFIG_PAX_SEGMEXEC
92575 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
92576 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92577 + if (!vma_m)
92578 + return -ENOMEM;
92579 + }
92580 +#endif
92581 +
92582 vma_link(mm, vma, prev, rb_link, rb_parent);
92583 +
92584 +#ifdef CONFIG_PAX_SEGMEXEC
92585 + if (vma_m)
92586 + BUG_ON(pax_mirror_vma(vma_m, vma));
92587 +#endif
92588 +
92589 return 0;
92590 }
92591
92592 @@ -2779,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92593 struct rb_node **rb_link, *rb_parent;
92594 bool faulted_in_anon_vma = true;
92595
92596 + BUG_ON(vma->vm_mirror);
92597 +
92598 /*
92599 * If anonymous vma has not yet been faulted, update new pgoff
92600 * to match new location, to increase its chance of merging.
92601 @@ -2843,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92602 return NULL;
92603 }
92604
92605 +#ifdef CONFIG_PAX_SEGMEXEC
92606 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
92607 +{
92608 + struct vm_area_struct *prev_m;
92609 + struct rb_node **rb_link_m, *rb_parent_m;
92610 + struct mempolicy *pol_m;
92611 +
92612 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
92613 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
92614 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
92615 + *vma_m = *vma;
92616 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
92617 + if (anon_vma_clone(vma_m, vma))
92618 + return -ENOMEM;
92619 + pol_m = vma_policy(vma_m);
92620 + mpol_get(pol_m);
92621 + set_vma_policy(vma_m, pol_m);
92622 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
92623 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
92624 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
92625 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
92626 + if (vma_m->vm_file)
92627 + get_file(vma_m->vm_file);
92628 + if (vma_m->vm_ops && vma_m->vm_ops->open)
92629 + vma_m->vm_ops->open(vma_m);
92630 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
92631 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
92632 + vma_m->vm_mirror = vma;
92633 + vma->vm_mirror = vma_m;
92634 + return 0;
92635 +}
92636 +#endif
92637 +
92638 /*
92639 * Return true if the calling process may expand its vm space by the passed
92640 * number of pages
92641 @@ -2854,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
92642
92643 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
92644
92645 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
92646 if (cur + npages > lim)
92647 return 0;
92648 return 1;
92649 @@ -2924,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
92650 vma->vm_start = addr;
92651 vma->vm_end = addr + len;
92652
92653 +#ifdef CONFIG_PAX_MPROTECT
92654 + if (mm->pax_flags & MF_PAX_MPROTECT) {
92655 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
92656 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
92657 + return -EPERM;
92658 + if (!(vm_flags & VM_EXEC))
92659 + vm_flags &= ~VM_MAYEXEC;
92660 +#else
92661 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92662 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92663 +#endif
92664 + else
92665 + vm_flags &= ~VM_MAYWRITE;
92666 + }
92667 +#endif
92668 +
92669 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
92670 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92671
92672 diff --git a/mm/mprotect.c b/mm/mprotect.c
92673 index bb53a65..249c052 100644
92674 --- a/mm/mprotect.c
92675 +++ b/mm/mprotect.c
92676 @@ -23,10 +23,18 @@
92677 #include <linux/mmu_notifier.h>
92678 #include <linux/migrate.h>
92679 #include <linux/perf_event.h>
92680 +#include <linux/sched/sysctl.h>
92681 +
92682 +#ifdef CONFIG_PAX_MPROTECT
92683 +#include <linux/elf.h>
92684 +#include <linux/binfmts.h>
92685 +#endif
92686 +
92687 #include <asm/uaccess.h>
92688 #include <asm/pgtable.h>
92689 #include <asm/cacheflush.h>
92690 #include <asm/tlbflush.h>
92691 +#include <asm/mmu_context.h>
92692
92693 #ifndef pgprot_modify
92694 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
92695 @@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
92696 return pages;
92697 }
92698
92699 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
92700 +/* called while holding the mmap semaphor for writing except stack expansion */
92701 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
92702 +{
92703 + unsigned long oldlimit, newlimit = 0UL;
92704 +
92705 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
92706 + return;
92707 +
92708 + spin_lock(&mm->page_table_lock);
92709 + oldlimit = mm->context.user_cs_limit;
92710 + if ((prot & VM_EXEC) && oldlimit < end)
92711 + /* USER_CS limit moved up */
92712 + newlimit = end;
92713 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
92714 + /* USER_CS limit moved down */
92715 + newlimit = start;
92716 +
92717 + if (newlimit) {
92718 + mm->context.user_cs_limit = newlimit;
92719 +
92720 +#ifdef CONFIG_SMP
92721 + wmb();
92722 + cpus_clear(mm->context.cpu_user_cs_mask);
92723 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
92724 +#endif
92725 +
92726 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
92727 + }
92728 + spin_unlock(&mm->page_table_lock);
92729 + if (newlimit == end) {
92730 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
92731 +
92732 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
92733 + if (is_vm_hugetlb_page(vma))
92734 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
92735 + else
92736 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
92737 + }
92738 +}
92739 +#endif
92740 +
92741 int
92742 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92743 unsigned long start, unsigned long end, unsigned long newflags)
92744 @@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92745 int error;
92746 int dirty_accountable = 0;
92747
92748 +#ifdef CONFIG_PAX_SEGMEXEC
92749 + struct vm_area_struct *vma_m = NULL;
92750 + unsigned long start_m, end_m;
92751 +
92752 + start_m = start + SEGMEXEC_TASK_SIZE;
92753 + end_m = end + SEGMEXEC_TASK_SIZE;
92754 +#endif
92755 +
92756 if (newflags == oldflags) {
92757 *pprev = vma;
92758 return 0;
92759 }
92760
92761 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
92762 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
92763 +
92764 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
92765 + return -ENOMEM;
92766 +
92767 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
92768 + return -ENOMEM;
92769 + }
92770 +
92771 /*
92772 * If we make a private mapping writable we increase our commit;
92773 * but (without finer accounting) cannot reduce our commit if we
92774 @@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92775 }
92776 }
92777
92778 +#ifdef CONFIG_PAX_SEGMEXEC
92779 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
92780 + if (start != vma->vm_start) {
92781 + error = split_vma(mm, vma, start, 1);
92782 + if (error)
92783 + goto fail;
92784 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
92785 + *pprev = (*pprev)->vm_next;
92786 + }
92787 +
92788 + if (end != vma->vm_end) {
92789 + error = split_vma(mm, vma, end, 0);
92790 + if (error)
92791 + goto fail;
92792 + }
92793 +
92794 + if (pax_find_mirror_vma(vma)) {
92795 + error = __do_munmap(mm, start_m, end_m - start_m);
92796 + if (error)
92797 + goto fail;
92798 + } else {
92799 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92800 + if (!vma_m) {
92801 + error = -ENOMEM;
92802 + goto fail;
92803 + }
92804 + vma->vm_flags = newflags;
92805 + error = pax_mirror_vma(vma_m, vma);
92806 + if (error) {
92807 + vma->vm_flags = oldflags;
92808 + goto fail;
92809 + }
92810 + }
92811 + }
92812 +#endif
92813 +
92814 /*
92815 * First try to merge with previous and/or next vma.
92816 */
92817 @@ -285,9 +389,21 @@ success:
92818 * vm_flags and vm_page_prot are protected by the mmap_sem
92819 * held in write mode.
92820 */
92821 +
92822 +#ifdef CONFIG_PAX_SEGMEXEC
92823 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
92824 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
92825 +#endif
92826 +
92827 vma->vm_flags = newflags;
92828 +
92829 +#ifdef CONFIG_PAX_MPROTECT
92830 + if (mm->binfmt && mm->binfmt->handle_mprotect)
92831 + mm->binfmt->handle_mprotect(vma, newflags);
92832 +#endif
92833 +
92834 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
92835 - vm_get_page_prot(newflags));
92836 + vm_get_page_prot(vma->vm_flags));
92837
92838 if (vma_wants_writenotify(vma)) {
92839 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
92840 @@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92841 end = start + len;
92842 if (end <= start)
92843 return -ENOMEM;
92844 +
92845 +#ifdef CONFIG_PAX_SEGMEXEC
92846 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92847 + if (end > SEGMEXEC_TASK_SIZE)
92848 + return -EINVAL;
92849 + } else
92850 +#endif
92851 +
92852 + if (end > TASK_SIZE)
92853 + return -EINVAL;
92854 +
92855 if (!arch_validate_prot(prot))
92856 return -EINVAL;
92857
92858 @@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92859 /*
92860 * Does the application expect PROT_READ to imply PROT_EXEC:
92861 */
92862 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92863 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92864 prot |= PROT_EXEC;
92865
92866 vm_flags = calc_vm_prot_bits(prot);
92867 @@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92868 if (start > vma->vm_start)
92869 prev = vma;
92870
92871 +#ifdef CONFIG_PAX_MPROTECT
92872 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
92873 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
92874 +#endif
92875 +
92876 for (nstart = start ; ; ) {
92877 unsigned long newflags;
92878
92879 @@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92880
92881 /* newflags >> 4 shift VM_MAY% in place of VM_% */
92882 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
92883 + if (prot & (PROT_WRITE | PROT_EXEC))
92884 + gr_log_rwxmprotect(vma);
92885 +
92886 + error = -EACCES;
92887 + goto out;
92888 + }
92889 +
92890 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
92891 error = -EACCES;
92892 goto out;
92893 }
92894 @@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92895 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
92896 if (error)
92897 goto out;
92898 +
92899 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
92900 +
92901 nstart = tmp;
92902
92903 if (nstart < prev->vm_end)
92904 diff --git a/mm/mremap.c b/mm/mremap.c
92905 index 0843feb..4f5b2e6 100644
92906 --- a/mm/mremap.c
92907 +++ b/mm/mremap.c
92908 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
92909 continue;
92910 pte = ptep_get_and_clear(mm, old_addr, old_pte);
92911 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
92912 +
92913 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
92914 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
92915 + pte = pte_exprotect(pte);
92916 +#endif
92917 +
92918 pte = move_soft_dirty_pte(pte);
92919 set_pte_at(mm, new_addr, new_pte, pte);
92920 }
92921 @@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
92922 if (is_vm_hugetlb_page(vma))
92923 goto Einval;
92924
92925 +#ifdef CONFIG_PAX_SEGMEXEC
92926 + if (pax_find_mirror_vma(vma))
92927 + goto Einval;
92928 +#endif
92929 +
92930 /* We can't remap across vm area boundaries */
92931 if (old_len > vma->vm_end - addr)
92932 goto Efault;
92933 @@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
92934 unsigned long ret = -EINVAL;
92935 unsigned long charged = 0;
92936 unsigned long map_flags;
92937 + unsigned long pax_task_size = TASK_SIZE;
92938
92939 if (new_addr & ~PAGE_MASK)
92940 goto out;
92941
92942 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
92943 +#ifdef CONFIG_PAX_SEGMEXEC
92944 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
92945 + pax_task_size = SEGMEXEC_TASK_SIZE;
92946 +#endif
92947 +
92948 + pax_task_size -= PAGE_SIZE;
92949 +
92950 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
92951 goto out;
92952
92953 /* Check if the location we're moving into overlaps the
92954 * old location at all, and fail if it does.
92955 */
92956 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
92957 - goto out;
92958 -
92959 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
92960 + if (addr + old_len > new_addr && new_addr + new_len > addr)
92961 goto out;
92962
92963 ret = do_munmap(mm, new_addr, new_len);
92964 @@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92965 unsigned long ret = -EINVAL;
92966 unsigned long charged = 0;
92967 bool locked = false;
92968 + unsigned long pax_task_size = TASK_SIZE;
92969
92970 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
92971 return ret;
92972 @@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92973 if (!new_len)
92974 return ret;
92975
92976 +#ifdef CONFIG_PAX_SEGMEXEC
92977 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
92978 + pax_task_size = SEGMEXEC_TASK_SIZE;
92979 +#endif
92980 +
92981 + pax_task_size -= PAGE_SIZE;
92982 +
92983 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
92984 + old_len > pax_task_size || addr > pax_task_size-old_len)
92985 + return ret;
92986 +
92987 down_write(&current->mm->mmap_sem);
92988
92989 if (flags & MREMAP_FIXED) {
92990 @@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92991 new_addr = addr;
92992 }
92993 ret = addr;
92994 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
92995 goto out;
92996 }
92997 }
92998 @@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
92999 goto out;
93000 }
93001
93002 + map_flags = vma->vm_flags;
93003 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
93004 + if (!(ret & ~PAGE_MASK)) {
93005 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
93006 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
93007 + }
93008 }
93009 out:
93010 if (ret & ~PAGE_MASK)
93011 diff --git a/mm/nommu.c b/mm/nommu.c
93012 index fec093a..8162f74 100644
93013 --- a/mm/nommu.c
93014 +++ b/mm/nommu.c
93015 @@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
93016 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
93017 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93018 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93019 -int heap_stack_gap = 0;
93020
93021 atomic_long_t mmap_pages_allocated;
93022
93023 @@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
93024 EXPORT_SYMBOL(find_vma);
93025
93026 /*
93027 - * find a VMA
93028 - * - we don't extend stack VMAs under NOMMU conditions
93029 - */
93030 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
93031 -{
93032 - return find_vma(mm, addr);
93033 -}
93034 -
93035 -/*
93036 * expand a stack to a given address
93037 * - not supported under NOMMU conditions
93038 */
93039 @@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93040
93041 /* most fields are the same, copy all, and then fixup */
93042 *new = *vma;
93043 + INIT_LIST_HEAD(&new->anon_vma_chain);
93044 *region = *vma->vm_region;
93045 new->vm_region = region;
93046
93047 @@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
93048 }
93049 EXPORT_SYMBOL(generic_file_remap_pages);
93050
93051 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93052 - unsigned long addr, void *buf, int len, int write)
93053 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93054 + unsigned long addr, void *buf, size_t len, int write)
93055 {
93056 struct vm_area_struct *vma;
93057
93058 @@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93059 *
93060 * The caller must hold a reference on @mm.
93061 */
93062 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93063 - void *buf, int len, int write)
93064 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93065 + void *buf, size_t len, int write)
93066 {
93067 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93068 }
93069 @@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93070 * Access another process' address space.
93071 * - source/target buffer must be kernel space
93072 */
93073 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
93074 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
93075 {
93076 struct mm_struct *mm;
93077
93078 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
93079 index 6380758..4064aec 100644
93080 --- a/mm/page-writeback.c
93081 +++ b/mm/page-writeback.c
93082 @@ -690,7 +690,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
93083 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
93084 * - the bdi dirty thresh drops quickly due to change of JBOD workload
93085 */
93086 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
93087 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
93088 unsigned long thresh,
93089 unsigned long bg_thresh,
93090 unsigned long dirty,
93091 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
93092 index 5248fe0..0f693aa 100644
93093 --- a/mm/page_alloc.c
93094 +++ b/mm/page_alloc.c
93095 @@ -61,6 +61,7 @@
93096 #include <linux/page-debug-flags.h>
93097 #include <linux/hugetlb.h>
93098 #include <linux/sched/rt.h>
93099 +#include <linux/random.h>
93100
93101 #include <asm/sections.h>
93102 #include <asm/tlbflush.h>
93103 @@ -354,7 +355,7 @@ out:
93104 * This usage means that zero-order pages may not be compound.
93105 */
93106
93107 -static void free_compound_page(struct page *page)
93108 +void free_compound_page(struct page *page)
93109 {
93110 __free_pages_ok(page, compound_order(page));
93111 }
93112 @@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93113 int i;
93114 int bad = 0;
93115
93116 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93117 + unsigned long index = 1UL << order;
93118 +#endif
93119 +
93120 trace_mm_page_free(page, order);
93121 kmemcheck_free_shadow(page, order);
93122
93123 @@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93124 debug_check_no_obj_freed(page_address(page),
93125 PAGE_SIZE << order);
93126 }
93127 +
93128 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93129 + for (; index; --index)
93130 + sanitize_highpage(page + index - 1);
93131 +#endif
93132 +
93133 arch_free_page(page, order);
93134 kernel_map_pages(page, 1 << order, 0);
93135
93136 @@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
93137 local_irq_restore(flags);
93138 }
93139
93140 +#ifdef CONFIG_PAX_LATENT_ENTROPY
93141 +bool __meminitdata extra_latent_entropy;
93142 +
93143 +static int __init setup_pax_extra_latent_entropy(char *str)
93144 +{
93145 + extra_latent_entropy = true;
93146 + return 0;
93147 +}
93148 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
93149 +
93150 +volatile u64 latent_entropy __latent_entropy;
93151 +EXPORT_SYMBOL(latent_entropy);
93152 +#endif
93153 +
93154 void __init __free_pages_bootmem(struct page *page, unsigned int order)
93155 {
93156 unsigned int nr_pages = 1 << order;
93157 @@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
93158 __ClearPageReserved(p);
93159 set_page_count(p, 0);
93160
93161 +#ifdef CONFIG_PAX_LATENT_ENTROPY
93162 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
93163 + u64 hash = 0;
93164 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
93165 + const u64 *data = lowmem_page_address(page);
93166 +
93167 + for (index = 0; index < end; index++)
93168 + hash ^= hash + data[index];
93169 + latent_entropy ^= hash;
93170 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
93171 + }
93172 +#endif
93173 +
93174 page_zone(page)->managed_pages += nr_pages;
93175 set_page_refcounted(page);
93176 __free_pages(page, order);
93177 @@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
93178 arch_alloc_page(page, order);
93179 kernel_map_pages(page, 1 << order, 1);
93180
93181 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
93182 if (gfp_flags & __GFP_ZERO)
93183 prep_zero_page(page, order, gfp_flags);
93184 +#endif
93185
93186 if (order && (gfp_flags & __GFP_COMP))
93187 prep_compound_page(page, order);
93188 diff --git a/mm/page_io.c b/mm/page_io.c
93189 index 8c79a47..a689e0d 100644
93190 --- a/mm/page_io.c
93191 +++ b/mm/page_io.c
93192 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
93193 struct file *swap_file = sis->swap_file;
93194 struct address_space *mapping = swap_file->f_mapping;
93195 struct iovec iov = {
93196 - .iov_base = kmap(page),
93197 + .iov_base = (void __force_user *)kmap(page),
93198 .iov_len = PAGE_SIZE,
93199 };
93200
93201 diff --git a/mm/percpu.c b/mm/percpu.c
93202 index 0d10def..6dc822d 100644
93203 --- a/mm/percpu.c
93204 +++ b/mm/percpu.c
93205 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
93206 static unsigned int pcpu_high_unit_cpu __read_mostly;
93207
93208 /* the address of the first chunk which starts with the kernel static area */
93209 -void *pcpu_base_addr __read_mostly;
93210 +void *pcpu_base_addr __read_only;
93211 EXPORT_SYMBOL_GPL(pcpu_base_addr);
93212
93213 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
93214 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
93215 index fd26d04..0cea1b0 100644
93216 --- a/mm/process_vm_access.c
93217 +++ b/mm/process_vm_access.c
93218 @@ -13,6 +13,7 @@
93219 #include <linux/uio.h>
93220 #include <linux/sched.h>
93221 #include <linux/highmem.h>
93222 +#include <linux/security.h>
93223 #include <linux/ptrace.h>
93224 #include <linux/slab.h>
93225 #include <linux/syscalls.h>
93226 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93227 size_t iov_l_curr_offset = 0;
93228 ssize_t iov_len;
93229
93230 + return -ENOSYS; // PaX: until properly audited
93231 +
93232 /*
93233 * Work out how many pages of struct pages we're going to need
93234 * when eventually calling get_user_pages
93235 */
93236 for (i = 0; i < riovcnt; i++) {
93237 iov_len = rvec[i].iov_len;
93238 - if (iov_len > 0) {
93239 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
93240 - + iov_len)
93241 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
93242 - / PAGE_SIZE + 1;
93243 - nr_pages = max(nr_pages, nr_pages_iov);
93244 - }
93245 + if (iov_len <= 0)
93246 + continue;
93247 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
93248 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
93249 + nr_pages = max(nr_pages, nr_pages_iov);
93250 }
93251
93252 if (nr_pages == 0)
93253 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93254 goto free_proc_pages;
93255 }
93256
93257 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
93258 + rc = -EPERM;
93259 + goto put_task_struct;
93260 + }
93261 +
93262 mm = mm_access(task, PTRACE_MODE_ATTACH);
93263 if (!mm || IS_ERR(mm)) {
93264 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
93265 diff --git a/mm/rmap.c b/mm/rmap.c
93266 index 068522d..f539f21 100644
93267 --- a/mm/rmap.c
93268 +++ b/mm/rmap.c
93269 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93270 struct anon_vma *anon_vma = vma->anon_vma;
93271 struct anon_vma_chain *avc;
93272
93273 +#ifdef CONFIG_PAX_SEGMEXEC
93274 + struct anon_vma_chain *avc_m = NULL;
93275 +#endif
93276 +
93277 might_sleep();
93278 if (unlikely(!anon_vma)) {
93279 struct mm_struct *mm = vma->vm_mm;
93280 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93281 if (!avc)
93282 goto out_enomem;
93283
93284 +#ifdef CONFIG_PAX_SEGMEXEC
93285 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
93286 + if (!avc_m)
93287 + goto out_enomem_free_avc;
93288 +#endif
93289 +
93290 anon_vma = find_mergeable_anon_vma(vma);
93291 allocated = NULL;
93292 if (!anon_vma) {
93293 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93294 /* page_table_lock to protect against threads */
93295 spin_lock(&mm->page_table_lock);
93296 if (likely(!vma->anon_vma)) {
93297 +
93298 +#ifdef CONFIG_PAX_SEGMEXEC
93299 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
93300 +
93301 + if (vma_m) {
93302 + BUG_ON(vma_m->anon_vma);
93303 + vma_m->anon_vma = anon_vma;
93304 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
93305 + avc_m = NULL;
93306 + }
93307 +#endif
93308 +
93309 vma->anon_vma = anon_vma;
93310 anon_vma_chain_link(vma, avc, anon_vma);
93311 allocated = NULL;
93312 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93313
93314 if (unlikely(allocated))
93315 put_anon_vma(allocated);
93316 +
93317 +#ifdef CONFIG_PAX_SEGMEXEC
93318 + if (unlikely(avc_m))
93319 + anon_vma_chain_free(avc_m);
93320 +#endif
93321 +
93322 if (unlikely(avc))
93323 anon_vma_chain_free(avc);
93324 }
93325 return 0;
93326
93327 out_enomem_free_avc:
93328 +
93329 +#ifdef CONFIG_PAX_SEGMEXEC
93330 + if (avc_m)
93331 + anon_vma_chain_free(avc_m);
93332 +#endif
93333 +
93334 anon_vma_chain_free(avc);
93335 out_enomem:
93336 return -ENOMEM;
93337 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
93338 * Attach the anon_vmas from src to dst.
93339 * Returns 0 on success, -ENOMEM on failure.
93340 */
93341 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93342 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
93343 {
93344 struct anon_vma_chain *avc, *pavc;
93345 struct anon_vma *root = NULL;
93346 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93347 * the corresponding VMA in the parent process is attached to.
93348 * Returns 0 on success, non-zero on failure.
93349 */
93350 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
93351 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
93352 {
93353 struct anon_vma_chain *avc;
93354 struct anon_vma *anon_vma;
93355 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
93356 void __init anon_vma_init(void)
93357 {
93358 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
93359 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
93360 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
93361 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
93362 + anon_vma_ctor);
93363 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
93364 + SLAB_PANIC|SLAB_NO_SANITIZE);
93365 }
93366
93367 /*
93368 diff --git a/mm/shmem.c b/mm/shmem.c
93369 index 902a148..58f9d59 100644
93370 --- a/mm/shmem.c
93371 +++ b/mm/shmem.c
93372 @@ -33,7 +33,7 @@
93373 #include <linux/swap.h>
93374 #include <linux/aio.h>
93375
93376 -static struct vfsmount *shm_mnt;
93377 +struct vfsmount *shm_mnt;
93378
93379 #ifdef CONFIG_SHMEM
93380 /*
93381 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
93382 #define BOGO_DIRENT_SIZE 20
93383
93384 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
93385 -#define SHORT_SYMLINK_LEN 128
93386 +#define SHORT_SYMLINK_LEN 64
93387
93388 /*
93389 * shmem_fallocate and shmem_writepage communicate via inode->i_private
93390 @@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
93391 static int shmem_xattr_validate(const char *name)
93392 {
93393 struct { const char *prefix; size_t len; } arr[] = {
93394 +
93395 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93396 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
93397 +#endif
93398 +
93399 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
93400 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
93401 };
93402 @@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
93403 if (err)
93404 return err;
93405
93406 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93407 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
93408 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
93409 + return -EOPNOTSUPP;
93410 + if (size > 8)
93411 + return -EINVAL;
93412 + }
93413 +#endif
93414 +
93415 return simple_xattr_set(&info->xattrs, name, value, size, flags);
93416 }
93417
93418 @@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
93419 int err = -ENOMEM;
93420
93421 /* Round up to L1_CACHE_BYTES to resist false sharing */
93422 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
93423 - L1_CACHE_BYTES), GFP_KERNEL);
93424 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
93425 if (!sbinfo)
93426 return -ENOMEM;
93427
93428 diff --git a/mm/slab.c b/mm/slab.c
93429 index eb043bf..d82f5a8 100644
93430 --- a/mm/slab.c
93431 +++ b/mm/slab.c
93432 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93433 if ((x)->max_freeable < i) \
93434 (x)->max_freeable = i; \
93435 } while (0)
93436 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
93437 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
93438 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
93439 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
93440 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
93441 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
93442 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
93443 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
93444 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
93445 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
93446 #else
93447 #define STATS_INC_ACTIVE(x) do { } while (0)
93448 #define STATS_DEC_ACTIVE(x) do { } while (0)
93449 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93450 #define STATS_INC_ALLOCMISS(x) do { } while (0)
93451 #define STATS_INC_FREEHIT(x) do { } while (0)
93452 #define STATS_INC_FREEMISS(x) do { } while (0)
93453 +#define STATS_INC_SANITIZED(x) do { } while (0)
93454 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
93455 #endif
93456
93457 #if DEBUG
93458 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
93459 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
93460 */
93461 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
93462 - const struct page *page, void *obj)
93463 + const struct page *page, const void *obj)
93464 {
93465 u32 offset = (obj - page->s_mem);
93466 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
93467 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
93468 */
93469
93470 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
93471 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
93472 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93473
93474 if (INDEX_AC != INDEX_NODE)
93475 kmalloc_caches[INDEX_NODE] =
93476 create_kmalloc_cache("kmalloc-node",
93477 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
93478 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93479
93480 slab_early_init = 0;
93481
93482 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
93483 struct array_cache *ac = cpu_cache_get(cachep);
93484
93485 check_irq_off();
93486 +
93487 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93488 + if (pax_sanitize_slab) {
93489 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
93490 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
93491 +
93492 + if (cachep->ctor)
93493 + cachep->ctor(objp);
93494 +
93495 + STATS_INC_SANITIZED(cachep);
93496 + } else
93497 + STATS_INC_NOT_SANITIZED(cachep);
93498 + }
93499 +#endif
93500 +
93501 kmemleak_free_recursive(objp, cachep->flags);
93502 objp = cache_free_debugcheck(cachep, objp, caller);
93503
93504 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
93505
93506 if (unlikely(ZERO_OR_NULL_PTR(objp)))
93507 return;
93508 + VM_BUG_ON(!virt_addr_valid(objp));
93509 local_irq_save(flags);
93510 kfree_debugcheck(objp);
93511 c = virt_to_cache(objp);
93512 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
93513 }
93514 /* cpu stats */
93515 {
93516 - unsigned long allochit = atomic_read(&cachep->allochit);
93517 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
93518 - unsigned long freehit = atomic_read(&cachep->freehit);
93519 - unsigned long freemiss = atomic_read(&cachep->freemiss);
93520 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
93521 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
93522 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
93523 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
93524
93525 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
93526 allochit, allocmiss, freehit, freemiss);
93527 }
93528 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93529 + {
93530 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
93531 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
93532 +
93533 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
93534 + }
93535 +#endif
93536 #endif
93537 }
93538
93539 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
93540 static int __init slab_proc_init(void)
93541 {
93542 #ifdef CONFIG_DEBUG_SLAB_LEAK
93543 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
93544 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
93545 #endif
93546 return 0;
93547 }
93548 module_init(slab_proc_init);
93549 #endif
93550
93551 +bool is_usercopy_object(const void *ptr)
93552 +{
93553 + struct page *page;
93554 + struct kmem_cache *cachep;
93555 +
93556 + if (ZERO_OR_NULL_PTR(ptr))
93557 + return false;
93558 +
93559 + if (!slab_is_available())
93560 + return false;
93561 +
93562 + if (!virt_addr_valid(ptr))
93563 + return false;
93564 +
93565 + page = virt_to_head_page(ptr);
93566 +
93567 + if (!PageSlab(page))
93568 + return false;
93569 +
93570 + cachep = page->slab_cache;
93571 + return cachep->flags & SLAB_USERCOPY;
93572 +}
93573 +
93574 +#ifdef CONFIG_PAX_USERCOPY
93575 +const char *check_heap_object(const void *ptr, unsigned long n)
93576 +{
93577 + struct page *page;
93578 + struct kmem_cache *cachep;
93579 + unsigned int objnr;
93580 + unsigned long offset;
93581 +
93582 + if (ZERO_OR_NULL_PTR(ptr))
93583 + return "<null>";
93584 +
93585 + if (!virt_addr_valid(ptr))
93586 + return NULL;
93587 +
93588 + page = virt_to_head_page(ptr);
93589 +
93590 + if (!PageSlab(page))
93591 + return NULL;
93592 +
93593 + cachep = page->slab_cache;
93594 + if (!(cachep->flags & SLAB_USERCOPY))
93595 + return cachep->name;
93596 +
93597 + objnr = obj_to_index(cachep, page, ptr);
93598 + BUG_ON(objnr >= cachep->num);
93599 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
93600 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
93601 + return NULL;
93602 +
93603 + return cachep->name;
93604 +}
93605 +#endif
93606 +
93607 /**
93608 * ksize - get the actual amount of memory allocated for a given object
93609 * @objp: Pointer to the object
93610 diff --git a/mm/slab.h b/mm/slab.h
93611 index 0859c42..2f7b737 100644
93612 --- a/mm/slab.h
93613 +++ b/mm/slab.h
93614 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
93615 /* The slab cache that manages slab cache information */
93616 extern struct kmem_cache *kmem_cache;
93617
93618 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93619 +#ifdef CONFIG_X86_64
93620 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
93621 +#else
93622 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
93623 +#endif
93624 +extern bool pax_sanitize_slab;
93625 +#endif
93626 +
93627 unsigned long calculate_alignment(unsigned long flags,
93628 unsigned long align, unsigned long size);
93629
93630 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
93631
93632 /* Legal flag mask for kmem_cache_create(), for various configurations */
93633 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
93634 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
93635 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
93636 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
93637
93638 #if defined(CONFIG_DEBUG_SLAB)
93639 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
93640 @@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
93641 return s;
93642
93643 page = virt_to_head_page(x);
93644 +
93645 + BUG_ON(!PageSlab(page));
93646 +
93647 cachep = page->slab_cache;
93648 if (slab_equal_or_root(cachep, s))
93649 return cachep;
93650 diff --git a/mm/slab_common.c b/mm/slab_common.c
93651 index 0b7bb39..334c328 100644
93652 --- a/mm/slab_common.c
93653 +++ b/mm/slab_common.c
93654 @@ -23,11 +23,22 @@
93655
93656 #include "slab.h"
93657
93658 -enum slab_state slab_state;
93659 +enum slab_state slab_state __read_only;
93660 LIST_HEAD(slab_caches);
93661 DEFINE_MUTEX(slab_mutex);
93662 struct kmem_cache *kmem_cache;
93663
93664 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93665 +bool pax_sanitize_slab __read_only = true;
93666 +static int __init pax_sanitize_slab_setup(char *str)
93667 +{
93668 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
93669 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
93670 + return 1;
93671 +}
93672 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
93673 +#endif
93674 +
93675 #ifdef CONFIG_DEBUG_VM
93676 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
93677 size_t size)
93678 @@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
93679
93680 err = __kmem_cache_create(s, flags);
93681 if (!err) {
93682 - s->refcount = 1;
93683 + atomic_set(&s->refcount, 1);
93684 list_add(&s->list, &slab_caches);
93685 memcg_cache_list_add(memcg, s);
93686 } else {
93687 @@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
93688
93689 get_online_cpus();
93690 mutex_lock(&slab_mutex);
93691 - s->refcount--;
93692 - if (!s->refcount) {
93693 + if (atomic_dec_and_test(&s->refcount)) {
93694 list_del(&s->list);
93695
93696 if (!__kmem_cache_shutdown(s)) {
93697 @@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
93698 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
93699 name, size, err);
93700
93701 - s->refcount = -1; /* Exempt from merging for now */
93702 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
93703 }
93704
93705 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93706 @@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93707
93708 create_boot_cache(s, name, size, flags);
93709 list_add(&s->list, &slab_caches);
93710 - s->refcount = 1;
93711 + atomic_set(&s->refcount, 1);
93712 return s;
93713 }
93714
93715 @@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
93716 EXPORT_SYMBOL(kmalloc_dma_caches);
93717 #endif
93718
93719 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93720 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
93721 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
93722 +#endif
93723 +
93724 /*
93725 * Conversion table for small slabs sizes / 8 to the index in the
93726 * kmalloc array. This is necessary for slabs < 192 since we have non power
93727 @@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
93728 return kmalloc_dma_caches[index];
93729
93730 #endif
93731 +
93732 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93733 + if (unlikely((flags & GFP_USERCOPY)))
93734 + return kmalloc_usercopy_caches[index];
93735 +
93736 +#endif
93737 +
93738 return kmalloc_caches[index];
93739 }
93740
93741 @@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
93742 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
93743 if (!kmalloc_caches[i]) {
93744 kmalloc_caches[i] = create_kmalloc_cache(NULL,
93745 - 1 << i, flags);
93746 + 1 << i, SLAB_USERCOPY | flags);
93747 }
93748
93749 /*
93750 @@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
93751 * earlier power of two caches
93752 */
93753 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
93754 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
93755 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
93756
93757 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
93758 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
93759 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
93760 }
93761
93762 /* Kmalloc array is now usable */
93763 @@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
93764 }
93765 }
93766 #endif
93767 +
93768 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93769 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
93770 + struct kmem_cache *s = kmalloc_caches[i];
93771 +
93772 + if (s) {
93773 + int size = kmalloc_size(i);
93774 + char *n = kasprintf(GFP_NOWAIT,
93775 + "usercopy-kmalloc-%d", size);
93776 +
93777 + BUG_ON(!n);
93778 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
93779 + size, SLAB_USERCOPY | flags);
93780 + }
93781 + }
93782 +#endif
93783 +
93784 }
93785 #endif /* !CONFIG_SLOB */
93786
93787 @@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
93788 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
93789 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
93790 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
93791 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93792 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
93793 +#endif
93794 #endif
93795 seq_putc(m, '\n');
93796 }
93797 diff --git a/mm/slob.c b/mm/slob.c
93798 index 4bf8809..98a6914 100644
93799 --- a/mm/slob.c
93800 +++ b/mm/slob.c
93801 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
93802 /*
93803 * Return the size of a slob block.
93804 */
93805 -static slobidx_t slob_units(slob_t *s)
93806 +static slobidx_t slob_units(const slob_t *s)
93807 {
93808 if (s->units > 0)
93809 return s->units;
93810 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
93811 /*
93812 * Return the next free slob block pointer after this one.
93813 */
93814 -static slob_t *slob_next(slob_t *s)
93815 +static slob_t *slob_next(const slob_t *s)
93816 {
93817 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
93818 slobidx_t next;
93819 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
93820 /*
93821 * Returns true if s is the last free block in its page.
93822 */
93823 -static int slob_last(slob_t *s)
93824 +static int slob_last(const slob_t *s)
93825 {
93826 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
93827 }
93828
93829 -static void *slob_new_pages(gfp_t gfp, int order, int node)
93830 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
93831 {
93832 - void *page;
93833 + struct page *page;
93834
93835 #ifdef CONFIG_NUMA
93836 if (node != NUMA_NO_NODE)
93837 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
93838 if (!page)
93839 return NULL;
93840
93841 - return page_address(page);
93842 + __SetPageSlab(page);
93843 + return page;
93844 }
93845
93846 -static void slob_free_pages(void *b, int order)
93847 +static void slob_free_pages(struct page *sp, int order)
93848 {
93849 if (current->reclaim_state)
93850 current->reclaim_state->reclaimed_slab += 1 << order;
93851 - free_pages((unsigned long)b, order);
93852 + __ClearPageSlab(sp);
93853 + page_mapcount_reset(sp);
93854 + sp->private = 0;
93855 + __free_pages(sp, order);
93856 }
93857
93858 /*
93859 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
93860
93861 /* Not enough space: must allocate a new page */
93862 if (!b) {
93863 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
93864 - if (!b)
93865 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
93866 + if (!sp)
93867 return NULL;
93868 - sp = virt_to_page(b);
93869 - __SetPageSlab(sp);
93870 + b = page_address(sp);
93871
93872 spin_lock_irqsave(&slob_lock, flags);
93873 sp->units = SLOB_UNITS(PAGE_SIZE);
93874 sp->freelist = b;
93875 + sp->private = 0;
93876 INIT_LIST_HEAD(&sp->list);
93877 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
93878 set_slob_page_free(sp, slob_list);
93879 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
93880 if (slob_page_free(sp))
93881 clear_slob_page_free(sp);
93882 spin_unlock_irqrestore(&slob_lock, flags);
93883 - __ClearPageSlab(sp);
93884 - page_mapcount_reset(sp);
93885 - slob_free_pages(b, 0);
93886 + slob_free_pages(sp, 0);
93887 return;
93888 }
93889
93890 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93891 + if (pax_sanitize_slab)
93892 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
93893 +#endif
93894 +
93895 if (!slob_page_free(sp)) {
93896 /* This slob page is about to become partially free. Easy! */
93897 sp->units = units;
93898 @@ -424,11 +431,10 @@ out:
93899 */
93900
93901 static __always_inline void *
93902 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
93903 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
93904 {
93905 - unsigned int *m;
93906 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
93907 - void *ret;
93908 + slob_t *m;
93909 + void *ret = NULL;
93910
93911 gfp &= gfp_allowed_mask;
93912
93913 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
93914
93915 if (!m)
93916 return NULL;
93917 - *m = size;
93918 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
93919 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
93920 + m[0].units = size;
93921 + m[1].units = align;
93922 ret = (void *)m + align;
93923
93924 trace_kmalloc_node(caller, ret,
93925 size, size + align, gfp, node);
93926 } else {
93927 unsigned int order = get_order(size);
93928 + struct page *page;
93929
93930 if (likely(order))
93931 gfp |= __GFP_COMP;
93932 - ret = slob_new_pages(gfp, order, node);
93933 + page = slob_new_pages(gfp, order, node);
93934 + if (page) {
93935 + ret = page_address(page);
93936 + page->private = size;
93937 + }
93938
93939 trace_kmalloc_node(caller, ret,
93940 size, PAGE_SIZE << order, gfp, node);
93941 }
93942
93943 - kmemleak_alloc(ret, size, 1, gfp);
93944 + return ret;
93945 +}
93946 +
93947 +static __always_inline void *
93948 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
93949 +{
93950 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
93951 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
93952 +
93953 + if (!ZERO_OR_NULL_PTR(ret))
93954 + kmemleak_alloc(ret, size, 1, gfp);
93955 return ret;
93956 }
93957
93958 @@ -493,34 +517,112 @@ void kfree(const void *block)
93959 return;
93960 kmemleak_free(block);
93961
93962 + VM_BUG_ON(!virt_addr_valid(block));
93963 sp = virt_to_page(block);
93964 - if (PageSlab(sp)) {
93965 + VM_BUG_ON(!PageSlab(sp));
93966 + if (!sp->private) {
93967 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
93968 - unsigned int *m = (unsigned int *)(block - align);
93969 - slob_free(m, *m + align);
93970 - } else
93971 + slob_t *m = (slob_t *)(block - align);
93972 + slob_free(m, m[0].units + align);
93973 + } else {
93974 + __ClearPageSlab(sp);
93975 + page_mapcount_reset(sp);
93976 + sp->private = 0;
93977 __free_pages(sp, compound_order(sp));
93978 + }
93979 }
93980 EXPORT_SYMBOL(kfree);
93981
93982 +bool is_usercopy_object(const void *ptr)
93983 +{
93984 + if (!slab_is_available())
93985 + return false;
93986 +
93987 + // PAX: TODO
93988 +
93989 + return false;
93990 +}
93991 +
93992 +#ifdef CONFIG_PAX_USERCOPY
93993 +const char *check_heap_object(const void *ptr, unsigned long n)
93994 +{
93995 + struct page *page;
93996 + const slob_t *free;
93997 + const void *base;
93998 + unsigned long flags;
93999 +
94000 + if (ZERO_OR_NULL_PTR(ptr))
94001 + return "<null>";
94002 +
94003 + if (!virt_addr_valid(ptr))
94004 + return NULL;
94005 +
94006 + page = virt_to_head_page(ptr);
94007 + if (!PageSlab(page))
94008 + return NULL;
94009 +
94010 + if (page->private) {
94011 + base = page;
94012 + if (base <= ptr && n <= page->private - (ptr - base))
94013 + return NULL;
94014 + return "<slob>";
94015 + }
94016 +
94017 + /* some tricky double walking to find the chunk */
94018 + spin_lock_irqsave(&slob_lock, flags);
94019 + base = (void *)((unsigned long)ptr & PAGE_MASK);
94020 + free = page->freelist;
94021 +
94022 + while (!slob_last(free) && (void *)free <= ptr) {
94023 + base = free + slob_units(free);
94024 + free = slob_next(free);
94025 + }
94026 +
94027 + while (base < (void *)free) {
94028 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
94029 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
94030 + int offset;
94031 +
94032 + if (ptr < base + align)
94033 + break;
94034 +
94035 + offset = ptr - base - align;
94036 + if (offset >= m) {
94037 + base += size;
94038 + continue;
94039 + }
94040 +
94041 + if (n > m - offset)
94042 + break;
94043 +
94044 + spin_unlock_irqrestore(&slob_lock, flags);
94045 + return NULL;
94046 + }
94047 +
94048 + spin_unlock_irqrestore(&slob_lock, flags);
94049 + return "<slob>";
94050 +}
94051 +#endif
94052 +
94053 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
94054 size_t ksize(const void *block)
94055 {
94056 struct page *sp;
94057 int align;
94058 - unsigned int *m;
94059 + slob_t *m;
94060
94061 BUG_ON(!block);
94062 if (unlikely(block == ZERO_SIZE_PTR))
94063 return 0;
94064
94065 sp = virt_to_page(block);
94066 - if (unlikely(!PageSlab(sp)))
94067 - return PAGE_SIZE << compound_order(sp);
94068 + VM_BUG_ON(!PageSlab(sp));
94069 + if (sp->private)
94070 + return sp->private;
94071
94072 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94073 - m = (unsigned int *)(block - align);
94074 - return SLOB_UNITS(*m) * SLOB_UNIT;
94075 + m = (slob_t *)(block - align);
94076 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
94077 }
94078 EXPORT_SYMBOL(ksize);
94079
94080 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
94081
94082 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
94083 {
94084 - void *b;
94085 + void *b = NULL;
94086
94087 flags &= gfp_allowed_mask;
94088
94089 lockdep_trace_alloc(flags);
94090
94091 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94092 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
94093 +#else
94094 if (c->size < PAGE_SIZE) {
94095 b = slob_alloc(c->size, flags, c->align, node);
94096 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94097 SLOB_UNITS(c->size) * SLOB_UNIT,
94098 flags, node);
94099 } else {
94100 - b = slob_new_pages(flags, get_order(c->size), node);
94101 + struct page *sp;
94102 +
94103 + sp = slob_new_pages(flags, get_order(c->size), node);
94104 + if (sp) {
94105 + b = page_address(sp);
94106 + sp->private = c->size;
94107 + }
94108 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94109 PAGE_SIZE << get_order(c->size),
94110 flags, node);
94111 }
94112 +#endif
94113
94114 if (b && c->ctor)
94115 c->ctor(b);
94116 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
94117
94118 static void __kmem_cache_free(void *b, int size)
94119 {
94120 - if (size < PAGE_SIZE)
94121 + struct page *sp;
94122 +
94123 + sp = virt_to_page(b);
94124 + BUG_ON(!PageSlab(sp));
94125 + if (!sp->private)
94126 slob_free(b, size);
94127 else
94128 - slob_free_pages(b, get_order(size));
94129 + slob_free_pages(sp, get_order(size));
94130 }
94131
94132 static void kmem_rcu_free(struct rcu_head *head)
94133 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
94134
94135 void kmem_cache_free(struct kmem_cache *c, void *b)
94136 {
94137 + int size = c->size;
94138 +
94139 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94140 + if (size + c->align < PAGE_SIZE) {
94141 + size += c->align;
94142 + b -= c->align;
94143 + }
94144 +#endif
94145 +
94146 kmemleak_free_recursive(b, c->flags);
94147 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
94148 struct slob_rcu *slob_rcu;
94149 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
94150 - slob_rcu->size = c->size;
94151 + slob_rcu = b + (size - sizeof(struct slob_rcu));
94152 + slob_rcu->size = size;
94153 call_rcu(&slob_rcu->head, kmem_rcu_free);
94154 } else {
94155 - __kmem_cache_free(b, c->size);
94156 + __kmem_cache_free(b, size);
94157 }
94158
94159 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94160 + trace_kfree(_RET_IP_, b);
94161 +#else
94162 trace_kmem_cache_free(_RET_IP_, b);
94163 +#endif
94164 +
94165 }
94166 EXPORT_SYMBOL(kmem_cache_free);
94167
94168 diff --git a/mm/slub.c b/mm/slub.c
94169 index 545a170..a086226 100644
94170 --- a/mm/slub.c
94171 +++ b/mm/slub.c
94172 @@ -207,7 +207,7 @@ struct track {
94173
94174 enum track_item { TRACK_ALLOC, TRACK_FREE };
94175
94176 -#ifdef CONFIG_SYSFS
94177 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94178 static int sysfs_slab_add(struct kmem_cache *);
94179 static int sysfs_slab_alias(struct kmem_cache *, const char *);
94180 static void sysfs_slab_remove(struct kmem_cache *);
94181 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
94182 if (!t->addr)
94183 return;
94184
94185 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
94186 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
94187 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
94188 #ifdef CONFIG_STACKTRACE
94189 {
94190 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
94191
94192 slab_free_hook(s, x);
94193
94194 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94195 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
94196 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
94197 + if (s->ctor)
94198 + s->ctor(x);
94199 + }
94200 +#endif
94201 +
94202 redo:
94203 /*
94204 * Determine the currently cpus per cpu slab.
94205 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
94206 * Merge control. If this is set then no merging of slab caches will occur.
94207 * (Could be removed. This was introduced to pacify the merge skeptics.)
94208 */
94209 -static int slub_nomerge;
94210 +static int slub_nomerge = 1;
94211
94212 /*
94213 * Calculate the order of allocation given an slab object size.
94214 @@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
94215 s->inuse = size;
94216
94217 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
94218 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94219 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
94220 +#endif
94221 s->ctor)) {
94222 /*
94223 * Relocate free pointer after the object if it is not
94224 @@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
94225 EXPORT_SYMBOL(__kmalloc_node);
94226 #endif
94227
94228 +bool is_usercopy_object(const void *ptr)
94229 +{
94230 + struct page *page;
94231 + struct kmem_cache *s;
94232 +
94233 + if (ZERO_OR_NULL_PTR(ptr))
94234 + return false;
94235 +
94236 + if (!slab_is_available())
94237 + return false;
94238 +
94239 + if (!virt_addr_valid(ptr))
94240 + return false;
94241 +
94242 + page = virt_to_head_page(ptr);
94243 +
94244 + if (!PageSlab(page))
94245 + return false;
94246 +
94247 + s = page->slab_cache;
94248 + return s->flags & SLAB_USERCOPY;
94249 +}
94250 +
94251 +#ifdef CONFIG_PAX_USERCOPY
94252 +const char *check_heap_object(const void *ptr, unsigned long n)
94253 +{
94254 + struct page *page;
94255 + struct kmem_cache *s;
94256 + unsigned long offset;
94257 +
94258 + if (ZERO_OR_NULL_PTR(ptr))
94259 + return "<null>";
94260 +
94261 + if (!virt_addr_valid(ptr))
94262 + return NULL;
94263 +
94264 + page = virt_to_head_page(ptr);
94265 +
94266 + if (!PageSlab(page))
94267 + return NULL;
94268 +
94269 + s = page->slab_cache;
94270 + if (!(s->flags & SLAB_USERCOPY))
94271 + return s->name;
94272 +
94273 + offset = (ptr - page_address(page)) % s->size;
94274 + if (offset <= s->object_size && n <= s->object_size - offset)
94275 + return NULL;
94276 +
94277 + return s->name;
94278 +}
94279 +#endif
94280 +
94281 size_t ksize(const void *object)
94282 {
94283 struct page *page;
94284 @@ -3360,6 +3424,7 @@ void kfree(const void *x)
94285 if (unlikely(ZERO_OR_NULL_PTR(x)))
94286 return;
94287
94288 + VM_BUG_ON(!virt_addr_valid(x));
94289 page = virt_to_head_page(x);
94290 if (unlikely(!PageSlab(page))) {
94291 BUG_ON(!PageCompound(page));
94292 @@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
94293 /*
94294 * We may have set a slab to be unmergeable during bootstrap.
94295 */
94296 - if (s->refcount < 0)
94297 + if (atomic_read(&s->refcount) < 0)
94298 return 1;
94299
94300 return 0;
94301 @@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94302
94303 s = find_mergeable(memcg, size, align, flags, name, ctor);
94304 if (s) {
94305 - s->refcount++;
94306 + atomic_inc(&s->refcount);
94307 /*
94308 * Adjust the object sizes so that we clear
94309 * the complete object on kzalloc.
94310 @@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94311 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
94312
94313 if (sysfs_slab_alias(s, name)) {
94314 - s->refcount--;
94315 + atomic_dec(&s->refcount);
94316 s = NULL;
94317 }
94318 }
94319 @@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
94320 }
94321 #endif
94322
94323 -#ifdef CONFIG_SYSFS
94324 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94325 static int count_inuse(struct page *page)
94326 {
94327 return page->inuse;
94328 @@ -4241,12 +4306,12 @@ static void resiliency_test(void)
94329 validate_slab_cache(kmalloc_caches[9]);
94330 }
94331 #else
94332 -#ifdef CONFIG_SYSFS
94333 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94334 static void resiliency_test(void) {};
94335 #endif
94336 #endif
94337
94338 -#ifdef CONFIG_SYSFS
94339 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94340 enum slab_stat_type {
94341 SL_ALL, /* All slabs */
94342 SL_PARTIAL, /* Only partially allocated slabs */
94343 @@ -4486,7 +4551,7 @@ SLAB_ATTR_RO(ctor);
94344
94345 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
94346 {
94347 - return sprintf(buf, "%d\n", s->refcount - 1);
94348 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
94349 }
94350 SLAB_ATTR_RO(aliases);
94351
94352 @@ -4574,6 +4639,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
94353 SLAB_ATTR_RO(cache_dma);
94354 #endif
94355
94356 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94357 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
94358 +{
94359 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
94360 +}
94361 +SLAB_ATTR_RO(usercopy);
94362 +#endif
94363 +
94364 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
94365 {
94366 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
94367 @@ -4908,6 +4981,9 @@ static struct attribute *slab_attrs[] = {
94368 #ifdef CONFIG_ZONE_DMA
94369 &cache_dma_attr.attr,
94370 #endif
94371 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94372 + &usercopy_attr.attr,
94373 +#endif
94374 #ifdef CONFIG_NUMA
94375 &remote_node_defrag_ratio_attr.attr,
94376 #endif
94377 @@ -5140,6 +5216,7 @@ static char *create_unique_id(struct kmem_cache *s)
94378 return name;
94379 }
94380
94381 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94382 static int sysfs_slab_add(struct kmem_cache *s)
94383 {
94384 int err;
94385 @@ -5163,7 +5240,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
94386 }
94387
94388 s->kobj.kset = slab_kset;
94389 - err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
94390 + err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
94391 if (err) {
94392 kobject_put(&s->kobj);
94393 return err;
94394 @@ -5197,6 +5274,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
94395 kobject_del(&s->kobj);
94396 kobject_put(&s->kobj);
94397 }
94398 +#endif
94399
94400 /*
94401 * Need to buffer aliases during bootup until sysfs becomes
94402 @@ -5210,6 +5288,7 @@ struct saved_alias {
94403
94404 static struct saved_alias *alias_list;
94405
94406 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94407 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94408 {
94409 struct saved_alias *al;
94410 @@ -5232,6 +5311,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94411 alias_list = al;
94412 return 0;
94413 }
94414 +#endif
94415
94416 static int __init slab_sysfs_init(void)
94417 {
94418 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
94419 index 27eeab3..7c3f7f2 100644
94420 --- a/mm/sparse-vmemmap.c
94421 +++ b/mm/sparse-vmemmap.c
94422 @@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
94423 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94424 if (!p)
94425 return NULL;
94426 - pud_populate(&init_mm, pud, p);
94427 + pud_populate_kernel(&init_mm, pud, p);
94428 }
94429 return pud;
94430 }
94431 @@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
94432 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94433 if (!p)
94434 return NULL;
94435 - pgd_populate(&init_mm, pgd, p);
94436 + pgd_populate_kernel(&init_mm, pgd, p);
94437 }
94438 return pgd;
94439 }
94440 diff --git a/mm/sparse.c b/mm/sparse.c
94441 index 8cc7be0..d0f7d7a 100644
94442 --- a/mm/sparse.c
94443 +++ b/mm/sparse.c
94444 @@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
94445
94446 for (i = 0; i < PAGES_PER_SECTION; i++) {
94447 if (PageHWPoison(&memmap[i])) {
94448 - atomic_long_sub(1, &num_poisoned_pages);
94449 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
94450 ClearPageHWPoison(&memmap[i]);
94451 }
94452 }
94453 diff --git a/mm/swap.c b/mm/swap.c
94454 index 84b26aa..ce39899 100644
94455 --- a/mm/swap.c
94456 +++ b/mm/swap.c
94457 @@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
94458
94459 __page_cache_release(page);
94460 dtor = get_compound_page_dtor(page);
94461 + if (!PageHuge(page))
94462 + BUG_ON(dtor != free_compound_page);
94463 (*dtor)(page);
94464 }
94465
94466 diff --git a/mm/swapfile.c b/mm/swapfile.c
94467 index 612a7c9..66b0f5a 100644
94468 --- a/mm/swapfile.c
94469 +++ b/mm/swapfile.c
94470 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
94471
94472 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
94473 /* Activity counter to indicate that a swapon or swapoff has occurred */
94474 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
94475 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
94476
94477 static inline unsigned char swap_count(unsigned char ent)
94478 {
94479 @@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
94480 }
94481 filp_close(swap_file, NULL);
94482 err = 0;
94483 - atomic_inc(&proc_poll_event);
94484 + atomic_inc_unchecked(&proc_poll_event);
94485 wake_up_interruptible(&proc_poll_wait);
94486
94487 out_dput:
94488 @@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
94489
94490 poll_wait(file, &proc_poll_wait, wait);
94491
94492 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
94493 - seq->poll_event = atomic_read(&proc_poll_event);
94494 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
94495 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94496 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
94497 }
94498
94499 @@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
94500 return ret;
94501
94502 seq = file->private_data;
94503 - seq->poll_event = atomic_read(&proc_poll_event);
94504 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94505 return 0;
94506 }
94507
94508 @@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
94509 (frontswap_map) ? "FS" : "");
94510
94511 mutex_unlock(&swapon_mutex);
94512 - atomic_inc(&proc_poll_event);
94513 + atomic_inc_unchecked(&proc_poll_event);
94514 wake_up_interruptible(&proc_poll_wait);
94515
94516 if (S_ISREG(inode->i_mode))
94517 diff --git a/mm/util.c b/mm/util.c
94518 index 808f375..e4764b5 100644
94519 --- a/mm/util.c
94520 +++ b/mm/util.c
94521 @@ -297,6 +297,12 @@ done:
94522 void arch_pick_mmap_layout(struct mm_struct *mm)
94523 {
94524 mm->mmap_base = TASK_UNMAPPED_BASE;
94525 +
94526 +#ifdef CONFIG_PAX_RANDMMAP
94527 + if (mm->pax_flags & MF_PAX_RANDMMAP)
94528 + mm->mmap_base += mm->delta_mmap;
94529 +#endif
94530 +
94531 mm->get_unmapped_area = arch_get_unmapped_area;
94532 }
94533 #endif
94534 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
94535 index 0fdf968..d6686e8 100644
94536 --- a/mm/vmalloc.c
94537 +++ b/mm/vmalloc.c
94538 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
94539
94540 pte = pte_offset_kernel(pmd, addr);
94541 do {
94542 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94543 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94544 +
94545 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94546 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
94547 + BUG_ON(!pte_exec(*pte));
94548 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
94549 + continue;
94550 + }
94551 +#endif
94552 +
94553 + {
94554 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94555 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94556 + }
94557 } while (pte++, addr += PAGE_SIZE, addr != end);
94558 }
94559
94560 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
94561 pte = pte_alloc_kernel(pmd, addr);
94562 if (!pte)
94563 return -ENOMEM;
94564 +
94565 + pax_open_kernel();
94566 do {
94567 struct page *page = pages[*nr];
94568
94569 - if (WARN_ON(!pte_none(*pte)))
94570 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94571 + if (pgprot_val(prot) & _PAGE_NX)
94572 +#endif
94573 +
94574 + if (!pte_none(*pte)) {
94575 + pax_close_kernel();
94576 + WARN_ON(1);
94577 return -EBUSY;
94578 - if (WARN_ON(!page))
94579 + }
94580 + if (!page) {
94581 + pax_close_kernel();
94582 + WARN_ON(1);
94583 return -ENOMEM;
94584 + }
94585 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
94586 (*nr)++;
94587 } while (pte++, addr += PAGE_SIZE, addr != end);
94588 + pax_close_kernel();
94589 return 0;
94590 }
94591
94592 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
94593 pmd_t *pmd;
94594 unsigned long next;
94595
94596 - pmd = pmd_alloc(&init_mm, pud, addr);
94597 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94598 if (!pmd)
94599 return -ENOMEM;
94600 do {
94601 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
94602 pud_t *pud;
94603 unsigned long next;
94604
94605 - pud = pud_alloc(&init_mm, pgd, addr);
94606 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
94607 if (!pud)
94608 return -ENOMEM;
94609 do {
94610 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
94611 if (addr >= MODULES_VADDR && addr < MODULES_END)
94612 return 1;
94613 #endif
94614 +
94615 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94616 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
94617 + return 1;
94618 +#endif
94619 +
94620 return is_vmalloc_addr(x);
94621 }
94622
94623 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
94624
94625 if (!pgd_none(*pgd)) {
94626 pud_t *pud = pud_offset(pgd, addr);
94627 +#ifdef CONFIG_X86
94628 + if (!pud_large(*pud))
94629 +#endif
94630 if (!pud_none(*pud)) {
94631 pmd_t *pmd = pmd_offset(pud, addr);
94632 +#ifdef CONFIG_X86
94633 + if (!pmd_large(*pmd))
94634 +#endif
94635 if (!pmd_none(*pmd)) {
94636 pte_t *ptep, pte;
94637
94638 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
94639 struct vm_struct *area;
94640
94641 BUG_ON(in_interrupt());
94642 +
94643 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94644 + if (flags & VM_KERNEXEC) {
94645 + if (start != VMALLOC_START || end != VMALLOC_END)
94646 + return NULL;
94647 + start = (unsigned long)MODULES_EXEC_VADDR;
94648 + end = (unsigned long)MODULES_EXEC_END;
94649 + }
94650 +#endif
94651 +
94652 if (flags & VM_IOREMAP)
94653 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
94654
94655 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
94656 if (count > totalram_pages)
94657 return NULL;
94658
94659 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94660 + if (!(pgprot_val(prot) & _PAGE_NX))
94661 + flags |= VM_KERNEXEC;
94662 +#endif
94663 +
94664 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
94665 __builtin_return_address(0));
94666 if (!area)
94667 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
94668 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
94669 goto fail;
94670
94671 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94672 + if (!(pgprot_val(prot) & _PAGE_NX))
94673 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
94674 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
94675 + else
94676 +#endif
94677 +
94678 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
94679 start, end, node, gfp_mask, caller);
94680 if (!area)
94681 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
94682 * For tight control over page level allocator and protection flags
94683 * use __vmalloc() instead.
94684 */
94685 -
94686 void *vmalloc_exec(unsigned long size)
94687 {
94688 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
94689 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
94690 NUMA_NO_NODE, __builtin_return_address(0));
94691 }
94692
94693 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
94694 {
94695 struct vm_struct *area;
94696
94697 + BUG_ON(vma->vm_mirror);
94698 +
94699 size = PAGE_ALIGN(size);
94700
94701 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
94702 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
94703 v->addr, v->addr + v->size, v->size);
94704
94705 if (v->caller)
94706 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94707 + seq_printf(m, " %pK", v->caller);
94708 +#else
94709 seq_printf(m, " %pS", v->caller);
94710 +#endif
94711
94712 if (v->nr_pages)
94713 seq_printf(m, " pages=%d", v->nr_pages);
94714 diff --git a/mm/vmstat.c b/mm/vmstat.c
94715 index 7249614..2639fc7 100644
94716 --- a/mm/vmstat.c
94717 +++ b/mm/vmstat.c
94718 @@ -20,6 +20,7 @@
94719 #include <linux/writeback.h>
94720 #include <linux/compaction.h>
94721 #include <linux/mm_inline.h>
94722 +#include <linux/grsecurity.h>
94723
94724 #include "internal.h"
94725
94726 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
94727 *
94728 * vm_stat contains the global counters
94729 */
94730 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94731 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94732 EXPORT_SYMBOL(vm_stat);
94733
94734 #ifdef CONFIG_SMP
94735 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
94736
94737 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94738 if (diff[i])
94739 - atomic_long_add(diff[i], &vm_stat[i]);
94740 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
94741 }
94742
94743 /*
94744 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
94745 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
94746 if (v) {
94747
94748 - atomic_long_add(v, &zone->vm_stat[i]);
94749 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94750 global_diff[i] += v;
94751 #ifdef CONFIG_NUMA
94752 /* 3 seconds idle till flush */
94753 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
94754
94755 v = p->vm_stat_diff[i];
94756 p->vm_stat_diff[i] = 0;
94757 - atomic_long_add(v, &zone->vm_stat[i]);
94758 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94759 global_diff[i] += v;
94760 }
94761 }
94762 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
94763 if (pset->vm_stat_diff[i]) {
94764 int v = pset->vm_stat_diff[i];
94765 pset->vm_stat_diff[i] = 0;
94766 - atomic_long_add(v, &zone->vm_stat[i]);
94767 - atomic_long_add(v, &vm_stat[i]);
94768 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94769 + atomic_long_add_unchecked(v, &vm_stat[i]);
94770 }
94771 }
94772 #endif
94773 @@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
94774 stat_items_size += sizeof(struct vm_event_state);
94775 #endif
94776
94777 - v = kmalloc(stat_items_size, GFP_KERNEL);
94778 + v = kzalloc(stat_items_size, GFP_KERNEL);
94779 m->private = v;
94780 if (!v)
94781 return ERR_PTR(-ENOMEM);
94782 +
94783 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94784 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
94785 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
94786 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
94787 + && !in_group_p(grsec_proc_gid)
94788 +#endif
94789 + )
94790 + return (unsigned long *)m->private + *pos;
94791 +#endif
94792 +#endif
94793 +
94794 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94795 v[i] = global_page_state(i);
94796 v += NR_VM_ZONE_STAT_ITEMS;
94797 @@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
94798 put_online_cpus();
94799 #endif
94800 #ifdef CONFIG_PROC_FS
94801 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
94802 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
94803 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94804 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
94805 + {
94806 + mode_t gr_mode = S_IRUGO;
94807 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94808 + gr_mode = S_IRUSR;
94809 +#endif
94810 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
94811 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
94812 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94813 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
94814 + }
94815 #endif
94816 return 0;
94817 }
94818 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
94819 index b3d17d1..e8e4cdd 100644
94820 --- a/net/8021q/vlan.c
94821 +++ b/net/8021q/vlan.c
94822 @@ -472,7 +472,7 @@ out:
94823 return NOTIFY_DONE;
94824 }
94825
94826 -static struct notifier_block vlan_notifier_block __read_mostly = {
94827 +static struct notifier_block vlan_notifier_block = {
94828 .notifier_call = vlan_device_event,
94829 };
94830
94831 @@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
94832 err = -EPERM;
94833 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
94834 break;
94835 - if ((args.u.name_type >= 0) &&
94836 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
94837 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
94838 struct vlan_net *vn;
94839
94840 vn = net_generic(net, vlan_net_id);
94841 diff --git a/net/9p/client.c b/net/9p/client.c
94842 index ee8fd6b..0469d50 100644
94843 --- a/net/9p/client.c
94844 +++ b/net/9p/client.c
94845 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
94846 len - inline_len);
94847 } else {
94848 err = copy_from_user(ename + inline_len,
94849 - uidata, len - inline_len);
94850 + (char __force_user *)uidata, len - inline_len);
94851 if (err) {
94852 err = -EFAULT;
94853 goto out_err;
94854 @@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
94855 kernel_buf = 1;
94856 indata = data;
94857 } else
94858 - indata = (__force char *)udata;
94859 + indata = (__force_kernel char *)udata;
94860 /*
94861 * response header len is 11
94862 * PDU Header(7) + IO Size (4)
94863 @@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
94864 kernel_buf = 1;
94865 odata = data;
94866 } else
94867 - odata = (char *)udata;
94868 + odata = (char __force_kernel *)udata;
94869 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
94870 P9_ZC_HDR_SZ, kernel_buf, "dqd",
94871 fid->fid, offset, rsize);
94872 diff --git a/net/9p/mod.c b/net/9p/mod.c
94873 index 6ab36ae..6f1841b 100644
94874 --- a/net/9p/mod.c
94875 +++ b/net/9p/mod.c
94876 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
94877 void v9fs_register_trans(struct p9_trans_module *m)
94878 {
94879 spin_lock(&v9fs_trans_lock);
94880 - list_add_tail(&m->list, &v9fs_trans_list);
94881 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
94882 spin_unlock(&v9fs_trans_lock);
94883 }
94884 EXPORT_SYMBOL(v9fs_register_trans);
94885 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
94886 void v9fs_unregister_trans(struct p9_trans_module *m)
94887 {
94888 spin_lock(&v9fs_trans_lock);
94889 - list_del_init(&m->list);
94890 + pax_list_del_init((struct list_head *)&m->list);
94891 spin_unlock(&v9fs_trans_lock);
94892 }
94893 EXPORT_SYMBOL(v9fs_unregister_trans);
94894 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
94895 index 9321a77..ed2f256 100644
94896 --- a/net/9p/trans_fd.c
94897 +++ b/net/9p/trans_fd.c
94898 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
94899 oldfs = get_fs();
94900 set_fs(get_ds());
94901 /* The cast to a user pointer is valid due to the set_fs() */
94902 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
94903 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
94904 set_fs(oldfs);
94905
94906 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
94907 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
94908 index 876fbe8..8bbea9f 100644
94909 --- a/net/atm/atm_misc.c
94910 +++ b/net/atm/atm_misc.c
94911 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
94912 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
94913 return 1;
94914 atm_return(vcc, truesize);
94915 - atomic_inc(&vcc->stats->rx_drop);
94916 + atomic_inc_unchecked(&vcc->stats->rx_drop);
94917 return 0;
94918 }
94919 EXPORT_SYMBOL(atm_charge);
94920 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
94921 }
94922 }
94923 atm_return(vcc, guess);
94924 - atomic_inc(&vcc->stats->rx_drop);
94925 + atomic_inc_unchecked(&vcc->stats->rx_drop);
94926 return NULL;
94927 }
94928 EXPORT_SYMBOL(atm_alloc_charge);
94929 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
94930
94931 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
94932 {
94933 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
94934 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
94935 __SONET_ITEMS
94936 #undef __HANDLE_ITEM
94937 }
94938 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
94939
94940 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
94941 {
94942 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
94943 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
94944 __SONET_ITEMS
94945 #undef __HANDLE_ITEM
94946 }
94947 diff --git a/net/atm/lec.c b/net/atm/lec.c
94948 index f23916b..dd4d26b 100644
94949 --- a/net/atm/lec.c
94950 +++ b/net/atm/lec.c
94951 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
94952 }
94953
94954 static struct lane2_ops lane2_ops = {
94955 - lane2_resolve, /* resolve, spec 3.1.3 */
94956 - lane2_associate_req, /* associate_req, spec 3.1.4 */
94957 - NULL /* associate indicator, spec 3.1.5 */
94958 + .resolve = lane2_resolve,
94959 + .associate_req = lane2_associate_req,
94960 + .associate_indicator = NULL
94961 };
94962
94963 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
94964 diff --git a/net/atm/lec.h b/net/atm/lec.h
94965 index 4149db1..f2ab682 100644
94966 --- a/net/atm/lec.h
94967 +++ b/net/atm/lec.h
94968 @@ -48,7 +48,7 @@ struct lane2_ops {
94969 const u8 *tlvs, u32 sizeoftlvs);
94970 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
94971 const u8 *tlvs, u32 sizeoftlvs);
94972 -};
94973 +} __no_const;
94974
94975 /*
94976 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
94977 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
94978 index d1b2d9a..d549f7f 100644
94979 --- a/net/atm/mpoa_caches.c
94980 +++ b/net/atm/mpoa_caches.c
94981 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
94982
94983
94984 static struct in_cache_ops ingress_ops = {
94985 - in_cache_add_entry, /* add_entry */
94986 - in_cache_get, /* get */
94987 - in_cache_get_with_mask, /* get_with_mask */
94988 - in_cache_get_by_vcc, /* get_by_vcc */
94989 - in_cache_put, /* put */
94990 - in_cache_remove_entry, /* remove_entry */
94991 - cache_hit, /* cache_hit */
94992 - clear_count_and_expired, /* clear_count */
94993 - check_resolving_entries, /* check_resolving */
94994 - refresh_entries, /* refresh */
94995 - in_destroy_cache /* destroy_cache */
94996 + .add_entry = in_cache_add_entry,
94997 + .get = in_cache_get,
94998 + .get_with_mask = in_cache_get_with_mask,
94999 + .get_by_vcc = in_cache_get_by_vcc,
95000 + .put = in_cache_put,
95001 + .remove_entry = in_cache_remove_entry,
95002 + .cache_hit = cache_hit,
95003 + .clear_count = clear_count_and_expired,
95004 + .check_resolving = check_resolving_entries,
95005 + .refresh = refresh_entries,
95006 + .destroy_cache = in_destroy_cache
95007 };
95008
95009 static struct eg_cache_ops egress_ops = {
95010 - eg_cache_add_entry, /* add_entry */
95011 - eg_cache_get_by_cache_id, /* get_by_cache_id */
95012 - eg_cache_get_by_tag, /* get_by_tag */
95013 - eg_cache_get_by_vcc, /* get_by_vcc */
95014 - eg_cache_get_by_src_ip, /* get_by_src_ip */
95015 - eg_cache_put, /* put */
95016 - eg_cache_remove_entry, /* remove_entry */
95017 - update_eg_cache_entry, /* update */
95018 - clear_expired, /* clear_expired */
95019 - eg_destroy_cache /* destroy_cache */
95020 + .add_entry = eg_cache_add_entry,
95021 + .get_by_cache_id = eg_cache_get_by_cache_id,
95022 + .get_by_tag = eg_cache_get_by_tag,
95023 + .get_by_vcc = eg_cache_get_by_vcc,
95024 + .get_by_src_ip = eg_cache_get_by_src_ip,
95025 + .put = eg_cache_put,
95026 + .remove_entry = eg_cache_remove_entry,
95027 + .update = update_eg_cache_entry,
95028 + .clear_expired = clear_expired,
95029 + .destroy_cache = eg_destroy_cache
95030 };
95031
95032
95033 diff --git a/net/atm/proc.c b/net/atm/proc.c
95034 index bbb6461..cf04016 100644
95035 --- a/net/atm/proc.c
95036 +++ b/net/atm/proc.c
95037 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
95038 const struct k_atm_aal_stats *stats)
95039 {
95040 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
95041 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
95042 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
95043 - atomic_read(&stats->rx_drop));
95044 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
95045 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
95046 + atomic_read_unchecked(&stats->rx_drop));
95047 }
95048
95049 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
95050 diff --git a/net/atm/resources.c b/net/atm/resources.c
95051 index 0447d5d..3cf4728 100644
95052 --- a/net/atm/resources.c
95053 +++ b/net/atm/resources.c
95054 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
95055 static void copy_aal_stats(struct k_atm_aal_stats *from,
95056 struct atm_aal_stats *to)
95057 {
95058 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95059 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95060 __AAL_STAT_ITEMS
95061 #undef __HANDLE_ITEM
95062 }
95063 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
95064 static void subtract_aal_stats(struct k_atm_aal_stats *from,
95065 struct atm_aal_stats *to)
95066 {
95067 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95068 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
95069 __AAL_STAT_ITEMS
95070 #undef __HANDLE_ITEM
95071 }
95072 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
95073 index 919a5ce..cc6b444 100644
95074 --- a/net/ax25/sysctl_net_ax25.c
95075 +++ b/net/ax25/sysctl_net_ax25.c
95076 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
95077 {
95078 char path[sizeof("net/ax25/") + IFNAMSIZ];
95079 int k;
95080 - struct ctl_table *table;
95081 + ctl_table_no_const *table;
95082
95083 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
95084 if (!table)
95085 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
95086 index b9c8a6e..ed0f711 100644
95087 --- a/net/batman-adv/bat_iv_ogm.c
95088 +++ b/net/batman-adv/bat_iv_ogm.c
95089 @@ -297,7 +297,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
95090
95091 /* randomize initial seqno to avoid collision */
95092 get_random_bytes(&random_seqno, sizeof(random_seqno));
95093 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95094 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95095
95096 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
95097 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
95098 @@ -884,9 +884,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
95099 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
95100
95101 /* change sequence number to network order */
95102 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
95103 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
95104 batadv_ogm_packet->seqno = htonl(seqno);
95105 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
95106 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
95107
95108 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
95109 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
95110 @@ -1251,7 +1251,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
95111 return;
95112
95113 /* could be changed by schedule_own_packet() */
95114 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
95115 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
95116
95117 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
95118 has_directlink_flag = 1;
95119 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
95120 index 6ddb614..ca7e886 100644
95121 --- a/net/batman-adv/fragmentation.c
95122 +++ b/net/batman-adv/fragmentation.c
95123 @@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
95124 frag_header.packet_type = BATADV_UNICAST_FRAG;
95125 frag_header.version = BATADV_COMPAT_VERSION;
95126 frag_header.ttl = BATADV_TTL;
95127 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
95128 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
95129 frag_header.reserved = 0;
95130 frag_header.no = 0;
95131 frag_header.total_size = htons(skb->len);
95132 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
95133 index a8f99d1..11797ef 100644
95134 --- a/net/batman-adv/soft-interface.c
95135 +++ b/net/batman-adv/soft-interface.c
95136 @@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
95137 primary_if->net_dev->dev_addr, ETH_ALEN);
95138
95139 /* set broadcast sequence number */
95140 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
95141 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
95142 bcast_packet->seqno = htonl(seqno);
95143
95144 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
95145 @@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95146 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
95147
95148 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
95149 - atomic_set(&bat_priv->bcast_seqno, 1);
95150 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
95151 atomic_set(&bat_priv->tt.vn, 0);
95152 atomic_set(&bat_priv->tt.local_changes, 0);
95153 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
95154 @@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95155
95156 /* randomize initial seqno to avoid collision */
95157 get_random_bytes(&random_seqno, sizeof(random_seqno));
95158 - atomic_set(&bat_priv->frag_seqno, random_seqno);
95159 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
95160
95161 bat_priv->primary_if = NULL;
95162 bat_priv->num_ifaces = 0;
95163 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
95164 index 91dd369..9c25750 100644
95165 --- a/net/batman-adv/types.h
95166 +++ b/net/batman-adv/types.h
95167 @@ -56,7 +56,7 @@
95168 struct batadv_hard_iface_bat_iv {
95169 unsigned char *ogm_buff;
95170 int ogm_buff_len;
95171 - atomic_t ogm_seqno;
95172 + atomic_unchecked_t ogm_seqno;
95173 };
95174
95175 /**
95176 @@ -673,7 +673,7 @@ struct batadv_priv {
95177 atomic_t bonding;
95178 atomic_t fragmentation;
95179 atomic_t packet_size_max;
95180 - atomic_t frag_seqno;
95181 + atomic_unchecked_t frag_seqno;
95182 #ifdef CONFIG_BATMAN_ADV_BLA
95183 atomic_t bridge_loop_avoidance;
95184 #endif
95185 @@ -687,7 +687,7 @@ struct batadv_priv {
95186 #ifdef CONFIG_BATMAN_ADV_DEBUG
95187 atomic_t log_level;
95188 #endif
95189 - atomic_t bcast_seqno;
95190 + atomic_unchecked_t bcast_seqno;
95191 atomic_t bcast_queue_left;
95192 atomic_t batman_queue_left;
95193 char num_ifaces;
95194 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
95195 index 7552f9e..074ce29 100644
95196 --- a/net/bluetooth/hci_sock.c
95197 +++ b/net/bluetooth/hci_sock.c
95198 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
95199 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
95200 }
95201
95202 - len = min_t(unsigned int, len, sizeof(uf));
95203 + len = min((size_t)len, sizeof(uf));
95204 if (copy_from_user(&uf, optval, len)) {
95205 err = -EFAULT;
95206 break;
95207 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
95208 index 4af3821..f2ba46c 100644
95209 --- a/net/bluetooth/l2cap_core.c
95210 +++ b/net/bluetooth/l2cap_core.c
95211 @@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
95212 break;
95213
95214 case L2CAP_CONF_RFC:
95215 - if (olen == sizeof(rfc))
95216 - memcpy(&rfc, (void *)val, olen);
95217 + if (olen != sizeof(rfc))
95218 + break;
95219 +
95220 + memcpy(&rfc, (void *)val, olen);
95221
95222 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
95223 rfc.mode != chan->mode)
95224 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
95225 index 7cc24d2..e83f531 100644
95226 --- a/net/bluetooth/l2cap_sock.c
95227 +++ b/net/bluetooth/l2cap_sock.c
95228 @@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95229 struct sock *sk = sock->sk;
95230 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
95231 struct l2cap_options opts;
95232 - int len, err = 0;
95233 + int err = 0;
95234 + size_t len = optlen;
95235 u32 opt;
95236
95237 BT_DBG("sk %p", sk);
95238 @@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95239 opts.max_tx = chan->max_tx;
95240 opts.txwin_size = chan->tx_win;
95241
95242 - len = min_t(unsigned int, sizeof(opts), optlen);
95243 + len = min(sizeof(opts), len);
95244 if (copy_from_user((char *) &opts, optval, len)) {
95245 err = -EFAULT;
95246 break;
95247 @@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95248 struct bt_security sec;
95249 struct bt_power pwr;
95250 struct l2cap_conn *conn;
95251 - int len, err = 0;
95252 + int err = 0;
95253 + size_t len = optlen;
95254 u32 opt;
95255
95256 BT_DBG("sk %p", sk);
95257 @@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95258
95259 sec.level = BT_SECURITY_LOW;
95260
95261 - len = min_t(unsigned int, sizeof(sec), optlen);
95262 + len = min(sizeof(sec), len);
95263 if (copy_from_user((char *) &sec, optval, len)) {
95264 err = -EFAULT;
95265 break;
95266 @@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95267
95268 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
95269
95270 - len = min_t(unsigned int, sizeof(pwr), optlen);
95271 + len = min(sizeof(pwr), len);
95272 if (copy_from_user((char *) &pwr, optval, len)) {
95273 err = -EFAULT;
95274 break;
95275 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
95276 index 3c2d3e4..884855a 100644
95277 --- a/net/bluetooth/rfcomm/sock.c
95278 +++ b/net/bluetooth/rfcomm/sock.c
95279 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95280 struct sock *sk = sock->sk;
95281 struct bt_security sec;
95282 int err = 0;
95283 - size_t len;
95284 + size_t len = optlen;
95285 u32 opt;
95286
95287 BT_DBG("sk %p", sk);
95288 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95289
95290 sec.level = BT_SECURITY_LOW;
95291
95292 - len = min_t(unsigned int, sizeof(sec), optlen);
95293 + len = min(sizeof(sec), len);
95294 if (copy_from_user((char *) &sec, optval, len)) {
95295 err = -EFAULT;
95296 break;
95297 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
95298 index 84fcf9f..e389b27 100644
95299 --- a/net/bluetooth/rfcomm/tty.c
95300 +++ b/net/bluetooth/rfcomm/tty.c
95301 @@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
95302 BT_DBG("tty %p id %d", tty, tty->index);
95303
95304 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
95305 - dev->channel, dev->port.count);
95306 + dev->channel, atomic_read(&dev->port.count));
95307
95308 err = tty_port_open(&dev->port, tty, filp);
95309 if (err)
95310 @@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
95311 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
95312
95313 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
95314 - dev->port.count);
95315 + atomic_read(&dev->port.count));
95316
95317 tty_port_close(&dev->port, tty, filp);
95318 }
95319 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
95320 index ac78024..161a80c 100644
95321 --- a/net/bridge/netfilter/ebtables.c
95322 +++ b/net/bridge/netfilter/ebtables.c
95323 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95324 tmp.valid_hooks = t->table->valid_hooks;
95325 }
95326 mutex_unlock(&ebt_mutex);
95327 - if (copy_to_user(user, &tmp, *len) != 0){
95328 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
95329 BUGPRINT("c2u Didn't work\n");
95330 ret = -EFAULT;
95331 break;
95332 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95333 goto out;
95334 tmp.valid_hooks = t->valid_hooks;
95335
95336 - if (copy_to_user(user, &tmp, *len) != 0) {
95337 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95338 ret = -EFAULT;
95339 break;
95340 }
95341 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95342 tmp.entries_size = t->table->entries_size;
95343 tmp.valid_hooks = t->table->valid_hooks;
95344
95345 - if (copy_to_user(user, &tmp, *len) != 0) {
95346 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95347 ret = -EFAULT;
95348 break;
95349 }
95350 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
95351 index 0f45522..dab651f 100644
95352 --- a/net/caif/cfctrl.c
95353 +++ b/net/caif/cfctrl.c
95354 @@ -10,6 +10,7 @@
95355 #include <linux/spinlock.h>
95356 #include <linux/slab.h>
95357 #include <linux/pkt_sched.h>
95358 +#include <linux/sched.h>
95359 #include <net/caif/caif_layer.h>
95360 #include <net/caif/cfpkt.h>
95361 #include <net/caif/cfctrl.h>
95362 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
95363 memset(&dev_info, 0, sizeof(dev_info));
95364 dev_info.id = 0xff;
95365 cfsrvl_init(&this->serv, 0, &dev_info, false);
95366 - atomic_set(&this->req_seq_no, 1);
95367 - atomic_set(&this->rsp_seq_no, 1);
95368 + atomic_set_unchecked(&this->req_seq_no, 1);
95369 + atomic_set_unchecked(&this->rsp_seq_no, 1);
95370 this->serv.layer.receive = cfctrl_recv;
95371 sprintf(this->serv.layer.name, "ctrl");
95372 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
95373 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
95374 struct cfctrl_request_info *req)
95375 {
95376 spin_lock_bh(&ctrl->info_list_lock);
95377 - atomic_inc(&ctrl->req_seq_no);
95378 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
95379 + atomic_inc_unchecked(&ctrl->req_seq_no);
95380 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
95381 list_add_tail(&req->list, &ctrl->list);
95382 spin_unlock_bh(&ctrl->info_list_lock);
95383 }
95384 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
95385 if (p != first)
95386 pr_warn("Requests are not received in order\n");
95387
95388 - atomic_set(&ctrl->rsp_seq_no,
95389 + atomic_set_unchecked(&ctrl->rsp_seq_no,
95390 p->sequence_no);
95391 list_del(&p->list);
95392 goto out;
95393 diff --git a/net/can/af_can.c b/net/can/af_can.c
95394 index d249874..99e197b 100644
95395 --- a/net/can/af_can.c
95396 +++ b/net/can/af_can.c
95397 @@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
95398 };
95399
95400 /* notifier block for netdevice event */
95401 -static struct notifier_block can_netdev_notifier __read_mostly = {
95402 +static struct notifier_block can_netdev_notifier = {
95403 .notifier_call = can_notifier,
95404 };
95405
95406 diff --git a/net/can/gw.c b/net/can/gw.c
95407 index 3f9b0f3..fc6d4fa 100644
95408 --- a/net/can/gw.c
95409 +++ b/net/can/gw.c
95410 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
95411 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
95412
95413 static HLIST_HEAD(cgw_list);
95414 -static struct notifier_block notifier;
95415
95416 static struct kmem_cache *cgw_cache __read_mostly;
95417
95418 @@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
95419 return err;
95420 }
95421
95422 +static struct notifier_block notifier = {
95423 + .notifier_call = cgw_notifier
95424 +};
95425 +
95426 static __init int cgw_module_init(void)
95427 {
95428 /* sanitize given module parameter */
95429 @@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
95430 return -ENOMEM;
95431
95432 /* set notifier */
95433 - notifier.notifier_call = cgw_notifier;
95434 register_netdevice_notifier(&notifier);
95435
95436 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
95437 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
95438 index 4a5df7b..9ad1f1d 100644
95439 --- a/net/ceph/messenger.c
95440 +++ b/net/ceph/messenger.c
95441 @@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
95442 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
95443
95444 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
95445 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
95446 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
95447
95448 static struct page *zero_page; /* used in certain error cases */
95449
95450 @@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
95451 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
95452 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
95453
95454 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95455 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95456 s = addr_str[i];
95457
95458 switch (ss->ss_family) {
95459 diff --git a/net/compat.c b/net/compat.c
95460 index dd32e34..94fa415 100644
95461 --- a/net/compat.c
95462 +++ b/net/compat.c
95463 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
95464 return -EFAULT;
95465 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
95466 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
95467 - kmsg->msg_name = compat_ptr(tmp1);
95468 - kmsg->msg_iov = compat_ptr(tmp2);
95469 - kmsg->msg_control = compat_ptr(tmp3);
95470 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
95471 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
95472 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
95473 return 0;
95474 }
95475
95476 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95477
95478 if (kern_msg->msg_namelen) {
95479 if (mode == VERIFY_READ) {
95480 - int err = move_addr_to_kernel(kern_msg->msg_name,
95481 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
95482 kern_msg->msg_namelen,
95483 kern_address);
95484 if (err < 0)
95485 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95486 kern_msg->msg_name = NULL;
95487
95488 tot_len = iov_from_user_compat_to_kern(kern_iov,
95489 - (struct compat_iovec __user *)kern_msg->msg_iov,
95490 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
95491 kern_msg->msg_iovlen);
95492 if (tot_len >= 0)
95493 kern_msg->msg_iov = kern_iov;
95494 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95495
95496 #define CMSG_COMPAT_FIRSTHDR(msg) \
95497 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
95498 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
95499 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
95500 (struct compat_cmsghdr __user *)NULL)
95501
95502 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
95503 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
95504 (ucmlen) <= (unsigned long) \
95505 ((mhdr)->msg_controllen - \
95506 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
95507 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
95508
95509 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
95510 struct compat_cmsghdr __user *cmsg, int cmsg_len)
95511 {
95512 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
95513 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
95514 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
95515 msg->msg_controllen)
95516 return NULL;
95517 return (struct compat_cmsghdr __user *)ptr;
95518 @@ -222,7 +222,7 @@ Efault:
95519
95520 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
95521 {
95522 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95523 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95524 struct compat_cmsghdr cmhdr;
95525 struct compat_timeval ctv;
95526 struct compat_timespec cts[3];
95527 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
95528
95529 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
95530 {
95531 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95532 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95533 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
95534 int fdnum = scm->fp->count;
95535 struct file **fp = scm->fp->fp;
95536 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
95537 return -EFAULT;
95538 old_fs = get_fs();
95539 set_fs(KERNEL_DS);
95540 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
95541 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
95542 set_fs(old_fs);
95543
95544 return err;
95545 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
95546 len = sizeof(ktime);
95547 old_fs = get_fs();
95548 set_fs(KERNEL_DS);
95549 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
95550 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
95551 set_fs(old_fs);
95552
95553 if (!err) {
95554 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95555 case MCAST_JOIN_GROUP:
95556 case MCAST_LEAVE_GROUP:
95557 {
95558 - struct compat_group_req __user *gr32 = (void *)optval;
95559 + struct compat_group_req __user *gr32 = (void __user *)optval;
95560 struct group_req __user *kgr =
95561 compat_alloc_user_space(sizeof(struct group_req));
95562 u32 interface;
95563 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95564 case MCAST_BLOCK_SOURCE:
95565 case MCAST_UNBLOCK_SOURCE:
95566 {
95567 - struct compat_group_source_req __user *gsr32 = (void *)optval;
95568 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
95569 struct group_source_req __user *kgsr = compat_alloc_user_space(
95570 sizeof(struct group_source_req));
95571 u32 interface;
95572 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95573 }
95574 case MCAST_MSFILTER:
95575 {
95576 - struct compat_group_filter __user *gf32 = (void *)optval;
95577 + struct compat_group_filter __user *gf32 = (void __user *)optval;
95578 struct group_filter __user *kgf;
95579 u32 interface, fmode, numsrc;
95580
95581 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
95582 char __user *optval, int __user *optlen,
95583 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
95584 {
95585 - struct compat_group_filter __user *gf32 = (void *)optval;
95586 + struct compat_group_filter __user *gf32 = (void __user *)optval;
95587 struct group_filter __user *kgf;
95588 int __user *koptlen;
95589 u32 interface, fmode, numsrc;
95590 @@ -780,21 +780,16 @@ asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
95591 if (flags & MSG_CMSG_COMPAT)
95592 return -EINVAL;
95593
95594 - if (COMPAT_USE_64BIT_TIME)
95595 - return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
95596 - flags | MSG_CMSG_COMPAT,
95597 - (struct timespec *) timeout);
95598 -
95599 if (timeout == NULL)
95600 return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
95601 flags | MSG_CMSG_COMPAT, NULL);
95602
95603 - if (get_compat_timespec(&ktspec, timeout))
95604 + if (compat_get_timespec(&ktspec, timeout))
95605 return -EFAULT;
95606
95607 datagrams = __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
95608 flags | MSG_CMSG_COMPAT, &ktspec);
95609 - if (datagrams > 0 && put_compat_timespec(&ktspec, timeout))
95610 + if (datagrams > 0 && compat_put_timespec(&ktspec, timeout))
95611 datagrams = -EFAULT;
95612
95613 return datagrams;
95614 @@ -808,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
95615
95616 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
95617 return -EINVAL;
95618 - if (copy_from_user(a, args, nas[call]))
95619 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
95620 return -EFAULT;
95621 a0 = a[0];
95622 a1 = a[1];
95623 diff --git a/net/core/datagram.c b/net/core/datagram.c
95624 index a16ed7b..eb44d17 100644
95625 --- a/net/core/datagram.c
95626 +++ b/net/core/datagram.c
95627 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
95628 }
95629
95630 kfree_skb(skb);
95631 - atomic_inc(&sk->sk_drops);
95632 + atomic_inc_unchecked(&sk->sk_drops);
95633 sk_mem_reclaim_partial(sk);
95634
95635 return err;
95636 diff --git a/net/core/dev.c b/net/core/dev.c
95637 index 0ce469e..dfb53d2 100644
95638 --- a/net/core/dev.c
95639 +++ b/net/core/dev.c
95640 @@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
95641 {
95642 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
95643 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
95644 - atomic_long_inc(&dev->rx_dropped);
95645 + atomic_long_inc_unchecked(&dev->rx_dropped);
95646 kfree_skb(skb);
95647 return NET_RX_DROP;
95648 }
95649 }
95650
95651 if (unlikely(!is_skb_forwardable(dev, skb))) {
95652 - atomic_long_inc(&dev->rx_dropped);
95653 + atomic_long_inc_unchecked(&dev->rx_dropped);
95654 kfree_skb(skb);
95655 return NET_RX_DROP;
95656 }
95657 @@ -2434,7 +2434,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
95658
95659 struct dev_gso_cb {
95660 void (*destructor)(struct sk_buff *skb);
95661 -};
95662 +} __no_const;
95663
95664 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
95665
95666 @@ -3222,7 +3222,7 @@ enqueue:
95667
95668 local_irq_restore(flags);
95669
95670 - atomic_long_inc(&skb->dev->rx_dropped);
95671 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95672 kfree_skb(skb);
95673 return NET_RX_DROP;
95674 }
95675 @@ -3294,7 +3294,7 @@ int netif_rx_ni(struct sk_buff *skb)
95676 }
95677 EXPORT_SYMBOL(netif_rx_ni);
95678
95679 -static void net_tx_action(struct softirq_action *h)
95680 +static __latent_entropy void net_tx_action(void)
95681 {
95682 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95683
95684 @@ -3628,7 +3628,7 @@ ncls:
95685 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
95686 } else {
95687 drop:
95688 - atomic_long_inc(&skb->dev->rx_dropped);
95689 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95690 kfree_skb(skb);
95691 /* Jamal, now you will not able to escape explaining
95692 * me how you were going to use this. :-)
95693 @@ -4288,7 +4288,7 @@ void netif_napi_del(struct napi_struct *napi)
95694 }
95695 EXPORT_SYMBOL(netif_napi_del);
95696
95697 -static void net_rx_action(struct softirq_action *h)
95698 +static __latent_entropy void net_rx_action(void)
95699 {
95700 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95701 unsigned long time_limit = jiffies + 2;
95702 @@ -6177,7 +6177,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
95703 } else {
95704 netdev_stats_to_stats64(storage, &dev->stats);
95705 }
95706 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
95707 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
95708 return storage;
95709 }
95710 EXPORT_SYMBOL(dev_get_stats);
95711 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
95712 index 5b7d0e1..cb960fc 100644
95713 --- a/net/core/dev_ioctl.c
95714 +++ b/net/core/dev_ioctl.c
95715 @@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
95716 if (no_module && capable(CAP_NET_ADMIN))
95717 no_module = request_module("netdev-%s", name);
95718 if (no_module && capable(CAP_SYS_MODULE)) {
95719 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
95720 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
95721 +#else
95722 if (!request_module("%s", name))
95723 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
95724 name);
95725 +#endif
95726 }
95727 }
95728 EXPORT_SYMBOL(dev_load);
95729 diff --git a/net/core/filter.c b/net/core/filter.c
95730 index ad30d62..c2757df 100644
95731 --- a/net/core/filter.c
95732 +++ b/net/core/filter.c
95733 @@ -679,7 +679,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
95734 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
95735 if (!fp)
95736 return -ENOMEM;
95737 - memcpy(fp->insns, fprog->filter, fsize);
95738 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
95739
95740 atomic_set(&fp->refcnt, 1);
95741 fp->len = fprog->len;
95742 diff --git a/net/core/flow.c b/net/core/flow.c
95743 index dfa602c..3103d88 100644
95744 --- a/net/core/flow.c
95745 +++ b/net/core/flow.c
95746 @@ -61,7 +61,7 @@ struct flow_cache {
95747 struct timer_list rnd_timer;
95748 };
95749
95750 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
95751 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
95752 EXPORT_SYMBOL(flow_cache_genid);
95753 static struct flow_cache flow_cache_global;
95754 static struct kmem_cache *flow_cachep __read_mostly;
95755 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
95756
95757 static int flow_entry_valid(struct flow_cache_entry *fle)
95758 {
95759 - if (atomic_read(&flow_cache_genid) != fle->genid)
95760 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
95761 return 0;
95762 if (fle->object && !fle->object->ops->check(fle->object))
95763 return 0;
95764 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
95765 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
95766 fcp->hash_count++;
95767 }
95768 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
95769 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
95770 flo = fle->object;
95771 if (!flo)
95772 goto ret_object;
95773 @@ -279,7 +279,7 @@ nocache:
95774 }
95775 flo = resolver(net, key, family, dir, flo, ctx);
95776 if (fle) {
95777 - fle->genid = atomic_read(&flow_cache_genid);
95778 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
95779 if (!IS_ERR(flo))
95780 fle->object = flo;
95781 else
95782 diff --git a/net/core/iovec.c b/net/core/iovec.c
95783 index b618694..192bbba 100644
95784 --- a/net/core/iovec.c
95785 +++ b/net/core/iovec.c
95786 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95787 if (m->msg_namelen) {
95788 if (mode == VERIFY_READ) {
95789 void __user *namep;
95790 - namep = (void __user __force *) m->msg_name;
95791 + namep = (void __force_user *) m->msg_name;
95792 err = move_addr_to_kernel(namep, m->msg_namelen,
95793 address);
95794 if (err < 0)
95795 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95796 }
95797
95798 size = m->msg_iovlen * sizeof(struct iovec);
95799 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
95800 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
95801 return -EFAULT;
95802
95803 m->msg_iov = iov;
95804 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
95805 index 932c6d7..7c7aa10 100644
95806 --- a/net/core/neighbour.c
95807 +++ b/net/core/neighbour.c
95808 @@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
95809 void __user *buffer, size_t *lenp, loff_t *ppos)
95810 {
95811 int size, ret;
95812 - struct ctl_table tmp = *ctl;
95813 + ctl_table_no_const tmp = *ctl;
95814
95815 tmp.extra1 = &zero;
95816 tmp.extra2 = &unres_qlen_max;
95817 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
95818 index 2bf8329..7960607 100644
95819 --- a/net/core/net-procfs.c
95820 +++ b/net/core/net-procfs.c
95821 @@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
95822 else
95823 seq_printf(seq, "%04x", ntohs(pt->type));
95824
95825 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95826 + seq_printf(seq, " %-8s %pf\n",
95827 + pt->dev ? pt->dev->name : "", NULL);
95828 +#else
95829 seq_printf(seq, " %-8s %pf\n",
95830 pt->dev ? pt->dev->name : "", pt->func);
95831 +#endif
95832 }
95833
95834 return 0;
95835 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
95836 index f3edf96..3cd8b40 100644
95837 --- a/net/core/net-sysfs.c
95838 +++ b/net/core/net-sysfs.c
95839 @@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
95840 }
95841 EXPORT_SYMBOL(netdev_class_remove_file_ns);
95842
95843 -int netdev_kobject_init(void)
95844 +int __init netdev_kobject_init(void)
95845 {
95846 kobj_ns_type_register(&net_ns_type_operations);
95847 return class_register(&net_class);
95848 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
95849 index 81d3a9a..a0bd7a8 100644
95850 --- a/net/core/net_namespace.c
95851 +++ b/net/core/net_namespace.c
95852 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
95853 int error;
95854 LIST_HEAD(net_exit_list);
95855
95856 - list_add_tail(&ops->list, list);
95857 + pax_list_add_tail((struct list_head *)&ops->list, list);
95858 if (ops->init || (ops->id && ops->size)) {
95859 for_each_net(net) {
95860 error = ops_init(ops, net);
95861 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
95862
95863 out_undo:
95864 /* If I have an error cleanup all namespaces I initialized */
95865 - list_del(&ops->list);
95866 + pax_list_del((struct list_head *)&ops->list);
95867 ops_exit_list(ops, &net_exit_list);
95868 ops_free_list(ops, &net_exit_list);
95869 return error;
95870 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
95871 struct net *net;
95872 LIST_HEAD(net_exit_list);
95873
95874 - list_del(&ops->list);
95875 + pax_list_del((struct list_head *)&ops->list);
95876 for_each_net(net)
95877 list_add_tail(&net->exit_list, &net_exit_list);
95878 ops_exit_list(ops, &net_exit_list);
95879 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
95880 mutex_lock(&net_mutex);
95881 error = register_pernet_operations(&pernet_list, ops);
95882 if (!error && (first_device == &pernet_list))
95883 - first_device = &ops->list;
95884 + first_device = (struct list_head *)&ops->list;
95885 mutex_unlock(&net_mutex);
95886 return error;
95887 }
95888 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
95889 index 19fe9c7..b6bb620 100644
95890 --- a/net/core/netpoll.c
95891 +++ b/net/core/netpoll.c
95892 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
95893 struct udphdr *udph;
95894 struct iphdr *iph;
95895 struct ethhdr *eth;
95896 - static atomic_t ip_ident;
95897 + static atomic_unchecked_t ip_ident;
95898 struct ipv6hdr *ip6h;
95899
95900 udp_len = len + sizeof(*udph);
95901 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
95902 put_unaligned(0x45, (unsigned char *)iph);
95903 iph->tos = 0;
95904 put_unaligned(htons(ip_len), &(iph->tot_len));
95905 - iph->id = htons(atomic_inc_return(&ip_ident));
95906 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
95907 iph->frag_off = 0;
95908 iph->ttl = 64;
95909 iph->protocol = IPPROTO_UDP;
95910 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
95911 index cf67144..12bf94c 100644
95912 --- a/net/core/rtnetlink.c
95913 +++ b/net/core/rtnetlink.c
95914 @@ -58,7 +58,7 @@ struct rtnl_link {
95915 rtnl_doit_func doit;
95916 rtnl_dumpit_func dumpit;
95917 rtnl_calcit_func calcit;
95918 -};
95919 +} __no_const;
95920
95921 static DEFINE_MUTEX(rtnl_mutex);
95922
95923 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
95924 if (rtnl_link_ops_get(ops->kind))
95925 return -EEXIST;
95926
95927 - if (!ops->dellink)
95928 - ops->dellink = unregister_netdevice_queue;
95929 + if (!ops->dellink) {
95930 + pax_open_kernel();
95931 + *(void **)&ops->dellink = unregister_netdevice_queue;
95932 + pax_close_kernel();
95933 + }
95934
95935 - list_add_tail(&ops->list, &link_ops);
95936 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
95937 return 0;
95938 }
95939 EXPORT_SYMBOL_GPL(__rtnl_link_register);
95940 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
95941 for_each_net(net) {
95942 __rtnl_kill_links(net, ops);
95943 }
95944 - list_del(&ops->list);
95945 + pax_list_del((struct list_head *)&ops->list);
95946 }
95947 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
95948
95949 diff --git a/net/core/scm.c b/net/core/scm.c
95950 index b442e7e..6f5b5a2 100644
95951 --- a/net/core/scm.c
95952 +++ b/net/core/scm.c
95953 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
95954 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
95955 {
95956 struct cmsghdr __user *cm
95957 - = (__force struct cmsghdr __user *)msg->msg_control;
95958 + = (struct cmsghdr __force_user *)msg->msg_control;
95959 struct cmsghdr cmhdr;
95960 int cmlen = CMSG_LEN(len);
95961 int err;
95962 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
95963 err = -EFAULT;
95964 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
95965 goto out;
95966 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
95967 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
95968 goto out;
95969 cmlen = CMSG_SPACE(len);
95970 if (msg->msg_controllen < cmlen)
95971 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
95972 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
95973 {
95974 struct cmsghdr __user *cm
95975 - = (__force struct cmsghdr __user*)msg->msg_control;
95976 + = (struct cmsghdr __force_user *)msg->msg_control;
95977
95978 int fdmax = 0;
95979 int fdnum = scm->fp->count;
95980 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
95981 if (fdnum < fdmax)
95982 fdmax = fdnum;
95983
95984 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
95985 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
95986 i++, cmfptr++)
95987 {
95988 struct socket *sock;
95989 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
95990 index 06e72d3..19dfa7b 100644
95991 --- a/net/core/skbuff.c
95992 +++ b/net/core/skbuff.c
95993 @@ -2034,7 +2034,7 @@ EXPORT_SYMBOL(__skb_checksum);
95994 __wsum skb_checksum(const struct sk_buff *skb, int offset,
95995 int len, __wsum csum)
95996 {
95997 - const struct skb_checksum_ops ops = {
95998 + static const struct skb_checksum_ops ops = {
95999 .update = csum_partial_ext,
96000 .combine = csum_block_add_ext,
96001 };
96002 @@ -3147,13 +3147,15 @@ void __init skb_init(void)
96003 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
96004 sizeof(struct sk_buff),
96005 0,
96006 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
96007 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96008 + SLAB_NO_SANITIZE,
96009 NULL);
96010 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
96011 (2*sizeof(struct sk_buff)) +
96012 sizeof(atomic_t),
96013 0,
96014 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
96015 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96016 + SLAB_NO_SANITIZE,
96017 NULL);
96018 }
96019
96020 diff --git a/net/core/sock.c b/net/core/sock.c
96021 index 5393b4b..997c88b 100644
96022 --- a/net/core/sock.c
96023 +++ b/net/core/sock.c
96024 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96025 struct sk_buff_head *list = &sk->sk_receive_queue;
96026
96027 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
96028 - atomic_inc(&sk->sk_drops);
96029 + atomic_inc_unchecked(&sk->sk_drops);
96030 trace_sock_rcvqueue_full(sk, skb);
96031 return -ENOMEM;
96032 }
96033 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96034 return err;
96035
96036 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
96037 - atomic_inc(&sk->sk_drops);
96038 + atomic_inc_unchecked(&sk->sk_drops);
96039 return -ENOBUFS;
96040 }
96041
96042 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96043 skb_dst_force(skb);
96044
96045 spin_lock_irqsave(&list->lock, flags);
96046 - skb->dropcount = atomic_read(&sk->sk_drops);
96047 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
96048 __skb_queue_tail(list, skb);
96049 spin_unlock_irqrestore(&list->lock, flags);
96050
96051 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96052 skb->dev = NULL;
96053
96054 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
96055 - atomic_inc(&sk->sk_drops);
96056 + atomic_inc_unchecked(&sk->sk_drops);
96057 goto discard_and_relse;
96058 }
96059 if (nested)
96060 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96061 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
96062 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
96063 bh_unlock_sock(sk);
96064 - atomic_inc(&sk->sk_drops);
96065 + atomic_inc_unchecked(&sk->sk_drops);
96066 goto discard_and_relse;
96067 }
96068
96069 @@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96070 struct timeval tm;
96071 } v;
96072
96073 - int lv = sizeof(int);
96074 - int len;
96075 + unsigned int lv = sizeof(int);
96076 + unsigned int len;
96077
96078 if (get_user(len, optlen))
96079 return -EFAULT;
96080 - if (len < 0)
96081 + if (len > INT_MAX)
96082 return -EINVAL;
96083
96084 memset(&v, 0, sizeof(v));
96085 @@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96086
96087 case SO_PEERNAME:
96088 {
96089 - char address[128];
96090 + char address[_K_SS_MAXSIZE];
96091
96092 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
96093 return -ENOTCONN;
96094 - if (lv < len)
96095 + if (lv < len || sizeof address < len)
96096 return -EINVAL;
96097 if (copy_to_user(optval, address, len))
96098 return -EFAULT;
96099 @@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96100
96101 if (len > lv)
96102 len = lv;
96103 - if (copy_to_user(optval, &v, len))
96104 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
96105 return -EFAULT;
96106 lenout:
96107 if (put_user(len, optlen))
96108 @@ -2351,7 +2351,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
96109 */
96110 smp_wmb();
96111 atomic_set(&sk->sk_refcnt, 1);
96112 - atomic_set(&sk->sk_drops, 0);
96113 + atomic_set_unchecked(&sk->sk_drops, 0);
96114 }
96115 EXPORT_SYMBOL(sock_init_data);
96116
96117 @@ -2476,6 +2476,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
96118 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96119 int level, int type)
96120 {
96121 + struct sock_extended_err ee;
96122 struct sock_exterr_skb *serr;
96123 struct sk_buff *skb, *skb2;
96124 int copied, err;
96125 @@ -2497,7 +2498,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96126 sock_recv_timestamp(msg, sk, skb);
96127
96128 serr = SKB_EXT_ERR(skb);
96129 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
96130 + ee = serr->ee;
96131 + put_cmsg(msg, level, type, sizeof ee, &ee);
96132
96133 msg->msg_flags |= MSG_ERRQUEUE;
96134 err = copied;
96135 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
96136 index a0e9cf6..ef7f9ed 100644
96137 --- a/net/core/sock_diag.c
96138 +++ b/net/core/sock_diag.c
96139 @@ -9,26 +9,33 @@
96140 #include <linux/inet_diag.h>
96141 #include <linux/sock_diag.h>
96142
96143 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
96144 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
96145 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
96146 static DEFINE_MUTEX(sock_diag_table_mutex);
96147
96148 int sock_diag_check_cookie(void *sk, __u32 *cookie)
96149 {
96150 +#ifndef CONFIG_GRKERNSEC_HIDESYM
96151 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
96152 cookie[1] != INET_DIAG_NOCOOKIE) &&
96153 ((u32)(unsigned long)sk != cookie[0] ||
96154 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
96155 return -ESTALE;
96156 else
96157 +#endif
96158 return 0;
96159 }
96160 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
96161
96162 void sock_diag_save_cookie(void *sk, __u32 *cookie)
96163 {
96164 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96165 + cookie[0] = 0;
96166 + cookie[1] = 0;
96167 +#else
96168 cookie[0] = (u32)(unsigned long)sk;
96169 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
96170 +#endif
96171 }
96172 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
96173
96174 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
96175 mutex_lock(&sock_diag_table_mutex);
96176 if (sock_diag_handlers[hndl->family])
96177 err = -EBUSY;
96178 - else
96179 + else {
96180 + pax_open_kernel();
96181 sock_diag_handlers[hndl->family] = hndl;
96182 + pax_close_kernel();
96183 + }
96184 mutex_unlock(&sock_diag_table_mutex);
96185
96186 return err;
96187 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
96188
96189 mutex_lock(&sock_diag_table_mutex);
96190 BUG_ON(sock_diag_handlers[family] != hnld);
96191 + pax_open_kernel();
96192 sock_diag_handlers[family] = NULL;
96193 + pax_close_kernel();
96194 mutex_unlock(&sock_diag_table_mutex);
96195 }
96196 EXPORT_SYMBOL_GPL(sock_diag_unregister);
96197 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
96198 index cca4441..5e616de 100644
96199 --- a/net/core/sysctl_net_core.c
96200 +++ b/net/core/sysctl_net_core.c
96201 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
96202 {
96203 unsigned int orig_size, size;
96204 int ret, i;
96205 - struct ctl_table tmp = {
96206 + ctl_table_no_const tmp = {
96207 .data = &size,
96208 .maxlen = sizeof(size),
96209 .mode = table->mode
96210 @@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
96211 void __user *buffer, size_t *lenp, loff_t *ppos)
96212 {
96213 char id[IFNAMSIZ];
96214 - struct ctl_table tbl = {
96215 + ctl_table_no_const tbl = {
96216 .data = id,
96217 .maxlen = IFNAMSIZ,
96218 };
96219 @@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
96220
96221 static __net_init int sysctl_core_net_init(struct net *net)
96222 {
96223 - struct ctl_table *tbl;
96224 + ctl_table_no_const *tbl = NULL;
96225
96226 net->core.sysctl_somaxconn = SOMAXCONN;
96227
96228 - tbl = netns_core_table;
96229 if (!net_eq(net, &init_net)) {
96230 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
96231 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
96232 if (tbl == NULL)
96233 goto err_dup;
96234
96235 @@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
96236 if (net->user_ns != &init_user_ns) {
96237 tbl[0].procname = NULL;
96238 }
96239 - }
96240 -
96241 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96242 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96243 + } else
96244 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
96245 if (net->core.sysctl_hdr == NULL)
96246 goto err_reg;
96247
96248 return 0;
96249
96250 err_reg:
96251 - if (tbl != netns_core_table)
96252 - kfree(tbl);
96253 + kfree(tbl);
96254 err_dup:
96255 return -ENOMEM;
96256 }
96257 @@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
96258 kfree(tbl);
96259 }
96260
96261 -static __net_initdata struct pernet_operations sysctl_core_ops = {
96262 +static __net_initconst struct pernet_operations sysctl_core_ops = {
96263 .init = sysctl_core_net_init,
96264 .exit = sysctl_core_net_exit,
96265 };
96266 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
96267 index dd4d506..fb2fb87 100644
96268 --- a/net/decnet/af_decnet.c
96269 +++ b/net/decnet/af_decnet.c
96270 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
96271 .sysctl_rmem = sysctl_decnet_rmem,
96272 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
96273 .obj_size = sizeof(struct dn_sock),
96274 + .slab_flags = SLAB_USERCOPY,
96275 };
96276
96277 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
96278 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
96279 index dd0dfb2..fdbc764 100644
96280 --- a/net/decnet/dn_dev.c
96281 +++ b/net/decnet/dn_dev.c
96282 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
96283 .extra1 = &min_t3,
96284 .extra2 = &max_t3
96285 },
96286 - {0}
96287 + { }
96288 },
96289 };
96290
96291 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
96292 index 5325b54..a0d4d69 100644
96293 --- a/net/decnet/sysctl_net_decnet.c
96294 +++ b/net/decnet/sysctl_net_decnet.c
96295 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
96296
96297 if (len > *lenp) len = *lenp;
96298
96299 - if (copy_to_user(buffer, addr, len))
96300 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
96301 return -EFAULT;
96302
96303 *lenp = len;
96304 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
96305
96306 if (len > *lenp) len = *lenp;
96307
96308 - if (copy_to_user(buffer, devname, len))
96309 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
96310 return -EFAULT;
96311
96312 *lenp = len;
96313 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
96314 index 1865fdf..581a595 100644
96315 --- a/net/ieee802154/dgram.c
96316 +++ b/net/ieee802154/dgram.c
96317 @@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
96318 if (saddr) {
96319 saddr->family = AF_IEEE802154;
96320 saddr->addr = mac_cb(skb)->sa;
96321 + }
96322 + if (addr_len)
96323 *addr_len = sizeof(*saddr);
96324 - }
96325
96326 if (flags & MSG_TRUNC)
96327 copied = skb->len;
96328 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
96329 index 70011e0..454ca6a 100644
96330 --- a/net/ipv4/af_inet.c
96331 +++ b/net/ipv4/af_inet.c
96332 @@ -1683,13 +1683,9 @@ static int __init inet_init(void)
96333
96334 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
96335
96336 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
96337 - if (!sysctl_local_reserved_ports)
96338 - goto out;
96339 -
96340 rc = proto_register(&tcp_prot, 1);
96341 if (rc)
96342 - goto out_free_reserved_ports;
96343 + goto out;
96344
96345 rc = proto_register(&udp_prot, 1);
96346 if (rc)
96347 @@ -1796,8 +1792,6 @@ out_unregister_udp_proto:
96348 proto_unregister(&udp_prot);
96349 out_unregister_tcp_proto:
96350 proto_unregister(&tcp_prot);
96351 -out_free_reserved_ports:
96352 - kfree(sysctl_local_reserved_ports);
96353 goto out;
96354 }
96355
96356 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
96357 index a1b5bcb..62ec5c6 100644
96358 --- a/net/ipv4/devinet.c
96359 +++ b/net/ipv4/devinet.c
96360 @@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
96361 idx = 0;
96362 head = &net->dev_index_head[h];
96363 rcu_read_lock();
96364 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96365 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96366 net->dev_base_seq;
96367 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96368 if (idx < s_idx)
96369 @@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
96370 idx = 0;
96371 head = &net->dev_index_head[h];
96372 rcu_read_lock();
96373 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96374 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96375 net->dev_base_seq;
96376 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96377 if (idx < s_idx)
96378 @@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
96379 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
96380 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
96381
96382 -static struct devinet_sysctl_table {
96383 +static const struct devinet_sysctl_table {
96384 struct ctl_table_header *sysctl_header;
96385 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
96386 } devinet_sysctl = {
96387 @@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
96388 int err;
96389 struct ipv4_devconf *all, *dflt;
96390 #ifdef CONFIG_SYSCTL
96391 - struct ctl_table *tbl = ctl_forward_entry;
96392 + ctl_table_no_const *tbl = NULL;
96393 struct ctl_table_header *forw_hdr;
96394 #endif
96395
96396 @@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
96397 goto err_alloc_dflt;
96398
96399 #ifdef CONFIG_SYSCTL
96400 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
96401 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
96402 if (tbl == NULL)
96403 goto err_alloc_ctl;
96404
96405 @@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
96406 goto err_reg_dflt;
96407
96408 err = -ENOMEM;
96409 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96410 + if (!net_eq(net, &init_net))
96411 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96412 + else
96413 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
96414 if (forw_hdr == NULL)
96415 goto err_reg_ctl;
96416 net->ipv4.forw_hdr = forw_hdr;
96417 @@ -2245,8 +2248,7 @@ err_reg_ctl:
96418 err_reg_dflt:
96419 __devinet_sysctl_unregister(all);
96420 err_reg_all:
96421 - if (tbl != ctl_forward_entry)
96422 - kfree(tbl);
96423 + kfree(tbl);
96424 err_alloc_ctl:
96425 #endif
96426 if (dflt != &ipv4_devconf_dflt)
96427 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
96428 index d846304..d0622bb 100644
96429 --- a/net/ipv4/fib_frontend.c
96430 +++ b/net/ipv4/fib_frontend.c
96431 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
96432 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96433 fib_sync_up(dev);
96434 #endif
96435 - atomic_inc(&net->ipv4.dev_addr_genid);
96436 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96437 rt_cache_flush(dev_net(dev));
96438 break;
96439 case NETDEV_DOWN:
96440 fib_del_ifaddr(ifa, NULL);
96441 - atomic_inc(&net->ipv4.dev_addr_genid);
96442 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96443 if (ifa->ifa_dev->ifa_list == NULL) {
96444 /* Last address was deleted from this interface.
96445 * Disable IP.
96446 @@ -1056,7 +1056,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
96447 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96448 fib_sync_up(dev);
96449 #endif
96450 - atomic_inc(&net->ipv4.dev_addr_genid);
96451 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96452 rt_cache_flush(net);
96453 break;
96454 case NETDEV_DOWN:
96455 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
96456 index e63f47a..e5c531d 100644
96457 --- a/net/ipv4/fib_semantics.c
96458 +++ b/net/ipv4/fib_semantics.c
96459 @@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
96460 nh->nh_saddr = inet_select_addr(nh->nh_dev,
96461 nh->nh_gw,
96462 nh->nh_parent->fib_scope);
96463 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
96464 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
96465
96466 return nh->nh_saddr;
96467 }
96468 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
96469 index fc0e649..febfa65 100644
96470 --- a/net/ipv4/inet_connection_sock.c
96471 +++ b/net/ipv4/inet_connection_sock.c
96472 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
96473 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
96474 #endif
96475
96476 -unsigned long *sysctl_local_reserved_ports;
96477 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
96478 EXPORT_SYMBOL(sysctl_local_reserved_ports);
96479
96480 void inet_get_local_port_range(struct net *net, int *low, int *high)
96481 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
96482 index 8b9cf27..0d8d592 100644
96483 --- a/net/ipv4/inet_hashtables.c
96484 +++ b/net/ipv4/inet_hashtables.c
96485 @@ -18,6 +18,7 @@
96486 #include <linux/sched.h>
96487 #include <linux/slab.h>
96488 #include <linux/wait.h>
96489 +#include <linux/security.h>
96490
96491 #include <net/inet_connection_sock.h>
96492 #include <net/inet_hashtables.h>
96493 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
96494 return inet_ehashfn(net, laddr, lport, faddr, fport);
96495 }
96496
96497 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
96498 +
96499 /*
96500 * Allocate and initialize a new local port bind bucket.
96501 * The bindhash mutex for snum's hash chain must be held here.
96502 @@ -554,6 +557,8 @@ ok:
96503 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
96504 spin_unlock(&head->lock);
96505
96506 + gr_update_task_in_ip_table(current, inet_sk(sk));
96507 +
96508 if (tw) {
96509 inet_twsk_deschedule(tw, death_row);
96510 while (twrefcnt) {
96511 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
96512 index 33d5537..da337a4 100644
96513 --- a/net/ipv4/inetpeer.c
96514 +++ b/net/ipv4/inetpeer.c
96515 @@ -503,8 +503,8 @@ relookup:
96516 if (p) {
96517 p->daddr = *daddr;
96518 atomic_set(&p->refcnt, 1);
96519 - atomic_set(&p->rid, 0);
96520 - atomic_set(&p->ip_id_count,
96521 + atomic_set_unchecked(&p->rid, 0);
96522 + atomic_set_unchecked(&p->ip_id_count,
96523 (daddr->family == AF_INET) ?
96524 secure_ip_id(daddr->addr.a4) :
96525 secure_ipv6_id(daddr->addr.a6));
96526 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
96527 index 2481993..2d9a7a7 100644
96528 --- a/net/ipv4/ip_fragment.c
96529 +++ b/net/ipv4/ip_fragment.c
96530 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
96531 return 0;
96532
96533 start = qp->rid;
96534 - end = atomic_inc_return(&peer->rid);
96535 + end = atomic_inc_return_unchecked(&peer->rid);
96536 qp->rid = end;
96537
96538 rc = qp->q.fragments && (end - start) > max;
96539 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
96540
96541 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96542 {
96543 - struct ctl_table *table;
96544 + ctl_table_no_const *table = NULL;
96545 struct ctl_table_header *hdr;
96546
96547 - table = ip4_frags_ns_ctl_table;
96548 if (!net_eq(net, &init_net)) {
96549 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96550 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96551 if (table == NULL)
96552 goto err_alloc;
96553
96554 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96555 /* Don't export sysctls to unprivileged users */
96556 if (net->user_ns != &init_user_ns)
96557 table[0].procname = NULL;
96558 - }
96559 + hdr = register_net_sysctl(net, "net/ipv4", table);
96560 + } else
96561 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
96562
96563 - hdr = register_net_sysctl(net, "net/ipv4", table);
96564 if (hdr == NULL)
96565 goto err_reg;
96566
96567 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96568 return 0;
96569
96570 err_reg:
96571 - if (!net_eq(net, &init_net))
96572 - kfree(table);
96573 + kfree(table);
96574 err_alloc:
96575 return -ENOMEM;
96576 }
96577 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
96578 index e560ef3..218c5c5 100644
96579 --- a/net/ipv4/ip_gre.c
96580 +++ b/net/ipv4/ip_gre.c
96581 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
96582 module_param(log_ecn_error, bool, 0644);
96583 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96584
96585 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
96586 +static struct rtnl_link_ops ipgre_link_ops;
96587 static int ipgre_tunnel_init(struct net_device *dev);
96588
96589 static int ipgre_net_id __read_mostly;
96590 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
96591 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
96592 };
96593
96594 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96595 +static struct rtnl_link_ops ipgre_link_ops = {
96596 .kind = "gre",
96597 .maxtype = IFLA_GRE_MAX,
96598 .policy = ipgre_policy,
96599 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96600 .fill_info = ipgre_fill_info,
96601 };
96602
96603 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
96604 +static struct rtnl_link_ops ipgre_tap_ops = {
96605 .kind = "gretap",
96606 .maxtype = IFLA_GRE_MAX,
96607 .policy = ipgre_policy,
96608 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
96609 index ddf32a6..3fdeea9 100644
96610 --- a/net/ipv4/ip_sockglue.c
96611 +++ b/net/ipv4/ip_sockglue.c
96612 @@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96613 len = min_t(unsigned int, len, opt->optlen);
96614 if (put_user(len, optlen))
96615 return -EFAULT;
96616 - if (copy_to_user(optval, opt->__data, len))
96617 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
96618 + copy_to_user(optval, opt->__data, len))
96619 return -EFAULT;
96620 return 0;
96621 }
96622 @@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96623 if (sk->sk_type != SOCK_STREAM)
96624 return -ENOPROTOOPT;
96625
96626 - msg.msg_control = optval;
96627 + msg.msg_control = (void __force_kernel *)optval;
96628 msg.msg_controllen = len;
96629 msg.msg_flags = flags;
96630
96631 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
96632 index 52b802a..b725179 100644
96633 --- a/net/ipv4/ip_vti.c
96634 +++ b/net/ipv4/ip_vti.c
96635 @@ -44,7 +44,7 @@
96636 #include <net/net_namespace.h>
96637 #include <net/netns/generic.h>
96638
96639 -static struct rtnl_link_ops vti_link_ops __read_mostly;
96640 +static struct rtnl_link_ops vti_link_ops;
96641
96642 static int vti_net_id __read_mostly;
96643 static int vti_tunnel_init(struct net_device *dev);
96644 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
96645 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
96646 };
96647
96648 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
96649 +static struct rtnl_link_ops vti_link_ops = {
96650 .kind = "vti",
96651 .maxtype = IFLA_VTI_MAX,
96652 .policy = vti_policy,
96653 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
96654 index efa1138..20dbba0 100644
96655 --- a/net/ipv4/ipconfig.c
96656 +++ b/net/ipv4/ipconfig.c
96657 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
96658
96659 mm_segment_t oldfs = get_fs();
96660 set_fs(get_ds());
96661 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96662 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96663 set_fs(oldfs);
96664 return res;
96665 }
96666 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
96667
96668 mm_segment_t oldfs = get_fs();
96669 set_fs(get_ds());
96670 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96671 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96672 set_fs(oldfs);
96673 return res;
96674 }
96675 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
96676
96677 mm_segment_t oldfs = get_fs();
96678 set_fs(get_ds());
96679 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
96680 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
96681 set_fs(oldfs);
96682 return res;
96683 }
96684 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
96685 index fe3e9f7..4956990 100644
96686 --- a/net/ipv4/ipip.c
96687 +++ b/net/ipv4/ipip.c
96688 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96689 static int ipip_net_id __read_mostly;
96690
96691 static int ipip_tunnel_init(struct net_device *dev);
96692 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
96693 +static struct rtnl_link_ops ipip_link_ops;
96694
96695 static int ipip_err(struct sk_buff *skb, u32 info)
96696 {
96697 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
96698 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
96699 };
96700
96701 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
96702 +static struct rtnl_link_ops ipip_link_ops = {
96703 .kind = "ipip",
96704 .maxtype = IFLA_IPTUN_MAX,
96705 .policy = ipip_policy,
96706 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
96707 index 59da7cd..e318de1 100644
96708 --- a/net/ipv4/netfilter/arp_tables.c
96709 +++ b/net/ipv4/netfilter/arp_tables.c
96710 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
96711 #endif
96712
96713 static int get_info(struct net *net, void __user *user,
96714 - const int *len, int compat)
96715 + int len, int compat)
96716 {
96717 char name[XT_TABLE_MAXNAMELEN];
96718 struct xt_table *t;
96719 int ret;
96720
96721 - if (*len != sizeof(struct arpt_getinfo)) {
96722 - duprintf("length %u != %Zu\n", *len,
96723 + if (len != sizeof(struct arpt_getinfo)) {
96724 + duprintf("length %u != %Zu\n", len,
96725 sizeof(struct arpt_getinfo));
96726 return -EINVAL;
96727 }
96728 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
96729 info.size = private->size;
96730 strcpy(info.name, name);
96731
96732 - if (copy_to_user(user, &info, *len) != 0)
96733 + if (copy_to_user(user, &info, len) != 0)
96734 ret = -EFAULT;
96735 else
96736 ret = 0;
96737 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
96738
96739 switch (cmd) {
96740 case ARPT_SO_GET_INFO:
96741 - ret = get_info(sock_net(sk), user, len, 1);
96742 + ret = get_info(sock_net(sk), user, *len, 1);
96743 break;
96744 case ARPT_SO_GET_ENTRIES:
96745 ret = compat_get_entries(sock_net(sk), user, len);
96746 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
96747
96748 switch (cmd) {
96749 case ARPT_SO_GET_INFO:
96750 - ret = get_info(sock_net(sk), user, len, 0);
96751 + ret = get_info(sock_net(sk), user, *len, 0);
96752 break;
96753
96754 case ARPT_SO_GET_ENTRIES:
96755 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
96756 index 718dfbd..cef4152 100644
96757 --- a/net/ipv4/netfilter/ip_tables.c
96758 +++ b/net/ipv4/netfilter/ip_tables.c
96759 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
96760 #endif
96761
96762 static int get_info(struct net *net, void __user *user,
96763 - const int *len, int compat)
96764 + int len, int compat)
96765 {
96766 char name[XT_TABLE_MAXNAMELEN];
96767 struct xt_table *t;
96768 int ret;
96769
96770 - if (*len != sizeof(struct ipt_getinfo)) {
96771 - duprintf("length %u != %zu\n", *len,
96772 + if (len != sizeof(struct ipt_getinfo)) {
96773 + duprintf("length %u != %zu\n", len,
96774 sizeof(struct ipt_getinfo));
96775 return -EINVAL;
96776 }
96777 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
96778 info.size = private->size;
96779 strcpy(info.name, name);
96780
96781 - if (copy_to_user(user, &info, *len) != 0)
96782 + if (copy_to_user(user, &info, len) != 0)
96783 ret = -EFAULT;
96784 else
96785 ret = 0;
96786 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96787
96788 switch (cmd) {
96789 case IPT_SO_GET_INFO:
96790 - ret = get_info(sock_net(sk), user, len, 1);
96791 + ret = get_info(sock_net(sk), user, *len, 1);
96792 break;
96793 case IPT_SO_GET_ENTRIES:
96794 ret = compat_get_entries(sock_net(sk), user, len);
96795 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96796
96797 switch (cmd) {
96798 case IPT_SO_GET_INFO:
96799 - ret = get_info(sock_net(sk), user, len, 0);
96800 + ret = get_info(sock_net(sk), user, *len, 0);
96801 break;
96802
96803 case IPT_SO_GET_ENTRIES:
96804 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
96805 index 242e7f4..a084e95 100644
96806 --- a/net/ipv4/ping.c
96807 +++ b/net/ipv4/ping.c
96808 @@ -55,7 +55,7 @@
96809
96810
96811 struct ping_table ping_table;
96812 -struct pingv6_ops pingv6_ops;
96813 +struct pingv6_ops *pingv6_ops;
96814 EXPORT_SYMBOL_GPL(pingv6_ops);
96815
96816 static u16 ping_port_rover;
96817 @@ -334,7 +334,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
96818 return -ENODEV;
96819 }
96820 }
96821 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
96822 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
96823 scoped);
96824 rcu_read_unlock();
96825
96826 @@ -542,7 +542,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
96827 }
96828 #if IS_ENABLED(CONFIG_IPV6)
96829 } else if (skb->protocol == htons(ETH_P_IPV6)) {
96830 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
96831 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
96832 #endif
96833 }
96834
96835 @@ -560,7 +560,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
96836 info, (u8 *)icmph);
96837 #if IS_ENABLED(CONFIG_IPV6)
96838 } else if (family == AF_INET6) {
96839 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
96840 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
96841 info, (u8 *)icmph);
96842 #endif
96843 }
96844 @@ -830,6 +830,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96845 {
96846 struct inet_sock *isk = inet_sk(sk);
96847 int family = sk->sk_family;
96848 + struct sockaddr_in *sin;
96849 + struct sockaddr_in6 *sin6;
96850 struct sk_buff *skb;
96851 int copied, err;
96852
96853 @@ -839,12 +841,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96854 if (flags & MSG_OOB)
96855 goto out;
96856
96857 + if (addr_len) {
96858 + if (family == AF_INET)
96859 + *addr_len = sizeof(*sin);
96860 + else if (family == AF_INET6 && addr_len)
96861 + *addr_len = sizeof(*sin6);
96862 + }
96863 +
96864 if (flags & MSG_ERRQUEUE) {
96865 if (family == AF_INET) {
96866 return ip_recv_error(sk, msg, len, addr_len);
96867 #if IS_ENABLED(CONFIG_IPV6)
96868 } else if (family == AF_INET6) {
96869 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
96870 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
96871 addr_len);
96872 #endif
96873 }
96874 @@ -876,7 +885,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96875 sin->sin_port = 0 /* skb->h.uh->source */;
96876 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
96877 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
96878 - *addr_len = sizeof(*sin);
96879 }
96880
96881 if (isk->cmsg_flags)
96882 @@ -899,11 +907,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96883 sin6->sin6_scope_id =
96884 ipv6_iface_scope_id(&sin6->sin6_addr,
96885 IP6CB(skb)->iif);
96886 - *addr_len = sizeof(*sin6);
96887 }
96888
96889 if (inet6_sk(sk)->rxopt.all)
96890 - pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
96891 + pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
96892 #endif
96893 } else {
96894 BUG();
96895 @@ -1093,7 +1100,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
96896 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
96897 0, sock_i_ino(sp),
96898 atomic_read(&sp->sk_refcnt), sp,
96899 - atomic_read(&sp->sk_drops));
96900 + atomic_read_unchecked(&sp->sk_drops));
96901 }
96902
96903 static int ping_v4_seq_show(struct seq_file *seq, void *v)
96904 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
96905 index 23c3e5b..cdb8b36 100644
96906 --- a/net/ipv4/raw.c
96907 +++ b/net/ipv4/raw.c
96908 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
96909 int raw_rcv(struct sock *sk, struct sk_buff *skb)
96910 {
96911 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
96912 - atomic_inc(&sk->sk_drops);
96913 + atomic_inc_unchecked(&sk->sk_drops);
96914 kfree_skb(skb);
96915 return NET_RX_DROP;
96916 }
96917 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96918 if (flags & MSG_OOB)
96919 goto out;
96920
96921 + if (addr_len)
96922 + *addr_len = sizeof(*sin);
96923 +
96924 if (flags & MSG_ERRQUEUE) {
96925 err = ip_recv_error(sk, msg, len, addr_len);
96926 goto out;
96927 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96928 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
96929 sin->sin_port = 0;
96930 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
96931 - *addr_len = sizeof(*sin);
96932 }
96933 if (inet->cmsg_flags)
96934 ip_cmsg_recv(msg, skb);
96935 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
96936
96937 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
96938 {
96939 + struct icmp_filter filter;
96940 +
96941 if (optlen > sizeof(struct icmp_filter))
96942 optlen = sizeof(struct icmp_filter);
96943 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
96944 + if (copy_from_user(&filter, optval, optlen))
96945 return -EFAULT;
96946 + raw_sk(sk)->filter = filter;
96947 return 0;
96948 }
96949
96950 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
96951 {
96952 int len, ret = -EFAULT;
96953 + struct icmp_filter filter;
96954
96955 if (get_user(len, optlen))
96956 goto out;
96957 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
96958 if (len > sizeof(struct icmp_filter))
96959 len = sizeof(struct icmp_filter);
96960 ret = -EFAULT;
96961 - if (put_user(len, optlen) ||
96962 - copy_to_user(optval, &raw_sk(sk)->filter, len))
96963 + filter = raw_sk(sk)->filter;
96964 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
96965 goto out;
96966 ret = 0;
96967 out: return ret;
96968 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
96969 0, 0L, 0,
96970 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
96971 0, sock_i_ino(sp),
96972 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
96973 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
96974 }
96975
96976 static int raw_seq_show(struct seq_file *seq, void *v)
96977 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
96978 index f8da282..133a1c7 100644
96979 --- a/net/ipv4/route.c
96980 +++ b/net/ipv4/route.c
96981 @@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
96982 .maxlen = sizeof(int),
96983 .mode = 0200,
96984 .proc_handler = ipv4_sysctl_rtcache_flush,
96985 + .extra1 = &init_net,
96986 },
96987 { },
96988 };
96989
96990 static __net_init int sysctl_route_net_init(struct net *net)
96991 {
96992 - struct ctl_table *tbl;
96993 + ctl_table_no_const *tbl = NULL;
96994
96995 - tbl = ipv4_route_flush_table;
96996 if (!net_eq(net, &init_net)) {
96997 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
96998 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
96999 if (tbl == NULL)
97000 goto err_dup;
97001
97002 /* Don't export sysctls to unprivileged users */
97003 if (net->user_ns != &init_user_ns)
97004 tbl[0].procname = NULL;
97005 - }
97006 - tbl[0].extra1 = net;
97007 + tbl[0].extra1 = net;
97008 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
97009 + } else
97010 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
97011
97012 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
97013 if (net->ipv4.route_hdr == NULL)
97014 goto err_reg;
97015 return 0;
97016
97017 err_reg:
97018 - if (tbl != ipv4_route_flush_table)
97019 - kfree(tbl);
97020 + kfree(tbl);
97021 err_dup:
97022 return -ENOMEM;
97023 }
97024 @@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
97025
97026 static __net_init int rt_genid_init(struct net *net)
97027 {
97028 - atomic_set(&net->ipv4.rt_genid, 0);
97029 - atomic_set(&net->fnhe_genid, 0);
97030 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
97031 + atomic_set_unchecked(&net->fnhe_genid, 0);
97032 get_random_bytes(&net->ipv4.dev_addr_genid,
97033 sizeof(net->ipv4.dev_addr_genid));
97034 return 0;
97035 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
97036 index 3d69ec8..57207b4 100644
97037 --- a/net/ipv4/sysctl_net_ipv4.c
97038 +++ b/net/ipv4/sysctl_net_ipv4.c
97039 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
97040 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
97041 int ret;
97042 int range[2];
97043 - struct ctl_table tmp = {
97044 + ctl_table_no_const tmp = {
97045 .data = &range,
97046 .maxlen = sizeof(range),
97047 .mode = table->mode,
97048 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
97049 int ret;
97050 gid_t urange[2];
97051 kgid_t low, high;
97052 - struct ctl_table tmp = {
97053 + ctl_table_no_const tmp = {
97054 .data = &urange,
97055 .maxlen = sizeof(urange),
97056 .mode = table->mode,
97057 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
97058 void __user *buffer, size_t *lenp, loff_t *ppos)
97059 {
97060 char val[TCP_CA_NAME_MAX];
97061 - struct ctl_table tbl = {
97062 + ctl_table_no_const tbl = {
97063 .data = val,
97064 .maxlen = TCP_CA_NAME_MAX,
97065 };
97066 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
97067 void __user *buffer, size_t *lenp,
97068 loff_t *ppos)
97069 {
97070 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
97071 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
97072 int ret;
97073
97074 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97075 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
97076 void __user *buffer, size_t *lenp,
97077 loff_t *ppos)
97078 {
97079 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
97080 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
97081 int ret;
97082
97083 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97084 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
97085 void __user *buffer, size_t *lenp,
97086 loff_t *ppos)
97087 {
97088 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97089 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97090 struct tcp_fastopen_context *ctxt;
97091 int ret;
97092 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
97093 @@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
97094 },
97095 {
97096 .procname = "ip_local_reserved_ports",
97097 - .data = NULL, /* initialized in sysctl_ipv4_init */
97098 + .data = sysctl_local_reserved_ports,
97099 .maxlen = 65536,
97100 .mode = 0644,
97101 .proc_handler = proc_do_large_bitmap,
97102 @@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
97103
97104 static __net_init int ipv4_sysctl_init_net(struct net *net)
97105 {
97106 - struct ctl_table *table;
97107 + ctl_table_no_const *table = NULL;
97108
97109 - table = ipv4_net_table;
97110 if (!net_eq(net, &init_net)) {
97111 int i;
97112
97113 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
97114 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
97115 if (table == NULL)
97116 goto err_alloc;
97117
97118 @@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
97119 net->ipv4.sysctl_local_ports.range[0] = 32768;
97120 net->ipv4.sysctl_local_ports.range[1] = 61000;
97121
97122 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97123 + if (!net_eq(net, &init_net))
97124 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97125 + else
97126 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
97127 if (net->ipv4.ipv4_hdr == NULL)
97128 goto err_reg;
97129
97130 return 0;
97131
97132 err_reg:
97133 - if (!net_eq(net, &init_net))
97134 - kfree(table);
97135 + kfree(table);
97136 err_alloc:
97137 return -ENOMEM;
97138 }
97139 @@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
97140 static __init int sysctl_ipv4_init(void)
97141 {
97142 struct ctl_table_header *hdr;
97143 - struct ctl_table *i;
97144 -
97145 - for (i = ipv4_table; i->procname; i++) {
97146 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
97147 - i->data = sysctl_local_reserved_ports;
97148 - break;
97149 - }
97150 - }
97151 - if (!i->procname)
97152 - return -EINVAL;
97153
97154 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
97155 if (hdr == NULL)
97156 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
97157 index c53b7f3..a89aadd 100644
97158 --- a/net/ipv4/tcp_input.c
97159 +++ b/net/ipv4/tcp_input.c
97160 @@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
97161 * without any lock. We want to make sure compiler wont store
97162 * intermediate values in this location.
97163 */
97164 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
97165 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
97166 sk->sk_max_pacing_rate);
97167 }
97168
97169 @@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
97170 * simplifies code)
97171 */
97172 static void
97173 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97174 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97175 struct sk_buff *head, struct sk_buff *tail,
97176 u32 start, u32 end)
97177 {
97178 @@ -5559,6 +5559,7 @@ discard:
97179 tcp_paws_reject(&tp->rx_opt, 0))
97180 goto discard_and_undo;
97181
97182 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
97183 if (th->syn) {
97184 /* We see SYN without ACK. It is attempt of
97185 * simultaneous connect with crossed SYNs.
97186 @@ -5609,6 +5610,7 @@ discard:
97187 goto discard;
97188 #endif
97189 }
97190 +#endif
97191 /* "fifth, if neither of the SYN or RST bits is set then
97192 * drop the segment and return."
97193 */
97194 @@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
97195 goto discard;
97196
97197 if (th->syn) {
97198 - if (th->fin)
97199 + if (th->fin || th->urg || th->psh)
97200 goto discard;
97201 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
97202 return 1;
97203 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
97204 index 0672139..cacc17d 100644
97205 --- a/net/ipv4/tcp_ipv4.c
97206 +++ b/net/ipv4/tcp_ipv4.c
97207 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
97208 EXPORT_SYMBOL(sysctl_tcp_low_latency);
97209
97210
97211 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97212 +extern int grsec_enable_blackhole;
97213 +#endif
97214 +
97215 #ifdef CONFIG_TCP_MD5SIG
97216 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
97217 __be32 daddr, __be32 saddr, const struct tcphdr *th);
97218 @@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
97219 return 0;
97220
97221 reset:
97222 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97223 + if (!grsec_enable_blackhole)
97224 +#endif
97225 tcp_v4_send_reset(rsk, skb);
97226 discard:
97227 kfree_skb(skb);
97228 @@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
97229 TCP_SKB_CB(skb)->sacked = 0;
97230
97231 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
97232 - if (!sk)
97233 + if (!sk) {
97234 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97235 + ret = 1;
97236 +#endif
97237 goto no_tcp_socket;
97238 -
97239 + }
97240 process:
97241 - if (sk->sk_state == TCP_TIME_WAIT)
97242 + if (sk->sk_state == TCP_TIME_WAIT) {
97243 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97244 + ret = 2;
97245 +#endif
97246 goto do_time_wait;
97247 + }
97248
97249 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
97250 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
97251 @@ -2034,6 +2048,10 @@ csum_error:
97252 bad_packet:
97253 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
97254 } else {
97255 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97256 + if (!grsec_enable_blackhole || (ret == 1 &&
97257 + (skb->dev->flags & IFF_LOOPBACK)))
97258 +#endif
97259 tcp_v4_send_reset(NULL, skb);
97260 }
97261
97262 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
97263 index 97b6841..0893357 100644
97264 --- a/net/ipv4/tcp_minisocks.c
97265 +++ b/net/ipv4/tcp_minisocks.c
97266 @@ -27,6 +27,10 @@
97267 #include <net/inet_common.h>
97268 #include <net/xfrm.h>
97269
97270 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97271 +extern int grsec_enable_blackhole;
97272 +#endif
97273 +
97274 int sysctl_tcp_syncookies __read_mostly = 1;
97275 EXPORT_SYMBOL(sysctl_tcp_syncookies);
97276
97277 @@ -708,7 +712,10 @@ embryonic_reset:
97278 * avoid becoming vulnerable to outside attack aiming at
97279 * resetting legit local connections.
97280 */
97281 - req->rsk_ops->send_reset(sk, skb);
97282 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97283 + if (!grsec_enable_blackhole)
97284 +#endif
97285 + req->rsk_ops->send_reset(sk, skb);
97286 } else if (fastopen) { /* received a valid RST pkt */
97287 reqsk_fastopen_remove(sk, req, true);
97288 tcp_reset(sk);
97289 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
97290 index 8b97d71..9d7ccf5 100644
97291 --- a/net/ipv4/tcp_probe.c
97292 +++ b/net/ipv4/tcp_probe.c
97293 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
97294 if (cnt + width >= len)
97295 break;
97296
97297 - if (copy_to_user(buf + cnt, tbuf, width))
97298 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
97299 return -EFAULT;
97300 cnt += width;
97301 }
97302 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
97303 index 64f0354..a81b39d 100644
97304 --- a/net/ipv4/tcp_timer.c
97305 +++ b/net/ipv4/tcp_timer.c
97306 @@ -22,6 +22,10 @@
97307 #include <linux/gfp.h>
97308 #include <net/tcp.h>
97309
97310 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97311 +extern int grsec_lastack_retries;
97312 +#endif
97313 +
97314 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
97315 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
97316 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
97317 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
97318 }
97319 }
97320
97321 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97322 + if ((sk->sk_state == TCP_LAST_ACK) &&
97323 + (grsec_lastack_retries > 0) &&
97324 + (grsec_lastack_retries < retry_until))
97325 + retry_until = grsec_lastack_retries;
97326 +#endif
97327 +
97328 if (retransmits_timed_out(sk, retry_until,
97329 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
97330 /* Has it gone just too far? */
97331 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
97332 index a7e4729..2758946 100644
97333 --- a/net/ipv4/udp.c
97334 +++ b/net/ipv4/udp.c
97335 @@ -87,6 +87,7 @@
97336 #include <linux/types.h>
97337 #include <linux/fcntl.h>
97338 #include <linux/module.h>
97339 +#include <linux/security.h>
97340 #include <linux/socket.h>
97341 #include <linux/sockios.h>
97342 #include <linux/igmp.h>
97343 @@ -113,6 +114,10 @@
97344 #include <net/busy_poll.h>
97345 #include "udp_impl.h"
97346
97347 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97348 +extern int grsec_enable_blackhole;
97349 +#endif
97350 +
97351 struct udp_table udp_table __read_mostly;
97352 EXPORT_SYMBOL(udp_table);
97353
97354 @@ -615,6 +620,9 @@ found:
97355 return s;
97356 }
97357
97358 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
97359 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
97360 +
97361 /*
97362 * This routine is called by the ICMP module when it gets some
97363 * sort of error condition. If err < 0 then the socket should
97364 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97365 dport = usin->sin_port;
97366 if (dport == 0)
97367 return -EINVAL;
97368 +
97369 + err = gr_search_udp_sendmsg(sk, usin);
97370 + if (err)
97371 + return err;
97372 } else {
97373 if (sk->sk_state != TCP_ESTABLISHED)
97374 return -EDESTADDRREQ;
97375 +
97376 + err = gr_search_udp_sendmsg(sk, NULL);
97377 + if (err)
97378 + return err;
97379 +
97380 daddr = inet->inet_daddr;
97381 dport = inet->inet_dport;
97382 /* Open fast path for connected socket.
97383 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
97384 IS_UDPLITE(sk));
97385 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97386 IS_UDPLITE(sk));
97387 - atomic_inc(&sk->sk_drops);
97388 + atomic_inc_unchecked(&sk->sk_drops);
97389 __skb_unlink(skb, rcvq);
97390 __skb_queue_tail(&list_kill, skb);
97391 }
97392 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97393 int is_udplite = IS_UDPLITE(sk);
97394 bool slow;
97395
97396 + /*
97397 + * Check any passed addresses
97398 + */
97399 + if (addr_len)
97400 + *addr_len = sizeof(*sin);
97401 +
97402 if (flags & MSG_ERRQUEUE)
97403 return ip_recv_error(sk, msg, len, addr_len);
97404
97405 @@ -1243,6 +1266,10 @@ try_again:
97406 if (!skb)
97407 goto out;
97408
97409 + err = gr_search_udp_recvmsg(sk, skb);
97410 + if (err)
97411 + goto out_free;
97412 +
97413 ulen = skb->len - sizeof(struct udphdr);
97414 copied = len;
97415 if (copied > ulen)
97416 @@ -1276,7 +1303,7 @@ try_again:
97417 if (unlikely(err)) {
97418 trace_kfree_skb(skb, udp_recvmsg);
97419 if (!peeked) {
97420 - atomic_inc(&sk->sk_drops);
97421 + atomic_inc_unchecked(&sk->sk_drops);
97422 UDP_INC_STATS_USER(sock_net(sk),
97423 UDP_MIB_INERRORS, is_udplite);
97424 }
97425 @@ -1295,7 +1322,6 @@ try_again:
97426 sin->sin_port = udp_hdr(skb)->source;
97427 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97428 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
97429 - *addr_len = sizeof(*sin);
97430 }
97431 if (inet->cmsg_flags)
97432 ip_cmsg_recv(msg, skb);
97433 @@ -1566,7 +1592,7 @@ csum_error:
97434 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
97435 drop:
97436 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
97437 - atomic_inc(&sk->sk_drops);
97438 + atomic_inc_unchecked(&sk->sk_drops);
97439 kfree_skb(skb);
97440 return -1;
97441 }
97442 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
97443 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
97444
97445 if (!skb1) {
97446 - atomic_inc(&sk->sk_drops);
97447 + atomic_inc_unchecked(&sk->sk_drops);
97448 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
97449 IS_UDPLITE(sk));
97450 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97451 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
97452 goto csum_error;
97453
97454 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
97455 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97456 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
97457 +#endif
97458 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
97459
97460 /*
97461 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
97462 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97463 0, sock_i_ino(sp),
97464 atomic_read(&sp->sk_refcnt), sp,
97465 - atomic_read(&sp->sk_drops));
97466 + atomic_read_unchecked(&sp->sk_drops));
97467 }
97468
97469 int udp4_seq_show(struct seq_file *seq, void *v)
97470 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
97471 index e1a6393..f634ce5 100644
97472 --- a/net/ipv4/xfrm4_policy.c
97473 +++ b/net/ipv4/xfrm4_policy.c
97474 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
97475 fl4->flowi4_tos = iph->tos;
97476 }
97477
97478 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
97479 +static int xfrm4_garbage_collect(struct dst_ops *ops)
97480 {
97481 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
97482
97483 - xfrm4_policy_afinfo.garbage_collect(net);
97484 + xfrm_garbage_collect_deferred(net);
97485 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
97486 }
97487
97488 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
97489
97490 static int __net_init xfrm4_net_init(struct net *net)
97491 {
97492 - struct ctl_table *table;
97493 + ctl_table_no_const *table = NULL;
97494 struct ctl_table_header *hdr;
97495
97496 - table = xfrm4_policy_table;
97497 if (!net_eq(net, &init_net)) {
97498 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97499 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97500 if (!table)
97501 goto err_alloc;
97502
97503 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
97504 - }
97505 -
97506 - hdr = register_net_sysctl(net, "net/ipv4", table);
97507 + hdr = register_net_sysctl(net, "net/ipv4", table);
97508 + } else
97509 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
97510 if (!hdr)
97511 goto err_reg;
97512
97513 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
97514 return 0;
97515
97516 err_reg:
97517 - if (!net_eq(net, &init_net))
97518 - kfree(table);
97519 + kfree(table);
97520 err_alloc:
97521 return -ENOMEM;
97522 }
97523 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
97524 index 4b6b720..272c0c5 100644
97525 --- a/net/ipv6/addrconf.c
97526 +++ b/net/ipv6/addrconf.c
97527 @@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
97528 idx = 0;
97529 head = &net->dev_index_head[h];
97530 rcu_read_lock();
97531 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
97532 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
97533 net->dev_base_seq;
97534 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97535 if (idx < s_idx)
97536 @@ -2334,7 +2334,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
97537 p.iph.ihl = 5;
97538 p.iph.protocol = IPPROTO_IPV6;
97539 p.iph.ttl = 64;
97540 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
97541 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
97542
97543 if (ops->ndo_do_ioctl) {
97544 mm_segment_t oldfs = get_fs();
97545 @@ -3962,7 +3962,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
97546 s_ip_idx = ip_idx = cb->args[2];
97547
97548 rcu_read_lock();
97549 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97550 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97551 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
97552 idx = 0;
97553 head = &net->dev_index_head[h];
97554 @@ -4569,7 +4569,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
97555 dst_free(&ifp->rt->dst);
97556 break;
97557 }
97558 - atomic_inc(&net->ipv6.dev_addr_genid);
97559 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
97560 rt_genid_bump_ipv6(net);
97561 }
97562
97563 @@ -4590,7 +4590,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
97564 int *valp = ctl->data;
97565 int val = *valp;
97566 loff_t pos = *ppos;
97567 - struct ctl_table lctl;
97568 + ctl_table_no_const lctl;
97569 int ret;
97570
97571 /*
97572 @@ -4675,7 +4675,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
97573 int *valp = ctl->data;
97574 int val = *valp;
97575 loff_t pos = *ppos;
97576 - struct ctl_table lctl;
97577 + ctl_table_no_const lctl;
97578 int ret;
97579
97580 /*
97581 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
97582 index 4fbdb70..f6411f2 100644
97583 --- a/net/ipv6/af_inet6.c
97584 +++ b/net/ipv6/af_inet6.c
97585 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
97586
97587 net->ipv6.sysctl.bindv6only = 0;
97588 net->ipv6.sysctl.icmpv6_time = 1*HZ;
97589 - atomic_set(&net->ipv6.rt_genid, 0);
97590 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
97591
97592 err = ipv6_init_mibs(net);
97593 if (err)
97594 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
97595 index 93b1aa3..e902855 100644
97596 --- a/net/ipv6/datagram.c
97597 +++ b/net/ipv6/datagram.c
97598 @@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
97599 0,
97600 sock_i_ino(sp),
97601 atomic_read(&sp->sk_refcnt), sp,
97602 - atomic_read(&sp->sk_drops));
97603 + atomic_read_unchecked(&sp->sk_drops));
97604 }
97605 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
97606 index eef8d94..cfa1852 100644
97607 --- a/net/ipv6/icmp.c
97608 +++ b/net/ipv6/icmp.c
97609 @@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
97610
97611 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
97612 {
97613 - struct ctl_table *table;
97614 + ctl_table_no_const *table;
97615
97616 table = kmemdup(ipv6_icmp_table_template,
97617 sizeof(ipv6_icmp_table_template),
97618 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
97619 index 8acb286..840dd06 100644
97620 --- a/net/ipv6/ip6_gre.c
97621 +++ b/net/ipv6/ip6_gre.c
97622 @@ -74,7 +74,7 @@ struct ip6gre_net {
97623 struct net_device *fb_tunnel_dev;
97624 };
97625
97626 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
97627 +static struct rtnl_link_ops ip6gre_link_ops;
97628 static int ip6gre_tunnel_init(struct net_device *dev);
97629 static void ip6gre_tunnel_setup(struct net_device *dev);
97630 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
97631 @@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
97632 }
97633
97634
97635 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
97636 +static struct inet6_protocol ip6gre_protocol = {
97637 .handler = ip6gre_rcv,
97638 .err_handler = ip6gre_err,
97639 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
97640 @@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
97641 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
97642 };
97643
97644 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97645 +static struct rtnl_link_ops ip6gre_link_ops = {
97646 .kind = "ip6gre",
97647 .maxtype = IFLA_GRE_MAX,
97648 .policy = ip6gre_policy,
97649 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97650 .fill_info = ip6gre_fill_info,
97651 };
97652
97653 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
97654 +static struct rtnl_link_ops ip6gre_tap_ops = {
97655 .kind = "ip6gretap",
97656 .maxtype = IFLA_GRE_MAX,
97657 .policy = ip6gre_policy,
97658 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
97659 index 7881965..9cf62c4 100644
97660 --- a/net/ipv6/ip6_tunnel.c
97661 +++ b/net/ipv6/ip6_tunnel.c
97662 @@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97663
97664 static int ip6_tnl_dev_init(struct net_device *dev);
97665 static void ip6_tnl_dev_setup(struct net_device *dev);
97666 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
97667 +static struct rtnl_link_ops ip6_link_ops;
97668
97669 static int ip6_tnl_net_id __read_mostly;
97670 struct ip6_tnl_net {
97671 @@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
97672 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
97673 };
97674
97675 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
97676 +static struct rtnl_link_ops ip6_link_ops = {
97677 .kind = "ip6tnl",
97678 .maxtype = IFLA_IPTUN_MAX,
97679 .policy = ip6_tnl_policy,
97680 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
97681 index 7b42d5e..1eff693 100644
97682 --- a/net/ipv6/ip6_vti.c
97683 +++ b/net/ipv6/ip6_vti.c
97684 @@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97685
97686 static int vti6_dev_init(struct net_device *dev);
97687 static void vti6_dev_setup(struct net_device *dev);
97688 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
97689 +static struct rtnl_link_ops vti6_link_ops;
97690
97691 static int vti6_net_id __read_mostly;
97692 struct vti6_net {
97693 @@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
97694 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
97695 };
97696
97697 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
97698 +static struct rtnl_link_ops vti6_link_ops = {
97699 .kind = "vti6",
97700 .maxtype = IFLA_VTI_MAX,
97701 .policy = vti6_policy,
97702 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
97703 index 1c6ce31..299e566 100644
97704 --- a/net/ipv6/ipv6_sockglue.c
97705 +++ b/net/ipv6/ipv6_sockglue.c
97706 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
97707 if (sk->sk_type != SOCK_STREAM)
97708 return -ENOPROTOOPT;
97709
97710 - msg.msg_control = optval;
97711 + msg.msg_control = (void __force_kernel *)optval;
97712 msg.msg_controllen = len;
97713 msg.msg_flags = flags;
97714
97715 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
97716 index 710238f..0fd1816 100644
97717 --- a/net/ipv6/netfilter/ip6_tables.c
97718 +++ b/net/ipv6/netfilter/ip6_tables.c
97719 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
97720 #endif
97721
97722 static int get_info(struct net *net, void __user *user,
97723 - const int *len, int compat)
97724 + int len, int compat)
97725 {
97726 char name[XT_TABLE_MAXNAMELEN];
97727 struct xt_table *t;
97728 int ret;
97729
97730 - if (*len != sizeof(struct ip6t_getinfo)) {
97731 - duprintf("length %u != %zu\n", *len,
97732 + if (len != sizeof(struct ip6t_getinfo)) {
97733 + duprintf("length %u != %zu\n", len,
97734 sizeof(struct ip6t_getinfo));
97735 return -EINVAL;
97736 }
97737 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
97738 info.size = private->size;
97739 strcpy(info.name, name);
97740
97741 - if (copy_to_user(user, &info, *len) != 0)
97742 + if (copy_to_user(user, &info, len) != 0)
97743 ret = -EFAULT;
97744 else
97745 ret = 0;
97746 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97747
97748 switch (cmd) {
97749 case IP6T_SO_GET_INFO:
97750 - ret = get_info(sock_net(sk), user, len, 1);
97751 + ret = get_info(sock_net(sk), user, *len, 1);
97752 break;
97753 case IP6T_SO_GET_ENTRIES:
97754 ret = compat_get_entries(sock_net(sk), user, len);
97755 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97756
97757 switch (cmd) {
97758 case IP6T_SO_GET_INFO:
97759 - ret = get_info(sock_net(sk), user, len, 0);
97760 + ret = get_info(sock_net(sk), user, *len, 0);
97761 break;
97762
97763 case IP6T_SO_GET_ENTRIES:
97764 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
97765 index 767ab8d..c5ec70a 100644
97766 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
97767 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
97768 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
97769
97770 static int nf_ct_frag6_sysctl_register(struct net *net)
97771 {
97772 - struct ctl_table *table;
97773 + ctl_table_no_const *table = NULL;
97774 struct ctl_table_header *hdr;
97775
97776 - table = nf_ct_frag6_sysctl_table;
97777 if (!net_eq(net, &init_net)) {
97778 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
97779 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
97780 GFP_KERNEL);
97781 if (table == NULL)
97782 goto err_alloc;
97783 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97784 table[0].data = &net->nf_frag.frags.timeout;
97785 table[1].data = &net->nf_frag.frags.low_thresh;
97786 table[2].data = &net->nf_frag.frags.high_thresh;
97787 - }
97788 -
97789 - hdr = register_net_sysctl(net, "net/netfilter", table);
97790 + hdr = register_net_sysctl(net, "net/netfilter", table);
97791 + } else
97792 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
97793 if (hdr == NULL)
97794 goto err_reg;
97795
97796 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97797 return 0;
97798
97799 err_reg:
97800 - if (!net_eq(net, &init_net))
97801 - kfree(table);
97802 + kfree(table);
97803 err_alloc:
97804 return -ENOMEM;
97805 }
97806 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
97807 index 827f795..7e28e82 100644
97808 --- a/net/ipv6/output_core.c
97809 +++ b/net/ipv6/output_core.c
97810 @@ -9,8 +9,8 @@
97811
97812 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97813 {
97814 - static atomic_t ipv6_fragmentation_id;
97815 - int old, new;
97816 + static atomic_unchecked_t ipv6_fragmentation_id;
97817 + int id;
97818
97819 #if IS_ENABLED(CONFIG_IPV6)
97820 if (rt && !(rt->dst.flags & DST_NOPEER)) {
97821 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97822 }
97823 }
97824 #endif
97825 - do {
97826 - old = atomic_read(&ipv6_fragmentation_id);
97827 - new = old + 1;
97828 - if (!new)
97829 - new = 1;
97830 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
97831 - fhdr->identification = htonl(new);
97832 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97833 + if (!id)
97834 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97835 + fhdr->identification = htonl(id);
97836 }
97837 EXPORT_SYMBOL(ipv6_select_ident);
97838
97839 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
97840 index a83243c..a1ca589 100644
97841 --- a/net/ipv6/ping.c
97842 +++ b/net/ipv6/ping.c
97843 @@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
97844 };
97845 #endif
97846
97847 +static struct pingv6_ops real_pingv6_ops = {
97848 + .ipv6_recv_error = ipv6_recv_error,
97849 + .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
97850 + .icmpv6_err_convert = icmpv6_err_convert,
97851 + .ipv6_icmp_error = ipv6_icmp_error,
97852 + .ipv6_chk_addr = ipv6_chk_addr,
97853 +};
97854 +
97855 +static struct pingv6_ops dummy_pingv6_ops = {
97856 + .ipv6_recv_error = dummy_ipv6_recv_error,
97857 + .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
97858 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
97859 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
97860 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
97861 +};
97862 +
97863 int __init pingv6_init(void)
97864 {
97865 #ifdef CONFIG_PROC_FS
97866 @@ -253,11 +269,7 @@ int __init pingv6_init(void)
97867 if (ret)
97868 return ret;
97869 #endif
97870 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
97871 - pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
97872 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
97873 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
97874 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
97875 + pingv6_ops = &real_pingv6_ops;
97876 return inet6_register_protosw(&pingv6_protosw);
97877 }
97878
97879 @@ -266,11 +278,7 @@ int __init pingv6_init(void)
97880 */
97881 void pingv6_exit(void)
97882 {
97883 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
97884 - pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
97885 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
97886 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
97887 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
97888 + pingv6_ops = &dummy_pingv6_ops;
97889 #ifdef CONFIG_PROC_FS
97890 unregister_pernet_subsys(&ping_v6_net_ops);
97891 #endif
97892 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
97893 index b6bb87e..06cc9ed 100644
97894 --- a/net/ipv6/raw.c
97895 +++ b/net/ipv6/raw.c
97896 @@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
97897 {
97898 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
97899 skb_checksum_complete(skb)) {
97900 - atomic_inc(&sk->sk_drops);
97901 + atomic_inc_unchecked(&sk->sk_drops);
97902 kfree_skb(skb);
97903 return NET_RX_DROP;
97904 }
97905 @@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
97906 struct raw6_sock *rp = raw6_sk(sk);
97907
97908 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
97909 - atomic_inc(&sk->sk_drops);
97910 + atomic_inc_unchecked(&sk->sk_drops);
97911 kfree_skb(skb);
97912 return NET_RX_DROP;
97913 }
97914 @@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
97915
97916 if (inet->hdrincl) {
97917 if (skb_checksum_complete(skb)) {
97918 - atomic_inc(&sk->sk_drops);
97919 + atomic_inc_unchecked(&sk->sk_drops);
97920 kfree_skb(skb);
97921 return NET_RX_DROP;
97922 }
97923 @@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
97924 if (flags & MSG_OOB)
97925 return -EOPNOTSUPP;
97926
97927 + if (addr_len)
97928 + *addr_len=sizeof(*sin6);
97929 +
97930 if (flags & MSG_ERRQUEUE)
97931 return ipv6_recv_error(sk, msg, len, addr_len);
97932
97933 @@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
97934 sin6->sin6_flowinfo = 0;
97935 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
97936 IP6CB(skb)->iif);
97937 - *addr_len = sizeof(*sin6);
97938 }
97939
97940 sock_recv_ts_and_drops(msg, sk, skb);
97941 @@ -606,7 +608,7 @@ out:
97942 return err;
97943 }
97944
97945 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
97946 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
97947 struct flowi6 *fl6, struct dst_entry **dstp,
97948 unsigned int flags)
97949 {
97950 @@ -918,12 +920,15 @@ do_confirm:
97951 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
97952 char __user *optval, int optlen)
97953 {
97954 + struct icmp6_filter filter;
97955 +
97956 switch (optname) {
97957 case ICMPV6_FILTER:
97958 if (optlen > sizeof(struct icmp6_filter))
97959 optlen = sizeof(struct icmp6_filter);
97960 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
97961 + if (copy_from_user(&filter, optval, optlen))
97962 return -EFAULT;
97963 + raw6_sk(sk)->filter = filter;
97964 return 0;
97965 default:
97966 return -ENOPROTOOPT;
97967 @@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
97968 char __user *optval, int __user *optlen)
97969 {
97970 int len;
97971 + struct icmp6_filter filter;
97972
97973 switch (optname) {
97974 case ICMPV6_FILTER:
97975 @@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
97976 len = sizeof(struct icmp6_filter);
97977 if (put_user(len, optlen))
97978 return -EFAULT;
97979 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
97980 + filter = raw6_sk(sk)->filter;
97981 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
97982 return -EFAULT;
97983 return 0;
97984 default:
97985 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
97986 index cc85a9b..526a133 100644
97987 --- a/net/ipv6/reassembly.c
97988 +++ b/net/ipv6/reassembly.c
97989 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
97990
97991 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
97992 {
97993 - struct ctl_table *table;
97994 + ctl_table_no_const *table = NULL;
97995 struct ctl_table_header *hdr;
97996
97997 - table = ip6_frags_ns_ctl_table;
97998 if (!net_eq(net, &init_net)) {
97999 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
98000 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
98001 if (table == NULL)
98002 goto err_alloc;
98003
98004 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98005 /* Don't export sysctls to unprivileged users */
98006 if (net->user_ns != &init_user_ns)
98007 table[0].procname = NULL;
98008 - }
98009 + hdr = register_net_sysctl(net, "net/ipv6", table);
98010 + } else
98011 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
98012
98013 - hdr = register_net_sysctl(net, "net/ipv6", table);
98014 if (hdr == NULL)
98015 goto err_reg;
98016
98017 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98018 return 0;
98019
98020 err_reg:
98021 - if (!net_eq(net, &init_net))
98022 - kfree(table);
98023 + kfree(table);
98024 err_alloc:
98025 return -ENOMEM;
98026 }
98027 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
98028 index 4b4944c..4580b91 100644
98029 --- a/net/ipv6/route.c
98030 +++ b/net/ipv6/route.c
98031 @@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
98032
98033 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
98034 {
98035 - struct ctl_table *table;
98036 + ctl_table_no_const *table;
98037
98038 table = kmemdup(ipv6_route_table_template,
98039 sizeof(ipv6_route_table_template),
98040 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
98041 index d3005b3..b36df4a 100644
98042 --- a/net/ipv6/sit.c
98043 +++ b/net/ipv6/sit.c
98044 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
98045 static void ipip6_dev_free(struct net_device *dev);
98046 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
98047 __be32 *v4dst);
98048 -static struct rtnl_link_ops sit_link_ops __read_mostly;
98049 +static struct rtnl_link_ops sit_link_ops;
98050
98051 static int sit_net_id __read_mostly;
98052 struct sit_net {
98053 @@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
98054 unregister_netdevice_queue(dev, head);
98055 }
98056
98057 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
98058 +static struct rtnl_link_ops sit_link_ops = {
98059 .kind = "sit",
98060 .maxtype = IFLA_IPTUN_MAX,
98061 .policy = ipip6_policy,
98062 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
98063 index 107b2f1..72741a9 100644
98064 --- a/net/ipv6/sysctl_net_ipv6.c
98065 +++ b/net/ipv6/sysctl_net_ipv6.c
98066 @@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
98067
98068 static int __net_init ipv6_sysctl_net_init(struct net *net)
98069 {
98070 - struct ctl_table *ipv6_table;
98071 + ctl_table_no_const *ipv6_table;
98072 struct ctl_table *ipv6_route_table;
98073 struct ctl_table *ipv6_icmp_table;
98074 int err;
98075 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
98076 index f67033b..6f974fc 100644
98077 --- a/net/ipv6/tcp_ipv6.c
98078 +++ b/net/ipv6/tcp_ipv6.c
98079 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
98080 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
98081 }
98082
98083 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98084 +extern int grsec_enable_blackhole;
98085 +#endif
98086 +
98087 static void tcp_v6_hash(struct sock *sk)
98088 {
98089 if (sk->sk_state != TCP_CLOSE) {
98090 @@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
98091 return 0;
98092
98093 reset:
98094 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98095 + if (!grsec_enable_blackhole)
98096 +#endif
98097 tcp_v6_send_reset(sk, skb);
98098 discard:
98099 if (opt_skb)
98100 @@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
98101 TCP_SKB_CB(skb)->sacked = 0;
98102
98103 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98104 - if (!sk)
98105 + if (!sk) {
98106 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98107 + ret = 1;
98108 +#endif
98109 goto no_tcp_socket;
98110 + }
98111
98112 process:
98113 - if (sk->sk_state == TCP_TIME_WAIT)
98114 + if (sk->sk_state == TCP_TIME_WAIT) {
98115 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98116 + ret = 2;
98117 +#endif
98118 goto do_time_wait;
98119 + }
98120
98121 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
98122 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98123 @@ -1536,6 +1551,10 @@ csum_error:
98124 bad_packet:
98125 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98126 } else {
98127 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98128 + if (!grsec_enable_blackhole || (ret == 1 &&
98129 + (skb->dev->flags & IFF_LOOPBACK)))
98130 +#endif
98131 tcp_v6_send_reset(NULL, skb);
98132 }
98133
98134 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
98135 index 089c741..cfee117 100644
98136 --- a/net/ipv6/udp.c
98137 +++ b/net/ipv6/udp.c
98138 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
98139 udp_ipv6_hash_secret + net_hash_mix(net));
98140 }
98141
98142 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98143 +extern int grsec_enable_blackhole;
98144 +#endif
98145 +
98146 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
98147 {
98148 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
98149 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98150 int is_udp4;
98151 bool slow;
98152
98153 + if (addr_len)
98154 + *addr_len = sizeof(struct sockaddr_in6);
98155 +
98156 if (flags & MSG_ERRQUEUE)
98157 return ipv6_recv_error(sk, msg, len, addr_len);
98158
98159 @@ -435,7 +442,7 @@ try_again:
98160 if (unlikely(err)) {
98161 trace_kfree_skb(skb, udpv6_recvmsg);
98162 if (!peeked) {
98163 - atomic_inc(&sk->sk_drops);
98164 + atomic_inc_unchecked(&sk->sk_drops);
98165 if (is_udp4)
98166 UDP_INC_STATS_USER(sock_net(sk),
98167 UDP_MIB_INERRORS,
98168 @@ -477,7 +484,7 @@ try_again:
98169 ipv6_iface_scope_id(&sin6->sin6_addr,
98170 IP6CB(skb)->iif);
98171 }
98172 - *addr_len = sizeof(*sin6);
98173 +
98174 }
98175 if (is_udp4) {
98176 if (inet->cmsg_flags)
98177 @@ -685,7 +692,7 @@ csum_error:
98178 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98179 drop:
98180 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98181 - atomic_inc(&sk->sk_drops);
98182 + atomic_inc_unchecked(&sk->sk_drops);
98183 kfree_skb(skb);
98184 return -1;
98185 }
98186 @@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98187 if (likely(skb1 == NULL))
98188 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98189 if (!skb1) {
98190 - atomic_inc(&sk->sk_drops);
98191 + atomic_inc_unchecked(&sk->sk_drops);
98192 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98193 IS_UDPLITE(sk));
98194 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98195 @@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98196 goto csum_error;
98197
98198 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98199 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98200 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98201 +#endif
98202 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
98203
98204 kfree_skb(skb);
98205 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
98206 index 5f8e128..865d38e 100644
98207 --- a/net/ipv6/xfrm6_policy.c
98208 +++ b/net/ipv6/xfrm6_policy.c
98209 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
98210 }
98211 }
98212
98213 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
98214 +static int xfrm6_garbage_collect(struct dst_ops *ops)
98215 {
98216 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
98217
98218 - xfrm6_policy_afinfo.garbage_collect(net);
98219 + xfrm_garbage_collect_deferred(net);
98220 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
98221 }
98222
98223 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
98224
98225 static int __net_init xfrm6_net_init(struct net *net)
98226 {
98227 - struct ctl_table *table;
98228 + ctl_table_no_const *table = NULL;
98229 struct ctl_table_header *hdr;
98230
98231 - table = xfrm6_policy_table;
98232 if (!net_eq(net, &init_net)) {
98233 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98234 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98235 if (!table)
98236 goto err_alloc;
98237
98238 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
98239 - }
98240 + hdr = register_net_sysctl(net, "net/ipv6", table);
98241 + } else
98242 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
98243
98244 - hdr = register_net_sysctl(net, "net/ipv6", table);
98245 if (!hdr)
98246 goto err_reg;
98247
98248 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
98249 return 0;
98250
98251 err_reg:
98252 - if (!net_eq(net, &init_net))
98253 - kfree(table);
98254 + kfree(table);
98255 err_alloc:
98256 return -ENOMEM;
98257 }
98258 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
98259 index 41ac7938..75e3bb1 100644
98260 --- a/net/irda/ircomm/ircomm_tty.c
98261 +++ b/net/irda/ircomm/ircomm_tty.c
98262 @@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98263 add_wait_queue(&port->open_wait, &wait);
98264
98265 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
98266 - __FILE__, __LINE__, tty->driver->name, port->count);
98267 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98268
98269 spin_lock_irqsave(&port->lock, flags);
98270 if (!tty_hung_up_p(filp))
98271 - port->count--;
98272 + atomic_dec(&port->count);
98273 port->blocked_open++;
98274 spin_unlock_irqrestore(&port->lock, flags);
98275
98276 @@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98277 }
98278
98279 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
98280 - __FILE__, __LINE__, tty->driver->name, port->count);
98281 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98282
98283 schedule();
98284 }
98285 @@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98286
98287 spin_lock_irqsave(&port->lock, flags);
98288 if (!tty_hung_up_p(filp))
98289 - port->count++;
98290 + atomic_inc(&port->count);
98291 port->blocked_open--;
98292 spin_unlock_irqrestore(&port->lock, flags);
98293
98294 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
98295 - __FILE__, __LINE__, tty->driver->name, port->count);
98296 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98297
98298 if (!retval)
98299 port->flags |= ASYNC_NORMAL_ACTIVE;
98300 @@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
98301
98302 /* ++ is not atomic, so this should be protected - Jean II */
98303 spin_lock_irqsave(&self->port.lock, flags);
98304 - self->port.count++;
98305 + atomic_inc(&self->port.count);
98306 spin_unlock_irqrestore(&self->port.lock, flags);
98307 tty_port_tty_set(&self->port, tty);
98308
98309 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
98310 - self->line, self->port.count);
98311 + self->line, atomic_read(&self->port.count));
98312
98313 /* Not really used by us, but lets do it anyway */
98314 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
98315 @@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
98316 tty_kref_put(port->tty);
98317 }
98318 port->tty = NULL;
98319 - port->count = 0;
98320 + atomic_set(&port->count, 0);
98321 spin_unlock_irqrestore(&port->lock, flags);
98322
98323 wake_up_interruptible(&port->open_wait);
98324 @@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
98325 seq_putc(m, '\n');
98326
98327 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
98328 - seq_printf(m, "Open count: %d\n", self->port.count);
98329 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
98330 seq_printf(m, "Max data size: %d\n", self->max_data_size);
98331 seq_printf(m, "Max header size: %d\n", self->max_header_size);
98332
98333 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
98334 index c4b7218..3e83259 100644
98335 --- a/net/iucv/af_iucv.c
98336 +++ b/net/iucv/af_iucv.c
98337 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
98338
98339 write_lock_bh(&iucv_sk_list.lock);
98340
98341 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
98342 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98343 while (__iucv_get_sock_by_name(name)) {
98344 sprintf(name, "%08x",
98345 - atomic_inc_return(&iucv_sk_list.autobind_name));
98346 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98347 }
98348
98349 write_unlock_bh(&iucv_sk_list.lock);
98350 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
98351 index cd5b8ec..f205e6b 100644
98352 --- a/net/iucv/iucv.c
98353 +++ b/net/iucv/iucv.c
98354 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
98355 return NOTIFY_OK;
98356 }
98357
98358 -static struct notifier_block __refdata iucv_cpu_notifier = {
98359 +static struct notifier_block iucv_cpu_notifier = {
98360 .notifier_call = iucv_cpu_notify,
98361 };
98362
98363 diff --git a/net/key/af_key.c b/net/key/af_key.c
98364 index 545f047..9757a9d 100644
98365 --- a/net/key/af_key.c
98366 +++ b/net/key/af_key.c
98367 @@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
98368 static u32 get_acqseq(void)
98369 {
98370 u32 res;
98371 - static atomic_t acqseq;
98372 + static atomic_unchecked_t acqseq;
98373
98374 do {
98375 - res = atomic_inc_return(&acqseq);
98376 + res = atomic_inc_return_unchecked(&acqseq);
98377 } while (!res);
98378 return res;
98379 }
98380 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
98381 index da1a1ce..571db8d 100644
98382 --- a/net/l2tp/l2tp_ip.c
98383 +++ b/net/l2tp/l2tp_ip.c
98384 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98385 if (flags & MSG_OOB)
98386 goto out;
98387
98388 + if (addr_len)
98389 + *addr_len = sizeof(*sin);
98390 +
98391 skb = skb_recv_datagram(sk, flags, noblock, &err);
98392 if (!skb)
98393 goto out;
98394 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98395 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98396 sin->sin_port = 0;
98397 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98398 - *addr_len = sizeof(*sin);
98399 }
98400 if (inet->cmsg_flags)
98401 ip_cmsg_recv(msg, skb);
98402 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
98403 index 364ce0c..3ebb5a4 100644
98404 --- a/net/mac80211/cfg.c
98405 +++ b/net/mac80211/cfg.c
98406 @@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
98407 ret = ieee80211_vif_use_channel(sdata, chandef,
98408 IEEE80211_CHANCTX_EXCLUSIVE);
98409 }
98410 - } else if (local->open_count == local->monitors) {
98411 + } else if (local_read(&local->open_count) == local->monitors) {
98412 local->_oper_chandef = *chandef;
98413 ieee80211_hw_config(local, 0);
98414 }
98415 @@ -3308,7 +3308,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
98416 else
98417 local->probe_req_reg--;
98418
98419 - if (!local->open_count)
98420 + if (!local_read(&local->open_count))
98421 break;
98422
98423 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
98424 @@ -3771,8 +3771,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
98425 if (chanctx_conf) {
98426 *chandef = chanctx_conf->def;
98427 ret = 0;
98428 - } else if (local->open_count > 0 &&
98429 - local->open_count == local->monitors &&
98430 + } else if (local_read(&local->open_count) > 0 &&
98431 + local_read(&local->open_count) == local->monitors &&
98432 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
98433 if (local->use_chanctx)
98434 *chandef = local->monitor_chandef;
98435 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
98436 index 4aea4e7..9e698d1 100644
98437 --- a/net/mac80211/ieee80211_i.h
98438 +++ b/net/mac80211/ieee80211_i.h
98439 @@ -28,6 +28,7 @@
98440 #include <net/ieee80211_radiotap.h>
98441 #include <net/cfg80211.h>
98442 #include <net/mac80211.h>
98443 +#include <asm/local.h>
98444 #include "key.h"
98445 #include "sta_info.h"
98446 #include "debug.h"
98447 @@ -961,7 +962,7 @@ struct ieee80211_local {
98448 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
98449 spinlock_t queue_stop_reason_lock;
98450
98451 - int open_count;
98452 + local_t open_count;
98453 int monitors, cooked_mntrs;
98454 /* number of interfaces with corresponding FIF_ flags */
98455 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
98456 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
98457 index a075791..1d0027f 100644
98458 --- a/net/mac80211/iface.c
98459 +++ b/net/mac80211/iface.c
98460 @@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98461 break;
98462 }
98463
98464 - if (local->open_count == 0) {
98465 + if (local_read(&local->open_count) == 0) {
98466 res = drv_start(local);
98467 if (res)
98468 goto err_del_bss;
98469 @@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98470 res = drv_add_interface(local, sdata);
98471 if (res)
98472 goto err_stop;
98473 - } else if (local->monitors == 0 && local->open_count == 0) {
98474 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
98475 res = ieee80211_add_virtual_monitor(local);
98476 if (res)
98477 goto err_stop;
98478 @@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98479 atomic_inc(&local->iff_promiscs);
98480
98481 if (coming_up)
98482 - local->open_count++;
98483 + local_inc(&local->open_count);
98484
98485 if (hw_reconf_flags)
98486 ieee80211_hw_config(local, hw_reconf_flags);
98487 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98488 err_del_interface:
98489 drv_remove_interface(local, sdata);
98490 err_stop:
98491 - if (!local->open_count)
98492 + if (!local_read(&local->open_count))
98493 drv_stop(local);
98494 err_del_bss:
98495 sdata->bss = NULL;
98496 @@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98497 }
98498
98499 if (going_down)
98500 - local->open_count--;
98501 + local_dec(&local->open_count);
98502
98503 switch (sdata->vif.type) {
98504 case NL80211_IFTYPE_AP_VLAN:
98505 @@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98506 }
98507 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
98508
98509 - if (local->open_count == 0)
98510 + if (local_read(&local->open_count) == 0)
98511 ieee80211_clear_tx_pending(local);
98512
98513 /*
98514 @@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98515
98516 ieee80211_recalc_ps(local, -1);
98517
98518 - if (local->open_count == 0) {
98519 + if (local_read(&local->open_count) == 0) {
98520 ieee80211_stop_device(local);
98521
98522 /* no reconfiguring after stop! */
98523 @@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98524 ieee80211_configure_filter(local);
98525 ieee80211_hw_config(local, hw_reconf_flags);
98526
98527 - if (local->monitors == local->open_count)
98528 + if (local->monitors == local_read(&local->open_count))
98529 ieee80211_add_virtual_monitor(local);
98530 }
98531
98532 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
98533 index 7d1c3ac..b62dd29 100644
98534 --- a/net/mac80211/main.c
98535 +++ b/net/mac80211/main.c
98536 @@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
98537 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
98538 IEEE80211_CONF_CHANGE_POWER);
98539
98540 - if (changed && local->open_count) {
98541 + if (changed && local_read(&local->open_count)) {
98542 ret = drv_config(local, changed);
98543 /*
98544 * Goal:
98545 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
98546 index 3401262..d5cd68d 100644
98547 --- a/net/mac80211/pm.c
98548 +++ b/net/mac80211/pm.c
98549 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98550 struct ieee80211_sub_if_data *sdata;
98551 struct sta_info *sta;
98552
98553 - if (!local->open_count)
98554 + if (!local_read(&local->open_count))
98555 goto suspend;
98556
98557 ieee80211_scan_cancel(local);
98558 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98559 cancel_work_sync(&local->dynamic_ps_enable_work);
98560 del_timer_sync(&local->dynamic_ps_timer);
98561
98562 - local->wowlan = wowlan && local->open_count;
98563 + local->wowlan = wowlan && local_read(&local->open_count);
98564 if (local->wowlan) {
98565 int err = drv_suspend(local, wowlan);
98566 if (err < 0) {
98567 @@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98568 WARN_ON(!list_empty(&local->chanctx_list));
98569
98570 /* stop hardware - this must stop RX */
98571 - if (local->open_count)
98572 + if (local_read(&local->open_count))
98573 ieee80211_stop_device(local);
98574
98575 suspend:
98576 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
98577 index 22b223f..ab70070 100644
98578 --- a/net/mac80211/rate.c
98579 +++ b/net/mac80211/rate.c
98580 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
98581
98582 ASSERT_RTNL();
98583
98584 - if (local->open_count)
98585 + if (local_read(&local->open_count))
98586 return -EBUSY;
98587
98588 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
98589 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
98590 index 6ff1346..936ca9a 100644
98591 --- a/net/mac80211/rc80211_pid_debugfs.c
98592 +++ b/net/mac80211/rc80211_pid_debugfs.c
98593 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
98594
98595 spin_unlock_irqrestore(&events->lock, status);
98596
98597 - if (copy_to_user(buf, pb, p))
98598 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
98599 return -EFAULT;
98600
98601 return p;
98602 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
98603 index 9f9b9bd..d6fcf59 100644
98604 --- a/net/mac80211/util.c
98605 +++ b/net/mac80211/util.c
98606 @@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98607 }
98608 #endif
98609 /* everything else happens only if HW was up & running */
98610 - if (!local->open_count)
98611 + if (!local_read(&local->open_count))
98612 goto wake_up;
98613
98614 /*
98615 @@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98616 local->in_reconfig = false;
98617 barrier();
98618
98619 - if (local->monitors == local->open_count && local->monitors > 0)
98620 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
98621 ieee80211_add_virtual_monitor(local);
98622
98623 /*
98624 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
98625 index c3398cd..98ad3b4 100644
98626 --- a/net/netfilter/Kconfig
98627 +++ b/net/netfilter/Kconfig
98628 @@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
98629
98630 To compile it as a module, choose M here. If unsure, say N.
98631
98632 +config NETFILTER_XT_MATCH_GRADM
98633 + tristate '"gradm" match support'
98634 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
98635 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
98636 + ---help---
98637 + The gradm match allows to match on grsecurity RBAC being enabled.
98638 + It is useful when iptables rules are applied early on bootup to
98639 + prevent connections to the machine (except from a trusted host)
98640 + while the RBAC system is disabled.
98641 +
98642 config NETFILTER_XT_MATCH_HASHLIMIT
98643 tristate '"hashlimit" match support'
98644 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
98645 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
98646 index 394483b..ed51f2d 100644
98647 --- a/net/netfilter/Makefile
98648 +++ b/net/netfilter/Makefile
98649 @@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
98650 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
98651 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
98652 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
98653 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
98654 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
98655 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
98656 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
98657 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
98658 index bac7e01..1d7a31a 100644
98659 --- a/net/netfilter/ipset/ip_set_core.c
98660 +++ b/net/netfilter/ipset/ip_set_core.c
98661 @@ -1950,7 +1950,7 @@ done:
98662 return ret;
98663 }
98664
98665 -static struct nf_sockopt_ops so_set __read_mostly = {
98666 +static struct nf_sockopt_ops so_set = {
98667 .pf = PF_INET,
98668 .get_optmin = SO_IP_SET,
98669 .get_optmax = SO_IP_SET + 1,
98670 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
98671 index 4c8e5c0..5a79b4d 100644
98672 --- a/net/netfilter/ipvs/ip_vs_conn.c
98673 +++ b/net/netfilter/ipvs/ip_vs_conn.c
98674 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
98675 /* Increase the refcnt counter of the dest */
98676 ip_vs_dest_hold(dest);
98677
98678 - conn_flags = atomic_read(&dest->conn_flags);
98679 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
98680 if (cp->protocol != IPPROTO_UDP)
98681 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
98682 flags = cp->flags;
98683 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
98684
98685 cp->control = NULL;
98686 atomic_set(&cp->n_control, 0);
98687 - atomic_set(&cp->in_pkts, 0);
98688 + atomic_set_unchecked(&cp->in_pkts, 0);
98689
98690 cp->packet_xmit = NULL;
98691 cp->app = NULL;
98692 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
98693
98694 /* Don't drop the entry if its number of incoming packets is not
98695 located in [0, 8] */
98696 - i = atomic_read(&cp->in_pkts);
98697 + i = atomic_read_unchecked(&cp->in_pkts);
98698 if (i > 8 || i < 0) return 0;
98699
98700 if (!todrop_rate[i]) return 0;
98701 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
98702 index 4f26ee4..6a9d7c3 100644
98703 --- a/net/netfilter/ipvs/ip_vs_core.c
98704 +++ b/net/netfilter/ipvs/ip_vs_core.c
98705 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
98706 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
98707 /* do not touch skb anymore */
98708
98709 - atomic_inc(&cp->in_pkts);
98710 + atomic_inc_unchecked(&cp->in_pkts);
98711 ip_vs_conn_put(cp);
98712 return ret;
98713 }
98714 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
98715 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
98716 pkts = sysctl_sync_threshold(ipvs);
98717 else
98718 - pkts = atomic_add_return(1, &cp->in_pkts);
98719 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98720
98721 if (ipvs->sync_state & IP_VS_STATE_MASTER)
98722 ip_vs_sync_conn(net, cp, pkts);
98723 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
98724 index 35be035..dad174b 100644
98725 --- a/net/netfilter/ipvs/ip_vs_ctl.c
98726 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
98727 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
98728 */
98729 ip_vs_rs_hash(ipvs, dest);
98730 }
98731 - atomic_set(&dest->conn_flags, conn_flags);
98732 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
98733
98734 /* bind the service */
98735 old_svc = rcu_dereference_protected(dest->svc, 1);
98736 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
98737 * align with netns init in ip_vs_control_net_init()
98738 */
98739
98740 -static struct ctl_table vs_vars[] = {
98741 +static ctl_table_no_const vs_vars[] __read_only = {
98742 {
98743 .procname = "amemthresh",
98744 .maxlen = sizeof(int),
98745 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98746 " %-7s %-6d %-10d %-10d\n",
98747 &dest->addr.in6,
98748 ntohs(dest->port),
98749 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98750 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98751 atomic_read(&dest->weight),
98752 atomic_read(&dest->activeconns),
98753 atomic_read(&dest->inactconns));
98754 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98755 "%-7s %-6d %-10d %-10d\n",
98756 ntohl(dest->addr.ip),
98757 ntohs(dest->port),
98758 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98759 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98760 atomic_read(&dest->weight),
98761 atomic_read(&dest->activeconns),
98762 atomic_read(&dest->inactconns));
98763 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
98764
98765 entry.addr = dest->addr.ip;
98766 entry.port = dest->port;
98767 - entry.conn_flags = atomic_read(&dest->conn_flags);
98768 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
98769 entry.weight = atomic_read(&dest->weight);
98770 entry.u_threshold = dest->u_threshold;
98771 entry.l_threshold = dest->l_threshold;
98772 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
98773 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
98774 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
98775 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
98776 - (atomic_read(&dest->conn_flags) &
98777 + (atomic_read_unchecked(&dest->conn_flags) &
98778 IP_VS_CONN_F_FWD_MASK)) ||
98779 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
98780 atomic_read(&dest->weight)) ||
98781 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
98782 {
98783 int idx;
98784 struct netns_ipvs *ipvs = net_ipvs(net);
98785 - struct ctl_table *tbl;
98786 + ctl_table_no_const *tbl;
98787
98788 atomic_set(&ipvs->dropentry, 0);
98789 spin_lock_init(&ipvs->dropentry_lock);
98790 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
98791 index ca056a3..9cf01ef 100644
98792 --- a/net/netfilter/ipvs/ip_vs_lblc.c
98793 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
98794 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
98795 * IPVS LBLC sysctl table
98796 */
98797 #ifdef CONFIG_SYSCTL
98798 -static struct ctl_table vs_vars_table[] = {
98799 +static ctl_table_no_const vs_vars_table[] __read_only = {
98800 {
98801 .procname = "lblc_expiration",
98802 .data = NULL,
98803 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
98804 index 3f21a2f..a112e85 100644
98805 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
98806 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
98807 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
98808 * IPVS LBLCR sysctl table
98809 */
98810
98811 -static struct ctl_table vs_vars_table[] = {
98812 +static ctl_table_no_const vs_vars_table[] __read_only = {
98813 {
98814 .procname = "lblcr_expiration",
98815 .data = NULL,
98816 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
98817 index f63c238..1b87f8a 100644
98818 --- a/net/netfilter/ipvs/ip_vs_sync.c
98819 +++ b/net/netfilter/ipvs/ip_vs_sync.c
98820 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
98821 cp = cp->control;
98822 if (cp) {
98823 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98824 - pkts = atomic_add_return(1, &cp->in_pkts);
98825 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98826 else
98827 pkts = sysctl_sync_threshold(ipvs);
98828 ip_vs_sync_conn(net, cp->control, pkts);
98829 @@ -771,7 +771,7 @@ control:
98830 if (!cp)
98831 return;
98832 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98833 - pkts = atomic_add_return(1, &cp->in_pkts);
98834 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98835 else
98836 pkts = sysctl_sync_threshold(ipvs);
98837 goto sloop;
98838 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
98839
98840 if (opt)
98841 memcpy(&cp->in_seq, opt, sizeof(*opt));
98842 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
98843 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
98844 cp->state = state;
98845 cp->old_state = cp->state;
98846 /*
98847 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
98848 index c47444e..b0961c6 100644
98849 --- a/net/netfilter/ipvs/ip_vs_xmit.c
98850 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
98851 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
98852 else
98853 rc = NF_ACCEPT;
98854 /* do not touch skb anymore */
98855 - atomic_inc(&cp->in_pkts);
98856 + atomic_inc_unchecked(&cp->in_pkts);
98857 goto out;
98858 }
98859
98860 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
98861 else
98862 rc = NF_ACCEPT;
98863 /* do not touch skb anymore */
98864 - atomic_inc(&cp->in_pkts);
98865 + atomic_inc_unchecked(&cp->in_pkts);
98866 goto out;
98867 }
98868
98869 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
98870 index a4b5e2a..13b1de3 100644
98871 --- a/net/netfilter/nf_conntrack_acct.c
98872 +++ b/net/netfilter/nf_conntrack_acct.c
98873 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
98874 #ifdef CONFIG_SYSCTL
98875 static int nf_conntrack_acct_init_sysctl(struct net *net)
98876 {
98877 - struct ctl_table *table;
98878 + ctl_table_no_const *table;
98879
98880 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
98881 GFP_KERNEL);
98882 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
98883 index 43549eb..0bbeace 100644
98884 --- a/net/netfilter/nf_conntrack_core.c
98885 +++ b/net/netfilter/nf_conntrack_core.c
98886 @@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
98887 #define DYING_NULLS_VAL ((1<<30)+1)
98888 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
98889
98890 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98891 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
98892 +#endif
98893 +
98894 int nf_conntrack_init_net(struct net *net)
98895 {
98896 int ret;
98897 @@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
98898 goto err_stat;
98899 }
98900
98901 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98902 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
98903 +#else
98904 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
98905 +#endif
98906 if (!net->ct.slabname) {
98907 ret = -ENOMEM;
98908 goto err_slabname;
98909 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
98910 index 1df1761..ce8b88a 100644
98911 --- a/net/netfilter/nf_conntrack_ecache.c
98912 +++ b/net/netfilter/nf_conntrack_ecache.c
98913 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
98914 #ifdef CONFIG_SYSCTL
98915 static int nf_conntrack_event_init_sysctl(struct net *net)
98916 {
98917 - struct ctl_table *table;
98918 + ctl_table_no_const *table;
98919
98920 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
98921 GFP_KERNEL);
98922 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
98923 index 974a2a4..52cc6ff 100644
98924 --- a/net/netfilter/nf_conntrack_helper.c
98925 +++ b/net/netfilter/nf_conntrack_helper.c
98926 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
98927
98928 static int nf_conntrack_helper_init_sysctl(struct net *net)
98929 {
98930 - struct ctl_table *table;
98931 + ctl_table_no_const *table;
98932
98933 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
98934 GFP_KERNEL);
98935 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
98936 index ce30041..3861b5d 100644
98937 --- a/net/netfilter/nf_conntrack_proto.c
98938 +++ b/net/netfilter/nf_conntrack_proto.c
98939 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
98940
98941 static void
98942 nf_ct_unregister_sysctl(struct ctl_table_header **header,
98943 - struct ctl_table **table,
98944 + ctl_table_no_const **table,
98945 unsigned int users)
98946 {
98947 if (users > 0)
98948 diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
98949 index a99b6c3..cb372f9 100644
98950 --- a/net/netfilter/nf_conntrack_proto_dccp.c
98951 +++ b/net/netfilter/nf_conntrack_proto_dccp.c
98952 @@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
98953 const char *msg;
98954 u_int8_t state;
98955
98956 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
98957 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
98958 BUG_ON(dh == NULL);
98959
98960 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
98961 @@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
98962 out_invalid:
98963 if (LOG_INVALID(net, IPPROTO_DCCP))
98964 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
98965 - NULL, msg);
98966 + NULL, "%s", msg);
98967 return false;
98968 }
98969
98970 @@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
98971 u_int8_t type, old_state, new_state;
98972 enum ct_dccp_roles role;
98973
98974 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
98975 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
98976 BUG_ON(dh == NULL);
98977 type = dh->dccph_type;
98978
98979 @@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
98980 unsigned int cscov;
98981 const char *msg;
98982
98983 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
98984 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
98985 if (dh == NULL) {
98986 msg = "nf_ct_dccp: short packet ";
98987 goto out_invalid;
98988 @@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
98989
98990 out_invalid:
98991 if (LOG_INVALID(net, IPPROTO_DCCP))
98992 - nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
98993 + nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
98994 return -NF_ACCEPT;
98995 }
98996
98997 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
98998 index f641751..d3c5b51 100644
98999 --- a/net/netfilter/nf_conntrack_standalone.c
99000 +++ b/net/netfilter/nf_conntrack_standalone.c
99001 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
99002
99003 static int nf_conntrack_standalone_init_sysctl(struct net *net)
99004 {
99005 - struct ctl_table *table;
99006 + ctl_table_no_const *table;
99007
99008 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
99009 GFP_KERNEL);
99010 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
99011 index 7a394df..bd91a8a 100644
99012 --- a/net/netfilter/nf_conntrack_timestamp.c
99013 +++ b/net/netfilter/nf_conntrack_timestamp.c
99014 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
99015 #ifdef CONFIG_SYSCTL
99016 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
99017 {
99018 - struct ctl_table *table;
99019 + ctl_table_no_const *table;
99020
99021 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
99022 GFP_KERNEL);
99023 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
99024 index 85296d4..8becdec 100644
99025 --- a/net/netfilter/nf_log.c
99026 +++ b/net/netfilter/nf_log.c
99027 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
99028
99029 #ifdef CONFIG_SYSCTL
99030 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
99031 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
99032 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
99033
99034 static int nf_log_proc_dostring(struct ctl_table *table, int write,
99035 void __user *buffer, size_t *lenp, loff_t *ppos)
99036 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
99037 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
99038 mutex_unlock(&nf_log_mutex);
99039 } else {
99040 + ctl_table_no_const nf_log_table = *table;
99041 +
99042 mutex_lock(&nf_log_mutex);
99043 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
99044 lockdep_is_held(&nf_log_mutex));
99045 if (!logger)
99046 - table->data = "NONE";
99047 + nf_log_table.data = "NONE";
99048 else
99049 - table->data = logger->name;
99050 - r = proc_dostring(table, write, buffer, lenp, ppos);
99051 + nf_log_table.data = logger->name;
99052 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
99053 mutex_unlock(&nf_log_mutex);
99054 }
99055
99056 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
99057 index f042ae5..30ea486 100644
99058 --- a/net/netfilter/nf_sockopt.c
99059 +++ b/net/netfilter/nf_sockopt.c
99060 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
99061 }
99062 }
99063
99064 - list_add(&reg->list, &nf_sockopts);
99065 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
99066 out:
99067 mutex_unlock(&nf_sockopt_mutex);
99068 return ret;
99069 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
99070 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
99071 {
99072 mutex_lock(&nf_sockopt_mutex);
99073 - list_del(&reg->list);
99074 + pax_list_del((struct list_head *)&reg->list);
99075 mutex_unlock(&nf_sockopt_mutex);
99076 }
99077 EXPORT_SYMBOL(nf_unregister_sockopt);
99078 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
99079 index a155d19..726b0f2 100644
99080 --- a/net/netfilter/nfnetlink_log.c
99081 +++ b/net/netfilter/nfnetlink_log.c
99082 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
99083 struct nfnl_log_net {
99084 spinlock_t instances_lock;
99085 struct hlist_head instance_table[INSTANCE_BUCKETS];
99086 - atomic_t global_seq;
99087 + atomic_unchecked_t global_seq;
99088 };
99089
99090 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
99091 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
99092 /* global sequence number */
99093 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
99094 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
99095 - htonl(atomic_inc_return(&log->global_seq))))
99096 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
99097 goto nla_put_failure;
99098
99099 if (data_len) {
99100 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
99101 index da0c1f4..f79737a 100644
99102 --- a/net/netfilter/nft_compat.c
99103 +++ b/net/netfilter/nft_compat.c
99104 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
99105 /* We want to reuse existing compat_to_user */
99106 old_fs = get_fs();
99107 set_fs(KERNEL_DS);
99108 - t->compat_to_user(out, in);
99109 + t->compat_to_user((void __force_user *)out, in);
99110 set_fs(old_fs);
99111 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
99112 kfree(out);
99113 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
99114 /* We want to reuse existing compat_to_user */
99115 old_fs = get_fs();
99116 set_fs(KERNEL_DS);
99117 - m->compat_to_user(out, in);
99118 + m->compat_to_user((void __force_user *)out, in);
99119 set_fs(old_fs);
99120 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
99121 kfree(out);
99122 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
99123 new file mode 100644
99124 index 0000000..c566332
99125 --- /dev/null
99126 +++ b/net/netfilter/xt_gradm.c
99127 @@ -0,0 +1,51 @@
99128 +/*
99129 + * gradm match for netfilter
99130 + * Copyright © Zbigniew Krzystolik, 2010
99131 + *
99132 + * This program is free software; you can redistribute it and/or modify
99133 + * it under the terms of the GNU General Public License; either version
99134 + * 2 or 3 as published by the Free Software Foundation.
99135 + */
99136 +#include <linux/module.h>
99137 +#include <linux/moduleparam.h>
99138 +#include <linux/skbuff.h>
99139 +#include <linux/netfilter/x_tables.h>
99140 +#include <linux/grsecurity.h>
99141 +#include <linux/netfilter/xt_gradm.h>
99142 +
99143 +static bool
99144 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
99145 +{
99146 + const struct xt_gradm_mtinfo *info = par->matchinfo;
99147 + bool retval = false;
99148 + if (gr_acl_is_enabled())
99149 + retval = true;
99150 + return retval ^ info->invflags;
99151 +}
99152 +
99153 +static struct xt_match gradm_mt_reg __read_mostly = {
99154 + .name = "gradm",
99155 + .revision = 0,
99156 + .family = NFPROTO_UNSPEC,
99157 + .match = gradm_mt,
99158 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
99159 + .me = THIS_MODULE,
99160 +};
99161 +
99162 +static int __init gradm_mt_init(void)
99163 +{
99164 + return xt_register_match(&gradm_mt_reg);
99165 +}
99166 +
99167 +static void __exit gradm_mt_exit(void)
99168 +{
99169 + xt_unregister_match(&gradm_mt_reg);
99170 +}
99171 +
99172 +module_init(gradm_mt_init);
99173 +module_exit(gradm_mt_exit);
99174 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
99175 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
99176 +MODULE_LICENSE("GPL");
99177 +MODULE_ALIAS("ipt_gradm");
99178 +MODULE_ALIAS("ip6t_gradm");
99179 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
99180 index 4fe4fb4..87a89e5 100644
99181 --- a/net/netfilter/xt_statistic.c
99182 +++ b/net/netfilter/xt_statistic.c
99183 @@ -19,7 +19,7 @@
99184 #include <linux/module.h>
99185
99186 struct xt_statistic_priv {
99187 - atomic_t count;
99188 + atomic_unchecked_t count;
99189 } ____cacheline_aligned_in_smp;
99190
99191 MODULE_LICENSE("GPL");
99192 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
99193 break;
99194 case XT_STATISTIC_MODE_NTH:
99195 do {
99196 - oval = atomic_read(&info->master->count);
99197 + oval = atomic_read_unchecked(&info->master->count);
99198 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
99199 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
99200 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
99201 if (nval == 0)
99202 ret = !ret;
99203 break;
99204 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
99205 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
99206 if (info->master == NULL)
99207 return -ENOMEM;
99208 - atomic_set(&info->master->count, info->u.nth.count);
99209 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
99210
99211 return 0;
99212 }
99213 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
99214 index bca50b9..8f8a85e 100644
99215 --- a/net/netlink/af_netlink.c
99216 +++ b/net/netlink/af_netlink.c
99217 @@ -249,7 +249,7 @@ static void netlink_overrun(struct sock *sk)
99218 sk->sk_error_report(sk);
99219 }
99220 }
99221 - atomic_inc(&sk->sk_drops);
99222 + atomic_inc_unchecked(&sk->sk_drops);
99223 }
99224
99225 static void netlink_rcv_wake(struct sock *sk)
99226 @@ -2940,7 +2940,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
99227 sk_wmem_alloc_get(s),
99228 nlk->cb_running,
99229 atomic_read(&s->sk_refcnt),
99230 - atomic_read(&s->sk_drops),
99231 + atomic_read_unchecked(&s->sk_drops),
99232 sock_i_ino(s)
99233 );
99234
99235 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
99236 index 53c19a3..b0ac04a 100644
99237 --- a/net/netrom/af_netrom.c
99238 +++ b/net/netrom/af_netrom.c
99239 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
99240 *uaddr_len = sizeof(struct full_sockaddr_ax25);
99241 } else {
99242 sax->fsa_ax25.sax25_family = AF_NETROM;
99243 - sax->fsa_ax25.sax25_ndigis = 0;
99244 sax->fsa_ax25.sax25_call = nr->source_addr;
99245 *uaddr_len = sizeof(struct sockaddr_ax25);
99246 }
99247 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
99248 index 88cfbc1..05d73f5 100644
99249 --- a/net/packet/af_packet.c
99250 +++ b/net/packet/af_packet.c
99251 @@ -1720,7 +1720,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
99252
99253 spin_lock(&sk->sk_receive_queue.lock);
99254 po->stats.stats1.tp_packets++;
99255 - skb->dropcount = atomic_read(&sk->sk_drops);
99256 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
99257 __skb_queue_tail(&sk->sk_receive_queue, skb);
99258 spin_unlock(&sk->sk_receive_queue.lock);
99259 sk->sk_data_ready(sk, skb->len);
99260 @@ -1729,7 +1729,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
99261 drop_n_acct:
99262 spin_lock(&sk->sk_receive_queue.lock);
99263 po->stats.stats1.tp_drops++;
99264 - atomic_inc(&sk->sk_drops);
99265 + atomic_inc_unchecked(&sk->sk_drops);
99266 spin_unlock(&sk->sk_receive_queue.lock);
99267
99268 drop_n_restore:
99269 @@ -3275,7 +3275,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
99270 case PACKET_HDRLEN:
99271 if (len > sizeof(int))
99272 len = sizeof(int);
99273 - if (copy_from_user(&val, optval, len))
99274 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
99275 return -EFAULT;
99276 switch (val) {
99277 case TPACKET_V1:
99278 @@ -3318,7 +3318,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
99279 len = lv;
99280 if (put_user(len, optlen))
99281 return -EFAULT;
99282 - if (copy_to_user(optval, data, len))
99283 + if (len > sizeof(st) || copy_to_user(optval, data, len))
99284 return -EFAULT;
99285 return 0;
99286 }
99287 diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
99288 index 38946b2..12c30f3 100644
99289 --- a/net/phonet/datagram.c
99290 +++ b/net/phonet/datagram.c
99291 @@ -139,6 +139,9 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
99292 MSG_CMSG_COMPAT))
99293 goto out_nofree;
99294
99295 + if (addr_len)
99296 + *addr_len = sizeof(sa);
99297 +
99298 skb = skb_recv_datagram(sk, flags, noblock, &rval);
99299 if (skb == NULL)
99300 goto out_nofree;
99301 @@ -159,10 +162,8 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
99302
99303 rval = (flags & MSG_TRUNC) ? skb->len : copylen;
99304
99305 - if (msg->msg_name != NULL) {
99306 - memcpy(msg->msg_name, &sa, sizeof(sa));
99307 - *addr_len = sizeof(sa);
99308 - }
99309 + if (msg->msg_name != NULL)
99310 + memcpy(msg->msg_name, &sa, sizeof(struct sockaddr_pn));
99311
99312 out:
99313 skb_free_datagram(sk, skb);
99314 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
99315 index e774117..900b8b7 100644
99316 --- a/net/phonet/pep.c
99317 +++ b/net/phonet/pep.c
99318 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
99319
99320 case PNS_PEP_CTRL_REQ:
99321 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
99322 - atomic_inc(&sk->sk_drops);
99323 + atomic_inc_unchecked(&sk->sk_drops);
99324 break;
99325 }
99326 __skb_pull(skb, 4);
99327 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
99328 }
99329
99330 if (pn->rx_credits == 0) {
99331 - atomic_inc(&sk->sk_drops);
99332 + atomic_inc_unchecked(&sk->sk_drops);
99333 err = -ENOBUFS;
99334 break;
99335 }
99336 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
99337 }
99338
99339 if (pn->rx_credits == 0) {
99340 - atomic_inc(&sk->sk_drops);
99341 + atomic_inc_unchecked(&sk->sk_drops);
99342 err = NET_RX_DROP;
99343 break;
99344 }
99345 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
99346 index 008214a..bb68240 100644
99347 --- a/net/phonet/socket.c
99348 +++ b/net/phonet/socket.c
99349 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
99350 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
99351 sock_i_ino(sk),
99352 atomic_read(&sk->sk_refcnt), sk,
99353 - atomic_read(&sk->sk_drops));
99354 + atomic_read_unchecked(&sk->sk_drops));
99355 }
99356 seq_pad(seq, '\n');
99357 return 0;
99358 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
99359 index c02a8c4..3c5b600 100644
99360 --- a/net/phonet/sysctl.c
99361 +++ b/net/phonet/sysctl.c
99362 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
99363 {
99364 int ret;
99365 int range[2] = {local_port_range[0], local_port_range[1]};
99366 - struct ctl_table tmp = {
99367 + ctl_table_no_const tmp = {
99368 .data = &range,
99369 .maxlen = sizeof(range),
99370 .mode = table->mode,
99371 diff --git a/net/rds/cong.c b/net/rds/cong.c
99372 index e5b65ac..f3b6fb7 100644
99373 --- a/net/rds/cong.c
99374 +++ b/net/rds/cong.c
99375 @@ -78,7 +78,7 @@
99376 * finds that the saved generation number is smaller than the global generation
99377 * number, it wakes up the process.
99378 */
99379 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
99380 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
99381
99382 /*
99383 * Congestion monitoring
99384 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
99385 rdsdebug("waking map %p for %pI4\n",
99386 map, &map->m_addr);
99387 rds_stats_inc(s_cong_update_received);
99388 - atomic_inc(&rds_cong_generation);
99389 + atomic_inc_unchecked(&rds_cong_generation);
99390 if (waitqueue_active(&map->m_waitq))
99391 wake_up(&map->m_waitq);
99392 if (waitqueue_active(&rds_poll_waitq))
99393 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
99394
99395 int rds_cong_updated_since(unsigned long *recent)
99396 {
99397 - unsigned long gen = atomic_read(&rds_cong_generation);
99398 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
99399
99400 if (likely(*recent == gen))
99401 return 0;
99402 diff --git a/net/rds/ib.h b/net/rds/ib.h
99403 index 7280ab8..e04f4ea 100644
99404 --- a/net/rds/ib.h
99405 +++ b/net/rds/ib.h
99406 @@ -128,7 +128,7 @@ struct rds_ib_connection {
99407 /* sending acks */
99408 unsigned long i_ack_flags;
99409 #ifdef KERNEL_HAS_ATOMIC64
99410 - atomic64_t i_ack_next; /* next ACK to send */
99411 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
99412 #else
99413 spinlock_t i_ack_lock; /* protect i_ack_next */
99414 u64 i_ack_next; /* next ACK to send */
99415 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
99416 index 31b74f5..dc1fbfa 100644
99417 --- a/net/rds/ib_cm.c
99418 +++ b/net/rds/ib_cm.c
99419 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
99420 /* Clear the ACK state */
99421 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
99422 #ifdef KERNEL_HAS_ATOMIC64
99423 - atomic64_set(&ic->i_ack_next, 0);
99424 + atomic64_set_unchecked(&ic->i_ack_next, 0);
99425 #else
99426 ic->i_ack_next = 0;
99427 #endif
99428 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
99429 index b7ebe23..b6352f6 100644
99430 --- a/net/rds/ib_recv.c
99431 +++ b/net/rds/ib_recv.c
99432 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
99433 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
99434 int ack_required)
99435 {
99436 - atomic64_set(&ic->i_ack_next, seq);
99437 + atomic64_set_unchecked(&ic->i_ack_next, seq);
99438 if (ack_required) {
99439 smp_mb__before_clear_bit();
99440 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99441 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
99442 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99443 smp_mb__after_clear_bit();
99444
99445 - return atomic64_read(&ic->i_ack_next);
99446 + return atomic64_read_unchecked(&ic->i_ack_next);
99447 }
99448 #endif
99449
99450 diff --git a/net/rds/iw.h b/net/rds/iw.h
99451 index 04ce3b1..48119a6 100644
99452 --- a/net/rds/iw.h
99453 +++ b/net/rds/iw.h
99454 @@ -134,7 +134,7 @@ struct rds_iw_connection {
99455 /* sending acks */
99456 unsigned long i_ack_flags;
99457 #ifdef KERNEL_HAS_ATOMIC64
99458 - atomic64_t i_ack_next; /* next ACK to send */
99459 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
99460 #else
99461 spinlock_t i_ack_lock; /* protect i_ack_next */
99462 u64 i_ack_next; /* next ACK to send */
99463 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
99464 index a91e1db..cf3053f 100644
99465 --- a/net/rds/iw_cm.c
99466 +++ b/net/rds/iw_cm.c
99467 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
99468 /* Clear the ACK state */
99469 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
99470 #ifdef KERNEL_HAS_ATOMIC64
99471 - atomic64_set(&ic->i_ack_next, 0);
99472 + atomic64_set_unchecked(&ic->i_ack_next, 0);
99473 #else
99474 ic->i_ack_next = 0;
99475 #endif
99476 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
99477 index 4503335..db566b4 100644
99478 --- a/net/rds/iw_recv.c
99479 +++ b/net/rds/iw_recv.c
99480 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
99481 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
99482 int ack_required)
99483 {
99484 - atomic64_set(&ic->i_ack_next, seq);
99485 + atomic64_set_unchecked(&ic->i_ack_next, seq);
99486 if (ack_required) {
99487 smp_mb__before_clear_bit();
99488 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99489 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
99490 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99491 smp_mb__after_clear_bit();
99492
99493 - return atomic64_read(&ic->i_ack_next);
99494 + return atomic64_read_unchecked(&ic->i_ack_next);
99495 }
99496 #endif
99497
99498 diff --git a/net/rds/rds.h b/net/rds/rds.h
99499 index 48f8ffc..0ef3eec 100644
99500 --- a/net/rds/rds.h
99501 +++ b/net/rds/rds.h
99502 @@ -449,7 +449,7 @@ struct rds_transport {
99503 void (*sync_mr)(void *trans_private, int direction);
99504 void (*free_mr)(void *trans_private, int invalidate);
99505 void (*flush_mrs)(void);
99506 -};
99507 +} __do_const;
99508
99509 struct rds_sock {
99510 struct sock rs_sk;
99511 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
99512 index edac9ef..16bcb98 100644
99513 --- a/net/rds/tcp.c
99514 +++ b/net/rds/tcp.c
99515 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
99516 int val = 1;
99517
99518 set_fs(KERNEL_DS);
99519 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
99520 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
99521 sizeof(val));
99522 set_fs(oldfs);
99523 }
99524 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
99525 index 81cf5a4..b5826ff 100644
99526 --- a/net/rds/tcp_send.c
99527 +++ b/net/rds/tcp_send.c
99528 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
99529
99530 oldfs = get_fs();
99531 set_fs(KERNEL_DS);
99532 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
99533 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
99534 sizeof(val));
99535 set_fs(oldfs);
99536 }
99537 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
99538 index e61aa60..f07cc89 100644
99539 --- a/net/rxrpc/af_rxrpc.c
99540 +++ b/net/rxrpc/af_rxrpc.c
99541 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
99542 __be32 rxrpc_epoch;
99543
99544 /* current debugging ID */
99545 -atomic_t rxrpc_debug_id;
99546 +atomic_unchecked_t rxrpc_debug_id;
99547
99548 /* count of skbs currently in use */
99549 atomic_t rxrpc_n_skbs;
99550 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
99551 index e4d9cbc..b229649 100644
99552 --- a/net/rxrpc/ar-ack.c
99553 +++ b/net/rxrpc/ar-ack.c
99554 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
99555
99556 _enter("{%d,%d,%d,%d},",
99557 call->acks_hard, call->acks_unacked,
99558 - atomic_read(&call->sequence),
99559 + atomic_read_unchecked(&call->sequence),
99560 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
99561
99562 stop = 0;
99563 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
99564
99565 /* each Tx packet has a new serial number */
99566 sp->hdr.serial =
99567 - htonl(atomic_inc_return(&call->conn->serial));
99568 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
99569
99570 hdr = (struct rxrpc_header *) txb->head;
99571 hdr->serial = sp->hdr.serial;
99572 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
99573 */
99574 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
99575 {
99576 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
99577 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
99578 }
99579
99580 /*
99581 @@ -629,7 +629,7 @@ process_further:
99582
99583 latest = ntohl(sp->hdr.serial);
99584 hard = ntohl(ack.firstPacket);
99585 - tx = atomic_read(&call->sequence);
99586 + tx = atomic_read_unchecked(&call->sequence);
99587
99588 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
99589 latest,
99590 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
99591 goto maybe_reschedule;
99592
99593 send_ACK_with_skew:
99594 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
99595 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
99596 ntohl(ack.serial));
99597 send_ACK:
99598 mtu = call->conn->trans->peer->if_mtu;
99599 @@ -1173,7 +1173,7 @@ send_ACK:
99600 ackinfo.rxMTU = htonl(5692);
99601 ackinfo.jumbo_max = htonl(4);
99602
99603 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
99604 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
99605 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
99606 ntohl(hdr.serial),
99607 ntohs(ack.maxSkew),
99608 @@ -1191,7 +1191,7 @@ send_ACK:
99609 send_message:
99610 _debug("send message");
99611
99612 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
99613 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
99614 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
99615 send_message_2:
99616
99617 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
99618 index a3bbb36..3341fb9 100644
99619 --- a/net/rxrpc/ar-call.c
99620 +++ b/net/rxrpc/ar-call.c
99621 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
99622 spin_lock_init(&call->lock);
99623 rwlock_init(&call->state_lock);
99624 atomic_set(&call->usage, 1);
99625 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
99626 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99627 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
99628
99629 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
99630 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
99631 index 4106ca9..a338d7a 100644
99632 --- a/net/rxrpc/ar-connection.c
99633 +++ b/net/rxrpc/ar-connection.c
99634 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
99635 rwlock_init(&conn->lock);
99636 spin_lock_init(&conn->state_lock);
99637 atomic_set(&conn->usage, 1);
99638 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
99639 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99640 conn->avail_calls = RXRPC_MAXCALLS;
99641 conn->size_align = 4;
99642 conn->header_size = sizeof(struct rxrpc_header);
99643 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
99644 index e7ed43a..6afa140 100644
99645 --- a/net/rxrpc/ar-connevent.c
99646 +++ b/net/rxrpc/ar-connevent.c
99647 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
99648
99649 len = iov[0].iov_len + iov[1].iov_len;
99650
99651 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
99652 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99653 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
99654
99655 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
99656 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
99657 index 529572f..c758ca7 100644
99658 --- a/net/rxrpc/ar-input.c
99659 +++ b/net/rxrpc/ar-input.c
99660 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
99661 /* track the latest serial number on this connection for ACK packet
99662 * information */
99663 serial = ntohl(sp->hdr.serial);
99664 - hi_serial = atomic_read(&call->conn->hi_serial);
99665 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
99666 while (serial > hi_serial)
99667 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
99668 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
99669 serial);
99670
99671 /* request ACK generation for any ACK or DATA packet that requests
99672 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
99673 index 5f43675..ca07817 100644
99674 --- a/net/rxrpc/ar-internal.h
99675 +++ b/net/rxrpc/ar-internal.h
99676 @@ -272,8 +272,8 @@ struct rxrpc_connection {
99677 int error; /* error code for local abort */
99678 int debug_id; /* debug ID for printks */
99679 unsigned int call_counter; /* call ID counter */
99680 - atomic_t serial; /* packet serial number counter */
99681 - atomic_t hi_serial; /* highest serial number received */
99682 + atomic_unchecked_t serial; /* packet serial number counter */
99683 + atomic_unchecked_t hi_serial; /* highest serial number received */
99684 u8 avail_calls; /* number of calls available */
99685 u8 size_align; /* data size alignment (for security) */
99686 u8 header_size; /* rxrpc + security header size */
99687 @@ -346,7 +346,7 @@ struct rxrpc_call {
99688 spinlock_t lock;
99689 rwlock_t state_lock; /* lock for state transition */
99690 atomic_t usage;
99691 - atomic_t sequence; /* Tx data packet sequence counter */
99692 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
99693 u32 abort_code; /* local/remote abort code */
99694 enum { /* current state of call */
99695 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
99696 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
99697 */
99698 extern atomic_t rxrpc_n_skbs;
99699 extern __be32 rxrpc_epoch;
99700 -extern atomic_t rxrpc_debug_id;
99701 +extern atomic_unchecked_t rxrpc_debug_id;
99702 extern struct workqueue_struct *rxrpc_workqueue;
99703
99704 /*
99705 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
99706 index 87f7135..74d3703 100644
99707 --- a/net/rxrpc/ar-local.c
99708 +++ b/net/rxrpc/ar-local.c
99709 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
99710 spin_lock_init(&local->lock);
99711 rwlock_init(&local->services_lock);
99712 atomic_set(&local->usage, 1);
99713 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
99714 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99715 memcpy(&local->srx, srx, sizeof(*srx));
99716 }
99717
99718 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
99719 index e1ac183..b43e10e 100644
99720 --- a/net/rxrpc/ar-output.c
99721 +++ b/net/rxrpc/ar-output.c
99722 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
99723 sp->hdr.cid = call->cid;
99724 sp->hdr.callNumber = call->call_id;
99725 sp->hdr.seq =
99726 - htonl(atomic_inc_return(&call->sequence));
99727 + htonl(atomic_inc_return_unchecked(&call->sequence));
99728 sp->hdr.serial =
99729 - htonl(atomic_inc_return(&conn->serial));
99730 + htonl(atomic_inc_return_unchecked(&conn->serial));
99731 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
99732 sp->hdr.userStatus = 0;
99733 sp->hdr.securityIndex = conn->security_ix;
99734 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
99735 index bebaa43..2644591 100644
99736 --- a/net/rxrpc/ar-peer.c
99737 +++ b/net/rxrpc/ar-peer.c
99738 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
99739 INIT_LIST_HEAD(&peer->error_targets);
99740 spin_lock_init(&peer->lock);
99741 atomic_set(&peer->usage, 1);
99742 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
99743 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99744 memcpy(&peer->srx, srx, sizeof(*srx));
99745
99746 rxrpc_assess_MTU_size(peer);
99747 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
99748 index 38047f7..9f48511 100644
99749 --- a/net/rxrpc/ar-proc.c
99750 +++ b/net/rxrpc/ar-proc.c
99751 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
99752 atomic_read(&conn->usage),
99753 rxrpc_conn_states[conn->state],
99754 key_serial(conn->key),
99755 - atomic_read(&conn->serial),
99756 - atomic_read(&conn->hi_serial));
99757 + atomic_read_unchecked(&conn->serial),
99758 + atomic_read_unchecked(&conn->hi_serial));
99759
99760 return 0;
99761 }
99762 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
99763 index 92df566..87ec1bf 100644
99764 --- a/net/rxrpc/ar-transport.c
99765 +++ b/net/rxrpc/ar-transport.c
99766 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
99767 spin_lock_init(&trans->client_lock);
99768 rwlock_init(&trans->conn_lock);
99769 atomic_set(&trans->usage, 1);
99770 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
99771 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99772
99773 if (peer->srx.transport.family == AF_INET) {
99774 switch (peer->srx.transport_type) {
99775 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
99776 index f226709..0e735a8 100644
99777 --- a/net/rxrpc/rxkad.c
99778 +++ b/net/rxrpc/rxkad.c
99779 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
99780
99781 len = iov[0].iov_len + iov[1].iov_len;
99782
99783 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
99784 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99785 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
99786
99787 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
99788 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
99789
99790 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
99791
99792 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
99793 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99794 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
99795
99796 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
99797 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
99798 index 7567e6f..299382b 100644
99799 --- a/net/sctp/ipv6.c
99800 +++ b/net/sctp/ipv6.c
99801 @@ -964,7 +964,7 @@ static const struct inet6_protocol sctpv6_protocol = {
99802 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
99803 };
99804
99805 -static struct sctp_af sctp_af_inet6 = {
99806 +static struct sctp_af sctp_af_inet6 __read_only = {
99807 .sa_family = AF_INET6,
99808 .sctp_xmit = sctp_v6_xmit,
99809 .setsockopt = ipv6_setsockopt,
99810 @@ -996,7 +996,7 @@ static struct sctp_af sctp_af_inet6 = {
99811 #endif
99812 };
99813
99814 -static struct sctp_pf sctp_pf_inet6 = {
99815 +static struct sctp_pf sctp_pf_inet6 __read_only = {
99816 .event_msgname = sctp_inet6_event_msgname,
99817 .skb_msgname = sctp_inet6_skb_msgname,
99818 .af_supported = sctp_inet6_af_supported,
99819 @@ -1021,7 +1021,7 @@ void sctp_v6_pf_init(void)
99820
99821 void sctp_v6_pf_exit(void)
99822 {
99823 - list_del(&sctp_af_inet6.list);
99824 + pax_list_del(&sctp_af_inet6.list);
99825 }
99826
99827 /* Initialize IPv6 support and register with socket layer. */
99828 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
99829 index 5e17092..19be1d4 100644
99830 --- a/net/sctp/protocol.c
99831 +++ b/net/sctp/protocol.c
99832 @@ -832,8 +832,10 @@ int sctp_register_af(struct sctp_af *af)
99833 return 0;
99834 }
99835
99836 + pax_open_kernel();
99837 INIT_LIST_HEAD(&af->list);
99838 - list_add_tail(&af->list, &sctp_address_families);
99839 + pax_close_kernel();
99840 + pax_list_add_tail(&af->list, &sctp_address_families);
99841 return 1;
99842 }
99843
99844 @@ -963,7 +965,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
99845
99846 static struct sctp_af sctp_af_inet;
99847
99848 -static struct sctp_pf sctp_pf_inet = {
99849 +static struct sctp_pf sctp_pf_inet __read_only = {
99850 .event_msgname = sctp_inet_event_msgname,
99851 .skb_msgname = sctp_inet_skb_msgname,
99852 .af_supported = sctp_inet_af_supported,
99853 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
99854 };
99855
99856 /* IPv4 address related functions. */
99857 -static struct sctp_af sctp_af_inet = {
99858 +static struct sctp_af sctp_af_inet __read_only = {
99859 .sa_family = AF_INET,
99860 .sctp_xmit = sctp_v4_xmit,
99861 .setsockopt = ip_setsockopt,
99862 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
99863
99864 static void sctp_v4_pf_exit(void)
99865 {
99866 - list_del(&sctp_af_inet.list);
99867 + pax_list_del(&sctp_af_inet.list);
99868 }
99869
99870 static int sctp_v4_protosw_init(void)
99871 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
99872 index 1a6eef3..17e898f 100644
99873 --- a/net/sctp/sm_sideeffect.c
99874 +++ b/net/sctp/sm_sideeffect.c
99875 @@ -440,7 +440,7 @@ static void sctp_generate_sack_event(unsigned long data)
99876 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
99877 }
99878
99879 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
99880 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
99881 NULL,
99882 sctp_generate_t1_cookie_event,
99883 sctp_generate_t1_init_event,
99884 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
99885 index 42b709c..e7d09ac 100644
99886 --- a/net/sctp/socket.c
99887 +++ b/net/sctp/socket.c
99888 @@ -2153,11 +2153,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
99889 {
99890 struct sctp_association *asoc;
99891 struct sctp_ulpevent *event;
99892 + struct sctp_event_subscribe subscribe;
99893
99894 if (optlen > sizeof(struct sctp_event_subscribe))
99895 return -EINVAL;
99896 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
99897 + if (copy_from_user(&subscribe, optval, optlen))
99898 return -EFAULT;
99899 + sctp_sk(sk)->subscribe = subscribe;
99900
99901 /*
99902 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
99903 @@ -4229,13 +4231,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
99904 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
99905 int __user *optlen)
99906 {
99907 + struct sctp_event_subscribe subscribe;
99908 +
99909 if (len <= 0)
99910 return -EINVAL;
99911 if (len > sizeof(struct sctp_event_subscribe))
99912 len = sizeof(struct sctp_event_subscribe);
99913 if (put_user(len, optlen))
99914 return -EFAULT;
99915 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
99916 + subscribe = sctp_sk(sk)->subscribe;
99917 + if (copy_to_user(optval, &subscribe, len))
99918 return -EFAULT;
99919 return 0;
99920 }
99921 @@ -4253,6 +4258,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
99922 */
99923 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
99924 {
99925 + __u32 autoclose;
99926 +
99927 /* Applicable to UDP-style socket only */
99928 if (sctp_style(sk, TCP))
99929 return -EOPNOTSUPP;
99930 @@ -4261,7 +4268,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
99931 len = sizeof(int);
99932 if (put_user(len, optlen))
99933 return -EFAULT;
99934 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
99935 + autoclose = sctp_sk(sk)->autoclose;
99936 + if (copy_to_user(optval, &autoclose, sizeof(int)))
99937 return -EFAULT;
99938 return 0;
99939 }
99940 @@ -4633,12 +4641,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
99941 */
99942 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
99943 {
99944 + struct sctp_initmsg initmsg;
99945 +
99946 if (len < sizeof(struct sctp_initmsg))
99947 return -EINVAL;
99948 len = sizeof(struct sctp_initmsg);
99949 if (put_user(len, optlen))
99950 return -EFAULT;
99951 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
99952 + initmsg = sctp_sk(sk)->initmsg;
99953 + if (copy_to_user(optval, &initmsg, len))
99954 return -EFAULT;
99955 return 0;
99956 }
99957 @@ -4679,6 +4690,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
99958 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
99959 if (space_left < addrlen)
99960 return -ENOMEM;
99961 + if (addrlen > sizeof(temp) || addrlen < 0)
99962 + return -EFAULT;
99963 if (copy_to_user(to, &temp, addrlen))
99964 return -EFAULT;
99965 to += addrlen;
99966 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
99967 index b0565af..d135e6e 100644
99968 --- a/net/sctp/sysctl.c
99969 +++ b/net/sctp/sysctl.c
99970 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
99971 {
99972 struct net *net = current->nsproxy->net_ns;
99973 char tmp[8];
99974 - struct ctl_table tbl;
99975 + ctl_table_no_const tbl;
99976 int ret;
99977 int changed = 0;
99978 char *none = "none";
99979 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
99980 {
99981 struct net *net = current->nsproxy->net_ns;
99982 int new_value;
99983 - struct ctl_table tbl;
99984 + ctl_table_no_const tbl;
99985 unsigned int min = *(unsigned int *) ctl->extra1;
99986 unsigned int max = *(unsigned int *) ctl->extra2;
99987 int ret;
99988 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
99989 {
99990 struct net *net = current->nsproxy->net_ns;
99991 int new_value;
99992 - struct ctl_table tbl;
99993 + ctl_table_no_const tbl;
99994 unsigned int min = *(unsigned int *) ctl->extra1;
99995 unsigned int max = *(unsigned int *) ctl->extra2;
99996 int ret;
99997 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
99998
99999 int sctp_sysctl_net_register(struct net *net)
100000 {
100001 - struct ctl_table *table;
100002 + ctl_table_no_const *table;
100003 int i;
100004
100005 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
100006 diff --git a/net/socket.c b/net/socket.c
100007 index e83c416..1094d88 100644
100008 --- a/net/socket.c
100009 +++ b/net/socket.c
100010 @@ -88,6 +88,7 @@
100011 #include <linux/magic.h>
100012 #include <linux/slab.h>
100013 #include <linux/xattr.h>
100014 +#include <linux/in.h>
100015
100016 #include <asm/uaccess.h>
100017 #include <asm/unistd.h>
100018 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
100019 unsigned int sysctl_net_busy_poll __read_mostly;
100020 #endif
100021
100022 +#include <linux/grsock.h>
100023 +
100024 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
100025 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
100026 unsigned long nr_segs, loff_t pos);
100027 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
100028 */
100029
100030 static DEFINE_SPINLOCK(net_family_lock);
100031 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
100032 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
100033
100034 /*
100035 * Statistics counters of the socket lists
100036 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
100037 &sockfs_dentry_operations, SOCKFS_MAGIC);
100038 }
100039
100040 -static struct vfsmount *sock_mnt __read_mostly;
100041 +struct vfsmount *sock_mnt __read_mostly;
100042
100043 static struct file_system_type sock_fs_type = {
100044 .name = "sockfs",
100045 @@ -1255,6 +1258,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
100046 return -EAFNOSUPPORT;
100047 if (type < 0 || type >= SOCK_MAX)
100048 return -EINVAL;
100049 + if (protocol < 0)
100050 + return -EINVAL;
100051
100052 /* Compatibility.
100053
100054 @@ -1275,6 +1280,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
100055 if (err)
100056 return err;
100057
100058 + if(!kern && !gr_search_socket(family, type, protocol)) {
100059 + if (rcu_access_pointer(net_families[family]) == NULL)
100060 + return -EAFNOSUPPORT;
100061 + else
100062 + return -EACCES;
100063 + }
100064 +
100065 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
100066 + if (rcu_access_pointer(net_families[family]) == NULL)
100067 + return -EAFNOSUPPORT;
100068 + else
100069 + return -EACCES;
100070 + }
100071 +
100072 /*
100073 * Allocate the socket and allow the family to set things up. if
100074 * the protocol is 0, the family is instructed to select an appropriate
100075 @@ -1513,6 +1532,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
100076 if (sock) {
100077 err = move_addr_to_kernel(umyaddr, addrlen, &address);
100078 if (err >= 0) {
100079 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
100080 + err = -EACCES;
100081 + goto error;
100082 + }
100083 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
100084 + if (err)
100085 + goto error;
100086 +
100087 err = security_socket_bind(sock,
100088 (struct sockaddr *)&address,
100089 addrlen);
100090 @@ -1521,6 +1548,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
100091 (struct sockaddr *)
100092 &address, addrlen);
100093 }
100094 +error:
100095 fput_light(sock->file, fput_needed);
100096 }
100097 return err;
100098 @@ -1544,10 +1572,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
100099 if ((unsigned int)backlog > somaxconn)
100100 backlog = somaxconn;
100101
100102 + if (gr_handle_sock_server_other(sock->sk)) {
100103 + err = -EPERM;
100104 + goto error;
100105 + }
100106 +
100107 + err = gr_search_listen(sock);
100108 + if (err)
100109 + goto error;
100110 +
100111 err = security_socket_listen(sock, backlog);
100112 if (!err)
100113 err = sock->ops->listen(sock, backlog);
100114
100115 +error:
100116 fput_light(sock->file, fput_needed);
100117 }
100118 return err;
100119 @@ -1591,6 +1629,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
100120 newsock->type = sock->type;
100121 newsock->ops = sock->ops;
100122
100123 + if (gr_handle_sock_server_other(sock->sk)) {
100124 + err = -EPERM;
100125 + sock_release(newsock);
100126 + goto out_put;
100127 + }
100128 +
100129 + err = gr_search_accept(sock);
100130 + if (err) {
100131 + sock_release(newsock);
100132 + goto out_put;
100133 + }
100134 +
100135 /*
100136 * We don't need try_module_get here, as the listening socket (sock)
100137 * has the protocol module (sock->ops->owner) held.
100138 @@ -1636,6 +1686,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
100139 fd_install(newfd, newfile);
100140 err = newfd;
100141
100142 + gr_attach_curr_ip(newsock->sk);
100143 +
100144 out_put:
100145 fput_light(sock->file, fput_needed);
100146 out:
100147 @@ -1668,6 +1720,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
100148 int, addrlen)
100149 {
100150 struct socket *sock;
100151 + struct sockaddr *sck;
100152 struct sockaddr_storage address;
100153 int err, fput_needed;
100154
100155 @@ -1678,6 +1731,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
100156 if (err < 0)
100157 goto out_put;
100158
100159 + sck = (struct sockaddr *)&address;
100160 +
100161 + if (gr_handle_sock_client(sck)) {
100162 + err = -EACCES;
100163 + goto out_put;
100164 + }
100165 +
100166 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
100167 + if (err)
100168 + goto out_put;
100169 +
100170 err =
100171 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
100172 if (err)
100173 @@ -1759,6 +1823,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
100174 * the protocol.
100175 */
100176
100177 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
100178 +
100179 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
100180 unsigned int, flags, struct sockaddr __user *, addr,
100181 int, addr_len)
100182 @@ -2047,7 +2113,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
100183 * checking falls down on this.
100184 */
100185 if (copy_from_user(ctl_buf,
100186 - (void __user __force *)msg_sys->msg_control,
100187 + (void __force_user *)msg_sys->msg_control,
100188 ctl_len))
100189 goto out_freectl;
100190 msg_sys->msg_control = ctl_buf;
100191 @@ -2227,7 +2293,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
100192 /* Save the user-mode address (verify_iovec will change the
100193 * kernel msghdr to use the kernel address space)
100194 */
100195 - uaddr = (__force void __user *)msg_sys->msg_name;
100196 + uaddr = (void __force_user *)msg_sys->msg_name;
100197 uaddr_len = COMPAT_NAMELEN(msg);
100198 if (MSG_CMSG_COMPAT & flags)
100199 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
100200 @@ -2871,7 +2937,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
100201 ifr = compat_alloc_user_space(buf_size);
100202 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
100203
100204 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
100205 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
100206 return -EFAULT;
100207
100208 if (put_user(convert_in ? rxnfc : compat_ptr(data),
100209 @@ -2985,14 +3051,14 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
100210 old_fs = get_fs();
100211 set_fs(KERNEL_DS);
100212 err = dev_ioctl(net, cmd,
100213 - (struct ifreq __user __force *) &kifr);
100214 + (struct ifreq __force_user *) &kifr);
100215 set_fs(old_fs);
100216
100217 return err;
100218 case SIOCBONDSLAVEINFOQUERY:
100219 case SIOCBONDINFOQUERY:
100220 uifr = compat_alloc_user_space(sizeof(*uifr));
100221 - if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
100222 + if (copy_in_user(uifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
100223 return -EFAULT;
100224
100225 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
100226 @@ -3094,7 +3160,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
100227
100228 old_fs = get_fs();
100229 set_fs(KERNEL_DS);
100230 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
100231 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
100232 set_fs(old_fs);
100233
100234 if (cmd == SIOCGIFMAP && !err) {
100235 @@ -3199,7 +3265,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
100236 ret |= get_user(rtdev, &(ur4->rt_dev));
100237 if (rtdev) {
100238 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
100239 - r4.rt_dev = (char __user __force *)devname;
100240 + r4.rt_dev = (char __force_user *)devname;
100241 devname[15] = 0;
100242 } else
100243 r4.rt_dev = NULL;
100244 @@ -3425,8 +3491,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
100245 int __user *uoptlen;
100246 int err;
100247
100248 - uoptval = (char __user __force *) optval;
100249 - uoptlen = (int __user __force *) optlen;
100250 + uoptval = (char __force_user *) optval;
100251 + uoptlen = (int __force_user *) optlen;
100252
100253 set_fs(KERNEL_DS);
100254 if (level == SOL_SOCKET)
100255 @@ -3446,7 +3512,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
100256 char __user *uoptval;
100257 int err;
100258
100259 - uoptval = (char __user __force *) optval;
100260 + uoptval = (char __force_user *) optval;
100261
100262 set_fs(KERNEL_DS);
100263 if (level == SOL_SOCKET)
100264 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
100265 index 008cdad..6f17474 100644
100266 --- a/net/sunrpc/auth_gss/svcauth_gss.c
100267 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
100268 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
100269 uint64_t *handle)
100270 {
100271 struct rsc rsci, *rscp = NULL;
100272 - static atomic64_t ctxhctr;
100273 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
100274 long long ctxh;
100275 struct gss_api_mech *gm = NULL;
100276 time_t expiry;
100277 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
100278 status = -ENOMEM;
100279 /* the handle needs to be just a unique id,
100280 * use a static counter */
100281 - ctxh = atomic64_inc_return(&ctxhctr);
100282 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
100283
100284 /* make a copy for the caller */
100285 *handle = ctxh;
100286 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
100287 index f09b7db..393c39e 100644
100288 --- a/net/sunrpc/clnt.c
100289 +++ b/net/sunrpc/clnt.c
100290 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
100291 (RPC_IS_ASYNC(task) ? "async" : "sync"));
100292
100293 /* Increment call count */
100294 - task->tk_msg.rpc_proc->p_count++;
100295 + pax_open_kernel();
100296 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
100297 + pax_close_kernel();
100298 clnt->cl_stats->rpccnt++;
100299 task->tk_action = call_reserve;
100300 }
100301 @@ -1529,9 +1531,13 @@ call_refreshresult(struct rpc_task *task)
100302 task->tk_action = call_refresh;
100303 switch (status) {
100304 case 0:
100305 - if (rpcauth_uptodatecred(task))
100306 + if (rpcauth_uptodatecred(task)) {
100307 task->tk_action = call_allocate;
100308 - return;
100309 + return;
100310 + }
100311 + /* Use rate-limiting and a max number of retries if refresh
100312 + * had status 0 but failed to update the cred.
100313 + */
100314 case -ETIMEDOUT:
100315 rpc_delay(task, 3*HZ);
100316 case -EAGAIN:
100317 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
100318 index ff3cc4b..7612a9e 100644
100319 --- a/net/sunrpc/sched.c
100320 +++ b/net/sunrpc/sched.c
100321 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
100322 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
100323 static void rpc_task_set_debuginfo(struct rpc_task *task)
100324 {
100325 - static atomic_t rpc_pid;
100326 + static atomic_unchecked_t rpc_pid;
100327
100328 - task->tk_pid = atomic_inc_return(&rpc_pid);
100329 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
100330 }
100331 #else
100332 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
100333 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
100334 index e7fbe36..8052603 100644
100335 --- a/net/sunrpc/svc.c
100336 +++ b/net/sunrpc/svc.c
100337 @@ -1158,7 +1158,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
100338 svc_putnl(resv, RPC_SUCCESS);
100339
100340 /* Bump per-procedure stats counter */
100341 - procp->pc_count++;
100342 + pax_open_kernel();
100343 + (*(unsigned int *)&procp->pc_count)++;
100344 + pax_close_kernel();
100345
100346 /* Initialize storage for argp and resp */
100347 memset(rqstp->rq_argp, 0, procp->pc_argsize);
100348 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
100349 index 621ca7b..59421dd 100644
100350 --- a/net/sunrpc/svcauth_unix.c
100351 +++ b/net/sunrpc/svcauth_unix.c
100352 @@ -414,7 +414,7 @@ struct unix_gid {
100353 struct group_info *gi;
100354 };
100355
100356 -static int unix_gid_hash(kuid_t uid)
100357 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
100358 {
100359 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
100360 }
100361 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
100362 (*bpp)[-1] = '\n';
100363 }
100364
100365 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
100366 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
100367
100368 static int unix_gid_parse(struct cache_detail *cd,
100369 char *mesg, int mlen)
100370 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
100371 index c1b6270..05089c1 100644
100372 --- a/net/sunrpc/xprtrdma/svc_rdma.c
100373 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
100374 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
100375 static unsigned int min_max_inline = 4096;
100376 static unsigned int max_max_inline = 65536;
100377
100378 -atomic_t rdma_stat_recv;
100379 -atomic_t rdma_stat_read;
100380 -atomic_t rdma_stat_write;
100381 -atomic_t rdma_stat_sq_starve;
100382 -atomic_t rdma_stat_rq_starve;
100383 -atomic_t rdma_stat_rq_poll;
100384 -atomic_t rdma_stat_rq_prod;
100385 -atomic_t rdma_stat_sq_poll;
100386 -atomic_t rdma_stat_sq_prod;
100387 +atomic_unchecked_t rdma_stat_recv;
100388 +atomic_unchecked_t rdma_stat_read;
100389 +atomic_unchecked_t rdma_stat_write;
100390 +atomic_unchecked_t rdma_stat_sq_starve;
100391 +atomic_unchecked_t rdma_stat_rq_starve;
100392 +atomic_unchecked_t rdma_stat_rq_poll;
100393 +atomic_unchecked_t rdma_stat_rq_prod;
100394 +atomic_unchecked_t rdma_stat_sq_poll;
100395 +atomic_unchecked_t rdma_stat_sq_prod;
100396
100397 /* Temporary NFS request map and context caches */
100398 struct kmem_cache *svc_rdma_map_cachep;
100399 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
100400 len -= *ppos;
100401 if (len > *lenp)
100402 len = *lenp;
100403 - if (len && copy_to_user(buffer, str_buf, len))
100404 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
100405 return -EFAULT;
100406 *lenp = len;
100407 *ppos += len;
100408 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
100409 {
100410 .procname = "rdma_stat_read",
100411 .data = &rdma_stat_read,
100412 - .maxlen = sizeof(atomic_t),
100413 + .maxlen = sizeof(atomic_unchecked_t),
100414 .mode = 0644,
100415 .proc_handler = read_reset_stat,
100416 },
100417 {
100418 .procname = "rdma_stat_recv",
100419 .data = &rdma_stat_recv,
100420 - .maxlen = sizeof(atomic_t),
100421 + .maxlen = sizeof(atomic_unchecked_t),
100422 .mode = 0644,
100423 .proc_handler = read_reset_stat,
100424 },
100425 {
100426 .procname = "rdma_stat_write",
100427 .data = &rdma_stat_write,
100428 - .maxlen = sizeof(atomic_t),
100429 + .maxlen = sizeof(atomic_unchecked_t),
100430 .mode = 0644,
100431 .proc_handler = read_reset_stat,
100432 },
100433 {
100434 .procname = "rdma_stat_sq_starve",
100435 .data = &rdma_stat_sq_starve,
100436 - .maxlen = sizeof(atomic_t),
100437 + .maxlen = sizeof(atomic_unchecked_t),
100438 .mode = 0644,
100439 .proc_handler = read_reset_stat,
100440 },
100441 {
100442 .procname = "rdma_stat_rq_starve",
100443 .data = &rdma_stat_rq_starve,
100444 - .maxlen = sizeof(atomic_t),
100445 + .maxlen = sizeof(atomic_unchecked_t),
100446 .mode = 0644,
100447 .proc_handler = read_reset_stat,
100448 },
100449 {
100450 .procname = "rdma_stat_rq_poll",
100451 .data = &rdma_stat_rq_poll,
100452 - .maxlen = sizeof(atomic_t),
100453 + .maxlen = sizeof(atomic_unchecked_t),
100454 .mode = 0644,
100455 .proc_handler = read_reset_stat,
100456 },
100457 {
100458 .procname = "rdma_stat_rq_prod",
100459 .data = &rdma_stat_rq_prod,
100460 - .maxlen = sizeof(atomic_t),
100461 + .maxlen = sizeof(atomic_unchecked_t),
100462 .mode = 0644,
100463 .proc_handler = read_reset_stat,
100464 },
100465 {
100466 .procname = "rdma_stat_sq_poll",
100467 .data = &rdma_stat_sq_poll,
100468 - .maxlen = sizeof(atomic_t),
100469 + .maxlen = sizeof(atomic_unchecked_t),
100470 .mode = 0644,
100471 .proc_handler = read_reset_stat,
100472 },
100473 {
100474 .procname = "rdma_stat_sq_prod",
100475 .data = &rdma_stat_sq_prod,
100476 - .maxlen = sizeof(atomic_t),
100477 + .maxlen = sizeof(atomic_unchecked_t),
100478 .mode = 0644,
100479 .proc_handler = read_reset_stat,
100480 },
100481 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100482 index 0ce7552..d074459 100644
100483 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100484 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100485 @@ -501,7 +501,7 @@ next_sge:
100486 svc_rdma_put_context(ctxt, 0);
100487 goto out;
100488 }
100489 - atomic_inc(&rdma_stat_read);
100490 + atomic_inc_unchecked(&rdma_stat_read);
100491
100492 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
100493 chl_map->ch[ch_no].count -= read_wr.num_sge;
100494 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
100495 dto_q);
100496 list_del_init(&ctxt->dto_q);
100497 } else {
100498 - atomic_inc(&rdma_stat_rq_starve);
100499 + atomic_inc_unchecked(&rdma_stat_rq_starve);
100500 clear_bit(XPT_DATA, &xprt->xpt_flags);
100501 ctxt = NULL;
100502 }
100503 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
100504 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
100505 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
100506 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
100507 - atomic_inc(&rdma_stat_recv);
100508 + atomic_inc_unchecked(&rdma_stat_recv);
100509
100510 /* Build up the XDR from the receive buffers. */
100511 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
100512 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100513 index c1d124d..acfc59e 100644
100514 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100515 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100516 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
100517 write_wr.wr.rdma.remote_addr = to;
100518
100519 /* Post It */
100520 - atomic_inc(&rdma_stat_write);
100521 + atomic_inc_unchecked(&rdma_stat_write);
100522 if (svc_rdma_send(xprt, &write_wr))
100523 goto err;
100524 return 0;
100525 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
100526 index 62e4f9b..dd3f2d7 100644
100527 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
100528 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
100529 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
100530 return;
100531
100532 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
100533 - atomic_inc(&rdma_stat_rq_poll);
100534 + atomic_inc_unchecked(&rdma_stat_rq_poll);
100535
100536 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
100537 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
100538 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
100539 }
100540
100541 if (ctxt)
100542 - atomic_inc(&rdma_stat_rq_prod);
100543 + atomic_inc_unchecked(&rdma_stat_rq_prod);
100544
100545 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
100546 /*
100547 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
100548 return;
100549
100550 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
100551 - atomic_inc(&rdma_stat_sq_poll);
100552 + atomic_inc_unchecked(&rdma_stat_sq_poll);
100553 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
100554 if (wc.status != IB_WC_SUCCESS)
100555 /* Close the transport */
100556 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
100557 }
100558
100559 if (ctxt)
100560 - atomic_inc(&rdma_stat_sq_prod);
100561 + atomic_inc_unchecked(&rdma_stat_sq_prod);
100562 }
100563
100564 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
100565 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
100566 spin_lock_bh(&xprt->sc_lock);
100567 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
100568 spin_unlock_bh(&xprt->sc_lock);
100569 - atomic_inc(&rdma_stat_sq_starve);
100570 + atomic_inc_unchecked(&rdma_stat_sq_starve);
100571
100572 /* See if we can opportunistically reap SQ WR to make room */
100573 sq_cq_reap(xprt);
100574 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
100575 index e7000be..e3b0ba7 100644
100576 --- a/net/sysctl_net.c
100577 +++ b/net/sysctl_net.c
100578 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
100579 kgid_t root_gid = make_kgid(net->user_ns, 0);
100580
100581 /* Allow network administrator to have same access as root. */
100582 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
100583 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
100584 uid_eq(root_uid, current_euid())) {
100585 int mode = (table->mode >> 6) & 7;
100586 return (mode << 6) | (mode << 3) | mode;
100587 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
100588 index d38bb45..38d5df5 100644
100589 --- a/net/tipc/subscr.c
100590 +++ b/net/tipc/subscr.c
100591 @@ -98,7 +98,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
100592 struct kvec msg_sect;
100593 int ret;
100594
100595 - msg_sect.iov_base = (void *)&sub->evt;
100596 + msg_sect.iov_base = &sub->evt;
100597 msg_sect.iov_len = sizeof(struct tipc_event);
100598
100599 sub->evt.event = htohl(event, sub->swap);
100600 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
100601 index a427623..387c80b 100644
100602 --- a/net/unix/af_unix.c
100603 +++ b/net/unix/af_unix.c
100604 @@ -790,6 +790,12 @@ static struct sock *unix_find_other(struct net *net,
100605 err = -ECONNREFUSED;
100606 if (!S_ISSOCK(inode->i_mode))
100607 goto put_fail;
100608 +
100609 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
100610 + err = -EACCES;
100611 + goto put_fail;
100612 + }
100613 +
100614 u = unix_find_socket_byinode(inode);
100615 if (!u)
100616 goto put_fail;
100617 @@ -810,6 +816,13 @@ static struct sock *unix_find_other(struct net *net,
100618 if (u) {
100619 struct dentry *dentry;
100620 dentry = unix_sk(u)->path.dentry;
100621 +
100622 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
100623 + err = -EPERM;
100624 + sock_put(u);
100625 + goto fail;
100626 + }
100627 +
100628 if (dentry)
100629 touch_atime(&unix_sk(u)->path);
100630 } else
100631 @@ -843,12 +856,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
100632 */
100633 err = security_path_mknod(&path, dentry, mode, 0);
100634 if (!err) {
100635 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
100636 + err = -EACCES;
100637 + goto out;
100638 + }
100639 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
100640 if (!err) {
100641 res->mnt = mntget(path.mnt);
100642 res->dentry = dget(dentry);
100643 + gr_handle_create(dentry, path.mnt);
100644 }
100645 }
100646 +out:
100647 done_path_create(&path, dentry);
100648 return err;
100649 }
100650 @@ -2336,9 +2355,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
100651 seq_puts(seq, "Num RefCount Protocol Flags Type St "
100652 "Inode Path\n");
100653 else {
100654 - struct sock *s = v;
100655 + struct sock *s = v, *peer;
100656 struct unix_sock *u = unix_sk(s);
100657 unix_state_lock(s);
100658 + peer = unix_peer(s);
100659 + unix_state_unlock(s);
100660 +
100661 + unix_state_double_lock(s, peer);
100662
100663 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
100664 s,
100665 @@ -2365,8 +2388,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
100666 }
100667 for ( ; i < len; i++)
100668 seq_putc(seq, u->addr->name->sun_path[i]);
100669 - }
100670 - unix_state_unlock(s);
100671 + } else if (peer)
100672 + seq_printf(seq, " P%lu", sock_i_ino(peer));
100673 +
100674 + unix_state_double_unlock(s, peer);
100675 seq_putc(seq, '\n');
100676 }
100677
100678 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
100679 index b3d5150..ff3a837 100644
100680 --- a/net/unix/sysctl_net_unix.c
100681 +++ b/net/unix/sysctl_net_unix.c
100682 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
100683
100684 int __net_init unix_sysctl_register(struct net *net)
100685 {
100686 - struct ctl_table *table;
100687 + ctl_table_no_const *table;
100688
100689 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
100690 if (table == NULL)
100691 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
100692 index 9a73074..aecba9a 100644
100693 --- a/net/vmw_vsock/vmci_transport_notify.c
100694 +++ b/net/vmw_vsock/vmci_transport_notify.c
100695 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
100696
100697 /* Socket control packet based operations. */
100698 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
100699 - vmci_transport_notify_pkt_socket_init,
100700 - vmci_transport_notify_pkt_socket_destruct,
100701 - vmci_transport_notify_pkt_poll_in,
100702 - vmci_transport_notify_pkt_poll_out,
100703 - vmci_transport_notify_pkt_handle_pkt,
100704 - vmci_transport_notify_pkt_recv_init,
100705 - vmci_transport_notify_pkt_recv_pre_block,
100706 - vmci_transport_notify_pkt_recv_pre_dequeue,
100707 - vmci_transport_notify_pkt_recv_post_dequeue,
100708 - vmci_transport_notify_pkt_send_init,
100709 - vmci_transport_notify_pkt_send_pre_block,
100710 - vmci_transport_notify_pkt_send_pre_enqueue,
100711 - vmci_transport_notify_pkt_send_post_enqueue,
100712 - vmci_transport_notify_pkt_process_request,
100713 - vmci_transport_notify_pkt_process_negotiate,
100714 + .socket_init = vmci_transport_notify_pkt_socket_init,
100715 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
100716 + .poll_in = vmci_transport_notify_pkt_poll_in,
100717 + .poll_out = vmci_transport_notify_pkt_poll_out,
100718 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
100719 + .recv_init = vmci_transport_notify_pkt_recv_init,
100720 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
100721 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
100722 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
100723 + .send_init = vmci_transport_notify_pkt_send_init,
100724 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
100725 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
100726 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
100727 + .process_request = vmci_transport_notify_pkt_process_request,
100728 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
100729 };
100730 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
100731 index 622bd7a..b92086c 100644
100732 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
100733 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
100734 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
100735
100736 /* Socket always on control packet based operations. */
100737 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
100738 - vmci_transport_notify_pkt_socket_init,
100739 - vmci_transport_notify_pkt_socket_destruct,
100740 - vmci_transport_notify_pkt_poll_in,
100741 - vmci_transport_notify_pkt_poll_out,
100742 - vmci_transport_notify_pkt_handle_pkt,
100743 - vmci_transport_notify_pkt_recv_init,
100744 - vmci_transport_notify_pkt_recv_pre_block,
100745 - vmci_transport_notify_pkt_recv_pre_dequeue,
100746 - vmci_transport_notify_pkt_recv_post_dequeue,
100747 - vmci_transport_notify_pkt_send_init,
100748 - vmci_transport_notify_pkt_send_pre_block,
100749 - vmci_transport_notify_pkt_send_pre_enqueue,
100750 - vmci_transport_notify_pkt_send_post_enqueue,
100751 - vmci_transport_notify_pkt_process_request,
100752 - vmci_transport_notify_pkt_process_negotiate,
100753 + .socket_init = vmci_transport_notify_pkt_socket_init,
100754 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
100755 + .poll_in = vmci_transport_notify_pkt_poll_in,
100756 + .poll_out = vmci_transport_notify_pkt_poll_out,
100757 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
100758 + .recv_init = vmci_transport_notify_pkt_recv_init,
100759 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
100760 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
100761 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
100762 + .send_init = vmci_transport_notify_pkt_send_init,
100763 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
100764 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
100765 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
100766 + .process_request = vmci_transport_notify_pkt_process_request,
100767 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
100768 };
100769 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
100770 index c8717c1..08539f5 100644
100771 --- a/net/wireless/wext-core.c
100772 +++ b/net/wireless/wext-core.c
100773 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
100774 */
100775
100776 /* Support for very large requests */
100777 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
100778 - (user_length > descr->max_tokens)) {
100779 + if (user_length > descr->max_tokens) {
100780 /* Allow userspace to GET more than max so
100781 * we can support any size GET requests.
100782 * There is still a limit : -ENOMEM.
100783 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
100784 }
100785 }
100786
100787 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
100788 - /*
100789 - * If this is a GET, but not NOMAX, it means that the extra
100790 - * data is not bounded by userspace, but by max_tokens. Thus
100791 - * set the length to max_tokens. This matches the extra data
100792 - * allocation.
100793 - * The driver should fill it with the number of tokens it
100794 - * provided, and it may check iwp->length rather than having
100795 - * knowledge of max_tokens. If the driver doesn't change the
100796 - * iwp->length, this ioctl just copies back max_token tokens
100797 - * filled with zeroes. Hopefully the driver isn't claiming
100798 - * them to be valid data.
100799 - */
100800 - iwp->length = descr->max_tokens;
100801 - }
100802 -
100803 err = handler(dev, info, (union iwreq_data *) iwp, extra);
100804
100805 iwp->length += essid_compat;
100806 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
100807 index 4323952..a06dfe1 100644
100808 --- a/net/x25/sysctl_net_x25.c
100809 +++ b/net/x25/sysctl_net_x25.c
100810 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
100811 .mode = 0644,
100812 .proc_handler = proc_dointvec,
100813 },
100814 - { 0, },
100815 + { },
100816 };
100817
100818 void __init x25_register_sysctl(void)
100819 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
100820 index 9a91f74..502f6605 100644
100821 --- a/net/xfrm/xfrm_policy.c
100822 +++ b/net/xfrm/xfrm_policy.c
100823 @@ -332,7 +332,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
100824 {
100825 policy->walk.dead = 1;
100826
100827 - atomic_inc(&policy->genid);
100828 + atomic_inc_unchecked(&policy->genid);
100829
100830 if (del_timer(&policy->polq.hold_timer))
100831 xfrm_pol_put(policy);
100832 @@ -660,7 +660,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
100833 hlist_add_head(&policy->bydst, chain);
100834 xfrm_pol_hold(policy);
100835 net->xfrm.policy_count[dir]++;
100836 - atomic_inc(&flow_cache_genid);
100837 + atomic_inc_unchecked(&flow_cache_genid);
100838
100839 /* After previous checking, family can either be AF_INET or AF_INET6 */
100840 if (policy->family == AF_INET)
100841 @@ -1636,7 +1636,7 @@ free_dst:
100842 goto out;
100843 }
100844
100845 -static int inline
100846 +static inline int
100847 xfrm_dst_alloc_copy(void **target, const void *src, int size)
100848 {
100849 if (!*target) {
100850 @@ -1648,7 +1648,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
100851 return 0;
100852 }
100853
100854 -static int inline
100855 +static inline int
100856 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
100857 {
100858 #ifdef CONFIG_XFRM_SUB_POLICY
100859 @@ -1660,7 +1660,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
100860 #endif
100861 }
100862
100863 -static int inline
100864 +static inline int
100865 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
100866 {
100867 #ifdef CONFIG_XFRM_SUB_POLICY
100868 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
100869
100870 xdst->num_pols = num_pols;
100871 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
100872 - xdst->policy_genid = atomic_read(&pols[0]->genid);
100873 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
100874
100875 return xdst;
100876 }
100877 @@ -2582,11 +2582,12 @@ void xfrm_garbage_collect(struct net *net)
100878 }
100879 EXPORT_SYMBOL(xfrm_garbage_collect);
100880
100881 -static void xfrm_garbage_collect_deferred(struct net *net)
100882 +void xfrm_garbage_collect_deferred(struct net *net)
100883 {
100884 flow_cache_flush_deferred();
100885 __xfrm_garbage_collect(net);
100886 }
100887 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
100888
100889 static void xfrm_init_pmtu(struct dst_entry *dst)
100890 {
100891 @@ -2636,7 +2637,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
100892 if (xdst->xfrm_genid != dst->xfrm->genid)
100893 return 0;
100894 if (xdst->num_pols > 0 &&
100895 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
100896 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
100897 return 0;
100898
100899 mtu = dst_mtu(dst->child);
100900 @@ -2724,8 +2725,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
100901 dst_ops->link_failure = xfrm_link_failure;
100902 if (likely(dst_ops->neigh_lookup == NULL))
100903 dst_ops->neigh_lookup = xfrm_neigh_lookup;
100904 - if (likely(afinfo->garbage_collect == NULL))
100905 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
100906 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
100907 }
100908 spin_unlock(&xfrm_policy_afinfo_lock);
100909 @@ -2779,7 +2778,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
100910 dst_ops->check = NULL;
100911 dst_ops->negative_advice = NULL;
100912 dst_ops->link_failure = NULL;
100913 - afinfo->garbage_collect = NULL;
100914 }
100915 return err;
100916 }
100917 @@ -3162,7 +3160,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
100918 sizeof(pol->xfrm_vec[i].saddr));
100919 pol->xfrm_vec[i].encap_family = mp->new_family;
100920 /* flush bundles */
100921 - atomic_inc(&pol->genid);
100922 + atomic_inc_unchecked(&pol->genid);
100923 }
100924 }
100925
100926 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
100927 index 68c2f35..9eb05ca 100644
100928 --- a/net/xfrm/xfrm_state.c
100929 +++ b/net/xfrm/xfrm_state.c
100930 @@ -174,12 +174,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
100931
100932 if (unlikely(afinfo == NULL))
100933 return -EAFNOSUPPORT;
100934 - typemap = afinfo->type_map;
100935 + typemap = (const struct xfrm_type **)afinfo->type_map;
100936 spin_lock_bh(&xfrm_type_lock);
100937
100938 - if (likely(typemap[type->proto] == NULL))
100939 + if (likely(typemap[type->proto] == NULL)) {
100940 + pax_open_kernel();
100941 typemap[type->proto] = type;
100942 - else
100943 + pax_close_kernel();
100944 + } else
100945 err = -EEXIST;
100946 spin_unlock_bh(&xfrm_type_lock);
100947 xfrm_state_put_afinfo(afinfo);
100948 @@ -195,13 +197,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
100949
100950 if (unlikely(afinfo == NULL))
100951 return -EAFNOSUPPORT;
100952 - typemap = afinfo->type_map;
100953 + typemap = (const struct xfrm_type **)afinfo->type_map;
100954 spin_lock_bh(&xfrm_type_lock);
100955
100956 if (unlikely(typemap[type->proto] != type))
100957 err = -ENOENT;
100958 - else
100959 + else {
100960 + pax_open_kernel();
100961 typemap[type->proto] = NULL;
100962 + pax_close_kernel();
100963 + }
100964 spin_unlock_bh(&xfrm_type_lock);
100965 xfrm_state_put_afinfo(afinfo);
100966 return err;
100967 @@ -211,7 +216,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
100968 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
100969 {
100970 struct xfrm_state_afinfo *afinfo;
100971 - const struct xfrm_type **typemap;
100972 const struct xfrm_type *type;
100973 int modload_attempted = 0;
100974
100975 @@ -219,9 +223,8 @@ retry:
100976 afinfo = xfrm_state_get_afinfo(family);
100977 if (unlikely(afinfo == NULL))
100978 return NULL;
100979 - typemap = afinfo->type_map;
100980
100981 - type = typemap[proto];
100982 + type = afinfo->type_map[proto];
100983 if (unlikely(type && !try_module_get(type->owner)))
100984 type = NULL;
100985 if (!type && !modload_attempted) {
100986 @@ -255,7 +258,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
100987 return -EAFNOSUPPORT;
100988
100989 err = -EEXIST;
100990 - modemap = afinfo->mode_map;
100991 + modemap = (struct xfrm_mode **)afinfo->mode_map;
100992 spin_lock_bh(&xfrm_mode_lock);
100993 if (modemap[mode->encap])
100994 goto out;
100995 @@ -264,8 +267,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
100996 if (!try_module_get(afinfo->owner))
100997 goto out;
100998
100999 - mode->afinfo = afinfo;
101000 + pax_open_kernel();
101001 + *(const void **)&mode->afinfo = afinfo;
101002 modemap[mode->encap] = mode;
101003 + pax_close_kernel();
101004 err = 0;
101005
101006 out:
101007 @@ -289,10 +294,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
101008 return -EAFNOSUPPORT;
101009
101010 err = -ENOENT;
101011 - modemap = afinfo->mode_map;
101012 + modemap = (struct xfrm_mode **)afinfo->mode_map;
101013 spin_lock_bh(&xfrm_mode_lock);
101014 if (likely(modemap[mode->encap] == mode)) {
101015 + pax_open_kernel();
101016 modemap[mode->encap] = NULL;
101017 + pax_close_kernel();
101018 module_put(mode->afinfo->owner);
101019 err = 0;
101020 }
101021 @@ -1486,10 +1493,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
101022 u32 xfrm_get_acqseq(void)
101023 {
101024 u32 res;
101025 - static atomic_t acqseq;
101026 + static atomic_unchecked_t acqseq;
101027
101028 do {
101029 - res = atomic_inc_return(&acqseq);
101030 + res = atomic_inc_return_unchecked(&acqseq);
101031 } while (!res);
101032
101033 return res;
101034 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
101035 index 05a6e3d..6716ec9 100644
101036 --- a/net/xfrm/xfrm_sysctl.c
101037 +++ b/net/xfrm/xfrm_sysctl.c
101038 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
101039
101040 int __net_init xfrm_sysctl_init(struct net *net)
101041 {
101042 - struct ctl_table *table;
101043 + ctl_table_no_const *table;
101044
101045 __xfrm_sysctl_init(net);
101046
101047 diff --git a/scripts/Makefile b/scripts/Makefile
101048 index 01e7adb..6176d5d 100644
101049 --- a/scripts/Makefile
101050 +++ b/scripts/Makefile
101051 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
101052
101053 # Let clean descend into subdirs
101054 subdir- += basic kconfig package selinux
101055 +
101056 +clean-files := randstruct.seed
101057 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
101058 index d5d859c..781cbcb 100644
101059 --- a/scripts/Makefile.build
101060 +++ b/scripts/Makefile.build
101061 @@ -111,7 +111,7 @@ endif
101062 endif
101063
101064 # Do not include host rules unless needed
101065 -ifneq ($(hostprogs-y)$(hostprogs-m),)
101066 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
101067 include scripts/Makefile.host
101068 endif
101069
101070 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
101071 index 686cb0d..9d653bf 100644
101072 --- a/scripts/Makefile.clean
101073 +++ b/scripts/Makefile.clean
101074 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
101075 __clean-files := $(extra-y) $(always) \
101076 $(targets) $(clean-files) \
101077 $(host-progs) \
101078 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
101079 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
101080 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
101081
101082 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
101083
101084 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
101085 index 1ac414f..38575f7 100644
101086 --- a/scripts/Makefile.host
101087 +++ b/scripts/Makefile.host
101088 @@ -31,6 +31,8 @@
101089 # Note: Shared libraries consisting of C++ files are not supported
101090
101091 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
101092 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
101093 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
101094
101095 # C code
101096 # Executables compiled from a single .c file
101097 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
101098 # Shared libaries (only .c supported)
101099 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
101100 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
101101 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
101102 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
101103 # Remove .so files from "xxx-objs"
101104 host-cobjs := $(filter-out %.so,$(host-cobjs))
101105 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
101106
101107 -#Object (.o) files used by the shared libaries
101108 +# Object (.o) files used by the shared libaries
101109 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
101110 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
101111
101112 # output directory for programs/.o files
101113 # hostprogs-y := tools/build may have been specified. Retrieve directory
101114 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
101115 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
101116 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
101117 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
101118 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
101119 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
101120 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
101121 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
101122
101123 obj-dirs += $(host-objdirs)
101124 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
101125 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
101126 $(call if_changed_dep,host-cshobjs)
101127
101128 +# Compile .c file, create position independent .o file
101129 +# host-cxxshobjs -> .o
101130 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
101131 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
101132 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
101133 + $(call if_changed_dep,host-cxxshobjs)
101134 +
101135 # Link a shared library, based on position independent .o files
101136 # *.o -> .so shared library (host-cshlib)
101137 quiet_cmd_host-cshlib = HOSTLLD -shared $@
101138 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
101139 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
101140 $(call if_changed,host-cshlib)
101141
101142 +# Link a shared library, based on position independent .o files
101143 +# *.o -> .so shared library (host-cxxshlib)
101144 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
101145 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
101146 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
101147 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
101148 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
101149 + $(call if_changed,host-cxxshlib)
101150 +
101151 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
101152 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
101153 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
101154
101155 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
101156 index 078fe1d..fbdb363 100644
101157 --- a/scripts/basic/fixdep.c
101158 +++ b/scripts/basic/fixdep.c
101159 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
101160 /*
101161 * Lookup a value in the configuration string.
101162 */
101163 -static int is_defined_config(const char *name, int len, unsigned int hash)
101164 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
101165 {
101166 struct item *aux;
101167
101168 @@ -211,10 +211,10 @@ static void clear_config(void)
101169 /*
101170 * Record the use of a CONFIG_* word.
101171 */
101172 -static void use_config(const char *m, int slen)
101173 +static void use_config(const char *m, unsigned int slen)
101174 {
101175 unsigned int hash = strhash(m, slen);
101176 - int c, i;
101177 + unsigned int c, i;
101178
101179 if (is_defined_config(m, slen, hash))
101180 return;
101181 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
101182
101183 static void parse_config_file(const char *map, size_t len)
101184 {
101185 - const int *end = (const int *) (map + len);
101186 + const unsigned int *end = (const unsigned int *) (map + len);
101187 /* start at +1, so that p can never be < map */
101188 - const int *m = (const int *) map + 1;
101189 + const unsigned int *m = (const unsigned int *) map + 1;
101190 const char *p, *q;
101191
101192 for (; m < end; m++) {
101193 @@ -435,7 +435,7 @@ static void print_deps(void)
101194 static void traps(void)
101195 {
101196 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
101197 - int *p = (int *)test;
101198 + unsigned int *p = (unsigned int *)test;
101199
101200 if (*p != INT_CONF) {
101201 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
101202 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
101203 new file mode 100644
101204 index 0000000..5e0222d
101205 --- /dev/null
101206 +++ b/scripts/gcc-plugin.sh
101207 @@ -0,0 +1,17 @@
101208 +#!/bin/bash
101209 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
101210 +#include "gcc-plugin.h"
101211 +#include "tree.h"
101212 +#include "tm.h"
101213 +#include "rtl.h"
101214 +#ifdef ENABLE_BUILD_WITH_CXX
101215 +#warning $2
101216 +#else
101217 +#warning $1
101218 +#endif
101219 +EOF`
101220 +if [ $? -eq 0 ]
101221 +then
101222 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
101223 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
101224 +fi
101225 diff --git a/scripts/gen-random-seed.sh b/scripts/gen-random-seed.sh
101226 new file mode 100644
101227 index 0000000..27e0f4a
101228 --- /dev/null
101229 +++ b/scripts/gen-random-seed.sh
101230 @@ -0,0 +1,8 @@
101231 +#!/bin/sh
101232 +
101233 +if [ ! -f 'tools/gcc/randstruct.seed' ]; then
101234 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
101235 + echo "$SEED" > tools/gcc/randstruct.seed
101236 + cat tools/gcc/randstruct.seed | sha256sum | cut -d" " -f1 | tr -d "\n" > tools/gcc/randstruct.hashed_seed
101237 +fi
101238 +cat tools/gcc/randstruct.seed
101239 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
101240 index 5de5660..d3deb89 100644
101241 --- a/scripts/headers_install.sh
101242 +++ b/scripts/headers_install.sh
101243 @@ -32,6 +32,7 @@ do
101244 FILE="$(basename "$i")"
101245 sed -r \
101246 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
101247 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
101248 -e 's/__attribute_const__([ \t]|$)/\1/g' \
101249 -e 's@^#include <linux/compiler.h>@@' \
101250 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
101251 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
101252 index 2dcb377..a82c500 100644
101253 --- a/scripts/link-vmlinux.sh
101254 +++ b/scripts/link-vmlinux.sh
101255 @@ -162,7 +162,7 @@ else
101256 fi;
101257
101258 # final build of init/
101259 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
101260 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
101261
101262 kallsymso=""
101263 kallsyms_vmlinux=""
101264 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
101265 index 2370863..212fbca 100644
101266 --- a/scripts/mod/file2alias.c
101267 +++ b/scripts/mod/file2alias.c
101268 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
101269 unsigned long size, unsigned long id_size,
101270 void *symval)
101271 {
101272 - int i;
101273 + unsigned int i;
101274
101275 if (size % id_size || size < id_size) {
101276 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
101277 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
101278 /* USB is special because the bcdDevice can be matched against a numeric range */
101279 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
101280 static void do_usb_entry(void *symval,
101281 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
101282 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
101283 unsigned char range_lo, unsigned char range_hi,
101284 unsigned char max, struct module *mod)
101285 {
101286 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
101287 {
101288 unsigned int devlo, devhi;
101289 unsigned char chi, clo, max;
101290 - int ndigits;
101291 + unsigned int ndigits;
101292
101293 DEF_FIELD(symval, usb_device_id, match_flags);
101294 DEF_FIELD(symval, usb_device_id, idVendor);
101295 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
101296 for (i = 0; i < count; i++) {
101297 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
101298 char acpi_id[sizeof(*id)];
101299 - int j;
101300 + unsigned int j;
101301
101302 buf_printf(&mod->dev_table_buf,
101303 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
101304 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
101305
101306 for (j = 0; j < PNP_MAX_DEVICES; j++) {
101307 const char *id = (char *)(*devs)[j].id;
101308 - int i2, j2;
101309 + unsigned int i2, j2;
101310 int dup = 0;
101311
101312 if (!id[0])
101313 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
101314 /* add an individual alias for every device entry */
101315 if (!dup) {
101316 char acpi_id[PNP_ID_LEN];
101317 - int k;
101318 + unsigned int k;
101319
101320 buf_printf(&mod->dev_table_buf,
101321 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
101322 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
101323 static int do_dmi_entry(const char *filename, void *symval,
101324 char *alias)
101325 {
101326 - int i, j;
101327 + unsigned int i, j;
101328 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
101329 sprintf(alias, "dmi*");
101330
101331 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
101332 index 1785576..5e8e06a 100644
101333 --- a/scripts/mod/modpost.c
101334 +++ b/scripts/mod/modpost.c
101335 @@ -941,6 +941,7 @@ enum mismatch {
101336 ANY_INIT_TO_ANY_EXIT,
101337 ANY_EXIT_TO_ANY_INIT,
101338 EXPORT_TO_INIT_EXIT,
101339 + DATA_TO_TEXT
101340 };
101341
101342 struct sectioncheck {
101343 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
101344 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
101345 .mismatch = EXPORT_TO_INIT_EXIT,
101346 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
101347 +},
101348 +/* Do not reference code from writable data */
101349 +{
101350 + .fromsec = { DATA_SECTIONS, NULL },
101351 + .tosec = { TEXT_SECTIONS, NULL },
101352 + .mismatch = DATA_TO_TEXT
101353 }
101354 };
101355
101356 @@ -1147,10 +1154,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
101357 continue;
101358 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
101359 continue;
101360 - if (sym->st_value == addr)
101361 - return sym;
101362 /* Find a symbol nearby - addr are maybe negative */
101363 d = sym->st_value - addr;
101364 + if (d == 0)
101365 + return sym;
101366 if (d < 0)
101367 d = addr - sym->st_value;
101368 if (d < distance) {
101369 @@ -1428,6 +1435,14 @@ static void report_sec_mismatch(const char *modname,
101370 tosym, prl_to, prl_to, tosym);
101371 free(prl_to);
101372 break;
101373 + case DATA_TO_TEXT:
101374 +#if 0
101375 + fprintf(stderr,
101376 + "The %s %s:%s references\n"
101377 + "the %s %s:%s%s\n",
101378 + from, fromsec, fromsym, to, tosec, tosym, to_p);
101379 +#endif
101380 + break;
101381 }
101382 fprintf(stderr, "\n");
101383 }
101384 @@ -1662,7 +1677,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
101385 static void check_sec_ref(struct module *mod, const char *modname,
101386 struct elf_info *elf)
101387 {
101388 - int i;
101389 + unsigned int i;
101390 Elf_Shdr *sechdrs = elf->sechdrs;
101391
101392 /* Walk through all sections */
101393 @@ -1781,7 +1796,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
101394 va_end(ap);
101395 }
101396
101397 -void buf_write(struct buffer *buf, const char *s, int len)
101398 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
101399 {
101400 if (buf->size - buf->pos < len) {
101401 buf->size += len + SZ;
101402 @@ -2000,7 +2015,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
101403 if (fstat(fileno(file), &st) < 0)
101404 goto close_write;
101405
101406 - if (st.st_size != b->pos)
101407 + if (st.st_size != (off_t)b->pos)
101408 goto close_write;
101409
101410 tmp = NOFAIL(malloc(b->pos));
101411 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
101412 index 51207e4..f7d603d 100644
101413 --- a/scripts/mod/modpost.h
101414 +++ b/scripts/mod/modpost.h
101415 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
101416
101417 struct buffer {
101418 char *p;
101419 - int pos;
101420 - int size;
101421 + unsigned int pos;
101422 + unsigned int size;
101423 };
101424
101425 void __attribute__((format(printf, 2, 3)))
101426 buf_printf(struct buffer *buf, const char *fmt, ...);
101427
101428 void
101429 -buf_write(struct buffer *buf, const char *s, int len);
101430 +buf_write(struct buffer *buf, const char *s, unsigned int len);
101431
101432 struct module {
101433 struct module *next;
101434 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
101435 index deb2994..af4f63e 100644
101436 --- a/scripts/mod/sumversion.c
101437 +++ b/scripts/mod/sumversion.c
101438 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
101439 goto out;
101440 }
101441
101442 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
101443 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
101444 warn("writing sum in %s failed: %s\n",
101445 filename, strerror(errno));
101446 goto out;
101447 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
101448 index 0865b3e..7235dd4 100644
101449 --- a/scripts/module-common.lds
101450 +++ b/scripts/module-common.lds
101451 @@ -6,6 +6,10 @@
101452 SECTIONS {
101453 /DISCARD/ : { *(.discard) }
101454
101455 + .rodata : {
101456 + *(.rodata) *(.rodata.*)
101457 + *(.data..read_only)
101458 + }
101459 __ksymtab : { *(SORT(___ksymtab+*)) }
101460 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
101461 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
101462 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
101463 index 90e521f..e9eaf8f 100644
101464 --- a/scripts/package/builddeb
101465 +++ b/scripts/package/builddeb
101466 @@ -281,6 +281,7 @@ fi
101467 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
101468 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
101469 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
101470 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
101471 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
101472 mkdir -p "$destdir"
101473 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
101474 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
101475 index 68bb4ef..2f419e1 100644
101476 --- a/scripts/pnmtologo.c
101477 +++ b/scripts/pnmtologo.c
101478 @@ -244,14 +244,14 @@ static void write_header(void)
101479 fprintf(out, " * Linux logo %s\n", logoname);
101480 fputs(" */\n\n", out);
101481 fputs("#include <linux/linux_logo.h>\n\n", out);
101482 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
101483 + fprintf(out, "static unsigned char %s_data[] = {\n",
101484 logoname);
101485 }
101486
101487 static void write_footer(void)
101488 {
101489 fputs("\n};\n\n", out);
101490 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
101491 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
101492 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
101493 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
101494 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
101495 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
101496 fputs("\n};\n\n", out);
101497
101498 /* write logo clut */
101499 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
101500 + fprintf(out, "static unsigned char %s_clut[] = {\n",
101501 logoname);
101502 write_hex_cnt = 0;
101503 for (i = 0; i < logo_clutsize; i++) {
101504 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
101505 index 8fac3fd..32ff38d 100644
101506 --- a/scripts/sortextable.h
101507 +++ b/scripts/sortextable.h
101508 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
101509 const char *secstrtab;
101510 const char *strtab;
101511 char *extab_image;
101512 - int extab_index = 0;
101513 - int i;
101514 - int idx;
101515 + unsigned int extab_index = 0;
101516 + unsigned int i;
101517 + unsigned int idx;
101518 unsigned int num_sections;
101519 unsigned int secindex_strings;
101520
101521 diff --git a/security/Kconfig b/security/Kconfig
101522 index e9c6ac7..9551ea7 100644
101523 --- a/security/Kconfig
101524 +++ b/security/Kconfig
101525 @@ -4,6 +4,958 @@
101526
101527 menu "Security options"
101528
101529 +menu "Grsecurity"
101530 +
101531 + config ARCH_TRACK_EXEC_LIMIT
101532 + bool
101533 +
101534 + config PAX_KERNEXEC_PLUGIN
101535 + bool
101536 +
101537 + config PAX_PER_CPU_PGD
101538 + bool
101539 +
101540 + config TASK_SIZE_MAX_SHIFT
101541 + int
101542 + depends on X86_64
101543 + default 47 if !PAX_PER_CPU_PGD
101544 + default 42 if PAX_PER_CPU_PGD
101545 +
101546 + config PAX_ENABLE_PAE
101547 + bool
101548 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
101549 +
101550 + config PAX_USERCOPY_SLABS
101551 + bool
101552 +
101553 +config GRKERNSEC
101554 + bool "Grsecurity"
101555 + select CRYPTO
101556 + select CRYPTO_SHA256
101557 + select PROC_FS
101558 + select STOP_MACHINE
101559 + select TTY
101560 + select DEBUG_LIST
101561 + help
101562 + If you say Y here, you will be able to configure many features
101563 + that will enhance the security of your system. It is highly
101564 + recommended that you say Y here and read through the help
101565 + for each option so that you fully understand the features and
101566 + can evaluate their usefulness for your machine.
101567 +
101568 +choice
101569 + prompt "Configuration Method"
101570 + depends on GRKERNSEC
101571 + default GRKERNSEC_CONFIG_CUSTOM
101572 + help
101573 +
101574 +config GRKERNSEC_CONFIG_AUTO
101575 + bool "Automatic"
101576 + help
101577 + If you choose this configuration method, you'll be able to answer a small
101578 + number of simple questions about how you plan to use this kernel.
101579 + The settings of grsecurity and PaX will be automatically configured for
101580 + the highest commonly-used settings within the provided constraints.
101581 +
101582 + If you require additional configuration, custom changes can still be made
101583 + from the "custom configuration" menu.
101584 +
101585 +config GRKERNSEC_CONFIG_CUSTOM
101586 + bool "Custom"
101587 + help
101588 + If you choose this configuration method, you'll be able to configure all
101589 + grsecurity and PaX settings manually. Via this method, no options are
101590 + automatically enabled.
101591 +
101592 +endchoice
101593 +
101594 +choice
101595 + prompt "Usage Type"
101596 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101597 + default GRKERNSEC_CONFIG_SERVER
101598 + help
101599 +
101600 +config GRKERNSEC_CONFIG_SERVER
101601 + bool "Server"
101602 + help
101603 + Choose this option if you plan to use this kernel on a server.
101604 +
101605 +config GRKERNSEC_CONFIG_DESKTOP
101606 + bool "Desktop"
101607 + help
101608 + Choose this option if you plan to use this kernel on a desktop.
101609 +
101610 +endchoice
101611 +
101612 +choice
101613 + prompt "Virtualization Type"
101614 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
101615 + default GRKERNSEC_CONFIG_VIRT_NONE
101616 + help
101617 +
101618 +config GRKERNSEC_CONFIG_VIRT_NONE
101619 + bool "None"
101620 + help
101621 + Choose this option if this kernel will be run on bare metal.
101622 +
101623 +config GRKERNSEC_CONFIG_VIRT_GUEST
101624 + bool "Guest"
101625 + help
101626 + Choose this option if this kernel will be run as a VM guest.
101627 +
101628 +config GRKERNSEC_CONFIG_VIRT_HOST
101629 + bool "Host"
101630 + help
101631 + Choose this option if this kernel will be run as a VM host.
101632 +
101633 +endchoice
101634 +
101635 +choice
101636 + prompt "Virtualization Hardware"
101637 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
101638 + help
101639 +
101640 +config GRKERNSEC_CONFIG_VIRT_EPT
101641 + bool "EPT/RVI Processor Support"
101642 + depends on X86
101643 + help
101644 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
101645 + hardware virtualization. This allows for additional kernel hardening protections
101646 + to operate without additional performance impact.
101647 +
101648 + To see if your Intel processor supports EPT, see:
101649 + http://ark.intel.com/Products/VirtualizationTechnology
101650 + (Most Core i3/5/7 support EPT)
101651 +
101652 + To see if your AMD processor supports RVI, see:
101653 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
101654 +
101655 +config GRKERNSEC_CONFIG_VIRT_SOFT
101656 + bool "First-gen/No Hardware Virtualization"
101657 + help
101658 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
101659 + support hardware virtualization or doesn't support the EPT/RVI extensions.
101660 +
101661 +endchoice
101662 +
101663 +choice
101664 + prompt "Virtualization Software"
101665 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
101666 + help
101667 +
101668 +config GRKERNSEC_CONFIG_VIRT_XEN
101669 + bool "Xen"
101670 + help
101671 + Choose this option if this kernel is running as a Xen guest or host.
101672 +
101673 +config GRKERNSEC_CONFIG_VIRT_VMWARE
101674 + bool "VMWare"
101675 + help
101676 + Choose this option if this kernel is running as a VMWare guest or host.
101677 +
101678 +config GRKERNSEC_CONFIG_VIRT_KVM
101679 + bool "KVM"
101680 + help
101681 + Choose this option if this kernel is running as a KVM guest or host.
101682 +
101683 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
101684 + bool "VirtualBox"
101685 + help
101686 + Choose this option if this kernel is running as a VirtualBox guest or host.
101687 +
101688 +endchoice
101689 +
101690 +choice
101691 + prompt "Required Priorities"
101692 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101693 + default GRKERNSEC_CONFIG_PRIORITY_PERF
101694 + help
101695 +
101696 +config GRKERNSEC_CONFIG_PRIORITY_PERF
101697 + bool "Performance"
101698 + help
101699 + Choose this option if performance is of highest priority for this deployment
101700 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
101701 + clearing of structures intended for userland, and freed memory sanitizing will
101702 + be disabled.
101703 +
101704 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
101705 + bool "Security"
101706 + help
101707 + Choose this option if security is of highest priority for this deployment of
101708 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
101709 + for userland, and freed memory sanitizing will be enabled for this kernel.
101710 + In a worst-case scenario, these features can introduce a 20% performance hit
101711 + (UDEREF on x64 contributing half of this hit).
101712 +
101713 +endchoice
101714 +
101715 +menu "Default Special Groups"
101716 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101717 +
101718 +config GRKERNSEC_PROC_GID
101719 + int "GID exempted from /proc restrictions"
101720 + default 1001
101721 + help
101722 + Setting this GID determines which group will be exempted from
101723 + grsecurity's /proc restrictions, allowing users of the specified
101724 + group to view network statistics and the existence of other users'
101725 + processes on the system. This GID may also be chosen at boot time
101726 + via "grsec_proc_gid=" on the kernel commandline.
101727 +
101728 +config GRKERNSEC_TPE_UNTRUSTED_GID
101729 + int "GID for TPE-untrusted users"
101730 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
101731 + default 1005
101732 + help
101733 + Setting this GID determines which group untrusted users should
101734 + be added to. These users will be placed under grsecurity's Trusted Path
101735 + Execution mechanism, preventing them from executing their own binaries.
101736 + The users will only be able to execute binaries in directories owned and
101737 + writable only by the root user. If the sysctl option is enabled, a sysctl
101738 + option with name "tpe_gid" is created.
101739 +
101740 +config GRKERNSEC_TPE_TRUSTED_GID
101741 + int "GID for TPE-trusted users"
101742 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
101743 + default 1005
101744 + help
101745 + Setting this GID determines what group TPE restrictions will be
101746 + *disabled* for. If the sysctl option is enabled, a sysctl option
101747 + with name "tpe_gid" is created.
101748 +
101749 +config GRKERNSEC_SYMLINKOWN_GID
101750 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
101751 + depends on GRKERNSEC_CONFIG_SERVER
101752 + default 1006
101753 + help
101754 + Setting this GID determines what group kernel-enforced
101755 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
101756 + is enabled, a sysctl option with name "symlinkown_gid" is created.
101757 +
101758 +
101759 +endmenu
101760 +
101761 +menu "Customize Configuration"
101762 +depends on GRKERNSEC
101763 +
101764 +menu "PaX"
101765 +
101766 +config PAX
101767 + bool "Enable various PaX features"
101768 + default y if GRKERNSEC_CONFIG_AUTO
101769 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
101770 + help
101771 + This allows you to enable various PaX features. PaX adds
101772 + intrusion prevention mechanisms to the kernel that reduce
101773 + the risks posed by exploitable memory corruption bugs.
101774 +
101775 +menu "PaX Control"
101776 + depends on PAX
101777 +
101778 +config PAX_SOFTMODE
101779 + bool 'Support soft mode'
101780 + help
101781 + Enabling this option will allow you to run PaX in soft mode, that
101782 + is, PaX features will not be enforced by default, only on executables
101783 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
101784 + support as they are the only way to mark executables for soft mode use.
101785 +
101786 + Soft mode can be activated by using the "pax_softmode=1" kernel command
101787 + line option on boot. Furthermore you can control various PaX features
101788 + at runtime via the entries in /proc/sys/kernel/pax.
101789 +
101790 +config PAX_EI_PAX
101791 + bool 'Use legacy ELF header marking'
101792 + default y if GRKERNSEC_CONFIG_AUTO
101793 + help
101794 + Enabling this option will allow you to control PaX features on
101795 + a per executable basis via the 'chpax' utility available at
101796 + http://pax.grsecurity.net/. The control flags will be read from
101797 + an otherwise reserved part of the ELF header. This marking has
101798 + numerous drawbacks (no support for soft-mode, toolchain does not
101799 + know about the non-standard use of the ELF header) therefore it
101800 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
101801 + support.
101802 +
101803 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
101804 + support as well, they will override the legacy EI_PAX marks.
101805 +
101806 + If you enable none of the marking options then all applications
101807 + will run with PaX enabled on them by default.
101808 +
101809 +config PAX_PT_PAX_FLAGS
101810 + bool 'Use ELF program header marking'
101811 + default y if GRKERNSEC_CONFIG_AUTO
101812 + help
101813 + Enabling this option will allow you to control PaX features on
101814 + a per executable basis via the 'paxctl' utility available at
101815 + http://pax.grsecurity.net/. The control flags will be read from
101816 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
101817 + has the benefits of supporting both soft mode and being fully
101818 + integrated into the toolchain (the binutils patch is available
101819 + from http://pax.grsecurity.net).
101820 +
101821 + Note that if you enable the legacy EI_PAX marking support as well,
101822 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
101823 +
101824 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
101825 + must make sure that the marks are the same if a binary has both marks.
101826 +
101827 + If you enable none of the marking options then all applications
101828 + will run with PaX enabled on them by default.
101829 +
101830 +config PAX_XATTR_PAX_FLAGS
101831 + bool 'Use filesystem extended attributes marking'
101832 + default y if GRKERNSEC_CONFIG_AUTO
101833 + select CIFS_XATTR if CIFS
101834 + select EXT2_FS_XATTR if EXT2_FS
101835 + select EXT3_FS_XATTR if EXT3_FS
101836 + select JFFS2_FS_XATTR if JFFS2_FS
101837 + select REISERFS_FS_XATTR if REISERFS_FS
101838 + select SQUASHFS_XATTR if SQUASHFS
101839 + select TMPFS_XATTR if TMPFS
101840 + select UBIFS_FS_XATTR if UBIFS_FS
101841 + help
101842 + Enabling this option will allow you to control PaX features on
101843 + a per executable basis via the 'setfattr' utility. The control
101844 + flags will be read from the user.pax.flags extended attribute of
101845 + the file. This marking has the benefit of supporting binary-only
101846 + applications that self-check themselves (e.g., skype) and would
101847 + not tolerate chpax/paxctl changes. The main drawback is that
101848 + extended attributes are not supported by some filesystems (e.g.,
101849 + isofs, udf, vfat) so copying files through such filesystems will
101850 + lose the extended attributes and these PaX markings.
101851 +
101852 + Note that if you enable the legacy EI_PAX marking support as well,
101853 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
101854 +
101855 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
101856 + must make sure that the marks are the same if a binary has both marks.
101857 +
101858 + If you enable none of the marking options then all applications
101859 + will run with PaX enabled on them by default.
101860 +
101861 +choice
101862 + prompt 'MAC system integration'
101863 + default PAX_HAVE_ACL_FLAGS
101864 + help
101865 + Mandatory Access Control systems have the option of controlling
101866 + PaX flags on a per executable basis, choose the method supported
101867 + by your particular system.
101868 +
101869 + - "none": if your MAC system does not interact with PaX,
101870 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
101871 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
101872 +
101873 + NOTE: this option is for developers/integrators only.
101874 +
101875 + config PAX_NO_ACL_FLAGS
101876 + bool 'none'
101877 +
101878 + config PAX_HAVE_ACL_FLAGS
101879 + bool 'direct'
101880 +
101881 + config PAX_HOOK_ACL_FLAGS
101882 + bool 'hook'
101883 +endchoice
101884 +
101885 +endmenu
101886 +
101887 +menu "Non-executable pages"
101888 + depends on PAX
101889 +
101890 +config PAX_NOEXEC
101891 + bool "Enforce non-executable pages"
101892 + default y if GRKERNSEC_CONFIG_AUTO
101893 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
101894 + help
101895 + By design some architectures do not allow for protecting memory
101896 + pages against execution or even if they do, Linux does not make
101897 + use of this feature. In practice this means that if a page is
101898 + readable (such as the stack or heap) it is also executable.
101899 +
101900 + There is a well known exploit technique that makes use of this
101901 + fact and a common programming mistake where an attacker can
101902 + introduce code of his choice somewhere in the attacked program's
101903 + memory (typically the stack or the heap) and then execute it.
101904 +
101905 + If the attacked program was running with different (typically
101906 + higher) privileges than that of the attacker, then he can elevate
101907 + his own privilege level (e.g. get a root shell, write to files for
101908 + which he does not have write access to, etc).
101909 +
101910 + Enabling this option will let you choose from various features
101911 + that prevent the injection and execution of 'foreign' code in
101912 + a program.
101913 +
101914 + This will also break programs that rely on the old behaviour and
101915 + expect that dynamically allocated memory via the malloc() family
101916 + of functions is executable (which it is not). Notable examples
101917 + are the XFree86 4.x server, the java runtime and wine.
101918 +
101919 +config PAX_PAGEEXEC
101920 + bool "Paging based non-executable pages"
101921 + default y if GRKERNSEC_CONFIG_AUTO
101922 + 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)
101923 + select ARCH_TRACK_EXEC_LIMIT if X86_32
101924 + help
101925 + This implementation is based on the paging feature of the CPU.
101926 + On i386 without hardware non-executable bit support there is a
101927 + variable but usually low performance impact, however on Intel's
101928 + P4 core based CPUs it is very high so you should not enable this
101929 + for kernels meant to be used on such CPUs.
101930 +
101931 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
101932 + with hardware non-executable bit support there is no performance
101933 + impact, on ppc the impact is negligible.
101934 +
101935 + Note that several architectures require various emulations due to
101936 + badly designed userland ABIs, this will cause a performance impact
101937 + but will disappear as soon as userland is fixed. For example, ppc
101938 + userland MUST have been built with secure-plt by a recent toolchain.
101939 +
101940 +config PAX_SEGMEXEC
101941 + bool "Segmentation based non-executable pages"
101942 + default y if GRKERNSEC_CONFIG_AUTO
101943 + depends on PAX_NOEXEC && X86_32
101944 + help
101945 + This implementation is based on the segmentation feature of the
101946 + CPU and has a very small performance impact, however applications
101947 + will be limited to a 1.5 GB address space instead of the normal
101948 + 3 GB.
101949 +
101950 +config PAX_EMUTRAMP
101951 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
101952 + default y if PARISC
101953 + help
101954 + There are some programs and libraries that for one reason or
101955 + another attempt to execute special small code snippets from
101956 + non-executable memory pages. Most notable examples are the
101957 + signal handler return code generated by the kernel itself and
101958 + the GCC trampolines.
101959 +
101960 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
101961 + such programs will no longer work under your kernel.
101962 +
101963 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
101964 + utilities to enable trampoline emulation for the affected programs
101965 + yet still have the protection provided by the non-executable pages.
101966 +
101967 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
101968 + your system will not even boot.
101969 +
101970 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
101971 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
101972 + for the affected files.
101973 +
101974 + NOTE: enabling this feature *may* open up a loophole in the
101975 + protection provided by non-executable pages that an attacker
101976 + could abuse. Therefore the best solution is to not have any
101977 + files on your system that would require this option. This can
101978 + be achieved by not using libc5 (which relies on the kernel
101979 + signal handler return code) and not using or rewriting programs
101980 + that make use of the nested function implementation of GCC.
101981 + Skilled users can just fix GCC itself so that it implements
101982 + nested function calls in a way that does not interfere with PaX.
101983 +
101984 +config PAX_EMUSIGRT
101985 + bool "Automatically emulate sigreturn trampolines"
101986 + depends on PAX_EMUTRAMP && PARISC
101987 + default y
101988 + help
101989 + Enabling this option will have the kernel automatically detect
101990 + and emulate signal return trampolines executing on the stack
101991 + that would otherwise lead to task termination.
101992 +
101993 + This solution is intended as a temporary one for users with
101994 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
101995 + Modula-3 runtime, etc) or executables linked to such, basically
101996 + everything that does not specify its own SA_RESTORER function in
101997 + normal executable memory like glibc 2.1+ does.
101998 +
101999 + On parisc you MUST enable this option, otherwise your system will
102000 + not even boot.
102001 +
102002 + NOTE: this feature cannot be disabled on a per executable basis
102003 + and since it *does* open up a loophole in the protection provided
102004 + by non-executable pages, the best solution is to not have any
102005 + files on your system that would require this option.
102006 +
102007 +config PAX_MPROTECT
102008 + bool "Restrict mprotect()"
102009 + default y if GRKERNSEC_CONFIG_AUTO
102010 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
102011 + help
102012 + Enabling this option will prevent programs from
102013 + - changing the executable status of memory pages that were
102014 + not originally created as executable,
102015 + - making read-only executable pages writable again,
102016 + - creating executable pages from anonymous memory,
102017 + - making read-only-after-relocations (RELRO) data pages writable again.
102018 +
102019 + You should say Y here to complete the protection provided by
102020 + the enforcement of non-executable pages.
102021 +
102022 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
102023 + this feature on a per file basis.
102024 +
102025 +config PAX_MPROTECT_COMPAT
102026 + bool "Use legacy/compat protection demoting (read help)"
102027 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
102028 + depends on PAX_MPROTECT
102029 + help
102030 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
102031 + by sending the proper error code to the application. For some broken
102032 + userland, this can cause problems with Python or other applications. The
102033 + current implementation however allows for applications like clamav to
102034 + detect if JIT compilation/execution is allowed and to fall back gracefully
102035 + to an interpreter-based mode if it does not. While we encourage everyone
102036 + to use the current implementation as-is and push upstream to fix broken
102037 + userland (note that the RWX logging option can assist with this), in some
102038 + environments this may not be possible. Having to disable MPROTECT
102039 + completely on certain binaries reduces the security benefit of PaX,
102040 + so this option is provided for those environments to revert to the old
102041 + behavior.
102042 +
102043 +config PAX_ELFRELOCS
102044 + bool "Allow ELF text relocations (read help)"
102045 + depends on PAX_MPROTECT
102046 + default n
102047 + help
102048 + Non-executable pages and mprotect() restrictions are effective
102049 + in preventing the introduction of new executable code into an
102050 + attacked task's address space. There remain only two venues
102051 + for this kind of attack: if the attacker can execute already
102052 + existing code in the attacked task then he can either have it
102053 + create and mmap() a file containing his code or have it mmap()
102054 + an already existing ELF library that does not have position
102055 + independent code in it and use mprotect() on it to make it
102056 + writable and copy his code there. While protecting against
102057 + the former approach is beyond PaX, the latter can be prevented
102058 + by having only PIC ELF libraries on one's system (which do not
102059 + need to relocate their code). If you are sure this is your case,
102060 + as is the case with all modern Linux distributions, then leave
102061 + this option disabled. You should say 'n' here.
102062 +
102063 +config PAX_ETEXECRELOCS
102064 + bool "Allow ELF ET_EXEC text relocations"
102065 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
102066 + select PAX_ELFRELOCS
102067 + default y
102068 + help
102069 + On some architectures there are incorrectly created applications
102070 + that require text relocations and would not work without enabling
102071 + this option. If you are an alpha, ia64 or parisc user, you should
102072 + enable this option and disable it once you have made sure that
102073 + none of your applications need it.
102074 +
102075 +config PAX_EMUPLT
102076 + bool "Automatically emulate ELF PLT"
102077 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
102078 + default y
102079 + help
102080 + Enabling this option will have the kernel automatically detect
102081 + and emulate the Procedure Linkage Table entries in ELF files.
102082 + On some architectures such entries are in writable memory, and
102083 + become non-executable leading to task termination. Therefore
102084 + it is mandatory that you enable this option on alpha, parisc,
102085 + sparc and sparc64, otherwise your system would not even boot.
102086 +
102087 + NOTE: this feature *does* open up a loophole in the protection
102088 + provided by the non-executable pages, therefore the proper
102089 + solution is to modify the toolchain to produce a PLT that does
102090 + not need to be writable.
102091 +
102092 +config PAX_DLRESOLVE
102093 + bool 'Emulate old glibc resolver stub'
102094 + depends on PAX_EMUPLT && SPARC
102095 + default n
102096 + help
102097 + This option is needed if userland has an old glibc (before 2.4)
102098 + that puts a 'save' instruction into the runtime generated resolver
102099 + stub that needs special emulation.
102100 +
102101 +config PAX_KERNEXEC
102102 + bool "Enforce non-executable kernel pages"
102103 + 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))
102104 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
102105 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
102106 + select PAX_KERNEXEC_PLUGIN if X86_64
102107 + help
102108 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
102109 + that is, enabling this option will make it harder to inject
102110 + and execute 'foreign' code in kernel memory itself.
102111 +
102112 +choice
102113 + prompt "Return Address Instrumentation Method"
102114 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
102115 + depends on PAX_KERNEXEC_PLUGIN
102116 + help
102117 + Select the method used to instrument function pointer dereferences.
102118 + Note that binary modules cannot be instrumented by this approach.
102119 +
102120 + Note that the implementation requires a gcc with plugin support,
102121 + i.e., gcc 4.5 or newer. You may need to install the supporting
102122 + headers explicitly in addition to the normal gcc package.
102123 +
102124 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
102125 + bool "bts"
102126 + help
102127 + This method is compatible with binary only modules but has
102128 + a higher runtime overhead.
102129 +
102130 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
102131 + bool "or"
102132 + depends on !PARAVIRT
102133 + help
102134 + This method is incompatible with binary only modules but has
102135 + a lower runtime overhead.
102136 +endchoice
102137 +
102138 +config PAX_KERNEXEC_PLUGIN_METHOD
102139 + string
102140 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
102141 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
102142 + default ""
102143 +
102144 +config PAX_KERNEXEC_MODULE_TEXT
102145 + int "Minimum amount of memory reserved for module code"
102146 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
102147 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
102148 + depends on PAX_KERNEXEC && X86_32
102149 + help
102150 + Due to implementation details the kernel must reserve a fixed
102151 + amount of memory for runtime allocated code (such as modules)
102152 + at compile time that cannot be changed at runtime. Here you
102153 + can specify the minimum amount in MB that will be reserved.
102154 + Due to the same implementation details this size will always
102155 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
102156 + the actually available memory for runtime allocated code will
102157 + usually be more than this minimum.
102158 +
102159 + The default 4 MB should be enough for most users but if you have
102160 + an excessive number of modules (e.g., most distribution configs
102161 + compile many drivers as modules) or use huge modules such as
102162 + nvidia's kernel driver, you will need to adjust this amount.
102163 + A good rule of thumb is to look at your currently loaded kernel
102164 + modules and add up their sizes.
102165 +
102166 +endmenu
102167 +
102168 +menu "Address Space Layout Randomization"
102169 + depends on PAX
102170 +
102171 +config PAX_ASLR
102172 + bool "Address Space Layout Randomization"
102173 + default y if GRKERNSEC_CONFIG_AUTO
102174 + help
102175 + Many if not most exploit techniques rely on the knowledge of
102176 + certain addresses in the attacked program. The following options
102177 + will allow the kernel to apply a certain amount of randomization
102178 + to specific parts of the program thereby forcing an attacker to
102179 + guess them in most cases. Any failed guess will most likely crash
102180 + the attacked program which allows the kernel to detect such attempts
102181 + and react on them. PaX itself provides no reaction mechanisms,
102182 + instead it is strongly encouraged that you make use of Nergal's
102183 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
102184 + (http://www.grsecurity.net/) built-in crash detection features or
102185 + develop one yourself.
102186 +
102187 + By saying Y here you can choose to randomize the following areas:
102188 + - top of the task's kernel stack
102189 + - top of the task's userland stack
102190 + - base address for mmap() requests that do not specify one
102191 + (this includes all libraries)
102192 + - base address of the main executable
102193 +
102194 + It is strongly recommended to say Y here as address space layout
102195 + randomization has negligible impact on performance yet it provides
102196 + a very effective protection.
102197 +
102198 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
102199 + this feature on a per file basis.
102200 +
102201 +config PAX_RANDKSTACK
102202 + bool "Randomize kernel stack base"
102203 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
102204 + depends on X86_TSC && X86
102205 + help
102206 + By saying Y here the kernel will randomize every task's kernel
102207 + stack on every system call. This will not only force an attacker
102208 + to guess it but also prevent him from making use of possible
102209 + leaked information about it.
102210 +
102211 + Since the kernel stack is a rather scarce resource, randomization
102212 + may cause unexpected stack overflows, therefore you should very
102213 + carefully test your system. Note that once enabled in the kernel
102214 + configuration, this feature cannot be disabled on a per file basis.
102215 +
102216 +config PAX_RANDUSTACK
102217 + bool "Randomize user stack base"
102218 + default y if GRKERNSEC_CONFIG_AUTO
102219 + depends on PAX_ASLR
102220 + help
102221 + By saying Y here the kernel will randomize every task's userland
102222 + stack. The randomization is done in two steps where the second
102223 + one may apply a big amount of shift to the top of the stack and
102224 + cause problems for programs that want to use lots of memory (more
102225 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
102226 + For this reason the second step can be controlled by 'chpax' or
102227 + 'paxctl' on a per file basis.
102228 +
102229 +config PAX_RANDMMAP
102230 + bool "Randomize mmap() base"
102231 + default y if GRKERNSEC_CONFIG_AUTO
102232 + depends on PAX_ASLR
102233 + help
102234 + By saying Y here the kernel will use a randomized base address for
102235 + mmap() requests that do not specify one themselves. As a result
102236 + all dynamically loaded libraries will appear at random addresses
102237 + and therefore be harder to exploit by a technique where an attacker
102238 + attempts to execute library code for his purposes (e.g. spawn a
102239 + shell from an exploited program that is running at an elevated
102240 + privilege level).
102241 +
102242 + Furthermore, if a program is relinked as a dynamic ELF file, its
102243 + base address will be randomized as well, completing the full
102244 + randomization of the address space layout. Attacking such programs
102245 + becomes a guess game. You can find an example of doing this at
102246 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
102247 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
102248 +
102249 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
102250 + feature on a per file basis.
102251 +
102252 +endmenu
102253 +
102254 +menu "Miscellaneous hardening features"
102255 +
102256 +config PAX_MEMORY_SANITIZE
102257 + bool "Sanitize all freed memory"
102258 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102259 + help
102260 + By saying Y here the kernel will erase memory pages and slab objects
102261 + as soon as they are freed. This in turn reduces the lifetime of data
102262 + stored in them, making it less likely that sensitive information such
102263 + as passwords, cryptographic secrets, etc stay in memory for too long.
102264 +
102265 + This is especially useful for programs whose runtime is short, long
102266 + lived processes and the kernel itself benefit from this as long as
102267 + they ensure timely freeing of memory that may hold sensitive
102268 + information.
102269 +
102270 + A nice side effect of the sanitization of slab objects is the
102271 + reduction of possible info leaks caused by padding bytes within the
102272 + leaky structures. Use-after-free bugs for structures containing
102273 + pointers can also be detected as dereferencing the sanitized pointer
102274 + will generate an access violation.
102275 +
102276 + The tradeoff is performance impact, on a single CPU system kernel
102277 + compilation sees a 3% slowdown, other systems and workloads may vary
102278 + and you are advised to test this feature on your expected workload
102279 + before deploying it.
102280 +
102281 + To reduce the performance penalty by sanitizing pages only, albeit
102282 + limiting the effectiveness of this feature at the same time, slab
102283 + sanitization can be disabled with the kernel commandline parameter
102284 + "pax_sanitize_slab=0".
102285 +
102286 + Note that this feature does not protect data stored in live pages,
102287 + e.g., process memory swapped to disk may stay there for a long time.
102288 +
102289 +config PAX_MEMORY_STACKLEAK
102290 + bool "Sanitize kernel stack"
102291 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102292 + depends on X86
102293 + help
102294 + By saying Y here the kernel will erase the kernel stack before it
102295 + returns from a system call. This in turn reduces the information
102296 + that a kernel stack leak bug can reveal.
102297 +
102298 + Note that such a bug can still leak information that was put on
102299 + the stack by the current system call (the one eventually triggering
102300 + the bug) but traces of earlier system calls on the kernel stack
102301 + cannot leak anymore.
102302 +
102303 + The tradeoff is performance impact: on a single CPU system kernel
102304 + compilation sees a 1% slowdown, other systems and workloads may vary
102305 + and you are advised to test this feature on your expected workload
102306 + before deploying it.
102307 +
102308 + Note that the full feature requires a gcc with plugin support,
102309 + i.e., gcc 4.5 or newer. You may need to install the supporting
102310 + headers explicitly in addition to the normal gcc package. Using
102311 + older gcc versions means that functions with large enough stack
102312 + frames may leave uninitialized memory behind that may be exposed
102313 + to a later syscall leaking the stack.
102314 +
102315 +config PAX_MEMORY_STRUCTLEAK
102316 + bool "Forcibly initialize local variables copied to userland"
102317 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102318 + help
102319 + By saying Y here the kernel will zero initialize some local
102320 + variables that are going to be copied to userland. This in
102321 + turn prevents unintended information leakage from the kernel
102322 + stack should later code forget to explicitly set all parts of
102323 + the copied variable.
102324 +
102325 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
102326 + at a much smaller coverage.
102327 +
102328 + Note that the implementation requires a gcc with plugin support,
102329 + i.e., gcc 4.5 or newer. You may need to install the supporting
102330 + headers explicitly in addition to the normal gcc package.
102331 +
102332 +config PAX_MEMORY_UDEREF
102333 + bool "Prevent invalid userland pointer dereference"
102334 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
102335 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
102336 + select PAX_PER_CPU_PGD if X86_64
102337 + help
102338 + By saying Y here the kernel will be prevented from dereferencing
102339 + userland pointers in contexts where the kernel expects only kernel
102340 + pointers. This is both a useful runtime debugging feature and a
102341 + security measure that prevents exploiting a class of kernel bugs.
102342 +
102343 + The tradeoff is that some virtualization solutions may experience
102344 + a huge slowdown and therefore you should not enable this feature
102345 + for kernels meant to run in such environments. Whether a given VM
102346 + solution is affected or not is best determined by simply trying it
102347 + out, the performance impact will be obvious right on boot as this
102348 + mechanism engages from very early on. A good rule of thumb is that
102349 + VMs running on CPUs without hardware virtualization support (i.e.,
102350 + the majority of IA-32 CPUs) will likely experience the slowdown.
102351 +
102352 + On X86_64 the kernel will make use of PCID support when available
102353 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
102354 + or performance impact. Pass pax_weakuderef on the kernel command
102355 + line to choose the latter.
102356 +
102357 +config PAX_REFCOUNT
102358 + bool "Prevent various kernel object reference counter overflows"
102359 + default y if GRKERNSEC_CONFIG_AUTO
102360 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
102361 + help
102362 + By saying Y here the kernel will detect and prevent overflowing
102363 + various (but not all) kinds of object reference counters. Such
102364 + overflows can normally occur due to bugs only and are often, if
102365 + not always, exploitable.
102366 +
102367 + The tradeoff is that data structures protected by an overflowed
102368 + refcount will never be freed and therefore will leak memory. Note
102369 + that this leak also happens even without this protection but in
102370 + that case the overflow can eventually trigger the freeing of the
102371 + data structure while it is still being used elsewhere, resulting
102372 + in the exploitable situation that this feature prevents.
102373 +
102374 + Since this has a negligible performance impact, you should enable
102375 + this feature.
102376 +
102377 +config PAX_CONSTIFY_PLUGIN
102378 + bool "Automatically constify eligible structures"
102379 + default y
102380 + depends on !UML && PAX_KERNEXEC
102381 + help
102382 + By saying Y here the compiler will automatically constify a class
102383 + of types that contain only function pointers. This reduces the
102384 + kernel's attack surface and also produces a better memory layout.
102385 +
102386 + Note that the implementation requires a gcc with plugin support,
102387 + i.e., gcc 4.5 or newer. You may need to install the supporting
102388 + headers explicitly in addition to the normal gcc package.
102389 +
102390 + Note that if some code really has to modify constified variables
102391 + then the source code will have to be patched to allow it. Examples
102392 + can be found in PaX itself (the no_const attribute) and for some
102393 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
102394 +
102395 +config PAX_USERCOPY
102396 + bool "Harden heap object copies between kernel and userland"
102397 + default y if GRKERNSEC_CONFIG_AUTO
102398 + depends on ARM || IA64 || PPC || SPARC || X86
102399 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
102400 + select PAX_USERCOPY_SLABS
102401 + help
102402 + By saying Y here the kernel will enforce the size of heap objects
102403 + when they are copied in either direction between the kernel and
102404 + userland, even if only a part of the heap object is copied.
102405 +
102406 + Specifically, this checking prevents information leaking from the
102407 + kernel heap during kernel to userland copies (if the kernel heap
102408 + object is otherwise fully initialized) and prevents kernel heap
102409 + overflows during userland to kernel copies.
102410 +
102411 + Note that the current implementation provides the strictest bounds
102412 + checks for the SLUB allocator.
102413 +
102414 + Enabling this option also enables per-slab cache protection against
102415 + data in a given cache being copied into/out of via userland
102416 + accessors. Though the whitelist of regions will be reduced over
102417 + time, it notably protects important data structures like task structs.
102418 +
102419 + If frame pointers are enabled on x86, this option will also restrict
102420 + copies into and out of the kernel stack to local variables within a
102421 + single frame.
102422 +
102423 + Since this has a negligible performance impact, you should enable
102424 + this feature.
102425 +
102426 +config PAX_USERCOPY_DEBUG
102427 + bool
102428 + depends on X86 && PAX_USERCOPY
102429 + default n
102430 +
102431 +config PAX_SIZE_OVERFLOW
102432 + bool "Prevent various integer overflows in function size parameters"
102433 + default y if GRKERNSEC_CONFIG_AUTO
102434 + depends on X86
102435 + help
102436 + By saying Y here the kernel recomputes expressions of function
102437 + arguments marked by a size_overflow attribute with double integer
102438 + precision (DImode/TImode for 32/64 bit integer types).
102439 +
102440 + The recomputed argument is checked against TYPE_MAX and an event
102441 + is logged on overflow and the triggering process is killed.
102442 +
102443 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
102444 +
102445 + Note that the implementation requires a gcc with plugin support,
102446 + i.e., gcc 4.5 or newer. You may need to install the supporting
102447 + headers explicitly in addition to the normal gcc package.
102448 +
102449 +config PAX_LATENT_ENTROPY
102450 + bool "Generate some entropy during boot and runtime"
102451 + default y if GRKERNSEC_CONFIG_AUTO
102452 + help
102453 + By saying Y here the kernel will instrument some kernel code to
102454 + extract some entropy from both original and artificially created
102455 + program state. This will help especially embedded systems where
102456 + there is little 'natural' source of entropy normally. The cost
102457 + is some slowdown of the boot process and fork and irq processing.
102458 +
102459 + When pax_extra_latent_entropy is passed on the kernel command line,
102460 + entropy will be extracted from up to the first 4GB of RAM while the
102461 + runtime memory allocator is being initialized. This costs even more
102462 + slowdown of the boot process.
102463 +
102464 + Note that the implementation requires a gcc with plugin support,
102465 + i.e., gcc 4.5 or newer. You may need to install the supporting
102466 + headers explicitly in addition to the normal gcc package.
102467 +
102468 + Note that entropy extracted this way is not cryptographically
102469 + secure!
102470 +
102471 +endmenu
102472 +
102473 +endmenu
102474 +
102475 +source grsecurity/Kconfig
102476 +
102477 +endmenu
102478 +
102479 +endmenu
102480 +
102481 source security/keys/Kconfig
102482
102483 config SECURITY_DMESG_RESTRICT
102484 @@ -103,7 +1055,7 @@ config INTEL_TXT
102485 config LSM_MMAP_MIN_ADDR
102486 int "Low address space for LSM to protect from user allocation"
102487 depends on SECURITY && SECURITY_SELINUX
102488 - default 32768 if ARM
102489 + default 32768 if ALPHA || ARM || PARISC || SPARC32
102490 default 65536
102491 help
102492 This is the portion of low virtual memory which should be protected
102493 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
102494 index 4257b7e..f0c9438 100644
102495 --- a/security/apparmor/lsm.c
102496 +++ b/security/apparmor/lsm.c
102497 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
102498 return error;
102499 }
102500
102501 -static struct security_operations apparmor_ops = {
102502 +static struct security_operations apparmor_ops __read_only = {
102503 .name = "apparmor",
102504
102505 .ptrace_access_check = apparmor_ptrace_access_check,
102506 diff --git a/security/commoncap.c b/security/commoncap.c
102507 index b9d613e..f68305c 100644
102508 --- a/security/commoncap.c
102509 +++ b/security/commoncap.c
102510 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
102511 return 0;
102512 }
102513
102514 +/* returns:
102515 + 1 for suid privilege
102516 + 2 for sgid privilege
102517 + 3 for fscap privilege
102518 +*/
102519 +int is_privileged_binary(const struct dentry *dentry)
102520 +{
102521 + struct cpu_vfs_cap_data capdata;
102522 + struct inode *inode = dentry->d_inode;
102523 +
102524 + if (!inode || S_ISDIR(inode->i_mode))
102525 + return 0;
102526 +
102527 + if (inode->i_mode & S_ISUID)
102528 + return 1;
102529 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
102530 + return 2;
102531 +
102532 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
102533 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
102534 + return 3;
102535 + }
102536 +
102537 + return 0;
102538 +}
102539 +
102540 /*
102541 * Attempt to get the on-exec apply capability sets for an executable file from
102542 * its xattrs and, if present, apply them to the proposed credentials being
102543 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
102544 const struct cred *cred = current_cred();
102545 kuid_t root_uid = make_kuid(cred->user_ns, 0);
102546
102547 + if (gr_acl_enable_at_secure())
102548 + return 1;
102549 +
102550 if (!uid_eq(cred->uid, root_uid)) {
102551 if (bprm->cap_effective)
102552 return 1;
102553 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
102554 index 0356e1d..72332ab 100644
102555 --- a/security/integrity/ima/ima.h
102556 +++ b/security/integrity/ima/ima.h
102557 @@ -118,8 +118,8 @@ int ima_init_template(void);
102558 extern spinlock_t ima_queue_lock;
102559
102560 struct ima_h_table {
102561 - atomic_long_t len; /* number of stored measurements in the list */
102562 - atomic_long_t violations;
102563 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
102564 + atomic_long_unchecked_t violations;
102565 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
102566 };
102567 extern struct ima_h_table ima_htable;
102568 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
102569 index c38bbce..f45133d 100644
102570 --- a/security/integrity/ima/ima_api.c
102571 +++ b/security/integrity/ima/ima_api.c
102572 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
102573 int result;
102574
102575 /* can overflow, only indicator */
102576 - atomic_long_inc(&ima_htable.violations);
102577 + atomic_long_inc_unchecked(&ima_htable.violations);
102578
102579 result = ima_alloc_init_template(NULL, file, filename,
102580 NULL, 0, &entry);
102581 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
102582 index db01125..61f6597 100644
102583 --- a/security/integrity/ima/ima_fs.c
102584 +++ b/security/integrity/ima/ima_fs.c
102585 @@ -28,12 +28,12 @@
102586 static int valid_policy = 1;
102587 #define TMPBUFLEN 12
102588 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
102589 - loff_t *ppos, atomic_long_t *val)
102590 + loff_t *ppos, atomic_long_unchecked_t *val)
102591 {
102592 char tmpbuf[TMPBUFLEN];
102593 ssize_t len;
102594
102595 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
102596 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
102597 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
102598 }
102599
102600 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
102601 index d85e997..6992813 100644
102602 --- a/security/integrity/ima/ima_queue.c
102603 +++ b/security/integrity/ima/ima_queue.c
102604 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
102605 INIT_LIST_HEAD(&qe->later);
102606 list_add_tail_rcu(&qe->later, &ima_measurements);
102607
102608 - atomic_long_inc(&ima_htable.len);
102609 + atomic_long_inc_unchecked(&ima_htable.len);
102610 key = ima_hash_key(entry->digest);
102611 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
102612 return 0;
102613 diff --git a/security/keys/compat.c b/security/keys/compat.c
102614 index bbd32c7..c60c927 100644
102615 --- a/security/keys/compat.c
102616 +++ b/security/keys/compat.c
102617 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
102618 if (ret == 0)
102619 goto no_payload_free;
102620
102621 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
102622 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
102623 err:
102624 if (iov != iovstack)
102625 kfree(iov);
102626 diff --git a/security/keys/internal.h b/security/keys/internal.h
102627 index 80b2aac..bb7ee65 100644
102628 --- a/security/keys/internal.h
102629 +++ b/security/keys/internal.h
102630 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
102631 extern long keyctl_invalidate_key(key_serial_t);
102632
102633 extern long keyctl_instantiate_key_common(key_serial_t,
102634 - const struct iovec *,
102635 + const struct iovec __user *,
102636 unsigned, size_t, key_serial_t);
102637 #ifdef CONFIG_PERSISTENT_KEYRINGS
102638 extern long keyctl_get_persistent(uid_t, key_serial_t);
102639 diff --git a/security/keys/key.c b/security/keys/key.c
102640 index 6e21c11..9ed67ca 100644
102641 --- a/security/keys/key.c
102642 +++ b/security/keys/key.c
102643 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
102644
102645 atomic_set(&key->usage, 1);
102646 init_rwsem(&key->sem);
102647 - lockdep_set_class(&key->sem, &type->lock_class);
102648 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
102649 key->index_key.type = type;
102650 key->user = user;
102651 key->quotalen = quotalen;
102652 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
102653 struct key_type *p;
102654 int ret;
102655
102656 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
102657 + pax_open_kernel();
102658 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
102659 + pax_close_kernel();
102660
102661 ret = -EEXIST;
102662 down_write(&key_types_sem);
102663 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
102664 }
102665
102666 /* store the type */
102667 - list_add(&ktype->link, &key_types_list);
102668 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
102669
102670 pr_notice("Key type %s registered\n", ktype->name);
102671 ret = 0;
102672 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
102673 void unregister_key_type(struct key_type *ktype)
102674 {
102675 down_write(&key_types_sem);
102676 - list_del_init(&ktype->link);
102677 + pax_list_del_init((struct list_head *)&ktype->link);
102678 downgrade_write(&key_types_sem);
102679 key_gc_keytype(ktype);
102680 pr_notice("Key type %s unregistered\n", ktype->name);
102681 @@ -1088,10 +1090,10 @@ void __init key_init(void)
102682 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
102683
102684 /* add the special key types */
102685 - list_add_tail(&key_type_keyring.link, &key_types_list);
102686 - list_add_tail(&key_type_dead.link, &key_types_list);
102687 - list_add_tail(&key_type_user.link, &key_types_list);
102688 - list_add_tail(&key_type_logon.link, &key_types_list);
102689 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
102690 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
102691 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
102692 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
102693
102694 /* record the root user tracking */
102695 rb_link_node(&root_key_user.node,
102696 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
102697 index cee72ce..e46074a 100644
102698 --- a/security/keys/keyctl.c
102699 +++ b/security/keys/keyctl.c
102700 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
102701 /*
102702 * Copy the iovec data from userspace
102703 */
102704 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
102705 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
102706 unsigned ioc)
102707 {
102708 for (; ioc > 0; ioc--) {
102709 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
102710 * If successful, 0 will be returned.
102711 */
102712 long keyctl_instantiate_key_common(key_serial_t id,
102713 - const struct iovec *payload_iov,
102714 + const struct iovec __user *payload_iov,
102715 unsigned ioc,
102716 size_t plen,
102717 key_serial_t ringid)
102718 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
102719 [0].iov_len = plen
102720 };
102721
102722 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
102723 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
102724 }
102725
102726 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
102727 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
102728 if (ret == 0)
102729 goto no_payload_free;
102730
102731 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
102732 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
102733 err:
102734 if (iov != iovstack)
102735 kfree(iov);
102736 diff --git a/security/min_addr.c b/security/min_addr.c
102737 index f728728..6457a0c 100644
102738 --- a/security/min_addr.c
102739 +++ b/security/min_addr.c
102740 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
102741 */
102742 static void update_mmap_min_addr(void)
102743 {
102744 +#ifndef SPARC
102745 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
102746 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
102747 mmap_min_addr = dac_mmap_min_addr;
102748 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
102749 #else
102750 mmap_min_addr = dac_mmap_min_addr;
102751 #endif
102752 +#endif
102753 }
102754
102755 /*
102756 diff --git a/security/security.c b/security/security.c
102757 index 15b6928..60d03ec 100644
102758 --- a/security/security.c
102759 +++ b/security/security.c
102760 @@ -33,8 +33,8 @@
102761 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
102762 CONFIG_DEFAULT_SECURITY;
102763
102764 -static struct security_operations *security_ops;
102765 -static struct security_operations default_security_ops = {
102766 +struct security_operations *security_ops __read_only;
102767 +struct security_operations default_security_ops __read_only = {
102768 .name = "default",
102769 };
102770
102771 @@ -73,11 +73,6 @@ int __init security_init(void)
102772 return 0;
102773 }
102774
102775 -void reset_security_ops(void)
102776 -{
102777 - security_ops = &default_security_ops;
102778 -}
102779 -
102780 /* Save user chosen LSM */
102781 static int __init choose_lsm(char *str)
102782 {
102783 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
102784 index fc3e662..7844c60 100644
102785 --- a/security/selinux/avc.c
102786 +++ b/security/selinux/avc.c
102787 @@ -59,7 +59,7 @@ struct avc_node {
102788 struct avc_cache {
102789 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
102790 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
102791 - atomic_t lru_hint; /* LRU hint for reclaim scan */
102792 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
102793 atomic_t active_nodes;
102794 u32 latest_notif; /* latest revocation notification */
102795 };
102796 @@ -167,7 +167,7 @@ void __init avc_init(void)
102797 spin_lock_init(&avc_cache.slots_lock[i]);
102798 }
102799 atomic_set(&avc_cache.active_nodes, 0);
102800 - atomic_set(&avc_cache.lru_hint, 0);
102801 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
102802
102803 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
102804 0, SLAB_PANIC, NULL);
102805 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
102806 spinlock_t *lock;
102807
102808 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
102809 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
102810 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
102811 head = &avc_cache.slots[hvalue];
102812 lock = &avc_cache.slots_lock[hvalue];
102813
102814 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
102815 index 57b0b49..402063e 100644
102816 --- a/security/selinux/hooks.c
102817 +++ b/security/selinux/hooks.c
102818 @@ -96,8 +96,6 @@
102819 #include "audit.h"
102820 #include "avc_ss.h"
102821
102822 -extern struct security_operations *security_ops;
102823 -
102824 /* SECMARK reference count */
102825 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
102826
102827 @@ -5745,7 +5743,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
102828
102829 #endif
102830
102831 -static struct security_operations selinux_ops = {
102832 +static struct security_operations selinux_ops __read_only = {
102833 .name = "selinux",
102834
102835 .ptrace_access_check = selinux_ptrace_access_check,
102836 @@ -6098,6 +6096,9 @@ static void selinux_nf_ip_exit(void)
102837 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
102838 static int selinux_disabled;
102839
102840 +extern struct security_operations *security_ops;
102841 +extern struct security_operations default_security_ops;
102842 +
102843 int selinux_disable(void)
102844 {
102845 if (ss_initialized) {
102846 @@ -6115,7 +6116,9 @@ int selinux_disable(void)
102847 selinux_disabled = 1;
102848 selinux_enabled = 0;
102849
102850 - reset_security_ops();
102851 + pax_open_kernel();
102852 + security_ops = &default_security_ops;
102853 + pax_close_kernel();
102854
102855 /* Try to destroy the avc node cache */
102856 avc_disable();
102857 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
102858 index 48c3cc9..8022cf7 100644
102859 --- a/security/selinux/include/xfrm.h
102860 +++ b/security/selinux/include/xfrm.h
102861 @@ -45,7 +45,7 @@ static inline void selinux_xfrm_notify_policyload(void)
102862 {
102863 struct net *net;
102864
102865 - atomic_inc(&flow_cache_genid);
102866 + atomic_inc_unchecked(&flow_cache_genid);
102867 rtnl_lock();
102868 for_each_net(net)
102869 rt_genid_bump_all(net);
102870 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
102871 index b0be893..646bd94 100644
102872 --- a/security/smack/smack_lsm.c
102873 +++ b/security/smack/smack_lsm.c
102874 @@ -3731,7 +3731,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
102875 return 0;
102876 }
102877
102878 -struct security_operations smack_ops = {
102879 +struct security_operations smack_ops __read_only = {
102880 .name = "smack",
102881
102882 .ptrace_access_check = smack_ptrace_access_check,
102883 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
102884 index 390c646..f2f8db3 100644
102885 --- a/security/tomoyo/mount.c
102886 +++ b/security/tomoyo/mount.c
102887 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
102888 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
102889 need_dev = -1; /* dev_name is a directory */
102890 } else {
102891 + if (!capable(CAP_SYS_ADMIN)) {
102892 + error = -EPERM;
102893 + goto out;
102894 + }
102895 fstype = get_fs_type(type);
102896 if (!fstype) {
102897 error = -ENODEV;
102898 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
102899 index f0b756e..b129202 100644
102900 --- a/security/tomoyo/tomoyo.c
102901 +++ b/security/tomoyo/tomoyo.c
102902 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
102903 * tomoyo_security_ops is a "struct security_operations" which is used for
102904 * registering TOMOYO.
102905 */
102906 -static struct security_operations tomoyo_security_ops = {
102907 +static struct security_operations tomoyo_security_ops __read_only = {
102908 .name = "tomoyo",
102909 .cred_alloc_blank = tomoyo_cred_alloc_blank,
102910 .cred_prepare = tomoyo_cred_prepare,
102911 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
102912 index 20ef514..4182bed 100644
102913 --- a/security/yama/Kconfig
102914 +++ b/security/yama/Kconfig
102915 @@ -1,6 +1,6 @@
102916 config SECURITY_YAMA
102917 bool "Yama support"
102918 - depends on SECURITY
102919 + depends on SECURITY && !GRKERNSEC
102920 select SECURITYFS
102921 select SECURITY_PATH
102922 default n
102923 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
102924 index 13c88fbc..f8c115e 100644
102925 --- a/security/yama/yama_lsm.c
102926 +++ b/security/yama/yama_lsm.c
102927 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
102928 }
102929
102930 #ifndef CONFIG_SECURITY_YAMA_STACKED
102931 -static struct security_operations yama_ops = {
102932 +static struct security_operations yama_ops __read_only = {
102933 .name = "yama",
102934
102935 .ptrace_access_check = yama_ptrace_access_check,
102936 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
102937 #endif
102938
102939 #ifdef CONFIG_SYSCTL
102940 +static int zero __read_only;
102941 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
102942 +
102943 static int yama_dointvec_minmax(struct ctl_table *table, int write,
102944 void __user *buffer, size_t *lenp, loff_t *ppos)
102945 {
102946 - int rc;
102947 + ctl_table_no_const yama_table;
102948
102949 if (write && !capable(CAP_SYS_PTRACE))
102950 return -EPERM;
102951
102952 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
102953 - if (rc)
102954 - return rc;
102955 -
102956 + yama_table = *table;
102957 /* Lock the max value if it ever gets set. */
102958 - if (write && *(int *)table->data == *(int *)table->extra2)
102959 - table->extra1 = table->extra2;
102960 -
102961 - return rc;
102962 + if (ptrace_scope == max_scope)
102963 + yama_table.extra1 = &max_scope;
102964 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
102965 }
102966
102967 -static int zero;
102968 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
102969 -
102970 struct ctl_path yama_sysctl_path[] = {
102971 { .procname = "kernel", },
102972 { .procname = "yama", },
102973 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
102974 index 4cedc69..e59d8a3 100644
102975 --- a/sound/aoa/codecs/onyx.c
102976 +++ b/sound/aoa/codecs/onyx.c
102977 @@ -54,7 +54,7 @@ struct onyx {
102978 spdif_locked:1,
102979 analog_locked:1,
102980 original_mute:2;
102981 - int open_count;
102982 + local_t open_count;
102983 struct codec_info *codec_info;
102984
102985 /* mutex serializes concurrent access to the device
102986 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
102987 struct onyx *onyx = cii->codec_data;
102988
102989 mutex_lock(&onyx->mutex);
102990 - onyx->open_count++;
102991 + local_inc(&onyx->open_count);
102992 mutex_unlock(&onyx->mutex);
102993
102994 return 0;
102995 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
102996 struct onyx *onyx = cii->codec_data;
102997
102998 mutex_lock(&onyx->mutex);
102999 - onyx->open_count--;
103000 - if (!onyx->open_count)
103001 + if (local_dec_and_test(&onyx->open_count))
103002 onyx->spdif_locked = onyx->analog_locked = 0;
103003 mutex_unlock(&onyx->mutex);
103004
103005 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
103006 index ffd2025..df062c9 100644
103007 --- a/sound/aoa/codecs/onyx.h
103008 +++ b/sound/aoa/codecs/onyx.h
103009 @@ -11,6 +11,7 @@
103010 #include <linux/i2c.h>
103011 #include <asm/pmac_low_i2c.h>
103012 #include <asm/prom.h>
103013 +#include <asm/local.h>
103014
103015 /* PCM3052 register definitions */
103016
103017 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
103018 index 4c1cc51..16040040 100644
103019 --- a/sound/core/oss/pcm_oss.c
103020 +++ b/sound/core/oss/pcm_oss.c
103021 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
103022 if (in_kernel) {
103023 mm_segment_t fs;
103024 fs = snd_enter_user();
103025 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
103026 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
103027 snd_leave_user(fs);
103028 } else {
103029 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
103030 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
103031 }
103032 if (ret != -EPIPE && ret != -ESTRPIPE)
103033 break;
103034 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
103035 if (in_kernel) {
103036 mm_segment_t fs;
103037 fs = snd_enter_user();
103038 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
103039 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
103040 snd_leave_user(fs);
103041 } else {
103042 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
103043 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
103044 }
103045 if (ret == -EPIPE) {
103046 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
103047 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
103048 struct snd_pcm_plugin_channel *channels;
103049 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
103050 if (!in_kernel) {
103051 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
103052 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
103053 return -EFAULT;
103054 buf = runtime->oss.buffer;
103055 }
103056 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
103057 }
103058 } else {
103059 tmp = snd_pcm_oss_write2(substream,
103060 - (const char __force *)buf,
103061 + (const char __force_kernel *)buf,
103062 runtime->oss.period_bytes, 0);
103063 if (tmp <= 0)
103064 goto err;
103065 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
103066 struct snd_pcm_runtime *runtime = substream->runtime;
103067 snd_pcm_sframes_t frames, frames1;
103068 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
103069 - char __user *final_dst = (char __force __user *)buf;
103070 + char __user *final_dst = (char __force_user *)buf;
103071 if (runtime->oss.plugin_first) {
103072 struct snd_pcm_plugin_channel *channels;
103073 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
103074 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
103075 xfer += tmp;
103076 runtime->oss.buffer_used -= tmp;
103077 } else {
103078 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
103079 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
103080 runtime->oss.period_bytes, 0);
103081 if (tmp <= 0)
103082 goto err;
103083 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
103084 size1);
103085 size1 /= runtime->channels; /* frames */
103086 fs = snd_enter_user();
103087 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
103088 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
103089 snd_leave_user(fs);
103090 }
103091 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
103092 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
103093 index af49721..e85058e 100644
103094 --- a/sound/core/pcm_compat.c
103095 +++ b/sound/core/pcm_compat.c
103096 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
103097 int err;
103098
103099 fs = snd_enter_user();
103100 - err = snd_pcm_delay(substream, &delay);
103101 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
103102 snd_leave_user(fs);
103103 if (err < 0)
103104 return err;
103105 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
103106 index 01a5e05..c6bb425 100644
103107 --- a/sound/core/pcm_native.c
103108 +++ b/sound/core/pcm_native.c
103109 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
103110 switch (substream->stream) {
103111 case SNDRV_PCM_STREAM_PLAYBACK:
103112 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
103113 - (void __user *)arg);
103114 + (void __force_user *)arg);
103115 break;
103116 case SNDRV_PCM_STREAM_CAPTURE:
103117 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
103118 - (void __user *)arg);
103119 + (void __force_user *)arg);
103120 break;
103121 default:
103122 result = -EINVAL;
103123 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
103124 index 8d4d5e8..fdd0826 100644
103125 --- a/sound/core/seq/oss/seq_oss.c
103126 +++ b/sound/core/seq/oss/seq_oss.c
103127 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
103128 {
103129 int rc;
103130 static struct snd_seq_dev_ops ops = {
103131 - snd_seq_oss_synth_register,
103132 - snd_seq_oss_synth_unregister,
103133 + .init_device = snd_seq_oss_synth_register,
103134 + .free_device = snd_seq_oss_synth_unregister,
103135 };
103136
103137 snd_seq_autoload_lock();
103138 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
103139 index 040c60e..989a19a 100644
103140 --- a/sound/core/seq/seq_device.c
103141 +++ b/sound/core/seq/seq_device.c
103142 @@ -64,7 +64,7 @@ struct ops_list {
103143 int argsize; /* argument size */
103144
103145 /* operators */
103146 - struct snd_seq_dev_ops ops;
103147 + struct snd_seq_dev_ops *ops;
103148
103149 /* registered devices */
103150 struct list_head dev_list; /* list of devices */
103151 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
103152
103153 mutex_lock(&ops->reg_mutex);
103154 /* copy driver operators */
103155 - ops->ops = *entry;
103156 + ops->ops = entry;
103157 ops->driver |= DRIVER_LOADED;
103158 ops->argsize = argsize;
103159
103160 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
103161 dev->name, ops->id, ops->argsize, dev->argsize);
103162 return -EINVAL;
103163 }
103164 - if (ops->ops.init_device(dev) >= 0) {
103165 + if (ops->ops->init_device(dev) >= 0) {
103166 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
103167 ops->num_init_devices++;
103168 } else {
103169 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
103170 dev->name, ops->id, ops->argsize, dev->argsize);
103171 return -EINVAL;
103172 }
103173 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
103174 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
103175 dev->status = SNDRV_SEQ_DEVICE_FREE;
103176 dev->driver_data = NULL;
103177 ops->num_init_devices--;
103178 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
103179 index 64069db..3c6d392 100644
103180 --- a/sound/core/seq/seq_midi.c
103181 +++ b/sound/core/seq/seq_midi.c
103182 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
103183 static int __init alsa_seq_midi_init(void)
103184 {
103185 static struct snd_seq_dev_ops ops = {
103186 - snd_seq_midisynth_register_port,
103187 - snd_seq_midisynth_unregister_port,
103188 + .init_device = snd_seq_midisynth_register_port,
103189 + .free_device = snd_seq_midisynth_unregister_port,
103190 };
103191 memset(&synths, 0, sizeof(synths));
103192 snd_seq_autoload_lock();
103193 diff --git a/sound/core/sound.c b/sound/core/sound.c
103194 index 437c25e..cd040ab 100644
103195 --- a/sound/core/sound.c
103196 +++ b/sound/core/sound.c
103197 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
103198 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
103199 default: return;
103200 }
103201 - request_module(str);
103202 + request_module("%s", str);
103203 }
103204
103205 #endif /* modular kernel */
103206 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
103207 index 4e0dd22..7a1f32c 100644
103208 --- a/sound/drivers/mts64.c
103209 +++ b/sound/drivers/mts64.c
103210 @@ -29,6 +29,7 @@
103211 #include <sound/initval.h>
103212 #include <sound/rawmidi.h>
103213 #include <sound/control.h>
103214 +#include <asm/local.h>
103215
103216 #define CARD_NAME "Miditerminal 4140"
103217 #define DRIVER_NAME "MTS64"
103218 @@ -67,7 +68,7 @@ struct mts64 {
103219 struct pardevice *pardev;
103220 int pardev_claimed;
103221
103222 - int open_count;
103223 + local_t open_count;
103224 int current_midi_output_port;
103225 int current_midi_input_port;
103226 u8 mode[MTS64_NUM_INPUT_PORTS];
103227 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
103228 {
103229 struct mts64 *mts = substream->rmidi->private_data;
103230
103231 - if (mts->open_count == 0) {
103232 + if (local_read(&mts->open_count) == 0) {
103233 /* We don't need a spinlock here, because this is just called
103234 if the device has not been opened before.
103235 So there aren't any IRQs from the device */
103236 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
103237
103238 msleep(50);
103239 }
103240 - ++(mts->open_count);
103241 + local_inc(&mts->open_count);
103242
103243 return 0;
103244 }
103245 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
103246 struct mts64 *mts = substream->rmidi->private_data;
103247 unsigned long flags;
103248
103249 - --(mts->open_count);
103250 - if (mts->open_count == 0) {
103251 + if (local_dec_return(&mts->open_count) == 0) {
103252 /* We need the spinlock_irqsave here because we can still
103253 have IRQs at this point */
103254 spin_lock_irqsave(&mts->lock, flags);
103255 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
103256
103257 msleep(500);
103258
103259 - } else if (mts->open_count < 0)
103260 - mts->open_count = 0;
103261 + } else if (local_read(&mts->open_count) < 0)
103262 + local_set(&mts->open_count, 0);
103263
103264 return 0;
103265 }
103266 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
103267 index 6839953..7a0f4b9 100644
103268 --- a/sound/drivers/opl3/opl3_seq.c
103269 +++ b/sound/drivers/opl3/opl3_seq.c
103270 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
103271 {
103272 static struct snd_seq_dev_ops ops =
103273 {
103274 - snd_opl3_seq_new_device,
103275 - snd_opl3_seq_delete_device
103276 + .init_device = snd_opl3_seq_new_device,
103277 + .free_device = snd_opl3_seq_delete_device
103278 };
103279
103280 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
103281 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
103282 index b953fb4..1999c01 100644
103283 --- a/sound/drivers/opl4/opl4_lib.c
103284 +++ b/sound/drivers/opl4/opl4_lib.c
103285 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
103286 MODULE_DESCRIPTION("OPL4 driver");
103287 MODULE_LICENSE("GPL");
103288
103289 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
103290 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
103291 {
103292 int timeout = 10;
103293 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
103294 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
103295 index 9919769..d7de36c 100644
103296 --- a/sound/drivers/opl4/opl4_seq.c
103297 +++ b/sound/drivers/opl4/opl4_seq.c
103298 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
103299 static int __init alsa_opl4_synth_init(void)
103300 {
103301 static struct snd_seq_dev_ops ops = {
103302 - snd_opl4_seq_new_device,
103303 - snd_opl4_seq_delete_device
103304 + .init_device = snd_opl4_seq_new_device,
103305 + .free_device = snd_opl4_seq_delete_device
103306 };
103307
103308 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
103309 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
103310 index 991018d..8984740 100644
103311 --- a/sound/drivers/portman2x4.c
103312 +++ b/sound/drivers/portman2x4.c
103313 @@ -48,6 +48,7 @@
103314 #include <sound/initval.h>
103315 #include <sound/rawmidi.h>
103316 #include <sound/control.h>
103317 +#include <asm/local.h>
103318
103319 #define CARD_NAME "Portman 2x4"
103320 #define DRIVER_NAME "portman"
103321 @@ -85,7 +86,7 @@ struct portman {
103322 struct pardevice *pardev;
103323 int pardev_claimed;
103324
103325 - int open_count;
103326 + local_t open_count;
103327 int mode[PORTMAN_NUM_INPUT_PORTS];
103328 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
103329 };
103330 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
103331 index 9048777..2d8b1fc 100644
103332 --- a/sound/firewire/amdtp.c
103333 +++ b/sound/firewire/amdtp.c
103334 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
103335 ptr = s->pcm_buffer_pointer + data_blocks;
103336 if (ptr >= pcm->runtime->buffer_size)
103337 ptr -= pcm->runtime->buffer_size;
103338 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
103339 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
103340
103341 s->pcm_period_pointer += data_blocks;
103342 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
103343 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
103344 */
103345 void amdtp_out_stream_update(struct amdtp_out_stream *s)
103346 {
103347 - ACCESS_ONCE(s->source_node_id_field) =
103348 + ACCESS_ONCE_RW(s->source_node_id_field) =
103349 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
103350 }
103351 EXPORT_SYMBOL(amdtp_out_stream_update);
103352 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
103353 index 2746ecd..c35dedd 100644
103354 --- a/sound/firewire/amdtp.h
103355 +++ b/sound/firewire/amdtp.h
103356 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
103357 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
103358 struct snd_pcm_substream *pcm)
103359 {
103360 - ACCESS_ONCE(s->pcm) = pcm;
103361 + ACCESS_ONCE_RW(s->pcm) = pcm;
103362 }
103363
103364 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
103365 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
103366 index fd42e6b..c041971 100644
103367 --- a/sound/firewire/isight.c
103368 +++ b/sound/firewire/isight.c
103369 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
103370 ptr += count;
103371 if (ptr >= runtime->buffer_size)
103372 ptr -= runtime->buffer_size;
103373 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
103374 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
103375
103376 isight->period_counter += count;
103377 if (isight->period_counter >= runtime->period_size) {
103378 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
103379 if (err < 0)
103380 return err;
103381
103382 - ACCESS_ONCE(isight->pcm_active) = true;
103383 + ACCESS_ONCE_RW(isight->pcm_active) = true;
103384
103385 return 0;
103386 }
103387 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
103388 {
103389 struct isight *isight = substream->private_data;
103390
103391 - ACCESS_ONCE(isight->pcm_active) = false;
103392 + ACCESS_ONCE_RW(isight->pcm_active) = false;
103393
103394 mutex_lock(&isight->mutex);
103395 isight_stop_streaming(isight);
103396 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
103397
103398 switch (cmd) {
103399 case SNDRV_PCM_TRIGGER_START:
103400 - ACCESS_ONCE(isight->pcm_running) = true;
103401 + ACCESS_ONCE_RW(isight->pcm_running) = true;
103402 break;
103403 case SNDRV_PCM_TRIGGER_STOP:
103404 - ACCESS_ONCE(isight->pcm_running) = false;
103405 + ACCESS_ONCE_RW(isight->pcm_running) = false;
103406 break;
103407 default:
103408 return -EINVAL;
103409 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
103410 index 858023c..83b3d3c 100644
103411 --- a/sound/firewire/scs1x.c
103412 +++ b/sound/firewire/scs1x.c
103413 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
103414 {
103415 struct scs *scs = stream->rmidi->private_data;
103416
103417 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
103418 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
103419 if (up) {
103420 scs->output_idle = false;
103421 tasklet_schedule(&scs->tasklet);
103422 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
103423 {
103424 struct scs *scs = stream->rmidi->private_data;
103425
103426 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
103427 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
103428 }
103429
103430 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
103431 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
103432
103433 snd_card_disconnect(scs->card);
103434
103435 - ACCESS_ONCE(scs->output) = NULL;
103436 - ACCESS_ONCE(scs->input) = NULL;
103437 + ACCESS_ONCE_RW(scs->output) = NULL;
103438 + ACCESS_ONCE_RW(scs->input) = NULL;
103439
103440 wait_event(scs->idle_wait, scs->output_idle);
103441
103442 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
103443 index 4e3fcfb..ab45a9d 100644
103444 --- a/sound/isa/sb/emu8000_synth.c
103445 +++ b/sound/isa/sb/emu8000_synth.c
103446 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
103447 {
103448
103449 static struct snd_seq_dev_ops ops = {
103450 - snd_emu8000_new_device,
103451 - snd_emu8000_delete_device,
103452 + .init_device = snd_emu8000_new_device,
103453 + .free_device = snd_emu8000_delete_device,
103454 };
103455 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
103456 sizeof(struct snd_emu8000*));
103457 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
103458 index 048439a..3be9f6f 100644
103459 --- a/sound/oss/sb_audio.c
103460 +++ b/sound/oss/sb_audio.c
103461 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
103462 buf16 = (signed short *)(localbuf + localoffs);
103463 while (c)
103464 {
103465 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
103466 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
103467 if (copy_from_user(lbuf8,
103468 userbuf+useroffs + p,
103469 locallen))
103470 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
103471 index 7d8803a..559f8d0 100644
103472 --- a/sound/oss/swarm_cs4297a.c
103473 +++ b/sound/oss/swarm_cs4297a.c
103474 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
103475 {
103476 struct cs4297a_state *s;
103477 u32 pwr, id;
103478 - mm_segment_t fs;
103479 int rval;
103480 #ifndef CONFIG_BCM_CS4297A_CSWARM
103481 u64 cfg;
103482 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
103483 if (!rval) {
103484 char *sb1250_duart_present;
103485
103486 +#if 0
103487 + mm_segment_t fs;
103488 fs = get_fs();
103489 set_fs(KERNEL_DS);
103490 -#if 0
103491 val = SOUND_MASK_LINE;
103492 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
103493 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
103494 val = initvol[i].vol;
103495 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
103496 }
103497 + set_fs(fs);
103498 // cs4297a_write_ac97(s, 0x18, 0x0808);
103499 #else
103500 // cs4297a_write_ac97(s, 0x5e, 0x180);
103501 cs4297a_write_ac97(s, 0x02, 0x0808);
103502 cs4297a_write_ac97(s, 0x18, 0x0808);
103503 #endif
103504 - set_fs(fs);
103505
103506 list_add(&s->list, &cs4297a_devs);
103507
103508 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
103509 index 4c41c90..37f3631 100644
103510 --- a/sound/pci/emu10k1/emu10k1_synth.c
103511 +++ b/sound/pci/emu10k1/emu10k1_synth.c
103512 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
103513 {
103514
103515 static struct snd_seq_dev_ops ops = {
103516 - snd_emu10k1_synth_new_device,
103517 - snd_emu10k1_synth_delete_device,
103518 + .init_device = snd_emu10k1_synth_new_device,
103519 + .free_device = snd_emu10k1_synth_delete_device,
103520 };
103521 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
103522 sizeof(struct snd_emu10k1_synth_arg));
103523 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
103524 index 69178c4..4493d52 100644
103525 --- a/sound/pci/hda/hda_codec.c
103526 +++ b/sound/pci/hda/hda_codec.c
103527 @@ -976,14 +976,10 @@ find_codec_preset(struct hda_codec *codec)
103528 mutex_unlock(&preset_mutex);
103529
103530 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
103531 - char name[32];
103532 if (!mod_requested)
103533 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
103534 - codec->vendor_id);
103535 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
103536 else
103537 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
103538 - (codec->vendor_id >> 16) & 0xffff);
103539 - request_module(name);
103540 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
103541 mod_requested++;
103542 goto again;
103543 }
103544 @@ -2668,7 +2664,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
103545 /* FIXME: set_fs() hack for obtaining user-space TLV data */
103546 mm_segment_t fs = get_fs();
103547 set_fs(get_ds());
103548 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
103549 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
103550 tlv = _tlv;
103551 set_fs(fs);
103552 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
103553 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
103554 index 4631a23..001ae57 100644
103555 --- a/sound/pci/ymfpci/ymfpci.h
103556 +++ b/sound/pci/ymfpci/ymfpci.h
103557 @@ -358,7 +358,7 @@ struct snd_ymfpci {
103558 spinlock_t reg_lock;
103559 spinlock_t voice_lock;
103560 wait_queue_head_t interrupt_sleep;
103561 - atomic_t interrupt_sleep_count;
103562 + atomic_unchecked_t interrupt_sleep_count;
103563 struct snd_info_entry *proc_entry;
103564 const struct firmware *dsp_microcode;
103565 const struct firmware *controller_microcode;
103566 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
103567 index d591c15..8cb8f94 100644
103568 --- a/sound/pci/ymfpci/ymfpci_main.c
103569 +++ b/sound/pci/ymfpci/ymfpci_main.c
103570 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
103571 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
103572 break;
103573 }
103574 - if (atomic_read(&chip->interrupt_sleep_count)) {
103575 - atomic_set(&chip->interrupt_sleep_count, 0);
103576 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
103577 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103578 wake_up(&chip->interrupt_sleep);
103579 }
103580 __end:
103581 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
103582 continue;
103583 init_waitqueue_entry(&wait, current);
103584 add_wait_queue(&chip->interrupt_sleep, &wait);
103585 - atomic_inc(&chip->interrupt_sleep_count);
103586 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
103587 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
103588 remove_wait_queue(&chip->interrupt_sleep, &wait);
103589 }
103590 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
103591 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
103592 spin_unlock(&chip->reg_lock);
103593
103594 - if (atomic_read(&chip->interrupt_sleep_count)) {
103595 - atomic_set(&chip->interrupt_sleep_count, 0);
103596 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
103597 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103598 wake_up(&chip->interrupt_sleep);
103599 }
103600 }
103601 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
103602 spin_lock_init(&chip->reg_lock);
103603 spin_lock_init(&chip->voice_lock);
103604 init_waitqueue_head(&chip->interrupt_sleep);
103605 - atomic_set(&chip->interrupt_sleep_count, 0);
103606 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103607 chip->card = card;
103608 chip->pci = pci;
103609 chip->irq = -1;
103610 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
103611 index 35e2773..6d6ceee 100644
103612 --- a/sound/soc/fsl/fsl_ssi.c
103613 +++ b/sound/soc/fsl/fsl_ssi.c
103614 @@ -857,7 +857,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
103615 {
103616 struct fsl_ssi_private *ssi_private;
103617 int ret = 0;
103618 - struct device_attribute *dev_attr = NULL;
103619 + device_attribute_no_const *dev_attr = NULL;
103620 struct device_node *np = pdev->dev.of_node;
103621 const char *p, *sprop;
103622 const uint32_t *iprop;
103623 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
103624 index a66783e..ed1d791 100644
103625 --- a/sound/soc/soc-core.c
103626 +++ b/sound/soc/soc-core.c
103627 @@ -2253,8 +2253,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
103628 if (ret)
103629 return ret;
103630
103631 - ops->warm_reset = snd_soc_ac97_warm_reset;
103632 - ops->reset = snd_soc_ac97_reset;
103633 + pax_open_kernel();
103634 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
103635 + *(void **)&ops->reset = snd_soc_ac97_reset;
103636 + pax_close_kernel();
103637
103638 snd_ac97_rst_cfg = cfg;
103639 return 0;
103640 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
103641 index 7778b8e..3d619fc 100644
103642 --- a/sound/synth/emux/emux_seq.c
103643 +++ b/sound/synth/emux/emux_seq.c
103644 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
103645 * MIDI emulation operators
103646 */
103647 static struct snd_midi_op emux_ops = {
103648 - snd_emux_note_on,
103649 - snd_emux_note_off,
103650 - snd_emux_key_press,
103651 - snd_emux_terminate_note,
103652 - snd_emux_control,
103653 - snd_emux_nrpn,
103654 - snd_emux_sysex,
103655 + .note_on = snd_emux_note_on,
103656 + .note_off = snd_emux_note_off,
103657 + .key_press = snd_emux_key_press,
103658 + .note_terminate = snd_emux_terminate_note,
103659 + .control = snd_emux_control,
103660 + .nrpn = snd_emux_nrpn,
103661 + .sysex = snd_emux_sysex,
103662 };
103663
103664
103665 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
103666 new file mode 100644
103667 index 0000000..8eb55ca
103668 --- /dev/null
103669 +++ b/tools/gcc/.gitignore
103670 @@ -0,0 +1,3 @@
103671 +size_overflow_hash.h
103672 +randstruct.seed
103673 +randstruct.hashed_seed
103674 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
103675 new file mode 100644
103676 index 0000000..f8ef8a3
103677 --- /dev/null
103678 +++ b/tools/gcc/Makefile
103679 @@ -0,0 +1,47 @@
103680 +#CC := gcc
103681 +#PLUGIN_SOURCE_FILES := pax_plugin.c
103682 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
103683 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
103684 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
103685 +
103686 +ifeq ($(PLUGINCC),$(HOSTCC))
103687 +HOSTLIBS := hostlibs
103688 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
103689 +else
103690 +HOSTLIBS := hostcxxlibs
103691 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter
103692 +endif
103693 +
103694 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
103695 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
103696 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
103697 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
103698 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
103699 +$(HOSTLIBS)-y += colorize_plugin.so
103700 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
103701 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
103702 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
103703 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
103704 +
103705 +always := $($(HOSTLIBS)-y)
103706 +
103707 +constify_plugin-objs := constify_plugin.o
103708 +stackleak_plugin-objs := stackleak_plugin.o
103709 +kallocstat_plugin-objs := kallocstat_plugin.o
103710 +kernexec_plugin-objs := kernexec_plugin.o
103711 +checker_plugin-objs := checker_plugin.o
103712 +colorize_plugin-objs := colorize_plugin.o
103713 +size_overflow_plugin-objs := size_overflow_plugin.o
103714 +latent_entropy_plugin-objs := latent_entropy_plugin.o
103715 +structleak_plugin-objs := structleak_plugin.o
103716 +randomize_layout_plugin-objs := randomize_layout_plugin.o
103717 +
103718 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
103719 +
103720 +quiet_cmd_build_size_overflow_hash = GENHASH $@
103721 + cmd_build_size_overflow_hash = \
103722 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
103723 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
103724 + $(call if_changed,build_size_overflow_hash)
103725 +
103726 +targets += size_overflow_hash.h
103727 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
103728 new file mode 100644
103729 index 0000000..5452feea
103730 --- /dev/null
103731 +++ b/tools/gcc/checker_plugin.c
103732 @@ -0,0 +1,150 @@
103733 +/*
103734 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
103735 + * Licensed under the GPL v2
103736 + *
103737 + * Note: the choice of the license means that the compilation process is
103738 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
103739 + * but for the kernel it doesn't matter since it doesn't link against
103740 + * any of the gcc libraries
103741 + *
103742 + * gcc plugin to implement various sparse (source code checker) features
103743 + *
103744 + * TODO:
103745 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
103746 + *
103747 + * BUGS:
103748 + * - none known
103749 + */
103750 +
103751 +#include "gcc-common.h"
103752 +
103753 +extern void c_register_addr_space (const char *str, addr_space_t as);
103754 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
103755 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
103756 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
103757 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
103758 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
103759 +
103760 +int plugin_is_GPL_compatible;
103761 +
103762 +static struct plugin_info checker_plugin_info = {
103763 + .version = "201304082245",
103764 + .help = NULL,
103765 +};
103766 +
103767 +#define ADDR_SPACE_KERNEL 0
103768 +#define ADDR_SPACE_FORCE_KERNEL 1
103769 +#define ADDR_SPACE_USER 2
103770 +#define ADDR_SPACE_FORCE_USER 3
103771 +#define ADDR_SPACE_IOMEM 0
103772 +#define ADDR_SPACE_FORCE_IOMEM 0
103773 +#define ADDR_SPACE_PERCPU 0
103774 +#define ADDR_SPACE_FORCE_PERCPU 0
103775 +#define ADDR_SPACE_RCU 0
103776 +#define ADDR_SPACE_FORCE_RCU 0
103777 +
103778 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
103779 +{
103780 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
103781 +}
103782 +
103783 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
103784 +{
103785 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
103786 +}
103787 +
103788 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
103789 +{
103790 + return default_addr_space_valid_pointer_mode(mode, as);
103791 +}
103792 +
103793 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
103794 +{
103795 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
103796 +}
103797 +
103798 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
103799 +{
103800 + return default_addr_space_legitimize_address(x, oldx, mode, as);
103801 +}
103802 +
103803 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
103804 +{
103805 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
103806 + return true;
103807 +
103808 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
103809 + return true;
103810 +
103811 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
103812 + return true;
103813 +
103814 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
103815 + return true;
103816 +
103817 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
103818 + return true;
103819 +
103820 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
103821 + return true;
103822 +
103823 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
103824 + return true;
103825 +
103826 + return subset == superset;
103827 +}
103828 +
103829 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
103830 +{
103831 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
103832 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
103833 +
103834 + return op;
103835 +}
103836 +
103837 +static void register_checker_address_spaces(void *event_data, void *data)
103838 +{
103839 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
103840 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
103841 + c_register_addr_space("__user", ADDR_SPACE_USER);
103842 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
103843 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
103844 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
103845 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
103846 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
103847 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
103848 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
103849 +
103850 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
103851 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
103852 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
103853 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
103854 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
103855 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
103856 + targetm.addr_space.convert = checker_addr_space_convert;
103857 +}
103858 +
103859 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
103860 +{
103861 + const char * const plugin_name = plugin_info->base_name;
103862 + const int argc = plugin_info->argc;
103863 + const struct plugin_argument * const argv = plugin_info->argv;
103864 + int i;
103865 +
103866 + if (!plugin_default_version_check(version, &gcc_version)) {
103867 + error(G_("incompatible gcc/plugin versions"));
103868 + return 1;
103869 + }
103870 +
103871 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
103872 +
103873 + for (i = 0; i < argc; ++i)
103874 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
103875 +
103876 + if (TARGET_64BIT == 0)
103877 + return 0;
103878 +
103879 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
103880 +
103881 + return 0;
103882 +}
103883 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
103884 new file mode 100644
103885 index 0000000..06dcfda
103886 --- /dev/null
103887 +++ b/tools/gcc/colorize_plugin.c
103888 @@ -0,0 +1,169 @@
103889 +/*
103890 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
103891 + * Licensed under the GPL v2
103892 + *
103893 + * Note: the choice of the license means that the compilation process is
103894 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
103895 + * but for the kernel it doesn't matter since it doesn't link against
103896 + * any of the gcc libraries
103897 + *
103898 + * gcc plugin to colorize diagnostic output
103899 + *
103900 + */
103901 +
103902 +#include "gcc-common.h"
103903 +
103904 +int plugin_is_GPL_compatible;
103905 +
103906 +static struct plugin_info colorize_plugin_info = {
103907 + .version = "201401260140",
103908 + .help = NULL,
103909 +};
103910 +
103911 +#define GREEN "\033[32m\033[2m"
103912 +#define LIGHTGREEN "\033[32m\033[1m"
103913 +#define YELLOW "\033[33m\033[2m"
103914 +#define LIGHTYELLOW "\033[33m\033[1m"
103915 +#define RED "\033[31m\033[2m"
103916 +#define LIGHTRED "\033[31m\033[1m"
103917 +#define BLUE "\033[34m\033[2m"
103918 +#define LIGHTBLUE "\033[34m\033[1m"
103919 +#define BRIGHT "\033[m\033[1m"
103920 +#define NORMAL "\033[m"
103921 +
103922 +static diagnostic_starter_fn old_starter;
103923 +static diagnostic_finalizer_fn old_finalizer;
103924 +
103925 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
103926 +{
103927 + const char *color;
103928 + char *newprefix;
103929 +
103930 + switch (diagnostic->kind) {
103931 + case DK_NOTE:
103932 + color = LIGHTBLUE;
103933 + break;
103934 +
103935 + case DK_PEDWARN:
103936 + case DK_WARNING:
103937 + color = LIGHTYELLOW;
103938 + break;
103939 +
103940 + case DK_ERROR:
103941 + case DK_FATAL:
103942 + case DK_ICE:
103943 + case DK_PERMERROR:
103944 + case DK_SORRY:
103945 + color = LIGHTRED;
103946 + break;
103947 +
103948 + default:
103949 + color = NORMAL;
103950 + }
103951 +
103952 + old_starter(context, diagnostic);
103953 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
103954 + return;
103955 + pp_destroy_prefix(context->printer);
103956 + pp_set_prefix(context->printer, newprefix);
103957 +}
103958 +
103959 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
103960 +{
103961 + old_finalizer(context, diagnostic);
103962 +}
103963 +
103964 +static void colorize_arm(void)
103965 +{
103966 + old_starter = diagnostic_starter(global_dc);
103967 + old_finalizer = diagnostic_finalizer(global_dc);
103968 +
103969 + diagnostic_starter(global_dc) = start_colorize;
103970 + diagnostic_finalizer(global_dc) = finalize_colorize;
103971 +}
103972 +
103973 +static unsigned int execute_colorize_rearm(void)
103974 +{
103975 + if (diagnostic_starter(global_dc) == start_colorize)
103976 + return 0;
103977 +
103978 + colorize_arm();
103979 + return 0;
103980 +}
103981 +
103982 +#if BUILDING_GCC_VERSION >= 4009
103983 +static const struct pass_data colorize_rearm_pass_data = {
103984 +#else
103985 +struct simple_ipa_opt_pass colorize_rearm_pass = {
103986 + .pass = {
103987 +#endif
103988 + .type = SIMPLE_IPA_PASS,
103989 + .name = "colorize_rearm",
103990 +#if BUILDING_GCC_VERSION >= 4008
103991 + .optinfo_flags = OPTGROUP_NONE,
103992 +#endif
103993 +#if BUILDING_GCC_VERSION >= 4009
103994 + .has_gate = false,
103995 + .has_execute = true,
103996 +#else
103997 + .gate = NULL,
103998 + .execute = execute_colorize_rearm,
103999 + .sub = NULL,
104000 + .next = NULL,
104001 + .static_pass_number = 0,
104002 +#endif
104003 + .tv_id = TV_NONE,
104004 + .properties_required = 0,
104005 + .properties_provided = 0,
104006 + .properties_destroyed = 0,
104007 + .todo_flags_start = 0,
104008 + .todo_flags_finish = 0
104009 +#if BUILDING_GCC_VERSION < 4009
104010 + }
104011 +#endif
104012 +};
104013 +
104014 +#if BUILDING_GCC_VERSION >= 4009
104015 +namespace {
104016 +class colorize_rearm_pass : public simple_ipa_opt_pass {
104017 +public:
104018 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
104019 + unsigned int execute() { return execute_colorize_rearm(); }
104020 +};
104021 +}
104022 +#endif
104023 +
104024 +static struct opt_pass *make_colorize_rearm_pass(void)
104025 +{
104026 +#if BUILDING_GCC_VERSION >= 4009
104027 + return new colorize_rearm_pass();
104028 +#else
104029 + return &colorize_rearm_pass.pass;
104030 +#endif
104031 +}
104032 +
104033 +static void colorize_start_unit(void *gcc_data, void *user_data)
104034 +{
104035 + colorize_arm();
104036 +}
104037 +
104038 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
104039 +{
104040 + const char * const plugin_name = plugin_info->base_name;
104041 + struct register_pass_info colorize_rearm_pass_info;
104042 +
104043 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
104044 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
104045 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
104046 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
104047 +
104048 + if (!plugin_default_version_check(version, &gcc_version)) {
104049 + error(G_("incompatible gcc/plugin versions"));
104050 + return 1;
104051 + }
104052 +
104053 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
104054 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
104055 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
104056 + return 0;
104057 +}
104058 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
104059 new file mode 100644
104060 index 0000000..4f67ac1
104061 --- /dev/null
104062 +++ b/tools/gcc/constify_plugin.c
104063 @@ -0,0 +1,552 @@
104064 +/*
104065 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
104066 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
104067 + * Licensed under the GPL v2, or (at your option) v3
104068 + *
104069 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
104070 + *
104071 + * Homepage:
104072 + * http://www.grsecurity.net/~ephox/const_plugin/
104073 + *
104074 + * Usage:
104075 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
104076 + * $ gcc -fplugin=constify_plugin.so test.c -O2
104077 + */
104078 +
104079 +#include "gcc-common.h"
104080 +
104081 +// unused C type flag in all versions 4.5-4.9
104082 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
104083 +
104084 +int plugin_is_GPL_compatible;
104085 +
104086 +static struct plugin_info const_plugin_info = {
104087 + .version = "201401270210",
104088 + .help = "no-constify\tturn off constification\n",
104089 +};
104090 +
104091 +typedef struct {
104092 + bool has_fptr_field;
104093 + bool has_writable_field;
104094 + bool has_do_const_field;
104095 + bool has_no_const_field;
104096 +} constify_info;
104097 +
104098 +static const_tree get_field_type(const_tree field)
104099 +{
104100 + return strip_array_types(TREE_TYPE(field));
104101 +}
104102 +
104103 +static bool is_fptr(const_tree field)
104104 +{
104105 + const_tree ptr = get_field_type(field);
104106 +
104107 + if (TREE_CODE(ptr) != POINTER_TYPE)
104108 + return false;
104109 +
104110 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
104111 +}
104112 +
104113 +/*
104114 + * determine whether the given structure type meets the requirements for automatic constification,
104115 + * including the constification attributes on nested structure types
104116 + */
104117 +static void constifiable(const_tree node, constify_info *cinfo)
104118 +{
104119 + const_tree field;
104120 +
104121 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
104122 +
104123 + // e.g., pointer to structure fields while still constructing the structure type
104124 + if (TYPE_FIELDS(node) == NULL_TREE)
104125 + return;
104126 +
104127 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
104128 + const_tree type = get_field_type(field);
104129 + enum tree_code code = TREE_CODE(type);
104130 +
104131 + if (node == type)
104132 + continue;
104133 +
104134 + if (is_fptr(field))
104135 + cinfo->has_fptr_field = true;
104136 + else if (!TREE_READONLY(field))
104137 + cinfo->has_writable_field = true;
104138 +
104139 + if (code == RECORD_TYPE || code == UNION_TYPE) {
104140 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
104141 + cinfo->has_do_const_field = true;
104142 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
104143 + cinfo->has_no_const_field = true;
104144 + else
104145 + constifiable(type, cinfo);
104146 + }
104147 + }
104148 +}
104149 +
104150 +static bool constified(const_tree node)
104151 +{
104152 + constify_info cinfo = {
104153 + .has_fptr_field = false,
104154 + .has_writable_field = false,
104155 + .has_do_const_field = false,
104156 + .has_no_const_field = false
104157 + };
104158 +
104159 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
104160 +
104161 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
104162 +// gcc_assert(!TYPE_READONLY(node));
104163 + return false;
104164 + }
104165 +
104166 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
104167 + gcc_assert(TYPE_READONLY(node));
104168 + return true;
104169 + }
104170 +
104171 + constifiable(node, &cinfo);
104172 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
104173 + return false;
104174 +
104175 + return TYPE_READONLY(node);
104176 +}
104177 +
104178 +static void deconstify_tree(tree node);
104179 +
104180 +static void deconstify_type(tree type)
104181 +{
104182 + tree field;
104183 +
104184 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
104185 +
104186 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
104187 + const_tree fieldtype = get_field_type(field);
104188 +
104189 + // special case handling of simple ptr-to-same-array-type members
104190 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
104191 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
104192 +
104193 + if (TREE_TYPE(TREE_TYPE(field)) == type)
104194 + continue;
104195 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
104196 + continue;
104197 + if (!constified(ptrtype))
104198 + continue;
104199 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
104200 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
104201 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
104202 + }
104203 + continue;
104204 + }
104205 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
104206 + continue;
104207 + if (!constified(fieldtype))
104208 + continue;
104209 +
104210 + deconstify_tree(field);
104211 + TREE_READONLY(field) = 0;
104212 + }
104213 + TYPE_READONLY(type) = 0;
104214 + C_TYPE_FIELDS_READONLY(type) = 0;
104215 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104216 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
104217 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
104218 + }
104219 +}
104220 +
104221 +static void deconstify_tree(tree node)
104222 +{
104223 + tree old_type, new_type, field;
104224 +
104225 + old_type = TREE_TYPE(node);
104226 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
104227 + node = TREE_TYPE(node) = copy_node(old_type);
104228 + old_type = TREE_TYPE(old_type);
104229 + }
104230 +
104231 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
104232 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
104233 +
104234 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
104235 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
104236 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
104237 + DECL_FIELD_CONTEXT(field) = new_type;
104238 +
104239 + deconstify_type(new_type);
104240 +
104241 + TREE_TYPE(node) = new_type;
104242 +}
104243 +
104244 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
104245 +{
104246 + tree type;
104247 + constify_info cinfo = {
104248 + .has_fptr_field = false,
104249 + .has_writable_field = false,
104250 + .has_do_const_field = false,
104251 + .has_no_const_field = false
104252 + };
104253 +
104254 + *no_add_attrs = true;
104255 + if (TREE_CODE(*node) == FUNCTION_DECL) {
104256 + error("%qE attribute does not apply to functions (%qF)", name, *node);
104257 + return NULL_TREE;
104258 + }
104259 +
104260 + if (TREE_CODE(*node) == PARM_DECL) {
104261 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
104262 + return NULL_TREE;
104263 + }
104264 +
104265 + if (TREE_CODE(*node) == VAR_DECL) {
104266 + error("%qE attribute does not apply to variables (%qD)", name, *node);
104267 + return NULL_TREE;
104268 + }
104269 +
104270 + if (TYPE_P(*node)) {
104271 + type = *node;
104272 + } else {
104273 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
104274 + type = TREE_TYPE(*node);
104275 + }
104276 +
104277 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
104278 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
104279 + return NULL_TREE;
104280 + }
104281 +
104282 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
104283 + error("%qE attribute is already applied to the type %qT", name, type);
104284 + return NULL_TREE;
104285 + }
104286 +
104287 + if (TYPE_P(*node)) {
104288 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
104289 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
104290 + else
104291 + *no_add_attrs = false;
104292 + return NULL_TREE;
104293 + }
104294 +
104295 + constifiable(type, &cinfo);
104296 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104297 + deconstify_tree(*node);
104298 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
104299 + return NULL_TREE;
104300 + }
104301 +
104302 + error("%qE attribute used on type %qT that is not constified", name, type);
104303 + return NULL_TREE;
104304 +}
104305 +
104306 +static void constify_type(tree type)
104307 +{
104308 + TYPE_READONLY(type) = 1;
104309 + C_TYPE_FIELDS_READONLY(type) = 1;
104310 + TYPE_CONSTIFY_VISITED(type) = 1;
104311 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
104312 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
104313 +}
104314 +
104315 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
104316 +{
104317 + *no_add_attrs = true;
104318 + if (!TYPE_P(*node)) {
104319 + error("%qE attribute applies to types only (%qD)", name, *node);
104320 + return NULL_TREE;
104321 + }
104322 +
104323 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
104324 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
104325 + return NULL_TREE;
104326 + }
104327 +
104328 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
104329 + error("%qE attribute used on %qT is already applied to the type", name, *node);
104330 + return NULL_TREE;
104331 + }
104332 +
104333 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
104334 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
104335 + return NULL_TREE;
104336 + }
104337 +
104338 + *no_add_attrs = false;
104339 + return NULL_TREE;
104340 +}
104341 +
104342 +static struct attribute_spec no_const_attr = {
104343 + .name = "no_const",
104344 + .min_length = 0,
104345 + .max_length = 0,
104346 + .decl_required = false,
104347 + .type_required = false,
104348 + .function_type_required = false,
104349 + .handler = handle_no_const_attribute,
104350 +#if BUILDING_GCC_VERSION >= 4007
104351 + .affects_type_identity = true
104352 +#endif
104353 +};
104354 +
104355 +static struct attribute_spec do_const_attr = {
104356 + .name = "do_const",
104357 + .min_length = 0,
104358 + .max_length = 0,
104359 + .decl_required = false,
104360 + .type_required = false,
104361 + .function_type_required = false,
104362 + .handler = handle_do_const_attribute,
104363 +#if BUILDING_GCC_VERSION >= 4007
104364 + .affects_type_identity = true
104365 +#endif
104366 +};
104367 +
104368 +static void register_attributes(void *event_data, void *data)
104369 +{
104370 + register_attribute(&no_const_attr);
104371 + register_attribute(&do_const_attr);
104372 +}
104373 +
104374 +static void finish_type(void *event_data, void *data)
104375 +{
104376 + tree type = (tree)event_data;
104377 + constify_info cinfo = {
104378 + .has_fptr_field = false,
104379 + .has_writable_field = false,
104380 + .has_do_const_field = false,
104381 + .has_no_const_field = false
104382 + };
104383 +
104384 + if (type == NULL_TREE || type == error_mark_node)
104385 + return;
104386 +
104387 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
104388 + return;
104389 +
104390 + constifiable(type, &cinfo);
104391 +
104392 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
104393 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
104394 + deconstify_type(type);
104395 + TYPE_CONSTIFY_VISITED(type) = 1;
104396 + } else
104397 + error("'no_const' attribute used on type %qT that is not constified", type);
104398 + return;
104399 + }
104400 +
104401 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104402 + if (!cinfo.has_writable_field) {
104403 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
104404 + return;
104405 + }
104406 + constify_type(type);
104407 + return;
104408 + }
104409 +
104410 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
104411 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104412 + error("'do_const' attribute used on type %qT that is constified", type);
104413 + return;
104414 + }
104415 + constify_type(type);
104416 + return;
104417 + }
104418 +
104419 + deconstify_type(type);
104420 + TYPE_CONSTIFY_VISITED(type) = 1;
104421 +}
104422 +
104423 +static void check_global_variables(void *event_data, void *data)
104424 +{
104425 + struct varpool_node *node;
104426 +
104427 + FOR_EACH_VARIABLE(node) {
104428 + tree var = NODE_DECL(node);
104429 + tree type = TREE_TYPE(var);
104430 +
104431 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
104432 + continue;
104433 +
104434 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
104435 + continue;
104436 +
104437 + if (!TYPE_CONSTIFY_VISITED(type))
104438 + continue;
104439 +
104440 + if (DECL_EXTERNAL(var))
104441 + continue;
104442 +
104443 + if (DECL_INITIAL(var))
104444 + continue;
104445 +
104446 + // this works around a gcc bug/feature where uninitialized globals
104447 + // are moved into the .bss section regardless of any constification
104448 + DECL_INITIAL(var) = build_constructor(type, NULL);
104449 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
104450 + }
104451 +}
104452 +
104453 +static unsigned int check_local_variables(void)
104454 +{
104455 + unsigned int ret = 0;
104456 + tree var;
104457 +
104458 + unsigned int i;
104459 +
104460 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
104461 + tree type = TREE_TYPE(var);
104462 +
104463 + gcc_assert(DECL_P(var));
104464 + if (is_global_var(var))
104465 + continue;
104466 +
104467 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
104468 + continue;
104469 +
104470 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
104471 + continue;
104472 +
104473 + if (!TYPE_CONSTIFY_VISITED(type))
104474 + continue;
104475 +
104476 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
104477 + ret = 1;
104478 + }
104479 + return ret;
104480 +}
104481 +
104482 +#if BUILDING_GCC_VERSION >= 4009
104483 +static const struct pass_data check_local_variables_pass_data = {
104484 +#else
104485 +static struct gimple_opt_pass check_local_variables_pass = {
104486 + .pass = {
104487 +#endif
104488 + .type = GIMPLE_PASS,
104489 + .name = "check_local_variables",
104490 +#if BUILDING_GCC_VERSION >= 4008
104491 + .optinfo_flags = OPTGROUP_NONE,
104492 +#endif
104493 +#if BUILDING_GCC_VERSION >= 4009
104494 + .has_gate = false,
104495 + .has_execute = true,
104496 +#else
104497 + .gate = NULL,
104498 + .execute = check_local_variables,
104499 + .sub = NULL,
104500 + .next = NULL,
104501 + .static_pass_number = 0,
104502 +#endif
104503 + .tv_id = TV_NONE,
104504 + .properties_required = 0,
104505 + .properties_provided = 0,
104506 + .properties_destroyed = 0,
104507 + .todo_flags_start = 0,
104508 + .todo_flags_finish = 0
104509 +#if BUILDING_GCC_VERSION < 4009
104510 + }
104511 +#endif
104512 +};
104513 +
104514 +#if BUILDING_GCC_VERSION >= 4009
104515 +namespace {
104516 +class check_local_variables_pass : public gimple_opt_pass {
104517 +public:
104518 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
104519 + unsigned int execute() { return check_local_variables(); }
104520 +};
104521 +}
104522 +#endif
104523 +
104524 +static struct opt_pass *make_check_local_variables_pass(void)
104525 +{
104526 +#if BUILDING_GCC_VERSION >= 4009
104527 + return new check_local_variables_pass();
104528 +#else
104529 + return &check_local_variables_pass.pass;
104530 +#endif
104531 +}
104532 +
104533 +static struct {
104534 + const char *name;
104535 + const char *asm_op;
104536 +} sections[] = {
104537 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
104538 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
104539 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
104540 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
104541 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
104542 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
104543 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
104544 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
104545 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
104546 +};
104547 +
104548 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
104549 +
104550 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
104551 +{
104552 + size_t i;
104553 +
104554 + for (i = 0; i < ARRAY_SIZE(sections); i++)
104555 + if (!strcmp(sections[i].name, name))
104556 + return 0;
104557 + return old_section_type_flags(decl, name, reloc);
104558 +}
104559 +
104560 +static void constify_start_unit(void *gcc_data, void *user_data)
104561 +{
104562 +// size_t i;
104563 +
104564 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
104565 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
104566 +// sections[i].section = get_section(sections[i].name, 0, NULL);
104567 +
104568 + old_section_type_flags = targetm.section_type_flags;
104569 + targetm.section_type_flags = constify_section_type_flags;
104570 +}
104571 +
104572 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
104573 +{
104574 + const char * const plugin_name = plugin_info->base_name;
104575 + const int argc = plugin_info->argc;
104576 + const struct plugin_argument * const argv = plugin_info->argv;
104577 + int i;
104578 + bool constify = true;
104579 +
104580 + struct register_pass_info check_local_variables_pass_info;
104581 +
104582 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
104583 + check_local_variables_pass_info.reference_pass_name = "ssa";
104584 + check_local_variables_pass_info.ref_pass_instance_number = 1;
104585 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
104586 +
104587 + if (!plugin_default_version_check(version, &gcc_version)) {
104588 + error(G_("incompatible gcc/plugin versions"));
104589 + return 1;
104590 + }
104591 +
104592 + for (i = 0; i < argc; ++i) {
104593 + if (!(strcmp(argv[i].key, "no-constify"))) {
104594 + constify = false;
104595 + continue;
104596 + }
104597 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
104598 + }
104599 +
104600 + if (strcmp(lang_hooks.name, "GNU C")) {
104601 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
104602 + constify = false;
104603 + }
104604 +
104605 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
104606 + if (constify) {
104607 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
104608 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
104609 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
104610 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
104611 + }
104612 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
104613 +
104614 + return 0;
104615 +}
104616 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
104617 new file mode 100644
104618 index 0000000..986f39b
104619 --- /dev/null
104620 +++ b/tools/gcc/gcc-common.h
104621 @@ -0,0 +1,267 @@
104622 +#ifndef GCC_COMMON_H_INCLUDED
104623 +#define GCC_COMMON_H_INCLUDED
104624 +
104625 +#include "plugin.h"
104626 +#include "bversion.h"
104627 +#include "plugin-version.h"
104628 +#include "config.h"
104629 +#include "system.h"
104630 +#include "coretypes.h"
104631 +#include "tm.h"
104632 +#include "line-map.h"
104633 +#include "input.h"
104634 +#include "tree.h"
104635 +
104636 +#include "tree-inline.h"
104637 +#include "version.h"
104638 +#include "rtl.h"
104639 +#include "tm_p.h"
104640 +#include "flags.h"
104641 +//#include "insn-attr.h"
104642 +//#include "insn-config.h"
104643 +//#include "insn-flags.h"
104644 +#include "hard-reg-set.h"
104645 +//#include "recog.h"
104646 +#include "output.h"
104647 +#include "except.h"
104648 +#include "function.h"
104649 +#include "toplev.h"
104650 +//#include "expr.h"
104651 +#include "basic-block.h"
104652 +#include "intl.h"
104653 +#include "ggc.h"
104654 +//#include "regs.h"
104655 +#include "timevar.h"
104656 +
104657 +#include "params.h"
104658 +#include "pointer-set.h"
104659 +#include "emit-rtl.h"
104660 +//#include "reload.h"
104661 +//#include "ira.h"
104662 +//#include "dwarf2asm.h"
104663 +#include "debug.h"
104664 +#include "target.h"
104665 +#include "langhooks.h"
104666 +#include "cfgloop.h"
104667 +//#include "hosthooks.h"
104668 +#include "cgraph.h"
104669 +#include "opts.h"
104670 +//#include "coverage.h"
104671 +//#include "value-prof.h"
104672 +
104673 +#if BUILDING_GCC_VERSION >= 4007
104674 +#include "tree-pretty-print.h"
104675 +#include "gimple-pretty-print.h"
104676 +#include "c-tree.h"
104677 +//#include "alloc-pool.h"
104678 +#endif
104679 +
104680 +#if BUILDING_GCC_VERSION <= 4008
104681 +#include "tree-flow.h"
104682 +#endif
104683 +
104684 +#include "diagnostic.h"
104685 +//#include "tree-diagnostic.h"
104686 +#include "tree-dump.h"
104687 +#include "tree-pass.h"
104688 +//#include "df.h"
104689 +#include "predict.h"
104690 +//#include "lto-streamer.h"
104691 +#include "ipa-utils.h"
104692 +
104693 +#if BUILDING_GCC_VERSION >= 4009
104694 +#include "varasm.h"
104695 +#include "stor-layout.h"
104696 +#include "internal-fn.h"
104697 +#include "gimple-expr.h"
104698 +//#include "diagnostic-color.h"
104699 +#include "context.h"
104700 +#include "tree-ssa-alias.h"
104701 +#include "stringpool.h"
104702 +#include "tree-ssanames.h"
104703 +#include "print-tree.h"
104704 +#include "tree-eh.h"
104705 +#endif
104706 +
104707 +#include "gimple.h"
104708 +
104709 +#if BUILDING_GCC_VERSION >= 4009
104710 +#include "tree-ssa-operands.h"
104711 +#include "tree-phinodes.h"
104712 +#include "gimple-iterator.h"
104713 +#include "gimple-ssa.h"
104714 +#include "ssa-iterators.h"
104715 +#endif
104716 +
104717 +//#include "expr.h" where are you...
104718 +extern rtx emit_move_insn(rtx x, rtx y);
104719 +
104720 +#define __unused __attribute__((__unused__))
104721 +
104722 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
104723 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
104724 +
104725 +#if BUILDING_GCC_VERSION == 4005
104726 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
104727 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
104728 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
104729 +
104730 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
104731 +{
104732 + tree fndecl;
104733 +
104734 + if (!is_gimple_call(stmt))
104735 + return false;
104736 + fndecl = gimple_call_fndecl(stmt);
104737 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
104738 + return false;
104739 +// print_node(stderr, "pax", fndecl, 4);
104740 + return DECL_FUNCTION_CODE(fndecl) == code;
104741 +}
104742 +
104743 +static inline bool is_simple_builtin(tree decl)
104744 +{
104745 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
104746 + return false;
104747 +
104748 + switch (DECL_FUNCTION_CODE(decl)) {
104749 + /* Builtins that expand to constants. */
104750 + case BUILT_IN_CONSTANT_P:
104751 + case BUILT_IN_EXPECT:
104752 + case BUILT_IN_OBJECT_SIZE:
104753 + case BUILT_IN_UNREACHABLE:
104754 + /* Simple register moves or loads from stack. */
104755 + case BUILT_IN_RETURN_ADDRESS:
104756 + case BUILT_IN_EXTRACT_RETURN_ADDR:
104757 + case BUILT_IN_FROB_RETURN_ADDR:
104758 + case BUILT_IN_RETURN:
104759 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
104760 + case BUILT_IN_FRAME_ADDRESS:
104761 + case BUILT_IN_VA_END:
104762 + case BUILT_IN_STACK_SAVE:
104763 + case BUILT_IN_STACK_RESTORE:
104764 + /* Exception state returns or moves registers around. */
104765 + case BUILT_IN_EH_FILTER:
104766 + case BUILT_IN_EH_POINTER:
104767 + case BUILT_IN_EH_COPY_VALUES:
104768 + return true;
104769 +
104770 + default:
104771 + return false;
104772 + }
104773 +}
104774 +#endif
104775 +
104776 +#if BUILDING_GCC_VERSION <= 4006
104777 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
104778 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
104779 +
104780 +// should come from c-tree.h if only it were installed for gcc 4.5...
104781 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
104782 +
104783 +#define get_random_seed(noinit) ({ \
104784 + unsigned HOST_WIDE_INT seed; \
104785 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
104786 + seed * seed; })
104787 +
104788 +static inline bool gimple_clobber_p(gimple s)
104789 +{
104790 + return false;
104791 +}
104792 +
104793 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
104794 +{
104795 + return implicit_built_in_decls[fncode];
104796 +}
104797 +
104798 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
104799 +{
104800 + struct cgraph_node *node = cgraph_get_node(decl);
104801 +
104802 + return node ? node : cgraph_node(decl);
104803 +}
104804 +
104805 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
104806 +{
104807 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
104808 +}
104809 +
104810 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
104811 +{
104812 + struct cgraph_node *node;
104813 +
104814 + for (node = cgraph_nodes; node; node = node->next)
104815 + if (cgraph_function_with_gimple_body_p(node))
104816 + return node;
104817 + return NULL;
104818 +}
104819 +
104820 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
104821 +{
104822 + for (node = node->next; node; node = node->next)
104823 + if (cgraph_function_with_gimple_body_p(node))
104824 + return node;
104825 + return NULL;
104826 +}
104827 +
104828 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
104829 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
104830 + (node) = cgraph_next_function_with_gimple_body(node))
104831 +#endif
104832 +
104833 +#if BUILDING_GCC_VERSION == 4006
104834 +extern void debug_gimple_stmt(gimple);
104835 +extern void debug_gimple_seq(gimple_seq);
104836 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
104837 +extern void print_gimple_stmt(FILE *, gimple, int, int);
104838 +extern void print_gimple_expr(FILE *, gimple, int, int);
104839 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
104840 +#endif
104841 +
104842 +#if BUILDING_GCC_VERSION <= 4007
104843 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
104844 +
104845 +static inline bool gimple_store_p(gimple gs)
104846 +{
104847 + tree lhs = gimple_get_lhs(gs);
104848 + return lhs && !is_gimple_reg(lhs);
104849 +}
104850 +#endif
104851 +
104852 +#if BUILDING_GCC_VERSION >= 4007
104853 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
104854 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
104855 +#endif
104856 +
104857 +#if BUILDING_GCC_VERSION <= 4008
104858 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
104859 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
104860 +
104861 +static inline const char *get_tree_code_name(enum tree_code code)
104862 +{
104863 + gcc_assert(code < MAX_TREE_CODES);
104864 + return tree_code_name[code];
104865 +}
104866 +
104867 +#define ipa_remove_stmt_references(cnode, stmt)
104868 +#endif
104869 +
104870 +#if BUILDING_GCC_VERSION == 4008
104871 +#define NODE_DECL(node) node->symbol.decl
104872 +#else
104873 +#define NODE_DECL(node) node->decl
104874 +#endif
104875 +
104876 +#if BUILDING_GCC_VERSION >= 4008
104877 +#define add_referenced_var(var)
104878 +#define mark_sym_for_renaming(var)
104879 +#define varpool_mark_needed_node(node)
104880 +#define TODO_dump_func 0
104881 +#define TODO_dump_cgraph 0
104882 +#endif
104883 +
104884 +#if BUILDING_GCC_VERSION >= 4009
104885 +#define TODO_ggc_collect 0
104886 +#endif
104887 +
104888 +#endif
104889 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
104890 new file mode 100644
104891 index 0000000..e518932
104892 --- /dev/null
104893 +++ b/tools/gcc/generate_size_overflow_hash.sh
104894 @@ -0,0 +1,94 @@
104895 +#!/bin/bash
104896 +
104897 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
104898 +
104899 +header1="size_overflow_hash.h"
104900 +database="size_overflow_hash.data"
104901 +n=65536
104902 +
104903 +usage() {
104904 +cat <<EOF
104905 +usage: $0 options
104906 +OPTIONS:
104907 + -h|--help help
104908 + -o header file
104909 + -d database file
104910 + -n hash array size
104911 +EOF
104912 + return 0
104913 +}
104914 +
104915 +while true
104916 +do
104917 + case "$1" in
104918 + -h|--help) usage && exit 0;;
104919 + -n) n=$2; shift 2;;
104920 + -o) header1="$2"; shift 2;;
104921 + -d) database="$2"; shift 2;;
104922 + --) shift 1; break ;;
104923 + *) break ;;
104924 + esac
104925 +done
104926 +
104927 +create_defines() {
104928 + for i in `seq 0 31`
104929 + do
104930 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
104931 + done
104932 + echo >> "$header1"
104933 +}
104934 +
104935 +create_structs() {
104936 + rm -f "$header1"
104937 +
104938 + create_defines
104939 +
104940 + cat "$database" | while read data
104941 + do
104942 + data_array=($data)
104943 + struct_hash_name="${data_array[0]}"
104944 + funcn="${data_array[1]}"
104945 + params="${data_array[2]}"
104946 + next="${data_array[4]}"
104947 +
104948 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
104949 +
104950 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
104951 + echo -en "\t.param\t= " >> "$header1"
104952 + line=
104953 + for param_num in ${params//-/ };
104954 + do
104955 + line="${line}PARAM"$param_num"|"
104956 + done
104957 +
104958 + echo -e "${line%?},\n};\n" >> "$header1"
104959 + done
104960 +}
104961 +
104962 +create_headers() {
104963 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
104964 +}
104965 +
104966 +create_array_elements() {
104967 + index=0
104968 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
104969 + do
104970 + data_array=($data)
104971 + i="${data_array[3]}"
104972 + hash="${data_array[0]}"
104973 + while [[ $index -lt $i ]]
104974 + do
104975 + echo -e "\t["$index"]\t= NULL," >> "$header1"
104976 + index=$(($index + 1))
104977 + done
104978 + index=$(($index + 1))
104979 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
104980 + done
104981 + echo '};' >> $header1
104982 +}
104983 +
104984 +create_structs
104985 +create_headers
104986 +create_array_elements
104987 +
104988 +exit 0
104989 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
104990 new file mode 100644
104991 index 0000000..b559327
104992 --- /dev/null
104993 +++ b/tools/gcc/kallocstat_plugin.c
104994 @@ -0,0 +1,182 @@
104995 +/*
104996 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
104997 + * Licensed under the GPL v2
104998 + *
104999 + * Note: the choice of the license means that the compilation process is
105000 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105001 + * but for the kernel it doesn't matter since it doesn't link against
105002 + * any of the gcc libraries
105003 + *
105004 + * gcc plugin to find the distribution of k*alloc sizes
105005 + *
105006 + * TODO:
105007 + *
105008 + * BUGS:
105009 + * - none known
105010 + */
105011 +
105012 +#include "gcc-common.h"
105013 +
105014 +int plugin_is_GPL_compatible;
105015 +
105016 +static struct plugin_info kallocstat_plugin_info = {
105017 + .version = "201401260140",
105018 + .help = NULL
105019 +};
105020 +
105021 +static const char * const kalloc_functions[] = {
105022 + "__kmalloc",
105023 + "kmalloc",
105024 + "kmalloc_large",
105025 + "kmalloc_node",
105026 + "kmalloc_order",
105027 + "kmalloc_order_trace",
105028 + "kmalloc_slab",
105029 + "kzalloc",
105030 + "kzalloc_node",
105031 +};
105032 +
105033 +static bool is_kalloc(const char *fnname)
105034 +{
105035 + size_t i;
105036 +
105037 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
105038 + if (!strcmp(fnname, kalloc_functions[i]))
105039 + return true;
105040 + return false;
105041 +}
105042 +
105043 +static unsigned int execute_kallocstat(void)
105044 +{
105045 + basic_block bb;
105046 +
105047 + // 1. loop through BBs and GIMPLE statements
105048 + FOR_EACH_BB_FN(bb, cfun) {
105049 + gimple_stmt_iterator gsi;
105050 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105051 + // gimple match:
105052 + tree fndecl, size;
105053 + gimple stmt;
105054 + const char *fnname;
105055 +
105056 + // is it a call
105057 + stmt = gsi_stmt(gsi);
105058 + if (!is_gimple_call(stmt))
105059 + continue;
105060 + fndecl = gimple_call_fndecl(stmt);
105061 + if (fndecl == NULL_TREE)
105062 + continue;
105063 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
105064 + continue;
105065 +
105066 + // is it a call to k*alloc
105067 + fnname = DECL_NAME_POINTER(fndecl);
105068 + if (!is_kalloc(fnname))
105069 + continue;
105070 +
105071 + // is the size arg const or the result of a simple const assignment
105072 + size = gimple_call_arg(stmt, 0);
105073 + while (true) {
105074 + expanded_location xloc;
105075 + size_t size_val;
105076 +
105077 + if (TREE_CONSTANT(size)) {
105078 + xloc = expand_location(gimple_location(stmt));
105079 + if (!xloc.file)
105080 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
105081 + size_val = TREE_INT_CST_LOW(size);
105082 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
105083 + break;
105084 + }
105085 +
105086 + if (TREE_CODE(size) != SSA_NAME)
105087 + break;
105088 + stmt = SSA_NAME_DEF_STMT(size);
105089 +//debug_gimple_stmt(stmt);
105090 +//debug_tree(size);
105091 + if (!stmt || !is_gimple_assign(stmt))
105092 + break;
105093 + if (gimple_num_ops(stmt) != 2)
105094 + break;
105095 + size = gimple_assign_rhs1(stmt);
105096 + }
105097 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
105098 +//debug_tree(gimple_call_fn(call_stmt));
105099 +//print_node(stderr, "pax", fndecl, 4);
105100 + }
105101 + }
105102 +
105103 + return 0;
105104 +}
105105 +
105106 +#if BUILDING_GCC_VERSION >= 4009
105107 +static const struct pass_data kallocstat_pass_data = {
105108 +#else
105109 +static struct gimple_opt_pass kallocstat_pass = {
105110 + .pass = {
105111 +#endif
105112 + .type = GIMPLE_PASS,
105113 + .name = "kallocstat",
105114 +#if BUILDING_GCC_VERSION >= 4008
105115 + .optinfo_flags = OPTGROUP_NONE,
105116 +#endif
105117 +#if BUILDING_GCC_VERSION >= 4009
105118 + .has_gate = false,
105119 + .has_execute = true,
105120 +#else
105121 + .gate = NULL,
105122 + .execute = execute_kallocstat,
105123 + .sub = NULL,
105124 + .next = NULL,
105125 + .static_pass_number = 0,
105126 +#endif
105127 + .tv_id = TV_NONE,
105128 + .properties_required = 0,
105129 + .properties_provided = 0,
105130 + .properties_destroyed = 0,
105131 + .todo_flags_start = 0,
105132 + .todo_flags_finish = 0
105133 +#if BUILDING_GCC_VERSION < 4009
105134 + }
105135 +#endif
105136 +};
105137 +
105138 +#if BUILDING_GCC_VERSION >= 4009
105139 +namespace {
105140 +class kallocstat_pass : public gimple_opt_pass {
105141 +public:
105142 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
105143 + unsigned int execute() { return execute_kallocstat(); }
105144 +};
105145 +}
105146 +#endif
105147 +
105148 +static struct opt_pass *make_kallocstat_pass(void)
105149 +{
105150 +#if BUILDING_GCC_VERSION >= 4009
105151 + return new kallocstat_pass();
105152 +#else
105153 + return &kallocstat_pass.pass;
105154 +#endif
105155 +}
105156 +
105157 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105158 +{
105159 + const char * const plugin_name = plugin_info->base_name;
105160 + struct register_pass_info kallocstat_pass_info;
105161 +
105162 + kallocstat_pass_info.pass = make_kallocstat_pass();
105163 + kallocstat_pass_info.reference_pass_name = "ssa";
105164 + kallocstat_pass_info.ref_pass_instance_number = 1;
105165 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105166 +
105167 + if (!plugin_default_version_check(version, &gcc_version)) {
105168 + error(G_("incompatible gcc/plugin versions"));
105169 + return 1;
105170 + }
105171 +
105172 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
105173 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
105174 +
105175 + return 0;
105176 +}
105177 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
105178 new file mode 100644
105179 index 0000000..dd73713
105180 --- /dev/null
105181 +++ b/tools/gcc/kernexec_plugin.c
105182 @@ -0,0 +1,519 @@
105183 +/*
105184 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105185 + * Licensed under the GPL v2
105186 + *
105187 + * Note: the choice of the license means that the compilation process is
105188 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105189 + * but for the kernel it doesn't matter since it doesn't link against
105190 + * any of the gcc libraries
105191 + *
105192 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
105193 + *
105194 + * TODO:
105195 + *
105196 + * BUGS:
105197 + * - none known
105198 + */
105199 +
105200 +#include "gcc-common.h"
105201 +
105202 +int plugin_is_GPL_compatible;
105203 +
105204 +static struct plugin_info kernexec_plugin_info = {
105205 + .version = "201401260140",
105206 + .help = "method=[bts|or]\tinstrumentation method\n"
105207 +};
105208 +
105209 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
105210 +static void (*kernexec_instrument_retaddr)(rtx);
105211 +
105212 +/*
105213 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
105214 + */
105215 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
105216 +{
105217 + gimple asm_movabs_stmt;
105218 +
105219 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
105220 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
105221 + gimple_asm_set_volatile(asm_movabs_stmt, true);
105222 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
105223 + update_stmt(asm_movabs_stmt);
105224 +}
105225 +
105226 +/*
105227 + * find all asm() stmts that clobber r12 and add a reload of r12
105228 + */
105229 +static unsigned int execute_kernexec_reload(void)
105230 +{
105231 + basic_block bb;
105232 +
105233 + // 1. loop through BBs and GIMPLE statements
105234 + FOR_EACH_BB_FN(bb, cfun) {
105235 + gimple_stmt_iterator gsi;
105236 +
105237 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105238 + // gimple match: __asm__ ("" : : : "r12");
105239 + gimple asm_stmt;
105240 + size_t nclobbers;
105241 +
105242 + // is it an asm ...
105243 + asm_stmt = gsi_stmt(gsi);
105244 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
105245 + continue;
105246 +
105247 + // ... clobbering r12
105248 + nclobbers = gimple_asm_nclobbers(asm_stmt);
105249 + while (nclobbers--) {
105250 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
105251 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
105252 + continue;
105253 + kernexec_reload_fptr_mask(&gsi);
105254 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
105255 + break;
105256 + }
105257 + }
105258 + }
105259 +
105260 + return 0;
105261 +}
105262 +
105263 +/*
105264 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
105265 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
105266 + */
105267 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
105268 +{
105269 + gimple assign_intptr, assign_new_fptr, call_stmt;
105270 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
105271 +
105272 + call_stmt = gsi_stmt(*gsi);
105273 + old_fptr = gimple_call_fn(call_stmt);
105274 +
105275 + // create temporary unsigned long variable used for bitops and cast fptr to it
105276 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
105277 + add_referenced_var(intptr);
105278 + intptr = make_ssa_name(intptr, NULL);
105279 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
105280 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
105281 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
105282 + update_stmt(assign_intptr);
105283 +
105284 + // apply logical or to temporary unsigned long and bitmask
105285 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
105286 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
105287 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
105288 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
105289 + assign_intptr = gimple_build_assign(intptr, orptr);
105290 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
105291 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
105292 + update_stmt(assign_intptr);
105293 +
105294 + // cast temporary unsigned long back to a temporary fptr variable
105295 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
105296 + add_referenced_var(new_fptr);
105297 + new_fptr = make_ssa_name(new_fptr, NULL);
105298 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
105299 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
105300 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
105301 + update_stmt(assign_new_fptr);
105302 +
105303 + // replace call stmt fn with the new fptr
105304 + gimple_call_set_fn(call_stmt, new_fptr);
105305 + update_stmt(call_stmt);
105306 +}
105307 +
105308 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
105309 +{
105310 + gimple asm_or_stmt, call_stmt;
105311 + tree old_fptr, new_fptr, input, output;
105312 +#if BUILDING_GCC_VERSION <= 4007
105313 + VEC(tree, gc) *inputs = NULL;
105314 + VEC(tree, gc) *outputs = NULL;
105315 +#else
105316 + vec<tree, va_gc> *inputs = NULL;
105317 + vec<tree, va_gc> *outputs = NULL;
105318 +#endif
105319 +
105320 + call_stmt = gsi_stmt(*gsi);
105321 + old_fptr = gimple_call_fn(call_stmt);
105322 +
105323 + // create temporary fptr variable
105324 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
105325 + add_referenced_var(new_fptr);
105326 + new_fptr = make_ssa_name(new_fptr, NULL);
105327 +
105328 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
105329 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
105330 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
105331 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
105332 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
105333 +#if BUILDING_GCC_VERSION <= 4007
105334 + VEC_safe_push(tree, gc, inputs, input);
105335 + VEC_safe_push(tree, gc, outputs, output);
105336 +#else
105337 + vec_safe_push(inputs, input);
105338 + vec_safe_push(outputs, output);
105339 +#endif
105340 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
105341 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
105342 + gimple_asm_set_volatile(asm_or_stmt, true);
105343 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
105344 + update_stmt(asm_or_stmt);
105345 +
105346 + // replace call stmt fn with the new fptr
105347 + gimple_call_set_fn(call_stmt, new_fptr);
105348 + update_stmt(call_stmt);
105349 +}
105350 +
105351 +/*
105352 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
105353 + */
105354 +static unsigned int execute_kernexec_fptr(void)
105355 +{
105356 + basic_block bb;
105357 +
105358 + // 1. loop through BBs and GIMPLE statements
105359 + FOR_EACH_BB_FN(bb, cfun) {
105360 + gimple_stmt_iterator gsi;
105361 +
105362 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105363 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
105364 + tree fn;
105365 + gimple call_stmt;
105366 +
105367 + // is it a call ...
105368 + call_stmt = gsi_stmt(gsi);
105369 + if (!is_gimple_call(call_stmt))
105370 + continue;
105371 + fn = gimple_call_fn(call_stmt);
105372 + if (TREE_CODE(fn) == ADDR_EXPR)
105373 + continue;
105374 + if (TREE_CODE(fn) != SSA_NAME)
105375 + gcc_unreachable();
105376 +
105377 + // ... through a function pointer
105378 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
105379 + fn = SSA_NAME_VAR(fn);
105380 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
105381 + debug_tree(fn);
105382 + gcc_unreachable();
105383 + }
105384 + }
105385 + fn = TREE_TYPE(fn);
105386 + if (TREE_CODE(fn) != POINTER_TYPE)
105387 + continue;
105388 + fn = TREE_TYPE(fn);
105389 + if (TREE_CODE(fn) != FUNCTION_TYPE)
105390 + continue;
105391 +
105392 + kernexec_instrument_fptr(&gsi);
105393 +
105394 +//debug_tree(gimple_call_fn(call_stmt));
105395 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
105396 + }
105397 + }
105398 +
105399 + return 0;
105400 +}
105401 +
105402 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
105403 +static void kernexec_instrument_retaddr_bts(rtx insn)
105404 +{
105405 + rtx btsq;
105406 + rtvec argvec, constraintvec, labelvec;
105407 + int line;
105408 +
105409 + // create asm volatile("btsq $63,(%%rsp)":::)
105410 + argvec = rtvec_alloc(0);
105411 + constraintvec = rtvec_alloc(0);
105412 + labelvec = rtvec_alloc(0);
105413 + line = expand_location(RTL_LOCATION(insn)).line;
105414 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
105415 + MEM_VOLATILE_P(btsq) = 1;
105416 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
105417 + emit_insn_before(btsq, insn);
105418 +}
105419 +
105420 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
105421 +static void kernexec_instrument_retaddr_or(rtx insn)
105422 +{
105423 + rtx orq;
105424 + rtvec argvec, constraintvec, labelvec;
105425 + int line;
105426 +
105427 + // create asm volatile("orq %%r12,(%%rsp)":::)
105428 + argvec = rtvec_alloc(0);
105429 + constraintvec = rtvec_alloc(0);
105430 + labelvec = rtvec_alloc(0);
105431 + line = expand_location(RTL_LOCATION(insn)).line;
105432 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
105433 + MEM_VOLATILE_P(orq) = 1;
105434 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
105435 + emit_insn_before(orq, insn);
105436 +}
105437 +
105438 +/*
105439 + * find all asm level function returns and forcibly set the highest bit of the return address
105440 + */
105441 +static unsigned int execute_kernexec_retaddr(void)
105442 +{
105443 + rtx insn;
105444 +
105445 +// if (stack_realign_drap)
105446 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
105447 +
105448 + // 1. find function returns
105449 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
105450 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
105451 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
105452 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
105453 + rtx body;
105454 +
105455 + // is it a retn
105456 + if (!JUMP_P(insn))
105457 + continue;
105458 + body = PATTERN(insn);
105459 + if (GET_CODE(body) == PARALLEL)
105460 + body = XVECEXP(body, 0, 0);
105461 + if (!ANY_RETURN_P(body))
105462 + continue;
105463 + kernexec_instrument_retaddr(insn);
105464 + }
105465 +
105466 +// print_simple_rtl(stderr, get_insns());
105467 +// print_rtl(stderr, get_insns());
105468 +
105469 + return 0;
105470 +}
105471 +
105472 +static bool kernexec_cmodel_check(void)
105473 +{
105474 + tree section;
105475 +
105476 + if (ix86_cmodel != CM_KERNEL)
105477 + return false;
105478 +
105479 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
105480 + if (!section || !TREE_VALUE(section))
105481 + return true;
105482 +
105483 + section = TREE_VALUE(TREE_VALUE(section));
105484 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
105485 + return true;
105486 +
105487 + return false;
105488 +}
105489 +
105490 +#if BUILDING_GCC_VERSION >= 4009
105491 +static const struct pass_data kernexec_reload_pass_data = {
105492 +#else
105493 +static struct gimple_opt_pass kernexec_reload_pass = {
105494 + .pass = {
105495 +#endif
105496 + .type = GIMPLE_PASS,
105497 + .name = "kernexec_reload",
105498 +#if BUILDING_GCC_VERSION >= 4008
105499 + .optinfo_flags = OPTGROUP_NONE,
105500 +#endif
105501 +#if BUILDING_GCC_VERSION >= 4009
105502 + .has_gate = true,
105503 + .has_execute = true,
105504 +#else
105505 + .gate = kernexec_cmodel_check,
105506 + .execute = execute_kernexec_reload,
105507 + .sub = NULL,
105508 + .next = NULL,
105509 + .static_pass_number = 0,
105510 +#endif
105511 + .tv_id = TV_NONE,
105512 + .properties_required = 0,
105513 + .properties_provided = 0,
105514 + .properties_destroyed = 0,
105515 + .todo_flags_start = 0,
105516 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
105517 +#if BUILDING_GCC_VERSION < 4009
105518 + }
105519 +#endif
105520 +};
105521 +
105522 +#if BUILDING_GCC_VERSION >= 4009
105523 +static const struct pass_data kernexec_fptr_pass_data = {
105524 +#else
105525 +static struct gimple_opt_pass kernexec_fptr_pass = {
105526 + .pass = {
105527 +#endif
105528 + .type = GIMPLE_PASS,
105529 + .name = "kernexec_fptr",
105530 +#if BUILDING_GCC_VERSION >= 4008
105531 + .optinfo_flags = OPTGROUP_NONE,
105532 +#endif
105533 +#if BUILDING_GCC_VERSION >= 4009
105534 + .has_gate = true,
105535 + .has_execute = true,
105536 +#else
105537 + .gate = kernexec_cmodel_check,
105538 + .execute = execute_kernexec_fptr,
105539 + .sub = NULL,
105540 + .next = NULL,
105541 + .static_pass_number = 0,
105542 +#endif
105543 + .tv_id = TV_NONE,
105544 + .properties_required = 0,
105545 + .properties_provided = 0,
105546 + .properties_destroyed = 0,
105547 + .todo_flags_start = 0,
105548 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
105549 +#if BUILDING_GCC_VERSION < 4009
105550 + }
105551 +#endif
105552 +};
105553 +
105554 +#if BUILDING_GCC_VERSION >= 4009
105555 +static const struct pass_data kernexec_retaddr_pass_data = {
105556 +#else
105557 +static struct rtl_opt_pass kernexec_retaddr_pass = {
105558 + .pass = {
105559 +#endif
105560 + .type = RTL_PASS,
105561 + .name = "kernexec_retaddr",
105562 +#if BUILDING_GCC_VERSION >= 4008
105563 + .optinfo_flags = OPTGROUP_NONE,
105564 +#endif
105565 +#if BUILDING_GCC_VERSION >= 4009
105566 + .has_gate = true,
105567 + .has_execute = true,
105568 +#else
105569 + .gate = kernexec_cmodel_check,
105570 + .execute = execute_kernexec_retaddr,
105571 + .sub = NULL,
105572 + .next = NULL,
105573 + .static_pass_number = 0,
105574 +#endif
105575 + .tv_id = TV_NONE,
105576 + .properties_required = 0,
105577 + .properties_provided = 0,
105578 + .properties_destroyed = 0,
105579 + .todo_flags_start = 0,
105580 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
105581 +#if BUILDING_GCC_VERSION < 4009
105582 + }
105583 +#endif
105584 +};
105585 +
105586 +#if BUILDING_GCC_VERSION >= 4009
105587 +namespace {
105588 +class kernexec_reload_pass : public gimple_opt_pass {
105589 +public:
105590 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
105591 + bool gate() { return kernexec_cmodel_check(); }
105592 + unsigned int execute() { return execute_kernexec_reload(); }
105593 +};
105594 +
105595 +class kernexec_fptr_pass : public gimple_opt_pass {
105596 +public:
105597 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
105598 + bool gate() { return kernexec_cmodel_check(); }
105599 + unsigned int execute() { return execute_kernexec_fptr(); }
105600 +};
105601 +
105602 +class kernexec_retaddr_pass : public rtl_opt_pass {
105603 +public:
105604 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
105605 + bool gate() { return kernexec_cmodel_check(); }
105606 + unsigned int execute() { return execute_kernexec_retaddr(); }
105607 +};
105608 +}
105609 +#endif
105610 +
105611 +static struct opt_pass *make_kernexec_reload_pass(void)
105612 +{
105613 +#if BUILDING_GCC_VERSION >= 4009
105614 + return new kernexec_reload_pass();
105615 +#else
105616 + return &kernexec_reload_pass.pass;
105617 +#endif
105618 +}
105619 +
105620 +static struct opt_pass *make_kernexec_fptr_pass(void)
105621 +{
105622 +#if BUILDING_GCC_VERSION >= 4009
105623 + return new kernexec_fptr_pass();
105624 +#else
105625 + return &kernexec_fptr_pass.pass;
105626 +#endif
105627 +}
105628 +
105629 +static struct opt_pass *make_kernexec_retaddr_pass(void)
105630 +{
105631 +#if BUILDING_GCC_VERSION >= 4009
105632 + return new kernexec_retaddr_pass();
105633 +#else
105634 + return &kernexec_retaddr_pass.pass;
105635 +#endif
105636 +}
105637 +
105638 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105639 +{
105640 + const char * const plugin_name = plugin_info->base_name;
105641 + const int argc = plugin_info->argc;
105642 + const struct plugin_argument * const argv = plugin_info->argv;
105643 + int i;
105644 + struct register_pass_info kernexec_reload_pass_info;
105645 + struct register_pass_info kernexec_fptr_pass_info;
105646 + struct register_pass_info kernexec_retaddr_pass_info;
105647 +
105648 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
105649 + kernexec_reload_pass_info.reference_pass_name = "ssa";
105650 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
105651 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105652 +
105653 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
105654 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
105655 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
105656 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105657 +
105658 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
105659 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
105660 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
105661 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105662 +
105663 + if (!plugin_default_version_check(version, &gcc_version)) {
105664 + error(G_("incompatible gcc/plugin versions"));
105665 + return 1;
105666 + }
105667 +
105668 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
105669 +
105670 + if (TARGET_64BIT == 0)
105671 + return 0;
105672 +
105673 + for (i = 0; i < argc; ++i) {
105674 + if (!strcmp(argv[i].key, "method")) {
105675 + if (!argv[i].value) {
105676 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105677 + continue;
105678 + }
105679 + if (!strcmp(argv[i].value, "bts")) {
105680 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
105681 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
105682 + } else if (!strcmp(argv[i].value, "or")) {
105683 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
105684 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
105685 + fix_register("r12", 1, 1);
105686 + } else
105687 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
105688 + continue;
105689 + }
105690 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105691 + }
105692 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
105693 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
105694 +
105695 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
105696 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
105697 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
105698 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
105699 +
105700 + return 0;
105701 +}
105702 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
105703 new file mode 100644
105704 index 0000000..f04b680
105705 --- /dev/null
105706 +++ b/tools/gcc/latent_entropy_plugin.c
105707 @@ -0,0 +1,325 @@
105708 +/*
105709 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
105710 + * Licensed under the GPL v2
105711 + *
105712 + * Note: the choice of the license means that the compilation process is
105713 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105714 + * but for the kernel it doesn't matter since it doesn't link against
105715 + * any of the gcc libraries
105716 + *
105717 + * gcc plugin to help generate a little bit of entropy from program state,
105718 + * used during boot in the kernel
105719 + *
105720 + * TODO:
105721 + * - add ipa pass to identify not explicitly marked candidate functions
105722 + * - mix in more program state (function arguments/return values, loop variables, etc)
105723 + * - more instrumentation control via attribute parameters
105724 + *
105725 + * BUGS:
105726 + * - LTO needs -flto-partition=none for now
105727 + */
105728 +
105729 +#include "gcc-common.h"
105730 +
105731 +int plugin_is_GPL_compatible;
105732 +
105733 +static tree latent_entropy_decl;
105734 +
105735 +static struct plugin_info latent_entropy_plugin_info = {
105736 + .version = "201401260140",
105737 + .help = NULL
105738 +};
105739 +
105740 +static unsigned HOST_WIDE_INT seed;
105741 +static unsigned HOST_WIDE_INT get_random_const(void)
105742 +{
105743 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
105744 + return seed;
105745 +}
105746 +
105747 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105748 +{
105749 + switch (TREE_CODE(*node)) {
105750 + default:
105751 + *no_add_attrs = true;
105752 + error("%qE attribute only applies to functions and variables", name);
105753 + break;
105754 +
105755 + case VAR_DECL:
105756 + if (DECL_INITIAL(*node)) {
105757 + *no_add_attrs = true;
105758 + error("variable %qD with %qE attribute must not be initialized", *node, name);
105759 + break;
105760 + }
105761 + DECL_INITIAL(*node) = build_int_cstu(long_long_unsigned_type_node, get_random_const());
105762 + break;
105763 +
105764 + case FUNCTION_DECL:
105765 + break;
105766 + }
105767 +
105768 + return NULL_TREE;
105769 +}
105770 +
105771 +static struct attribute_spec latent_entropy_attr = {
105772 + .name = "latent_entropy",
105773 + .min_length = 0,
105774 + .max_length = 0,
105775 + .decl_required = true,
105776 + .type_required = false,
105777 + .function_type_required = false,
105778 + .handler = handle_latent_entropy_attribute,
105779 +#if BUILDING_GCC_VERSION >= 4007
105780 + .affects_type_identity = false
105781 +#endif
105782 +};
105783 +
105784 +static void register_attributes(void *event_data, void *data)
105785 +{
105786 + register_attribute(&latent_entropy_attr);
105787 +}
105788 +
105789 +static bool gate_latent_entropy(void)
105790 +{
105791 + tree latent_entropy_attr;
105792 +
105793 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
105794 + return latent_entropy_attr != NULL_TREE;
105795 +}
105796 +
105797 +static enum tree_code get_op(tree *rhs)
105798 +{
105799 + static enum tree_code op;
105800 + unsigned HOST_WIDE_INT random_const;
105801 +
105802 + random_const = get_random_const();
105803 +
105804 + switch (op) {
105805 + case BIT_XOR_EXPR:
105806 + op = PLUS_EXPR;
105807 + break;
105808 +
105809 + case PLUS_EXPR:
105810 + if (rhs) {
105811 + op = LROTATE_EXPR;
105812 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
105813 + break;
105814 + }
105815 +
105816 + case LROTATE_EXPR:
105817 + default:
105818 + op = BIT_XOR_EXPR;
105819 + break;
105820 + }
105821 + if (rhs)
105822 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
105823 + return op;
105824 +}
105825 +
105826 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
105827 +{
105828 + gimple_stmt_iterator gsi;
105829 + gimple assign;
105830 + tree addxorrol, rhs;
105831 + enum tree_code op;
105832 +
105833 + op = get_op(&rhs);
105834 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
105835 + assign = gimple_build_assign(local_entropy, addxorrol);
105836 + gsi = gsi_after_labels(bb);
105837 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
105838 + update_stmt(assign);
105839 +//debug_bb(bb);
105840 +}
105841 +
105842 +static void perturb_latent_entropy(basic_block bb, tree rhs)
105843 +{
105844 + gimple_stmt_iterator gsi;
105845 + gimple assign;
105846 + tree addxorrol, temp;
105847 +
105848 + // 1. create temporary copy of latent_entropy
105849 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
105850 + add_referenced_var(temp);
105851 +
105852 + // 2. read...
105853 + temp = make_ssa_name(temp, NULL);
105854 + assign = gimple_build_assign(temp, latent_entropy_decl);
105855 + SSA_NAME_DEF_STMT(temp) = assign;
105856 + add_referenced_var(latent_entropy_decl);
105857 + gsi = gsi_after_labels(bb);
105858 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
105859 + update_stmt(assign);
105860 +
105861 + // 3. ...modify...
105862 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
105863 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
105864 + assign = gimple_build_assign(temp, addxorrol);
105865 + SSA_NAME_DEF_STMT(temp) = assign;
105866 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
105867 + update_stmt(assign);
105868 +
105869 + // 4. ...write latent_entropy
105870 + assign = gimple_build_assign(latent_entropy_decl, temp);
105871 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
105872 + update_stmt(assign);
105873 +}
105874 +
105875 +static unsigned int execute_latent_entropy(void)
105876 +{
105877 + basic_block bb;
105878 + gimple assign;
105879 + gimple_stmt_iterator gsi;
105880 + tree local_entropy;
105881 +
105882 + if (!latent_entropy_decl) {
105883 + struct varpool_node *node;
105884 +
105885 + FOR_EACH_VARIABLE(node) {
105886 + tree var = NODE_DECL(node);
105887 +
105888 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
105889 + continue;
105890 + latent_entropy_decl = var;
105891 +// debug_tree(var);
105892 + break;
105893 + }
105894 + if (!latent_entropy_decl) {
105895 +// debug_tree(current_function_decl);
105896 + return 0;
105897 + }
105898 + }
105899 +
105900 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
105901 +
105902 + // 1. create local entropy variable
105903 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
105904 + add_referenced_var(local_entropy);
105905 + mark_sym_for_renaming(local_entropy);
105906 +
105907 + // 2. initialize local entropy variable
105908 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
105909 + if (dom_info_available_p(CDI_DOMINATORS))
105910 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
105911 + gsi = gsi_start_bb(bb);
105912 +
105913 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
105914 +// gimple_set_location(assign, loc);
105915 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
105916 + update_stmt(assign);
105917 +//debug_bb(bb);
105918 + bb = bb->next_bb;
105919 +
105920 + // 3. instrument each BB with an operation on the local entropy variable
105921 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
105922 + perturb_local_entropy(bb, local_entropy);
105923 +//debug_bb(bb);
105924 + bb = bb->next_bb;
105925 + };
105926 +
105927 + // 4. mix local entropy into the global entropy variable
105928 + perturb_latent_entropy(EXIT_BLOCK_PTR_FOR_FN(cfun)->prev_bb, local_entropy);
105929 +//debug_bb(EXIT_BLOCK_PTR_FOR_FN(cfun)->prev_bb);
105930 + return 0;
105931 +}
105932 +
105933 +static void start_unit_callback(void *gcc_data, void *user_data)
105934 +{
105935 + tree latent_entropy_type;
105936 +
105937 + seed = get_random_seed(false);
105938 +
105939 + if (in_lto_p)
105940 + return;
105941 +
105942 + // extern volatile u64 latent_entropy
105943 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
105944 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
105945 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
105946 +
105947 + TREE_STATIC(latent_entropy_decl) = 1;
105948 + TREE_PUBLIC(latent_entropy_decl) = 1;
105949 + TREE_USED(latent_entropy_decl) = 1;
105950 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
105951 + DECL_EXTERNAL(latent_entropy_decl) = 1;
105952 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
105953 + lang_hooks.decls.pushdecl(latent_entropy_decl);
105954 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
105955 +// varpool_finalize_decl(latent_entropy_decl);
105956 +// varpool_mark_needed_node(latent_entropy_decl);
105957 +}
105958 +
105959 +#if BUILDING_GCC_VERSION >= 4009
105960 +static const struct pass_data latent_entropy_pass_data = {
105961 +#else
105962 +static struct gimple_opt_pass latent_entropy_pass = {
105963 + .pass = {
105964 +#endif
105965 + .type = GIMPLE_PASS,
105966 + .name = "latent_entropy",
105967 +#if BUILDING_GCC_VERSION >= 4008
105968 + .optinfo_flags = OPTGROUP_NONE,
105969 +#endif
105970 +#if BUILDING_GCC_VERSION >= 4009
105971 + .has_gate = true,
105972 + .has_execute = true,
105973 +#else
105974 + .gate = gate_latent_entropy,
105975 + .execute = execute_latent_entropy,
105976 + .sub = NULL,
105977 + .next = NULL,
105978 + .static_pass_number = 0,
105979 +#endif
105980 + .tv_id = TV_NONE,
105981 + .properties_required = PROP_gimple_leh | PROP_cfg,
105982 + .properties_provided = 0,
105983 + .properties_destroyed = 0,
105984 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
105985 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
105986 +#if BUILDING_GCC_VERSION < 4009
105987 + }
105988 +#endif
105989 +};
105990 +
105991 +#if BUILDING_GCC_VERSION >= 4009
105992 +namespace {
105993 +class latent_entropy_pass : public gimple_opt_pass {
105994 +public:
105995 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
105996 + bool gate() { return gate_latent_entropy(); }
105997 + unsigned int execute() { return execute_latent_entropy(); }
105998 +};
105999 +}
106000 +#endif
106001 +
106002 +static struct opt_pass *make_latent_entropy_pass(void)
106003 +{
106004 +#if BUILDING_GCC_VERSION >= 4009
106005 + return new latent_entropy_pass();
106006 +#else
106007 + return &latent_entropy_pass.pass;
106008 +#endif
106009 +}
106010 +
106011 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106012 +{
106013 + const char * const plugin_name = plugin_info->base_name;
106014 + struct register_pass_info latent_entropy_pass_info;
106015 +
106016 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
106017 + latent_entropy_pass_info.reference_pass_name = "optimized";
106018 + latent_entropy_pass_info.ref_pass_instance_number = 1;
106019 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
106020 +
106021 + if (!plugin_default_version_check(version, &gcc_version)) {
106022 + error(G_("incompatible gcc/plugin versions"));
106023 + return 1;
106024 + }
106025 +
106026 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
106027 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
106028 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
106029 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106030 +
106031 + return 0;
106032 +}
106033 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
106034 new file mode 100644
106035 index 0000000..bc4aefd
106036 --- /dev/null
106037 +++ b/tools/gcc/randomize_layout_plugin.c
106038 @@ -0,0 +1,891 @@
106039 +/*
106040 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
106041 + * and PaX Team <pageexec@freemail.hu>
106042 + * Licensed under the GPL v2
106043 + *
106044 + * Usage:
106045 + * $ # for 4.5/4.6/C based 4.7
106046 + * $ 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
106047 + * $ # for C++ based 4.7/4.8+
106048 + * $ 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
106049 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
106050 + */
106051 +
106052 +#include "gcc-common.h"
106053 +
106054 +#define ORIG_TYPE_NAME(node) \
106055 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
106056 +
106057 +int plugin_is_GPL_compatible;
106058 +
106059 +static int performance_mode;
106060 +
106061 +static struct plugin_info randomize_layout_plugin_info = {
106062 + .version = "201402011940",
106063 + .help = "disable\t\t\tdo not activate plugin\n"
106064 + "seed\t\t\tprovide a required 64-byte seed in hex format\n"
106065 + "performance-mode\tenable cacheline-aware layout randomization\n"
106066 +};
106067 +
106068 +/* from old Linux dcache.h */
106069 +static inline unsigned long
106070 +partial_name_hash(unsigned long c, unsigned long prevhash)
106071 +{
106072 + return (prevhash + (c << 4) + (c >> 4)) * 11;
106073 +}
106074 +static inline unsigned int
106075 +name_hash(const unsigned char *name)
106076 +{
106077 + unsigned long hash = 0;
106078 + unsigned int len = strlen((const char *)name);
106079 + while (len--)
106080 + hash = partial_name_hash(*name++, hash);
106081 + return (unsigned int)hash;
106082 +}
106083 +
106084 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106085 +{
106086 + tree type;
106087 +
106088 + *no_add_attrs = true;
106089 + if (TREE_CODE(*node) == FUNCTION_DECL) {
106090 + error("%qE attribute does not apply to functions (%qF)", name, *node);
106091 + return NULL_TREE;
106092 + }
106093 +
106094 + if (TREE_CODE(*node) == PARM_DECL) {
106095 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
106096 + return NULL_TREE;
106097 + }
106098 +
106099 + if (TREE_CODE(*node) == VAR_DECL) {
106100 + error("%qE attribute does not apply to variables (%qD)", name, *node);
106101 + return NULL_TREE;
106102 + }
106103 +
106104 + if (TYPE_P(*node)) {
106105 + type = *node;
106106 + } else {
106107 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
106108 + type = TREE_TYPE(*node);
106109 + }
106110 +
106111 + if (TREE_CODE(type) != RECORD_TYPE) {
106112 + error("%qE attribute used on %qT applies to struct types only", name, type);
106113 + return NULL_TREE;
106114 + }
106115 +
106116 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
106117 + error("%qE attribute is already applied to the type %qT", name, type);
106118 + return NULL_TREE;
106119 + }
106120 +
106121 + *no_add_attrs = false;
106122 +
106123 + return NULL_TREE;
106124 +}
106125 +
106126 +/* set on complete types that we don't need to inspect further at all */
106127 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106128 +{
106129 + *no_add_attrs = false;
106130 + return NULL_TREE;
106131 +}
106132 +
106133 +/*
106134 + * set on types that we've performed a shuffle on, to prevent re-shuffling
106135 + * this does not preclude us from inspecting its fields for potential shuffles
106136 + */
106137 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106138 +{
106139 + *no_add_attrs = false;
106140 + return NULL_TREE;
106141 +}
106142 +
106143 +/*
106144 + * 64bit variant of Bob Jenkins' public domain PRNG
106145 + * 256 bits of internal state
106146 + */
106147 +
106148 +typedef unsigned long long u64;
106149 +
106150 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
106151 +
106152 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
106153 +static u64 ranval(ranctx *x) {
106154 + u64 e = x->a - rot(x->b, 7);
106155 + x->a = x->b ^ rot(x->c, 13);
106156 + x->b = x->c + rot(x->d, 37);
106157 + x->c = x->d + e;
106158 + x->d = e + x->a;
106159 + return x->d;
106160 +}
106161 +
106162 +static void raninit(ranctx *x, u64 *seed) {
106163 + int i;
106164 +
106165 + x->a = seed[0];
106166 + x->b = seed[1];
106167 + x->c = seed[2];
106168 + x->d = seed[3];
106169 +
106170 + for (i=0; i < 30; ++i)
106171 + (void)ranval(x);
106172 +}
106173 +
106174 +static u64 shuffle_seed[4];
106175 +
106176 +struct partition_group {
106177 + tree tree_start;
106178 + unsigned long start;
106179 + unsigned long length;
106180 +};
106181 +
106182 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
106183 +{
106184 + unsigned long i;
106185 + unsigned long accum_size = 0;
106186 + unsigned long accum_length = 0;
106187 + unsigned long group_idx = 0;
106188 +
106189 + gcc_assert(length < INT_MAX);
106190 +
106191 + memset(size_groups, 0, sizeof(struct partition_group) * length);
106192 +
106193 + for (i = 0; i < length; i++) {
106194 + if (size_groups[group_idx].tree_start == NULL_TREE) {
106195 + size_groups[group_idx].tree_start = fields[i];
106196 + size_groups[group_idx].start = i;
106197 + accum_length = 0;
106198 + accum_size = 0;
106199 + }
106200 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
106201 + accum_length++;
106202 + if (accum_size >= 64) {
106203 + size_groups[group_idx].length = accum_length;
106204 + accum_length = 0;
106205 + group_idx++;
106206 + }
106207 + }
106208 +
106209 + if (size_groups[group_idx].tree_start != NULL_TREE &&
106210 + !size_groups[group_idx].length) {
106211 + size_groups[group_idx].length = accum_length;
106212 + group_idx++;
106213 + }
106214 +
106215 + *num_groups = group_idx;
106216 +}
106217 +
106218 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
106219 +{
106220 + unsigned long i, x;
106221 + struct partition_group size_group[length];
106222 + unsigned long num_groups = 0;
106223 + unsigned long randnum;
106224 +
106225 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
106226 + for (i = num_groups - 1; i > 0; i--) {
106227 + struct partition_group tmp;
106228 + randnum = ranval(prng_state) % (i + 1);
106229 + tmp = size_group[i];
106230 + size_group[i] = size_group[randnum];
106231 + size_group[randnum] = tmp;
106232 + }
106233 +
106234 + for (x = 0; x < num_groups; x++) {
106235 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
106236 + tree tmp;
106237 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
106238 + continue;
106239 + randnum = ranval(prng_state) % (i + 1);
106240 + // we could handle this case differently if desired
106241 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
106242 + continue;
106243 + tmp = newtree[i];
106244 + newtree[i] = newtree[randnum];
106245 + newtree[randnum] = tmp;
106246 + }
106247 + }
106248 +}
106249 +
106250 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
106251 +{
106252 + unsigned long i, randnum;
106253 +
106254 + for (i = length - 1; i > 0; i--) {
106255 + tree tmp;
106256 + randnum = ranval(prng_state) % (i + 1);
106257 + tmp = newtree[i];
106258 + newtree[i] = newtree[randnum];
106259 + newtree[randnum] = tmp;
106260 + }
106261 +}
106262 +
106263 +/* modern in-place Fisher-Yates shuffle */
106264 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
106265 +{
106266 + unsigned long i;
106267 + u64 seed[4];
106268 + ranctx prng_state;
106269 + const unsigned char *structname;
106270 +
106271 + if (length == 0)
106272 + return;
106273 +
106274 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106275 +
106276 + structname = ORIG_TYPE_NAME(type);
106277 +
106278 +#ifdef __DEBUG_PLUGIN
106279 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
106280 +#ifdef __DEBUG_VERBOSE
106281 + debug_tree((tree)type);
106282 +#endif
106283 +#endif
106284 +
106285 + for (i = 0; i < 4; i++) {
106286 + seed[i] = shuffle_seed[i];
106287 + seed[i] ^= name_hash(structname);
106288 + }
106289 +
106290 + raninit(&prng_state, (u64 *)&seed);
106291 +
106292 + if (performance_mode)
106293 + performance_shuffle(newtree, length, &prng_state);
106294 + else
106295 + full_shuffle(newtree, length, &prng_state);
106296 +}
106297 +
106298 +static bool is_flexible_array(const_tree field)
106299 +{
106300 + const_tree fieldtype;
106301 + const_tree typesize;
106302 + const_tree elemtype;
106303 + const_tree elemsize;
106304 +
106305 + fieldtype = TREE_TYPE(field);
106306 + typesize = TYPE_SIZE(fieldtype);
106307 +
106308 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
106309 + return false;
106310 +
106311 + elemtype = TREE_TYPE(fieldtype);
106312 + elemsize = TYPE_SIZE(elemtype);
106313 +
106314 + /* size of type is represented in bits */
106315 +
106316 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
106317 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
106318 + return true;
106319 +
106320 + if (typesize != NULL_TREE &&
106321 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
106322 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
106323 + return true;
106324 +
106325 + return false;
106326 +}
106327 +
106328 +static int relayout_struct(tree type)
106329 +{
106330 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
106331 + unsigned long shuffle_length = num_fields;
106332 + tree field;
106333 + tree newtree[num_fields];
106334 + unsigned long i;
106335 + tree list;
106336 + tree variant;
106337 + expanded_location xloc;
106338 +
106339 + if (TYPE_FIELDS(type) == NULL_TREE)
106340 + return 0;
106341 +
106342 + if (num_fields < 2)
106343 + return 0;
106344 +
106345 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106346 +
106347 + gcc_assert(num_fields < INT_MAX);
106348 +
106349 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
106350 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
106351 + return 0;
106352 +
106353 + /* throw out any structs in uapi */
106354 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
106355 +
106356 + if (strstr(xloc.file, "/uapi/"))
106357 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
106358 +
106359 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
106360 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
106361 + newtree[i] = field;
106362 + }
106363 +
106364 + /*
106365 + * enforce that we don't randomize the layout of the last
106366 + * element of a struct if it's a 0 or 1-length array
106367 + * or a proper flexible array
106368 + */
106369 + if (is_flexible_array(newtree[num_fields - 1]))
106370 + shuffle_length--;
106371 +
106372 + shuffle(type, (tree *)newtree, shuffle_length);
106373 +
106374 + /*
106375 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
106376 + * as gcc provides no other way to detect such code
106377 + */
106378 + list = make_node(FIELD_DECL);
106379 + TREE_CHAIN(list) = newtree[0];
106380 + TREE_TYPE(list) = void_type_node;
106381 + DECL_SIZE(list) = bitsize_zero_node;
106382 + DECL_NONADDRESSABLE_P(list) = 1;
106383 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
106384 + DECL_SIZE_UNIT(list) = size_zero_node;
106385 + DECL_FIELD_OFFSET(list) = size_zero_node;
106386 + // to satisfy the constify plugin
106387 + TREE_READONLY(list) = 1;
106388 +
106389 + for (i = 0; i < num_fields - 1; i++)
106390 + TREE_CHAIN(newtree[i]) = newtree[i+1];
106391 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
106392 +
106393 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
106394 + TYPE_FIELDS(variant) = list;
106395 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
106396 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
106397 + // force a re-layout
106398 + TYPE_SIZE(variant) = NULL_TREE;
106399 + layout_type(variant);
106400 + }
106401 +
106402 + return 1;
106403 +}
106404 +
106405 +/* from constify plugin */
106406 +static const_tree get_field_type(const_tree field)
106407 +{
106408 + return strip_array_types(TREE_TYPE(field));
106409 +}
106410 +
106411 +/* from constify plugin */
106412 +static bool is_fptr(const_tree fieldtype)
106413 +{
106414 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
106415 + return false;
106416 +
106417 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
106418 +}
106419 +
106420 +/* derived from constify plugin */
106421 +static int is_pure_ops_struct(const_tree node)
106422 +{
106423 + const_tree field;
106424 +
106425 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
106426 +
106427 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
106428 + const_tree fieldtype = get_field_type(field);
106429 + enum tree_code code = TREE_CODE(fieldtype);
106430 +
106431 + if (node == fieldtype)
106432 + continue;
106433 +
106434 + if (!is_fptr(fieldtype))
106435 + return 0;
106436 +
106437 + if (code != RECORD_TYPE && code != UNION_TYPE)
106438 + continue;
106439 +
106440 + if (!is_pure_ops_struct(fieldtype))
106441 + return 0;
106442 + }
106443 +
106444 + return 1;
106445 +}
106446 +
106447 +static void randomize_type(tree type)
106448 +{
106449 + tree variant;
106450 +
106451 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106452 +
106453 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
106454 + return;
106455 +
106456 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
106457 + relayout_struct(type);
106458 +
106459 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
106460 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
106461 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
106462 + }
106463 +#ifdef __DEBUG_PLUGIN
106464 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
106465 +#ifdef __DEBUG_VERBOSE
106466 + debug_tree(type);
106467 +#endif
106468 +#endif
106469 +}
106470 +
106471 +static void finish_type(void *event_data, void *data)
106472 +{
106473 + tree type = (tree)event_data;
106474 +
106475 + if (type == NULL_TREE || type == error_mark_node)
106476 + return;
106477 +
106478 + if (TREE_CODE(type) != RECORD_TYPE)
106479 + return;
106480 +
106481 + if (TYPE_FIELDS(type) == NULL_TREE)
106482 + return;
106483 +
106484 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
106485 + return;
106486 +
106487 +#ifdef __DEBUG_PLUGIN
106488 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
106489 +#endif
106490 +#ifdef __DEBUG_VERBOSE
106491 + debug_tree(type);
106492 +#endif
106493 + randomize_type(type);
106494 +
106495 + return;
106496 +}
106497 +
106498 +static struct attribute_spec randomize_layout_attr = {
106499 + .name = "randomize_layout",
106500 + // related to args
106501 + .min_length = 0,
106502 + .max_length = 0,
106503 + .decl_required = false,
106504 + // need type declaration
106505 + .type_required = true,
106506 + .function_type_required = false,
106507 + .handler = handle_randomize_layout_attr,
106508 +#if BUILDING_GCC_VERSION >= 4007
106509 + .affects_type_identity = true
106510 +#endif
106511 +};
106512 +
106513 +static struct attribute_spec no_randomize_layout_attr = {
106514 + .name = "no_randomize_layout",
106515 + // related to args
106516 + .min_length = 0,
106517 + .max_length = 0,
106518 + .decl_required = false,
106519 + // need type declaration
106520 + .type_required = true,
106521 + .function_type_required = false,
106522 + .handler = handle_randomize_layout_attr,
106523 +#if BUILDING_GCC_VERSION >= 4007
106524 + .affects_type_identity = true
106525 +#endif
106526 +};
106527 +
106528 +static struct attribute_spec randomize_considered_attr = {
106529 + .name = "randomize_considered",
106530 + // related to args
106531 + .min_length = 0,
106532 + .max_length = 0,
106533 + .decl_required = false,
106534 + // need type declaration
106535 + .type_required = true,
106536 + .function_type_required = false,
106537 + .handler = handle_randomize_considered_attr,
106538 +#if BUILDING_GCC_VERSION >= 4007
106539 + .affects_type_identity = false
106540 +#endif
106541 +};
106542 +
106543 +static struct attribute_spec randomize_performed_attr = {
106544 + .name = "randomize_performed",
106545 + // related to args
106546 + .min_length = 0,
106547 + .max_length = 0,
106548 + .decl_required = false,
106549 + // need type declaration
106550 + .type_required = true,
106551 + .function_type_required = false,
106552 + .handler = handle_randomize_performed_attr,
106553 +#if BUILDING_GCC_VERSION >= 4007
106554 + .affects_type_identity = false
106555 +#endif
106556 +};
106557 +
106558 +static void register_attributes(void *event_data, void *data)
106559 +{
106560 + register_attribute(&randomize_layout_attr);
106561 + register_attribute(&no_randomize_layout_attr);
106562 + register_attribute(&randomize_considered_attr);
106563 + register_attribute(&randomize_performed_attr);
106564 +}
106565 +
106566 +static void check_bad_casts_in_constructor(tree var, tree init)
106567 +{
106568 + unsigned HOST_WIDE_INT idx;
106569 + tree field, val;
106570 + tree field_type, val_type;
106571 +
106572 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
106573 + if (TREE_CODE(val) == CONSTRUCTOR) {
106574 + check_bad_casts_in_constructor(var, val);
106575 + continue;
106576 + }
106577 +
106578 + field_type = TREE_TYPE(field);
106579 + val_type = TREE_TYPE(val);
106580 +
106581 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
106582 + continue;
106583 +
106584 + if (field_type == val_type)
106585 + continue;
106586 +
106587 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
106588 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
106589 +
106590 + if (field_type == void_type_node)
106591 + continue;
106592 + if (field_type == val_type)
106593 + continue;
106594 + if (TREE_CODE(val_type) != RECORD_TYPE)
106595 + continue;
106596 +
106597 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
106598 + continue;
106599 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
106600 + }
106601 +}
106602 +
106603 +/* derived from the constify plugin */
106604 +static void check_global_variables(void *event_data, void *data)
106605 +{
106606 + struct varpool_node *node;
106607 + tree init;
106608 +
106609 +#if BUILDING_GCC_VERSION <= 4007
106610 + for (node = varpool_nodes; node; node = node->next) {
106611 + tree var = node->decl;
106612 +#else
106613 + FOR_EACH_VARIABLE(node) {
106614 + tree var = node->symbol.decl;
106615 +#endif
106616 + init = DECL_INITIAL(var);
106617 + if (init == NULL_TREE)
106618 + continue;
106619 +
106620 + if (TREE_CODE(init) != CONSTRUCTOR)
106621 + continue;
106622 +
106623 + check_bad_casts_in_constructor(var, init);
106624 + }
106625 +}
106626 +
106627 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
106628 +{
106629 + basic_block dom;
106630 + gimple dom_stmt;
106631 + gimple call_stmt;
106632 + const_tree dom_lhs;
106633 + const_tree poss_is_err_cond;
106634 + const_tree poss_is_err_func;
106635 + const_tree is_err_arg;
106636 +
106637 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
106638 + if (!dom)
106639 + return false;
106640 +
106641 + dom_stmt = last_stmt(dom);
106642 + if (!dom_stmt)
106643 + return false;
106644 +
106645 + if (gimple_code(dom_stmt) != GIMPLE_COND)
106646 + return false;
106647 +
106648 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
106649 + return false;
106650 +
106651 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
106652 + return false;
106653 +
106654 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
106655 +
106656 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
106657 + return false;
106658 +
106659 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
106660 +
106661 + if (gimple_code(call_stmt) != GIMPLE_CALL)
106662 + return false;
106663 +
106664 + dom_lhs = gimple_get_lhs(call_stmt);
106665 + poss_is_err_func = gimple_call_fndecl(call_stmt);
106666 + if (!poss_is_err_func)
106667 + return false;
106668 + if (dom_lhs != poss_is_err_cond)
106669 + return false;
106670 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
106671 + return false;
106672 +
106673 + is_err_arg = gimple_call_arg(call_stmt, 0);
106674 + if (!is_err_arg)
106675 + return false;
106676 +
106677 + if (is_err_arg != rhs)
106678 + return false;
106679 +
106680 + return true;
106681 +}
106682 +
106683 +static void handle_local_var_initializers(void)
106684 +{
106685 + tree var;
106686 + unsigned int i;
106687 +
106688 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
106689 + tree init = DECL_INITIAL(var);
106690 + if (!init)
106691 + continue;
106692 + if (TREE_CODE(init) != CONSTRUCTOR)
106693 + continue;
106694 + check_bad_casts_in_constructor(var, init);
106695 + }
106696 +}
106697 +
106698 +/*
106699 + * iterate over all statements to find "bad" casts:
106700 + * those where the address of the start of a structure is cast
106701 + * to a pointer of a structure of a different type, or a
106702 + * structure pointer type is cast to a different structure pointer type
106703 + */
106704 +static unsigned int find_bad_casts(void)
106705 +{
106706 + basic_block bb;
106707 +
106708 + handle_local_var_initializers();
106709 +
106710 + FOR_ALL_BB_FN(bb, cfun) {
106711 + gimple_stmt_iterator gsi;
106712 +
106713 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106714 + gimple stmt;
106715 + const_tree lhs;
106716 + const_tree lhs_type;
106717 + const_tree rhs1;
106718 + const_tree rhs_type;
106719 + const_tree ptr_lhs_type;
106720 + const_tree ptr_rhs_type;
106721 + const_tree op0;
106722 + const_tree op0_type;
106723 + enum tree_code rhs_code;
106724 +
106725 + stmt = gsi_stmt(gsi);
106726 +
106727 +#ifdef __DEBUG_PLUGIN
106728 +#ifdef __DEBUG_VERBOSE
106729 + debug_gimple_stmt(stmt);
106730 + debug_tree(gimple_get_lhs(stmt));
106731 +#endif
106732 +#endif
106733 +
106734 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
106735 + continue;
106736 +
106737 +#ifdef __DEBUG_PLUGIN
106738 +#ifdef __DEBUG_VERBOSE
106739 + debug_tree(gimple_assign_rhs1(stmt));
106740 +#endif
106741 +#endif
106742 +
106743 + rhs_code = gimple_assign_rhs_code(stmt);
106744 +
106745 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
106746 + continue;
106747 +
106748 + lhs = gimple_get_lhs(stmt);
106749 + lhs_type = TREE_TYPE(lhs);
106750 + rhs1 = gimple_assign_rhs1(stmt);
106751 + rhs_type = TREE_TYPE(rhs1);
106752 +
106753 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
106754 + TREE_CODE(lhs_type) != POINTER_TYPE)
106755 + continue;
106756 +
106757 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
106758 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
106759 +
106760 + if (ptr_rhs_type == void_type_node)
106761 + continue;
106762 +
106763 + if (ptr_lhs_type == void_type_node)
106764 + continue;
106765 +
106766 + if (dominated_by_is_err(rhs1, bb))
106767 + continue;
106768 +
106769 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
106770 +#ifndef __DEBUG_PLUGIN
106771 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
106772 +#endif
106773 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
106774 + continue;
106775 + }
106776 +
106777 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
106778 + continue;
106779 +
106780 + if (rhs_code == ADDR_EXPR) {
106781 + op0 = TREE_OPERAND(rhs1, 0);
106782 +
106783 + if (op0 == NULL_TREE)
106784 + continue;
106785 +
106786 + if (TREE_CODE(op0) != VAR_DECL)
106787 + continue;
106788 +
106789 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
106790 + if (op0_type == ptr_lhs_type)
106791 + continue;
106792 +
106793 +#ifndef __DEBUG_PLUGIN
106794 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
106795 +#endif
106796 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
106797 + } else {
106798 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
106799 + /* skip bogus type casts introduced by container_of */
106800 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
106801 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
106802 + continue;
106803 +#ifndef __DEBUG_PLUGIN
106804 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
106805 +#endif
106806 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
106807 + }
106808 +
106809 + }
106810 + }
106811 + return 0;
106812 +}
106813 +
106814 +#if BUILDING_GCC_VERSION >= 4009
106815 +static const struct pass_data randomize_layout_bad_cast_data = {
106816 +#else
106817 +static struct gimple_opt_pass randomize_layout_bad_cast = {
106818 + .pass = {
106819 +#endif
106820 + .type = GIMPLE_PASS,
106821 + .name = "randomize_layout_bad_cast",
106822 +#if BUILDING_GCC_VERSION >= 4008
106823 + .optinfo_flags = OPTGROUP_NONE,
106824 +#endif
106825 +#if BUILDING_GCC_VERSION >= 4009
106826 + .has_gate = false,
106827 + .has_execute = true,
106828 +#else
106829 + .gate = NULL,
106830 + .execute = find_bad_casts,
106831 + .sub = NULL,
106832 + .next = NULL,
106833 + .static_pass_number = 0,
106834 +#endif
106835 + .tv_id = TV_NONE,
106836 + .properties_required = PROP_cfg,
106837 + .properties_provided = 0,
106838 + .properties_destroyed = 0,
106839 + .todo_flags_start = 0,
106840 + .todo_flags_finish = TODO_dump_func
106841 +#if BUILDING_GCC_VERSION < 4009
106842 + }
106843 +#endif
106844 +};
106845 +
106846 +#if BUILDING_GCC_VERSION >= 4009
106847 +namespace {
106848 +class randomize_layout_bad_cast : public gimple_opt_pass {
106849 +public:
106850 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
106851 + unsigned int execute() { return find_bad_casts(); }
106852 +};
106853 +}
106854 +#endif
106855 +
106856 +static struct opt_pass *make_randomize_layout_bad_cast(void)
106857 +{
106858 +#if BUILDING_GCC_VERSION >= 4009
106859 + return new randomize_layout_bad_cast();
106860 +#else
106861 + return &randomize_layout_bad_cast.pass;
106862 +#endif
106863 +}
106864 +
106865 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106866 +{
106867 + int i;
106868 + const char * const plugin_name = plugin_info->base_name;
106869 + const int argc = plugin_info->argc;
106870 + const struct plugin_argument * const argv = plugin_info->argv;
106871 + bool enable = true;
106872 + int obtained_seed = 0;
106873 + struct register_pass_info randomize_layout_bad_cast_info;
106874 +
106875 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
106876 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
106877 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
106878 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
106879 +
106880 + if (!plugin_default_version_check(version, &gcc_version)) {
106881 + error(G_("incompatible gcc/plugin versions"));
106882 + return 1;
106883 + }
106884 +
106885 + if (strcmp(lang_hooks.name, "GNU C")) {
106886 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
106887 + enable = false;
106888 + }
106889 +
106890 + for (i = 0; i < argc; ++i) {
106891 + if (!strcmp(argv[i].key, "disable")) {
106892 + enable = false;
106893 + continue;
106894 + }
106895 + if (!strcmp(argv[i].key, "performance-mode")) {
106896 + performance_mode = 1;
106897 + continue;
106898 + }
106899 + if (!strcmp(argv[i].key, "seed")) {
106900 + if (!argv[i].value) {
106901 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106902 + continue;
106903 + }
106904 + if (strlen(argv[i].value) != 64) {
106905 + error(G_("invalid value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106906 + continue;
106907 + }
106908 + obtained_seed = sscanf(argv[i].value, "%016llx%016llx%016llx%016llx",
106909 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
106910 + continue;
106911 + }
106912 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106913 + }
106914 +
106915 + if (obtained_seed != 4) {
106916 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
106917 + return 1;
106918 + }
106919 +
106920 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
106921 + if (enable) {
106922 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
106923 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
106924 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
106925 + }
106926 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106927 +
106928 + return 0;
106929 +}
106930 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
106931 new file mode 100644
106932 index 0000000..0c980be
106933 --- /dev/null
106934 +++ b/tools/gcc/size_overflow_hash.data
106935 @@ -0,0 +1,5697 @@
106936 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
106937 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
106938 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
106939 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
106940 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
106941 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
106942 +padzero_55 padzero 1 55 &sel_read_policyvers_55
106943 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
106944 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
106945 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
106946 +load_msg_95 load_msg 2 95 NULL
106947 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
106948 +init_q_132 init_q 4 132 NULL
106949 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
106950 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
106951 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
106952 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
106953 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
106954 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
106955 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
106956 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
106957 +br_port_info_size_268 br_port_info_size 0 268 NULL
106958 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
106959 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
106960 +SYSC_connect_304 SYSC_connect 3 304 NULL
106961 +syslog_print_307 syslog_print 2 307 NULL
106962 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
106963 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
106964 +hw_device_state_409 hw_device_state 0 409 NULL
106965 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
106966 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
106967 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
106968 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
106969 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
106970 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
106971 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
106972 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
106973 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
106974 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
106975 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
106976 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
106977 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
106978 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
106979 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
106980 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
106981 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
106982 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
106983 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
106984 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
106985 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
106986 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
106987 +clone_split_bio_633 clone_split_bio 6 633 NULL
106988 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
106989 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
106990 +unlink_queued_645 unlink_queued 4 645 NULL
106991 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
106992 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
106993 +persistent_ram_vmap_709 persistent_ram_vmap 1-2 709 NULL
106994 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
106995 +dvb_video_write_754 dvb_video_write 3 754 NULL
106996 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
106997 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
106998 +if_writecmd_815 if_writecmd 2 815 NULL
106999 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
107000 +error_state_read_859 error_state_read 6 859 NULL
107001 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
107002 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
107003 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
107004 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
107005 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
107006 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
107007 +memcmp_990 memcmp 0 990 NULL
107008 +readreg_1017 readreg 0-1 1017 NULL
107009 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
107010 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
107011 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
107012 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
107013 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
107014 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
107015 +llc_mac_hdr_init_1094 llc_mac_hdr_init 0 1094 NULL
107016 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
107017 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
107018 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
107019 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
107020 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
107021 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
107022 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
107023 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
107024 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
107025 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
107026 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
107027 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
107028 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
107029 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
107030 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
107031 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
107032 +ffs_1322 ffs 0 1322 NULL
107033 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
107034 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
107035 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
107036 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
107037 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
107038 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
107039 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
107040 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
107041 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
107042 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
107043 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
107044 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
107045 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
107046 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
107047 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
107048 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
107049 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
107050 +fpregs_set_1497 fpregs_set 4 1497 NULL
107051 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
107052 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
107053 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
107054 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
107055 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
107056 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
107057 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
107058 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
107059 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
107060 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
107061 +rmap_add_1677 rmap_add 3 1677 NULL
107062 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
107063 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
107064 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
107065 +internal_create_group_1733 internal_create_group 0 1733 NULL
107066 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
107067 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
107068 +cosa_write_1774 cosa_write 3 1774 NULL
107069 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
107070 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
107071 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
107072 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
107073 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
107074 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
107075 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
107076 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
107077 +bdev_erase_1933 bdev_erase 3 1933 NULL
107078 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
107079 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
107080 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
107081 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
107082 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
107083 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
107084 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
107085 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
107086 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
107087 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
107088 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
107089 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
107090 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
107091 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
107092 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
107093 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
107094 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
107095 +audit_expand_2098 audit_expand 0 2098 NULL
107096 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
107097 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
107098 +enable_read_2117 enable_read 3 2117 NULL
107099 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
107100 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
107101 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
107102 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
107103 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
107104 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
107105 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
107106 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
107107 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
107108 +vhci_write_2224 vhci_write 3 2224 NULL
107109 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
107110 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
107111 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
107112 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
107113 +do_update_counters_2259 do_update_counters 4 2259 NULL
107114 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
107115 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
107116 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
107117 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
107118 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
107119 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
107120 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
107121 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
107122 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
107123 +sysfs_add_file_mode_ns_2362 sysfs_add_file_mode_ns 0 2362 NULL
107124 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
107125 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
107126 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
107127 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
107128 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
107129 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
107130 +raid1_size_2419 raid1_size 0-2 2419 NULL
107131 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
107132 +wiphy_new_2482 wiphy_new 2 2482 NULL
107133 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
107134 +hfsplus_user_setxattr_2485 hfsplus_user_setxattr 4 2485 NULL
107135 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
107136 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
107137 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
107138 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
107139 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
107140 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
107141 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
107142 +slot_bytes_2609 slot_bytes 0 2609 NULL
107143 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
107144 +switch_status_2629 switch_status 5 2629 NULL
107145 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
107146 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
107147 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
107148 +oti6858_write_2692 oti6858_write 4 2692 NULL
107149 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
107150 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
107151 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
107152 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
107153 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
107154 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
107155 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
107156 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
107157 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
107158 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
107159 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
107160 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
107161 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
107162 +nla_padlen_2883 nla_padlen 1 2883 NULL
107163 +cmm_write_2896 cmm_write 3 2896 NULL
107164 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
107165 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
107166 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
107167 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
107168 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
107169 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
107170 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
107171 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
107172 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
107173 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
107174 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
107175 +depth_write_3021 depth_write 3 3021 NULL
107176 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
107177 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
107178 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
107179 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
107180 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
107181 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
107182 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
107183 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
107184 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
107185 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
107186 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
107187 +clone_bio_3100 clone_bio 6 3100 NULL nohasharray
107188 +ttusb2_msg_3100 ttusb2_msg 4 3100 &clone_bio_3100
107189 +rb_alloc_3102 rb_alloc 1 3102 NULL
107190 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
107191 +print_time_3132 print_time 0 3132 NULL
107192 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
107193 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
107194 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
107195 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
107196 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
107197 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
107198 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
107199 +alloc_context_3194 alloc_context 1 3194 NULL
107200 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
107201 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
107202 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
107203 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
107204 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
107205 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
107206 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
107207 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
107208 +key_key_read_3241 key_key_read 3 3241 NULL
107209 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
107210 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
107211 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
107212 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
107213 +ocfs2_extend_xattr_bucket_3328 ocfs2_extend_xattr_bucket 4 3328 NULL
107214 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
107215 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
107216 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
107217 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
107218 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
107219 +scnprintf_3360 scnprintf 0-2 3360 NULL
107220 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
107221 +sr_read_3366 sr_read 3 3366 NULL
107222 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
107223 +send_stream_3397 send_stream 4 3397 NULL
107224 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
107225 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
107226 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
107227 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
107228 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
107229 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
107230 +s3fb_ddc_read_3451 s3fb_ddc_read 0 3451 NULL
107231 +softsynth_write_3455 softsynth_write 3 3455 NULL
107232 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL nohasharray
107233 +jffs2_acl_setxattr_3464 jffs2_acl_setxattr 4 3464 &snd_pcm_lib_readv_transfer_3464
107234 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
107235 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
107236 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
107237 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
107238 +SyS_readv_3539 SyS_readv 3 3539 NULL
107239 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
107240 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
107241 +evtchn_read_3569 evtchn_read 3 3569 NULL
107242 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
107243 +vc_resize_3585 vc_resize 3-2 3585 NULL
107244 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
107245 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
107246 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
107247 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
107248 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
107249 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
107250 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
107251 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
107252 +ci_ll_write_3740 ci_ll_write 4 3740 NULL nohasharray
107253 +ath6kl_mgmt_tx_3740 ath6kl_mgmt_tx 7 3740 &ci_ll_write_3740
107254 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
107255 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
107256 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
107257 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
107258 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
107259 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
107260 +get_fd_set_3866 get_fd_set 1 3866 NULL
107261 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
107262 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
107263 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
107264 +nvram_write_3894 nvram_write 3 3894 NULL
107265 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
107266 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
107267 +vcs_write_3910 vcs_write 3 3910 NULL
107268 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
107269 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
107270 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
107271 +ll_get_max_mdsize_3962 ll_get_max_mdsize 0 3962 NULL
107272 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
107273 +do_add_counters_3992 do_add_counters 3 3992 NULL
107274 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
107275 +userspace_status_4004 userspace_status 4 4004 NULL
107276 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
107277 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
107278 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
107279 +blk_end_request_4024 blk_end_request 3 4024 NULL
107280 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
107281 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
107282 +read_file_queues_4078 read_file_queues 3 4078 NULL
107283 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
107284 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
107285 +tm6000_read_4151 tm6000_read 3 4151 NULL
107286 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
107287 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
107288 +get_alua_req_4166 get_alua_req 3 4166 NULL
107289 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
107290 +read_file_bool_4180 read_file_bool 3 4180 NULL
107291 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
107292 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
107293 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
107294 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
107295 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
107296 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
107297 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
107298 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
107299 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 3-2-5 4303 NULL
107300 +count_strings_4315 count_strings 0 4315 NULL
107301 +__sysfs_add_one_4326 __sysfs_add_one 0 4326 NULL
107302 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
107303 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
107304 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
107305 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
107306 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
107307 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
107308 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
107309 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
107310 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
107311 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
107312 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
107313 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
107314 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
107315 +set_link_security_4502 set_link_security 4 4502 NULL
107316 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
107317 +tty_register_device_4544 tty_register_device 2 4544 NULL
107318 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
107319 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
107320 +bch_alloc_4593 bch_alloc 1 4593 NULL
107321 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
107322 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
107323 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
107324 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
107325 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
107326 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
107327 +kone_receive_4690 kone_receive 4 4690 NULL
107328 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
107329 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
107330 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
107331 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
107332 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
107333 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
107334 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
107335 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
107336 +create_subvol_4791 create_subvol 4 4791 NULL
107337 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
107338 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
107339 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
107340 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
107341 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
107342 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
107343 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
107344 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
107345 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
107346 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
107347 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
107348 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
107349 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
107350 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
107351 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
107352 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
107353 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
107354 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
107355 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
107356 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
107357 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
107358 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
107359 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
107360 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
107361 +sound_write_5102 sound_write 3 5102 NULL
107362 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
107363 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
107364 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
107365 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
107366 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
107367 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
107368 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
107369 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
107370 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
107371 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
107372 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
107373 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
107374 +cq_free_res_5355 cq_free_res 5 5355 NULL
107375 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
107376 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
107377 +__split_bvec_across_targets_5454 __split_bvec_across_targets 3 5454 NULL
107378 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
107379 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
107380 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
107381 +tty_write_5494 tty_write 3 5494 NULL
107382 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
107383 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
107384 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
107385 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
107386 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
107387 +le_readq_5557 le_readq 0 5557 NULL
107388 +inw_5558 inw 0 5558 NULL
107389 +bioset_create_5580 bioset_create 1 5580 NULL
107390 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
107391 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
107392 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
107393 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
107394 +get_arg_5694 get_arg 3 5694 NULL
107395 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
107396 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
107397 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
107398 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
107399 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
107400 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
107401 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
107402 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
107403 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
107404 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
107405 +setup_req_5848 setup_req 3-0 5848 NULL
107406 +ria_page_count_5849 ria_page_count 0 5849 NULL
107407 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
107408 +config_buf_5862 config_buf 0 5862 NULL
107409 +iwl_dbgfs_scan_ant_rxchain_write_5877 iwl_dbgfs_scan_ant_rxchain_write 3 5877 NULL
107410 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
107411 +port_show_regs_5904 port_show_regs 3 5904 NULL
107412 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
107413 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
107414 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
107415 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
107416 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
107417 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
107418 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
107419 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
107420 +SyS_semop_5980 SyS_semop 3 5980 NULL
107421 +alloc_msg_6072 alloc_msg 1 6072 NULL
107422 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
107423 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
107424 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
107425 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
107426 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
107427 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
107428 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
107429 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
107430 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
107431 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
107432 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
107433 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
107434 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
107435 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
107436 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
107437 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
107438 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
107439 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
107440 +serial_port_in_6291 serial_port_in 0 6291 NULL
107441 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
107442 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
107443 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
107444 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
107445 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
107446 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
107447 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
107448 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
107449 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
107450 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
107451 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
107452 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
107453 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
107454 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
107455 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
107456 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
107457 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
107458 +mei_read_6507 mei_read 3 6507 NULL
107459 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
107460 +wdm_read_6549 wdm_read 3 6549 NULL
107461 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
107462 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
107463 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
107464 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
107465 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
107466 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
107467 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
107468 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
107469 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
107470 +mpeg_read_6708 mpeg_read 3 6708 NULL
107471 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
107472 +video_proc_write_6724 video_proc_write 3 6724 NULL
107473 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
107474 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
107475 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
107476 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
107477 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
107478 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
107479 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
107480 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
107481 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
107482 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
107483 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
107484 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
107485 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
107486 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
107487 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
107488 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
107489 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
107490 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
107491 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
107492 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
107493 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
107494 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
107495 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
107496 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
107497 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
107498 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
107499 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
107500 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
107501 +request_key_async_6990 request_key_async 4 6990 NULL
107502 +tpl_write_6998 tpl_write 3 6998 NULL
107503 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
107504 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
107505 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
107506 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
107507 +wimax_msg_7030 wimax_msg 4 7030 NULL
107508 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
107509 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
107510 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
107511 +event_enable_read_7074 event_enable_read 3 7074 NULL
107512 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
107513 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
107514 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
107515 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
107516 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
107517 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
107518 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
107519 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
107520 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
107521 +get_string_7302 get_string 0 7302 NULL
107522 +mgmt_control_7349 mgmt_control 3 7349 NULL
107523 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
107524 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
107525 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
107526 +hweight_long_7388 hweight_long 1-0 7388 NULL
107527 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
107528 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
107529 +readb_7401 readb 0 7401 NULL
107530 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
107531 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
107532 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
107533 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
107534 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
107535 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
107536 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
107537 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
107538 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
107539 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
107540 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
107541 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
107542 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
107543 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
107544 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
107545 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
107546 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
107547 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
107548 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
107549 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
107550 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
107551 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
107552 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
107553 +dev_write_7708 dev_write 3 7708 NULL
107554 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
107555 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
107556 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
107557 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
107558 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
107559 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
107560 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
107561 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
107562 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
107563 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
107564 +config_desc_7878 config_desc 0 7878 NULL
107565 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
107566 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
107567 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
107568 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
107569 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
107570 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
107571 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
107572 +vcs_read_8017 vcs_read 3 8017 NULL
107573 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
107574 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
107575 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
107576 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
107577 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
107578 +venus_lookup_8121 venus_lookup 4 8121 NULL
107579 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
107580 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
107581 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
107582 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
107583 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
107584 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
107585 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
107586 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
107587 +play_iframe_8219 play_iframe 3 8219 NULL
107588 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
107589 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
107590 +ceph_sync_write_8233 ceph_sync_write 4 8233 NULL
107591 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
107592 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
107593 +init_cdev_8274 init_cdev 1 8274 NULL
107594 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
107595 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
107596 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
107597 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
107598 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
107599 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
107600 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
107601 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
107602 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
107603 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
107604 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
107605 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
107606 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
107607 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
107608 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
107609 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
107610 +dev_config_8506 dev_config 3 8506 NULL
107611 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
107612 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
107613 +user_on_off_8552 user_on_off 2 8552 NULL
107614 +profile_remove_8556 profile_remove 3 8556 NULL
107615 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
107616 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
107617 +tower_write_8580 tower_write 3 8580 NULL
107618 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
107619 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
107620 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
107621 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
107622 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
107623 +generic_acl_set_8658 generic_acl_set 4 8658 NULL
107624 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
107625 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
107626 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
107627 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
107628 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
107629 +arcfb_write_8702 arcfb_write 3 8702 NULL
107630 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
107631 +init_header_8703 init_header 0 8703 &i_size_read_8703
107632 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
107633 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
107634 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
107635 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
107636 +__create_irqs_8733 __create_irqs 2 8733 NULL
107637 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
107638 +compound_order_8750 compound_order 0 8750 NULL
107639 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
107640 +yurex_write_8761 yurex_write 3 8761 NULL
107641 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
107642 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
107643 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
107644 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
107645 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
107646 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
107647 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
107648 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
107649 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
107650 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
107651 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
107652 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
107653 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
107654 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
107655 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
107656 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
107657 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
107658 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
107659 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
107660 +write_file_ani_8918 write_file_ani 3 8918 NULL
107661 +layout_commit_8926 layout_commit 3 8926 NULL
107662 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
107663 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
107664 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
107665 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
107666 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
107667 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
107668 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
107669 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
107670 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
107671 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
107672 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
107673 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
107674 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
107675 +nla_put_9042 nla_put 3 9042 NULL
107676 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
107677 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
107678 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
107679 +create_queues_9088 create_queues 2-3 9088 NULL
107680 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
107681 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
107682 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
107683 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110
107684 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
107685 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
107686 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
107687 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
107688 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
107689 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
107690 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
107691 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
107692 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
107693 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
107694 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
107695 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
107696 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
107697 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
107698 +flakey_status_9274 flakey_status 5 9274 NULL
107699 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
107700 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
107701 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
107702 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
107703 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
107704 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
107705 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
107706 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
107707 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
107708 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
107709 +read_9397 read 3 9397 NULL
107710 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
107711 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
107712 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
107713 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
107714 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
107715 +ext3_xattr_set_acl_9467 ext3_xattr_set_acl 4 9467 NULL
107716 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
107717 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
107718 +crypt_status_9492 crypt_status 5 9492 NULL
107719 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
107720 +lp_write_9511 lp_write 3 9511 NULL
107721 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
107722 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
107723 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
107724 +read_file_dma_9530 read_file_dma 3 9530 NULL
107725 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
107726 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
107727 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
107728 +fw_node_create_9559 fw_node_create 2 9559 NULL
107729 +kobj_map_9566 kobj_map 2-3 9566 NULL
107730 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
107731 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
107732 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
107733 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
107734 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
107735 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
107736 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
107737 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
107738 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
107739 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
107740 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
107741 +dns_query_9676 dns_query 3 9676 NULL
107742 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
107743 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
107744 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
107745 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
107746 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
107747 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
107748 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
107749 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
107750 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
107751 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
107752 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
107753 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
107754 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
107755 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
107756 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
107757 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
107758 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
107759 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
107760 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
107761 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
107762 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
107763 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
107764 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
107765 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
107766 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
107767 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
107768 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
107769 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
107770 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
107771 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
107772 +read_file_misc_9948 read_file_misc 3 9948 NULL
107773 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
107774 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
107775 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
107776 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
107777 +gameport_read_9983 gameport_read 0 9983 NULL
107778 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
107779 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
107780 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
107781 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
107782 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
107783 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
107784 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
107785 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
107786 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
107787 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
107788 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
107789 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
107790 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
107791 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
107792 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
107793 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
107794 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
107795 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
107796 +read_emulate_10310 read_emulate 2-4 10310 NULL
107797 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
107798 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
107799 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
107800 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
107801 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
107802 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
107803 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
107804 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
107805 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
107806 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
107807 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
107808 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
107809 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
107810 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
107811 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
107812 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
107813 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
107814 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
107815 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
107816 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
107817 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
107818 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
107819 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
107820 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
107821 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
107822 +otp_read_10594 otp_read 2-4-5 10594 NULL
107823 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
107824 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
107825 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
107826 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
107827 +parport_write_10669 parport_write 0 10669 NULL
107828 +edge_write_10692 edge_write 4 10692 NULL
107829 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
107830 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
107831 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
107832 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
107833 +spi_sync_10731 spi_sync 0 10731 NULL
107834 +apu_get_register_10737 apu_get_register 0 10737 NULL nohasharray
107835 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 &apu_get_register_10737
107836 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
107837 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
107838 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
107839 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
107840 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
107841 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
107842 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
107843 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
107844 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
107845 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
107846 +get_scq_10897 get_scq 2 10897 NULL
107847 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
107848 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
107849 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
107850 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
107851 +kobject_add_10919 kobject_add 0 10919 NULL
107852 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
107853 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
107854 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
107855 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
107856 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
107857 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
107858 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
107859 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
107860 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
107861 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
107862 +count_argc_11083 count_argc 0 11083 NULL
107863 +ocfs2_blocks_per_xattr_bucket_11099 ocfs2_blocks_per_xattr_bucket 0 11099 NULL
107864 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
107865 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
107866 +page_offset_11120 page_offset 0 11120 NULL
107867 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
107868 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
107869 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
107870 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
107871 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
107872 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
107873 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
107874 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
107875 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
107876 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
107877 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
107878 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
107879 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
107880 +construct_key_11329 construct_key 3 11329 NULL nohasharray
107881 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
107882 +next_segment_11330 next_segment 0-2-1 11330 NULL
107883 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 2-1 11332 NULL
107884 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
107885 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
107886 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
107887 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
107888 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
107889 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
107890 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
107891 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
107892 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
107893 +str_to_user_11411 str_to_user 2 11411 NULL
107894 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
107895 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
107896 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL nohasharray
107897 +import_sec_validate_get_11417 import_sec_validate_get 0 11417 &adis16480_show_firmware_revision_11417
107898 +trace_options_read_11419 trace_options_read 3 11419 NULL
107899 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
107900 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
107901 +bttv_read_11432 bttv_read 3 11432 NULL
107902 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
107903 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
107904 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
107905 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
107906 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
107907 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
107908 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
107909 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
107910 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
107911 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
107912 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
107913 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
107914 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
107915 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
107916 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
107917 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
107918 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
107919 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
107920 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
107921 +slab_ksize_11664 slab_ksize 0 11664 NULL
107922 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
107923 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
107924 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
107925 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
107926 +split_11691 split 2 11691 NULL
107927 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
107928 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
107929 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
107930 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
107931 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
107932 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
107933 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
107934 +umc_device_register_11824 umc_device_register 0 11824 NULL
107935 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
107936 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
107937 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
107938 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
107939 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
107940 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
107941 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
107942 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
107943 +ti_write_11916 ti_write 4 11916 NULL
107944 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
107945 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
107946 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
107947 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
107948 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
107949 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
107950 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
107951 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
107952 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
107953 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
107954 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
107955 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
107956 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
107957 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
107958 +set_powered_12129 set_powered 4 12129 NULL
107959 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
107960 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
107961 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
107962 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
107963 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
107964 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
107965 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
107966 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
107967 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
107968 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
107969 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
107970 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
107971 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
107972 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
107973 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
107974 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
107975 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
107976 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
107977 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
107978 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
107979 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
107980 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
107981 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
107982 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
107983 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
107984 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
107985 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 NULL nohasharray
107986 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391 nohasharray
107987 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
107988 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
107989 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
107990 +ptlrpc_set_wait_12426 ptlrpc_set_wait 0 12426 NULL
107991 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
107992 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
107993 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
107994 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
107995 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
107996 +xfs_get_extsz_hint_12531 xfs_get_extsz_hint 0 12531 NULL
107997 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
107998 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
107999 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
108000 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
108001 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
108002 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
108003 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
108004 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
108005 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
108006 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
108007 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
108008 +lustre_pack_request_v2_12665 lustre_pack_request_v2 0 12665 NULL
108009 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
108010 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
108011 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
108012 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
108013 +ivtv_write_12721 ivtv_write 3 12721 NULL
108014 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
108015 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
108016 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
108017 +listxattr_12769 listxattr 3 12769 NULL
108018 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
108019 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
108020 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
108021 +readq_12825 readq 0 12825 NULL
108022 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
108023 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
108024 +spidev_sync_12842 spidev_sync 0 12842 NULL
108025 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
108026 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
108027 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
108028 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
108029 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
108030 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
108031 +bm_status_write_12964 bm_status_write 3 12964 NULL
108032 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
108033 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
108034 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
108035 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
108036 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
108037 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
108038 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
108039 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
108040 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
108041 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
108042 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
108043 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
108044 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
108045 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
108046 +blk_update_request_13146 blk_update_request 3 13146 NULL
108047 +ocfs2_quota_trans_credits_13150 ocfs2_quota_trans_credits 0 13150 NULL
108048 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
108049 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
108050 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
108051 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
108052 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
108053 +comedi_read_13199 comedi_read 3 13199 NULL
108054 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
108055 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
108056 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
108057 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
108058 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
108059 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
108060 +bio_integrity_trim_13259 bio_integrity_trim 3 13259 NULL
108061 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
108062 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
108063 +il4965_stats_flag_13281 il4965_stats_flag 3-0 13281 NULL
108064 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
108065 +sd_major_13294 sd_major 0-1 13294 NULL
108066 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
108067 +__clone_and_map_data_bio_13334 __clone_and_map_data_bio 4-8 13334 NULL
108068 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
108069 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
108070 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
108071 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
108072 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
108073 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
108074 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
108075 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
108076 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
108077 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
108078 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
108079 +data_read_13494 data_read 3 13494 NULL
108080 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
108081 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
108082 +core_status_13515 core_status 4 13515 NULL
108083 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
108084 +bm_init_13529 bm_init 2 13529 NULL
108085 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
108086 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
108087 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
108088 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
108089 +cache_write_13589 cache_write 3 13589 NULL
108090 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
108091 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
108092 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
108093 +packet_snd_13634 packet_snd 3 13634 NULL
108094 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
108095 +cache_downcall_13666 cache_downcall 3 13666 NULL
108096 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
108097 +nv94_aux_13689 nv94_aux 2-5 13689 NULL
108098 +usb_get_string_13693 usb_get_string 0 13693 NULL
108099 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
108100 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
108101 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
108102 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
108103 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
108104 +random_read_13815 random_read 3 13815 NULL
108105 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
108106 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
108107 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
108108 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
108109 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
108110 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
108111 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
108112 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
108113 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
108114 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
108115 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
108116 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
108117 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
108118 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
108119 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
108120 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
108121 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
108122 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
108123 +qcam_read_13977 qcam_read 3 13977 NULL
108124 +dsp_read_13980 dsp_read 2 13980 NULL
108125 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
108126 +create_files_14003 create_files 0 14003 NULL
108127 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
108128 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
108129 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
108130 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
108131 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
108132 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
108133 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
108134 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
108135 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
108136 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
108137 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
108138 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
108139 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
108140 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
108141 +em_canid_change_14150 em_canid_change 3 14150 NULL
108142 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
108143 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
108144 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
108145 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
108146 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
108147 +alloc_async_14208 alloc_async 1 14208 NULL
108148 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
108149 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
108150 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
108151 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
108152 +rr_status_14293 rr_status 5 14293 NULL
108153 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
108154 +oo_objects_14319 oo_objects 0 14319 NULL
108155 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
108156 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
108157 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
108158 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
108159 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
108160 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
108161 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
108162 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
108163 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
108164 +block_size_14443 block_size 0 14443 NULL
108165 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
108166 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
108167 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
108168 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
108169 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
108170 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
108171 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
108172 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
108173 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
108174 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
108175 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
108176 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
108177 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
108178 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
108179 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
108180 +dbJoin_14644 dbJoin 0 14644 NULL
108181 +profile_replace_14652 profile_replace 3 14652 NULL
108182 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
108183 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
108184 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
108185 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
108186 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
108187 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
108188 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
108189 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
108190 +cgroup_path_14713 cgroup_path 3 14713 NULL
108191 +vfd_write_14717 vfd_write 3 14717 NULL
108192 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
108193 +raid1_resize_14740 raid1_resize 2 14740 NULL
108194 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
108195 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
108196 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
108197 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
108198 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
108199 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
108200 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
108201 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
108202 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
108203 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
108204 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
108205 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
108206 +lcd_write_14857 lcd_write 3 14857 NULL
108207 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
108208 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
108209 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
108210 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
108211 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
108212 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
108213 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
108214 +queue_cnt_14951 queue_cnt 0 14951 NULL
108215 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
108216 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
108217 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
108218 +setkey_14987 setkey 3 14987 NULL nohasharray
108219 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
108220 +xfs_dinode_size_14996 xfs_dinode_size 0 14996 NULL
108221 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
108222 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
108223 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
108224 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
108225 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
108226 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
108227 +ceph_calc_ceph_pg_15075 ceph_calc_ceph_pg 0 15075 NULL
108228 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
108229 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
108230 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
108231 +start_port_15124 start_port 0 15124 NULL
108232 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
108233 +iwl_dbgfs_sta_drain_write_15167 iwl_dbgfs_sta_drain_write 3 15167 NULL
108234 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
108235 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
108236 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
108237 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
108238 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
108239 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
108240 +simple_strtol_15273 simple_strtol 0 15273 NULL
108241 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
108242 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
108243 +xlog_ticket_alloc_15335 xlog_ticket_alloc 2 15335 NULL
108244 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
108245 +ioread16_15342 ioread16 0 15342 NULL
108246 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
108247 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
108248 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
108249 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
108250 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
108251 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
108252 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
108253 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
108254 +get_modalias_15406 get_modalias 2 15406 NULL
108255 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
108256 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
108257 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
108258 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
108259 +memweight_15450 memweight 2 15450 NULL
108260 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
108261 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
108262 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
108263 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
108264 +persistent_status_15574 persistent_status 4 15574 NULL
108265 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
108266 +vme_user_write_15587 vme_user_write 3 15587 NULL
108267 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
108268 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
108269 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
108270 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
108271 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
108272 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
108273 +fs_path_add_15648 fs_path_add 3 15648 NULL
108274 +xsd_read_15653 xsd_read 3 15653 NULL
108275 +unix_bind_15668 unix_bind 3 15668 NULL
108276 +dm_read_15674 dm_read 3 15674 NULL nohasharray
108277 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
108278 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
108279 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
108280 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
108281 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
108282 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
108283 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
108284 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
108285 +table_size_15851 table_size 0-1-2 15851 NULL
108286 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
108287 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
108288 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
108289 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
108290 +native_read_msr_15905 native_read_msr 0 15905 NULL
108291 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
108292 +power_read_15939 power_read 3 15939 NULL
108293 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
108294 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
108295 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
108296 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
108297 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
108298 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
108299 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
108300 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
108301 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
108302 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
108303 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
108304 +fsm_init_16134 fsm_init 2 16134 NULL
108305 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
108306 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
108307 +mapping_level_16188 mapping_level 2-0 16188 NULL
108308 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
108309 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
108310 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
108311 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
108312 +create_table_16213 create_table 2 16213 NULL
108313 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
108314 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
108315 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
108316 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
108317 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
108318 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
108319 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
108320 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
108321 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
108322 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
108323 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
108324 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
108325 +account_16283 account 0-4-2 16283 NULL nohasharray
108326 +mirror_status_16283 mirror_status 5 16283 &account_16283
108327 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
108328 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
108329 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
108330 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
108331 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
108332 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
108333 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
108334 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
108335 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
108336 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
108337 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
108338 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
108339 +cmdline_store_16442 cmdline_store 4 16442 NULL
108340 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
108341 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
108342 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
108343 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
108344 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
108345 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
108346 +raid10_resize_16537 raid10_resize 2 16537 NULL
108347 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
108348 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
108349 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
108350 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
108351 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
108352 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
108353 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
108354 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
108355 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
108356 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
108357 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
108358 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
108359 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
108360 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
108361 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
108362 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
108363 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
108364 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
108365 +st_write_16874 st_write 3 16874 NULL
108366 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
108367 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
108368 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
108369 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
108370 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
108371 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
108372 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
108373 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
108374 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
108375 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
108376 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
108377 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
108378 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
108379 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
108380 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
108381 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
108382 +entry_length_17093 entry_length 0 17093 NULL
108383 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
108384 +write_mem_17114 write_mem 3 17114 NULL
108385 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
108386 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
108387 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
108388 +sep_read_17161 sep_read 3 17161 NULL
108389 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
108390 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
108391 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
108392 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
108393 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
108394 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
108395 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
108396 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
108397 +sync_request_17208 sync_request 2 17208 NULL
108398 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
108399 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
108400 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
108401 +alloc_ep_17269 alloc_ep 1 17269 NULL
108402 +pg_read_17276 pg_read 3 17276 NULL
108403 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
108404 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
108405 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
108406 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
108407 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 0 17298 NULL
108408 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
108409 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
108410 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
108411 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
108412 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
108413 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
108414 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
108415 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
108416 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
108417 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
108418 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
108419 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
108420 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
108421 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
108422 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
108423 +qp_free_res_17541 qp_free_res 5 17541 NULL
108424 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
108425 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
108426 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
108427 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
108428 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
108429 +osst_execute_17607 osst_execute 7-6 17607 NULL
108430 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
108431 +dma_map_page_17628 dma_map_page 0 17628 NULL
108432 +ocfs2_rotate_subtree_left_17634 ocfs2_rotate_subtree_left 5 17634 NULL
108433 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
108434 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
108435 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
108436 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
108437 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
108438 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
108439 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
108440 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
108441 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
108442 +brcmf_sdio_chip_verifynvram_17776 brcmf_sdio_chip_verifynvram 4 17776 NULL
108443 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
108444 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
108445 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
108446 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
108447 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
108448 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
108449 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
108450 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
108451 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
108452 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
108453 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
108454 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
108455 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
108456 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
108457 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
108458 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
108459 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
108460 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
108461 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
108462 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
108463 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
108464 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
108465 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
108466 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
108467 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
108468 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
108469 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
108470 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
108471 +fpregs_get_18066 fpregs_get 4 18066 NULL
108472 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
108473 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
108474 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
108475 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
108476 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
108477 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
108478 +svc_getnl_18120 svc_getnl 0 18120 NULL
108479 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
108480 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
108481 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
108482 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
108483 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
108484 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
108485 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
108486 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
108487 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
108488 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
108489 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
108490 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
108491 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
108492 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
108493 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
108494 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
108495 +um_idi_write_18293 um_idi_write 3 18293 NULL
108496 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
108497 +vga_r_18310 vga_r 0 18310 NULL
108498 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
108499 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
108500 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
108501 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
108502 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
108503 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
108504 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
108505 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
108506 +ep_io_18367 ep_io 0 18367 NULL
108507 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
108508 +ci_role_write_18388 ci_role_write 3 18388 NULL
108509 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
108510 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
108511 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
108512 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
108513 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
108514 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
108515 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
108516 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
108517 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
108518 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
108519 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
108520 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
108521 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
108522 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
108523 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
108524 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
108525 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
108526 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
108527 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
108528 +debug_output_18575 debug_output 3 18575 NULL
108529 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
108530 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
108531 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
108532 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL nohasharray
108533 +audio_get_endpoint_req_18624 audio_get_endpoint_req 0 18624 &nvc0_ram_create__18624
108534 +from_buffer_18625 from_buffer 3 18625 NULL
108535 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
108536 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
108537 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
108538 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
108539 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
108540 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
108541 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
108542 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
108543 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
108544 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
108545 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
108546 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
108547 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
108548 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
108549 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
108550 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
108551 +prealloc_18800 prealloc 0 18800 NULL
108552 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
108553 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
108554 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
108555 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
108556 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
108557 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
108558 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
108559 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
108560 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
108561 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
108562 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
108563 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
108564 +huge_page_size_19008 huge_page_size 0 19008 NULL
108565 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
108566 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
108567 +revalidate_19043 revalidate 2 19043 NULL
108568 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
108569 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
108570 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
108571 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
108572 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
108573 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
108574 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
108575 +ATOMIC_SUB_RETURN_19115 ATOMIC_SUB_RETURN 2 19115 NULL
108576 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
108577 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
108578 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
108579 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
108580 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
108581 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
108582 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
108583 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
108584 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
108585 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
108586 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
108587 +ucma_query_19260 ucma_query 4 19260 NULL
108588 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
108589 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
108590 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
108591 +qc_capture_19298 qc_capture 3 19298 NULL
108592 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
108593 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
108594 +debug_read_19322 debug_read 3 19322 NULL
108595 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
108596 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
108597 +closure_sub_19359 closure_sub 2 19359 NULL
108598 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
108599 +read_zero_19366 read_zero 3 19366 NULL
108600 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
108601 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
108602 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
108603 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
108604 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
108605 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
108606 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
108607 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
108608 +sky2_read16_19475 sky2_read16 0 19475 NULL
108609 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
108610 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
108611 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
108612 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
108613 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
108614 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
108615 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
108616 +howmany_64_19548 howmany_64 2 19548 NULL
108617 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
108618 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
108619 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
108620 +nfsd_read_19568 nfsd_read 5 19568 NULL
108621 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
108622 +bm_status_read_19583 bm_status_read 3 19583 NULL
108623 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
108624 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
108625 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
108626 +iwl_dbgfs_pm_params_write_19660 iwl_dbgfs_pm_params_write 3 19660 NULL
108627 +read_reg_19723 read_reg 0 19723 NULL
108628 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
108629 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
108630 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
108631 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
108632 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
108633 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
108634 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
108635 +readhscx_19769 readhscx 0 19769 NULL
108636 +__set_print_fmt_19776 __set_print_fmt 0 19776 NULL
108637 +iwl_dbgfs_disable_power_off_write_19823 iwl_dbgfs_disable_power_off_write 3 19823 NULL
108638 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
108639 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
108640 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
108641 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
108642 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
108643 +__nla_put_19857 __nla_put 3 19857 NULL
108644 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
108645 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
108646 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
108647 +mangle_name_19923 mangle_name 0 19923 NULL
108648 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
108649 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
108650 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
108651 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
108652 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
108653 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
108654 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
108655 +lustre_pack_request_19992 lustre_pack_request 0 19992 NULL
108656 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
108657 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL
108658 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
108659 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
108660 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
108661 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
108662 +target_message_20072 target_message 2 20072 NULL
108663 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
108664 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
108665 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
108666 +team_options_register_20091 team_options_register 3 20091 NULL
108667 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
108668 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
108669 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
108670 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
108671 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
108672 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
108673 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
108674 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
108675 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
108676 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
108677 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
108678 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
108679 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
108680 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
108681 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
108682 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
108683 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
108684 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
108685 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
108686 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
108687 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
108688 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
108689 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
108690 +nfs3_setxattr_20458 nfs3_setxattr 4 20458 NULL
108691 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
108692 +read_buf_20469 read_buf 2 20469 NULL
108693 +bio_trim_20472 bio_trim 2 20472 NULL
108694 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
108695 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
108696 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
108697 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
108698 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
108699 +venus_create_20555 venus_create 4 20555 NULL
108700 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
108701 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
108702 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
108703 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
108704 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
108705 +lirc_write_20604 lirc_write 3 20604 NULL
108706 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
108707 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
108708 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
108709 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
108710 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
108711 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
108712 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
108713 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
108714 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
108715 +cpumask_size_20683 cpumask_size 0 20683 NULL
108716 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
108717 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
108718 +__maestro_read_20700 __maestro_read 0 20700 NULL
108719 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
108720 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
108721 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
108722 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
108723 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
108724 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
108725 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
108726 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
108727 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
108728 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
108729 +strndup_user_20819 strndup_user 2 20819 NULL
108730 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
108731 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
108732 +uvc_alloc_entity_20836 uvc_alloc_entity 3-4 20836 NULL
108733 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
108734 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
108735 +get_name_20855 get_name 4 20855 NULL
108736 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
108737 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
108738 +srq_free_res_20868 srq_free_res 5 20868 NULL
108739 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
108740 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
108741 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
108742 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
108743 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
108744 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
108745 +htable_bits_20933 htable_bits 0 20933 NULL
108746 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
108747 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
108748 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
108749 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
108750 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
108751 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
108752 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
108753 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
108754 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
108755 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
108756 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
108757 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
108758 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
108759 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
108760 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
108761 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
108762 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
108763 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
108764 +ocfs2_extend_meta_needed_21104 ocfs2_extend_meta_needed 0 21104 NULL
108765 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
108766 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
108767 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
108768 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
108769 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
108770 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
108771 +input_ff_create_21240 input_ff_create 2 21240 NULL
108772 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
108773 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
108774 +fru_length_21257 fru_length 0 21257 NULL
108775 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
108776 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
108777 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
108778 +add_res_range_21310 add_res_range 4 21310 NULL
108779 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
108780 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
108781 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
108782 +ocfs2_find_subtree_root_21351 ocfs2_find_subtree_root 0 21351 NULL
108783 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
108784 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
108785 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
108786 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
108787 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
108788 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
108789 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
108790 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
108791 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
108792 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
108793 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
108794 +ReadISAR_21453 ReadISAR 0 21453 NULL
108795 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
108796 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
108797 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
108798 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
108799 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
108800 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
108801 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
108802 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
108803 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
108804 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
108805 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
108806 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
108807 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
108808 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
108809 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
108810 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
108811 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
108812 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
108813 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
108814 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
108815 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
108816 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
108817 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
108818 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
108819 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
108820 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
108821 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
108822 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
108823 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
108824 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
108825 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
108826 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
108827 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
108828 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
108829 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
108830 +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
108831 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
108832 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
108833 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
108834 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
108835 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
108836 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
108837 +mem_rw_22085 mem_rw 3 22085 NULL
108838 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
108839 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
108840 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
108841 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
108842 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
108843 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
108844 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
108845 +mem_write_22232 mem_write 3 22232 NULL
108846 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
108847 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
108848 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
108849 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
108850 +add_res_tree_22263 add_res_tree 7 22263 NULL
108851 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
108852 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
108853 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
108854 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
108855 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
108856 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
108857 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
108858 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
108859 +atomic_read_22342 atomic_read 0 22342 NULL
108860 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
108861 +memcg_size_22360 memcg_size 0 22360 NULL
108862 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
108863 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
108864 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
108865 +zoran_write_22404 zoran_write 3 22404 NULL
108866 +ATOMIC_ADD_RETURN_22413 ATOMIC_ADD_RETURN 2 22413 NULL
108867 +queue_reply_22416 queue_reply 3 22416 NULL
108868 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
108869 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
108870 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
108871 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
108872 +source_sink_start_ep_22472 source_sink_start_ep 0 22472 NULL
108873 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
108874 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
108875 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
108876 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
108877 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
108878 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
108879 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
108880 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
108881 +snapshot_read_22601 snapshot_read 3 22601 NULL
108882 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
108883 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
108884 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
108885 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
108886 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
108887 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
108888 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
108889 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
108890 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
108891 +reg_umr_22686 reg_umr 5 22686 NULL
108892 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
108893 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
108894 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
108895 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
108896 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
108897 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
108898 +print_frame_22769 print_frame 0 22769 NULL
108899 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
108900 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
108901 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
108902 +clone_bio_integrity_22842 clone_bio_integrity 4 22842 NULL
108903 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
108904 +create_attr_set_22861 create_attr_set 1 22861 NULL
108905 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
108906 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
108907 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
108908 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
108909 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 NULL
108910 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
108911 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
108912 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
108913 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
108914 +vme_get_size_22964 vme_get_size 0 22964 NULL
108915 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
108916 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
108917 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
108918 +brcmf_sdio_chip_exit_download_23001 brcmf_sdio_chip_exit_download 4 23001 NULL
108919 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
108920 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
108921 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0-6-7 23029 NULL
108922 +st_status_23032 st_status 5 23032 NULL
108923 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
108924 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
108925 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
108926 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
108927 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
108928 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
108929 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
108930 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
108931 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
108932 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
108933 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
108934 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
108935 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
108936 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
108937 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL
108938 +__clear_user_23118 __clear_user 0-2 23118 NULL
108939 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
108940 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
108941 +read_file_ani_23161 read_file_ani 3 23161 NULL
108942 +usblp_write_23178 usblp_write 3 23178 NULL
108943 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
108944 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
108945 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
108946 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
108947 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
108948 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
108949 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
108950 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
108951 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
108952 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
108953 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
108954 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
108955 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
108956 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
108957 +page_readlink_23346 page_readlink 3 23346 NULL
108958 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
108959 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
108960 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
108961 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
108962 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
108963 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
108964 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
108965 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
108966 +linear_conf_23485 linear_conf 2 23485 NULL
108967 +event_filter_read_23494 event_filter_read 3 23494 NULL
108968 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
108969 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
108970 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
108971 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
108972 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
108973 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
108974 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
108975 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
108976 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
108977 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
108978 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
108979 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
108980 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
108981 +sInW_23663 sInW 0 23663 NULL
108982 +SyS_connect_23669 SyS_connect 3 23669 NULL
108983 +cx18_read_23699 cx18_read 3 23699 NULL
108984 +at_get_23708 at_get 0 23708 NULL
108985 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
108986 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
108987 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
108988 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
108989 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
108990 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
108991 +map_write_23795 map_write 3 23795 NULL
108992 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
108993 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
108994 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
108995 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
108996 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 3-4 23829 NULL
108997 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
108998 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
108999 +p54_init_common_23850 p54_init_common 1 23850 NULL
109000 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
109001 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
109002 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
109003 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL
109004 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
109005 +usbg_prepare_w_request_23895 usbg_prepare_w_request 0 23895 NULL
109006 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
109007 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
109008 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
109009 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
109010 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
109011 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
109012 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
109013 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
109014 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
109015 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
109016 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
109017 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
109018 +give_pages_24021 give_pages 3 24021 NULL
109019 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
109020 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
109021 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
109022 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
109023 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
109024 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
109025 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
109026 +lov_brw_24122 lov_brw 4 24122 NULL
109027 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
109028 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
109029 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
109030 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
109031 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
109032 +adu_read_24177 adu_read 3 24177 NULL
109033 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
109034 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
109035 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
109036 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
109037 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
109038 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
109039 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
109040 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
109041 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
109042 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
109043 +thin_status_24278 thin_status 5 24278 NULL
109044 +msg_size_24288 msg_size 0 24288 NULL
109045 +gserial_connect_24302 gserial_connect 0 24302 NULL
109046 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
109047 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
109048 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
109049 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
109050 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
109051 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
109052 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
109053 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
109054 +igetword_24373 igetword 0 24373 NULL
109055 +max_io_len_24384 max_io_len 0-1 24384 NULL
109056 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
109057 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
109058 +getxattr_24398 getxattr 4 24398 NULL nohasharray
109059 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
109060 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
109061 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
109062 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
109063 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
109064 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
109065 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
109066 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
109067 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
109068 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
109069 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
109070 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
109071 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
109072 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
109073 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
109074 +pd_video_read_24510 pd_video_read 3 24510 NULL
109075 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
109076 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
109077 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
109078 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
109079 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
109080 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
109081 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
109082 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
109083 +SyS_poll_24620 SyS_poll 2 24620 NULL
109084 +context_alloc_24645 context_alloc 3 24645 NULL
109085 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
109086 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
109087 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
109088 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
109089 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
109090 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
109091 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
109092 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
109093 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
109094 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
109095 +cache_read_24790 cache_read 3 24790 NULL
109096 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
109097 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
109098 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
109099 +net2272_read_24825 net2272_read 0 24825 NULL
109100 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
109101 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
109102 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
109103 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
109104 +queues_read_24877 queues_read 3 24877 NULL
109105 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
109106 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
109107 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
109108 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
109109 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
109110 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
109111 +ll_layout_fetch_24961 ll_layout_fetch 0 24961 NULL
109112 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
109113 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
109114 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
109115 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
109116 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
109117 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
109118 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
109119 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
109120 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
109121 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
109122 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
109123 +iwl_dbgfs_tx_flush_write_25091 iwl_dbgfs_tx_flush_write 3 25091 NULL
109124 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
109125 +blkg_path_25099 blkg_path 3 25099 NULL
109126 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
109127 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
109128 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
109129 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
109130 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
109131 +stripe_status_25259 stripe_status 5 25259 NULL
109132 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
109133 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
109134 +vfs_writev_25278 vfs_writev 3 25278 NULL
109135 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
109136 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
109137 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
109138 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
109139 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
109140 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
109141 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
109142 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
109143 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
109144 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
109145 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
109146 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
109147 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
109148 +sb_permission_25523 sb_permission 0 25523 NULL
109149 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
109150 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
109151 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
109152 +ht_print_chan_25556 ht_print_chan 3-4-0 25556 NULL
109153 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
109154 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
109155 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
109156 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
109157 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
109158 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
109159 +__direct_map_25647 __direct_map 6-5 25647 NULL
109160 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
109161 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
109162 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
109163 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
109164 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
109165 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
109166 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
109167 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
109168 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
109169 +sg_read_25799 sg_read 3 25799 NULL
109170 +system_enable_read_25815 system_enable_read 3 25815 NULL
109171 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
109172 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
109173 +parport_read_25855 parport_read 0 25855 NULL
109174 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
109175 +key_attr_size_25865 key_attr_size 0 25865 NULL
109176 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
109177 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
109178 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
109179 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
109180 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
109181 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
109182 +rcname_read_25919 rcname_read 3 25919 NULL
109183 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
109184 +key_flags_read_25931 key_flags_read 3 25931 NULL
109185 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
109186 +flush_25957 flush 2 25957 NULL
109187 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
109188 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
109189 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
109190 +xfs_xattr_acl_set_26028 xfs_xattr_acl_set 4 26028 NULL
109191 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
109192 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
109193 +tun_do_read_26047 tun_do_read 5 26047 NULL
109194 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
109195 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
109196 +read_sb_page_26119 read_sb_page 5 26119 NULL
109197 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
109198 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
109199 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
109200 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
109201 +disk_devt_26180 disk_devt 0 26180 NULL
109202 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
109203 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
109204 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
109205 +mce_write_26201 mce_write 3 26201 NULL
109206 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
109207 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
109208 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
109209 +bio_split_26235 bio_split 2 26235 NULL
109210 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
109211 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
109212 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
109213 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL nohasharray
109214 +pax_get_random_long_26309 pax_get_random_long 0 26309 &snd_pcm_plug_client_channels_buf_26309
109215 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
109216 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
109217 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
109218 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
109219 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
109220 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
109221 +ntty_write_26404 ntty_write 3 26404 NULL
109222 +firmware_store_26408 firmware_store 4 26408 NULL
109223 +pagemap_read_26441 pagemap_read 3 26441 NULL
109224 +tower_read_26461 tower_read 3 26461 NULL nohasharray
109225 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
109226 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
109227 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
109228 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
109229 +read_vmcore_26501 read_vmcore 3 26501 NULL
109230 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
109231 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
109232 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
109233 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
109234 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
109235 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
109236 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
109237 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
109238 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
109239 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
109240 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
109241 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
109242 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
109243 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
109244 +bos_desc_26752 bos_desc 0 26752 NULL
109245 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
109246 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
109247 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
109248 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
109249 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
109250 +smk_write_load_26829 smk_write_load 3 26829 NULL
109251 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
109252 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
109253 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
109254 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
109255 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
109256 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
109257 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
109258 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
109259 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
109260 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
109261 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
109262 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
109263 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
109264 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
109265 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
109266 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
109267 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
109268 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
109269 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
109270 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
109271 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
109272 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
109273 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
109274 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
109275 +pms_capture_27142 pms_capture 4 27142 NULL
109276 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
109277 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
109278 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
109279 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
109280 +write_kmem_27225 write_kmem 3 27225 NULL
109281 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
109282 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
109283 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
109284 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
109285 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
109286 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
109287 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
109288 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
109289 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
109290 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
109291 +seq_read_27411 seq_read 3 27411 NULL
109292 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
109293 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
109294 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0-3-4 27422 NULL
109295 +cypress_write_27423 cypress_write 4 27423 NULL
109296 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
109297 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
109298 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
109299 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
109300 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
109301 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
109302 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
109303 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
109304 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
109305 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
109306 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
109307 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
109308 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
109309 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
109310 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
109311 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642
109312 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
109313 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
109314 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
109315 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
109316 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
109317 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
109318 +evm_write_key_27715 evm_write_key 3 27715 NULL
109319 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
109320 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
109321 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
109322 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
109323 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
109324 +SyS_readv_27804 SyS_readv 3 27804 NULL
109325 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
109326 +fwtty_buffer_rx_27821 fwtty_buffer_rx 3 27821 NULL
109327 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
109328 +init_header_complete_27833 init_header_complete 0 27833 NULL
109329 +read_profile_27859 read_profile 3 27859 NULL
109330 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
109331 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
109332 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
109333 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
109334 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
109335 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
109336 +device_register_27972 device_register 0 27972 NULL nohasharray
109337 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
109338 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
109339 +f2fs_bio_alloc_27983 f2fs_bio_alloc 2 27983 NULL
109340 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
109341 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
109342 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
109343 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
109344 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
109345 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
109346 +pool_status_28055 pool_status 5 28055 NULL
109347 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
109348 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
109349 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
109350 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
109351 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
109352 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
109353 +video_read_28148 video_read 3 28148 NULL
109354 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
109355 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
109356 +vread_28173 vread 0-3 28173 NULL
109357 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
109358 +counter_free_res_28187 counter_free_res 5 28187 NULL
109359 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
109360 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
109361 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
109362 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
109363 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
109364 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
109365 +usemap_size_28281 usemap_size 0 28281 NULL
109366 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
109367 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
109368 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
109369 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
109370 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
109371 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
109372 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
109373 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
109374 +snapshot_write_28351 snapshot_write 3 28351 NULL
109375 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
109376 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
109377 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
109378 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
109379 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
109380 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
109381 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
109382 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
109383 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
109384 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
109385 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
109386 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
109387 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
109388 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
109389 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
109390 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
109391 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
109392 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
109393 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
109394 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
109395 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
109396 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
109397 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
109398 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
109399 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
109400 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
109401 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
109402 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
109403 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
109404 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
109405 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
109406 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
109407 +spi_execute_28736 spi_execute 5 28736 NULL
109408 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
109409 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
109410 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
109411 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
109412 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
109413 +sel_write_member_28800 sel_write_member 3 28800 NULL
109414 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
109415 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
109416 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
109417 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
109418 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
109419 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
109420 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
109421 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
109422 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
109423 +push_rx_28939 push_rx 3 28939 NULL
109424 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
109425 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
109426 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
109427 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
109428 +bin_uuid_28999 bin_uuid 3 28999 NULL
109429 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
109430 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
109431 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
109432 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
109433 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
109434 +roundup_64_29066 roundup_64 2-0-1 29066 NULL
109435 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
109436 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
109437 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
109438 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
109439 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
109440 +snprintf_29125 snprintf 0 29125 NULL
109441 +iov_shorten_29130 iov_shorten 0 29130 NULL
109442 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
109443 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
109444 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
109445 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
109446 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
109447 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
109448 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
109449 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
109450 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
109451 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
109452 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
109453 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
109454 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
109455 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
109456 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
109457 +tun_put_user_29337 tun_put_user 5 29337 NULL
109458 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
109459 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
109460 +mwifiex_cfg80211_mgmt_tx_29387 mwifiex_cfg80211_mgmt_tx 7 29387 NULL
109461 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
109462 +mempool_create_29437 mempool_create 1 29437 NULL
109463 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
109464 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
109465 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
109466 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
109467 +do_register_entry_29478 do_register_entry 4 29478 NULL
109468 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
109469 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
109470 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
109471 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
109472 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
109473 +ftrace_write_29551 ftrace_write 3 29551 NULL
109474 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
109475 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
109476 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
109477 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
109478 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
109479 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
109480 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
109481 +slots_per_page_29601 slots_per_page 0 29601 NULL
109482 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
109483 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
109484 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
109485 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
109486 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
109487 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
109488 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
109489 +probes_write_29711 probes_write 3 29711 NULL
109490 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
109491 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
109492 +std_nic_write_29752 std_nic_write 3 29752 NULL
109493 +dbAlloc_29794 dbAlloc 0 29794 NULL
109494 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
109495 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
109496 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
109497 +count_partial_29850 count_partial 0 29850 NULL
109498 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
109499 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
109500 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
109501 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
109502 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
109503 +write_file_queue_29922 write_file_queue 3 29922 NULL
109504 +ext4_xattr_set_acl_29930 ext4_xattr_set_acl 4 29930 NULL
109505 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
109506 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
109507 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
109508 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
109509 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
109510 +drp_wmove_30043 drp_wmove 4 30043 NULL
109511 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
109512 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
109513 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
109514 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
109515 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
109516 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
109517 +recv_stream_30138 recv_stream 4 30138 NULL
109518 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
109519 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
109520 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
109521 +expand_inode_data_30169 expand_inode_data 2-3 30169 NULL
109522 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
109523 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
109524 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
109525 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
109526 +SyS_semop_30227 SyS_semop 3 30227 NULL
109527 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
109528 +ocfs2_calc_bg_discontig_credits_30230 ocfs2_calc_bg_discontig_credits 0 30230 NULL
109529 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
109530 +hfsplus_trusted_setxattr_30270 hfsplus_trusted_setxattr 4 30270 NULL
109531 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
109532 +compat_readv_30273 compat_readv 3 30273 NULL
109533 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
109534 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
109535 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
109536 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
109537 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
109538 +i8254_read_30330 i8254_read 0 30330 NULL
109539 +resource_from_user_30341 resource_from_user 3 30341 NULL
109540 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
109541 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
109542 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
109543 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
109544 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
109545 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
109546 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
109547 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
109548 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
109549 +enable_write_30456 enable_write 3 30456 NULL
109550 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
109551 +urandom_read_30462 urandom_read 3 30462 NULL
109552 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
109553 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
109554 +adu_write_30487 adu_write 3 30487 NULL
109555 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
109556 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
109557 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
109558 +set_config_30526 set_config 0 30526 NULL nohasharray
109559 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
109560 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
109561 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
109562 +set_le_30581 set_le 4 30581 NULL
109563 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
109564 +i2c_hid_get_report_length_30598 i2c_hid_get_report_length 0 30598 NULL
109565 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL nohasharray
109566 +cpufreq_get_global_kobject_30610 cpufreq_get_global_kobject 0 30610 &sgl_map_user_pages_30610
109567 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
109568 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
109569 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
109570 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
109571 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
109572 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
109573 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
109574 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
109575 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
109576 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
109577 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
109578 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
109579 +snapshot_status_30744 snapshot_status 5 30744 NULL
109580 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
109581 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
109582 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
109583 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
109584 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
109585 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
109586 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
109587 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
109588 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
109589 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
109590 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
109591 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
109592 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
109593 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
109594 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
109595 +stride_pg_count_31053 stride_pg_count 0-2-1-4-3-5 31053 NULL
109596 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
109597 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
109598 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
109599 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
109600 +depth_read_31112 depth_read 3 31112 NULL
109601 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
109602 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
109603 +size_inside_page_31141 size_inside_page 0 31141 NULL
109604 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
109605 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
109606 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
109607 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
109608 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
109609 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
109610 +__read_reg_31216 __read_reg 0 31216 NULL
109611 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
109612 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
109613 +cyy_readb_31240 cyy_readb 0 31240 NULL
109614 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
109615 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
109616 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
109617 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
109618 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
109619 +command_file_write_31318 command_file_write 3 31318 NULL
109620 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
109621 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
109622 +outlen_write_31358 outlen_write 3 31358 NULL
109623 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
109624 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
109625 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
109626 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
109627 +inb_31388 inb 0 31388 NULL
109628 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
109629 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
109630 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
109631 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
109632 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
109633 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
109634 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
109635 +alg_setkey_31485 alg_setkey 3 31485 NULL
109636 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
109637 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
109638 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
109639 +hidraw_write_31536 hidraw_write 3 31536 NULL
109640 +usbvision_read_31555 usbvision_read 3 31555 NULL
109641 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
109642 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
109643 +osst_write_31581 osst_write 3 31581 NULL
109644 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
109645 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
109646 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
109647 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
109648 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
109649 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
109650 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
109651 +__lgread_31668 __lgread 4 31668 NULL
109652 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
109653 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
109654 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
109655 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
109656 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
109657 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
109658 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
109659 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
109660 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
109661 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
109662 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
109663 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
109664 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
109665 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
109666 +data_write_31805 data_write 3 31805 NULL
109667 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
109668 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
109669 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
109670 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
109671 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
109672 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
109673 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
109674 +xattr_permission_31907 xattr_permission 0 31907 NULL
109675 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
109676 +new_dir_31919 new_dir 3 31919 NULL
109677 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
109678 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
109679 +read_mem_31942 read_mem 3 31942 NULL nohasharray
109680 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
109681 +vb2_write_31948 vb2_write 3 31948 NULL
109682 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
109683 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
109684 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
109685 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
109686 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
109687 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
109688 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
109689 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
109690 +calc_hmac_32010 calc_hmac 3 32010 NULL
109691 +aead_len_32021 aead_len 0 32021 NULL
109692 +posix_acl_set_32037 posix_acl_set 4 32037 NULL
109693 +stk_read_32038 stk_read 3 32038 NULL
109694 +ocfs2_update_edge_lengths_32046 ocfs2_update_edge_lengths 3 32046 NULL
109695 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
109696 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
109697 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
109698 +bio_alloc_32095 bio_alloc 2 32095 NULL
109699 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
109700 +disk_status_32120 disk_status 4 32120 NULL
109701 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
109702 +venus_link_32165 venus_link 5 32165 NULL
109703 +do_writepages_32173 do_writepages 0 32173 NULL
109704 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
109705 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
109706 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
109707 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
109708 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
109709 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
109710 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
109711 +SyS_select_32319 SyS_select 1 32319 NULL
109712 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
109713 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
109714 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
109715 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
109716 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
109717 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
109718 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
109719 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
109720 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
109721 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
109722 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
109723 +cache_status_32462 cache_status 5 32462 NULL
109724 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
109725 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
109726 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
109727 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
109728 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
109729 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
109730 +disconnect_32521 disconnect 4 32521 NULL
109731 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
109732 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL nohasharray
109733 +audio_get_intf_req_32524 audio_get_intf_req 0 32524 &ocfs2_refresh_qinfo_32524
109734 +ilo_read_32531 ilo_read 3 32531 NULL
109735 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
109736 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
109737 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
109738 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
109739 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
109740 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
109741 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
109742 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
109743 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
109744 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
109745 +kvmalloc_32646 kvmalloc 1 32646 NULL
109746 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
109747 +generic_readlink_32654 generic_readlink 3 32654 NULL
109748 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
109749 +apei_res_add_32674 apei_res_add 0 32674 NULL
109750 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
109751 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
109752 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
109753 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
109754 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
109755 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
109756 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
109757 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
109758 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
109759 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
109760 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
109761 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
109762 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 6-4 32884 NULL
109763 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
109764 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
109765 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
109766 +xfs_log_reserve_32959 xfs_log_reserve 2 32959 NULL
109767 +ocfs2_check_dir_trailer_32968 ocfs2_check_dir_trailer 0 32968 NULL
109768 +compat_filldir_32999 compat_filldir 3 32999 NULL
109769 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
109770 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
109771 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
109772 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
109773 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
109774 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
109775 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
109776 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
109777 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
109778 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
109779 +alloc_tio_33077 alloc_tio 3 33077 NULL
109780 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
109781 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
109782 +__len_within_target_33132 __len_within_target 0 33132 NULL
109783 +SyS_poll_33152 SyS_poll 2 33152 NULL
109784 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
109785 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
109786 +pp_read_33210 pp_read 3 33210 NULL
109787 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
109788 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
109789 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
109790 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
109791 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
109792 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
109793 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
109794 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
109795 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
109796 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
109797 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
109798 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
109799 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
109800 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
109801 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
109802 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
109803 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
109804 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
109805 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
109806 +message_stats_list_33440 message_stats_list 5 33440 NULL
109807 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
109808 +create_entry_33479 create_entry 2 33479 NULL
109809 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL nohasharray
109810 +elf_map_33487 elf_map 0-2 33487 &ip_setsockopt_33487
109811 +res_counter_read_33499 res_counter_read 4 33499 NULL
109812 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
109813 +fb_read_33506 fb_read 3 33506 NULL
109814 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
109815 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
109816 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
109817 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
109818 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
109819 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
109820 +count_subheaders_33591 count_subheaders 0 33591 NULL
109821 +scsi_execute_33596 scsi_execute 5 33596 NULL
109822 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
109823 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
109824 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
109825 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
109826 +stride_page_count_33641 stride_page_count 2 33641 NULL
109827 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
109828 +inw_p_33668 inw_p 0 33668 NULL
109829 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
109830 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
109831 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
109832 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
109833 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
109834 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
109835 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
109836 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
109837 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
109838 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
109839 +hashtab_create_33769 hashtab_create 3 33769 NULL
109840 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
109841 +filter_write_33819 filter_write 3 33819 NULL
109842 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
109843 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
109844 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
109845 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
109846 +get_user_pages_33908 get_user_pages 0 33908 NULL
109847 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
109848 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
109849 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
109850 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
109851 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
109852 +hfsplus_osx_setxattr_33952 hfsplus_osx_setxattr 4 33952 NULL
109853 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
109854 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
109855 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
109856 +ppp_write_34034 ppp_write 3 34034 NULL
109857 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
109858 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
109859 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
109860 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
109861 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
109862 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
109863 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
109864 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
109865 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
109866 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
109867 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
109868 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
109869 +sysfs_bin_read_34228 sysfs_bin_read 3 34228 NULL
109870 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
109871 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
109872 +device_private_init_34279 device_private_init 0 34279 NULL
109873 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
109874 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
109875 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
109876 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
109877 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
109878 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
109879 +ea_read_34378 ea_read 0 34378 NULL
109880 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
109881 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
109882 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
109883 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
109884 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
109885 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
109886 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
109887 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
109888 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
109889 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
109890 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
109891 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
109892 +ocfs2_mv_xattr_buckets_34484 ocfs2_mv_xattr_buckets 6 34484 NULL
109893 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
109894 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
109895 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
109896 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
109897 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
109898 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
109899 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
109900 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
109901 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
109902 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
109903 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
109904 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
109905 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
109906 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
109907 +brcmf_cfg80211_mgmt_tx_34608 brcmf_cfg80211_mgmt_tx 7 34608 NULL
109908 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
109909 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
109910 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
109911 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
109912 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
109913 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
109914 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
109915 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
109916 +port_print_34704 port_print 3 34704 NULL
109917 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
109918 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
109919 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
109920 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
109921 +bootmode_store_34762 bootmode_store 4 34762 NULL
109922 +device_add_34766 device_add 0 34766 NULL
109923 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
109924 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
109925 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
109926 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
109927 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
109928 +file_page_index_34820 file_page_index 0-2 34820 NULL
109929 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
109930 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
109931 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
109932 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
109933 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
109934 +msg_print_text_34889 msg_print_text 0 34889 NULL
109935 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
109936 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
109937 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
109938 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
109939 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
109940 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
109941 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
109942 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
109943 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
109944 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
109945 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
109946 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
109947 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
109948 +brcmf_sdio_chip_writenvram_35042 brcmf_sdio_chip_writenvram 4 35042 NULL
109949 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
109950 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
109951 +capi_write_35104 capi_write 3 35104 NULL nohasharray
109952 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
109953 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
109954 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
109955 +message_stats_print_35158 message_stats_print 6 35158 NULL
109956 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
109957 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
109958 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
109959 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
109960 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
109961 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
109962 +set_fd_set_35249 set_fd_set 1 35249 NULL
109963 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
109964 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
109965 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
109966 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
109967 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
109968 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
109969 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
109970 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
109971 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
109972 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
109973 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
109974 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
109975 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
109976 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
109977 +read_kmem_35372 read_kmem 3 35372 NULL
109978 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
109979 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
109980 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
109981 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
109982 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
109983 +async_setkey_35521 async_setkey 3 35521 NULL
109984 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
109985 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
109986 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
109987 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
109988 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
109989 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
109990 +sysfs_create_subdir_35567 sysfs_create_subdir 0 35567 NULL
109991 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
109992 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
109993 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
109994 +kernel_readv_35617 kernel_readv 3 35617 NULL
109995 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
109996 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
109997 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
109998 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
109999 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
110000 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
110001 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
110002 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
110003 +md_super_write_35703 md_super_write 4 35703 NULL
110004 +ocfs2_extent_recs_per_gd_35710 ocfs2_extent_recs_per_gd 0 35710 NULL
110005 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
110006 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
110007 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
110008 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
110009 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
110010 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
110011 +fls64_35862 fls64 0 35862 NULL
110012 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
110013 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
110014 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
110015 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
110016 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
110017 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
110018 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
110019 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
110020 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
110021 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
110022 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
110023 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
110024 +acl_alloc_35979 acl_alloc 1 35979 NULL
110025 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
110026 +generic_file_aio_read_35987 generic_file_aio_read 0 35987 NULL
110027 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
110028 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
110029 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
110030 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
110031 +account_shadowed_36048 account_shadowed 2 36048 NULL
110032 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
110033 +write_emulate_36065 write_emulate 2-4 36065 NULL
110034 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
110035 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
110036 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
110037 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
110038 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
110039 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
110040 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
110041 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
110042 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
110043 +twl_set_36154 twl_set 2 36154 NULL
110044 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
110045 +btrfs_file_extent_inline_len_36158 btrfs_file_extent_inline_len 0 36158 NULL
110046 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
110047 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
110048 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
110049 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
110050 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
110051 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
110052 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
110053 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
110054 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
110055 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
110056 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
110057 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
110058 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
110059 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
110060 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
110061 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
110062 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
110063 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
110064 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
110065 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
110066 +lc_create_36332 lc_create 4 36332 NULL
110067 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
110068 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
110069 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
110070 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
110071 +to_sector_36361 to_sector 0-1 36361 NULL
110072 +tunables_read_36385 tunables_read 3 36385 NULL
110073 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
110074 +sierra_write_36402 sierra_write 4 36402 NULL
110075 +iwl_dbgfs_d3_sram_write_36403 iwl_dbgfs_d3_sram_write 3 36403 NULL
110076 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
110077 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
110078 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
110079 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
110080 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
110081 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
110082 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
110083 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
110084 +cmd_loop_36491 cmd_loop 0 36491 NULL
110085 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
110086 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
110087 +get_param_l_36518 get_param_l 0 36518 NULL
110088 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
110089 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
110090 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
110091 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL nohasharray
110092 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
110093 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
110094 +__erst_read_36579 __erst_read 0 36579 NULL
110095 +put_cmsg_36589 put_cmsg 4 36589 NULL
110096 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
110097 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
110098 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
110099 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
110100 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
110101 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
110102 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
110103 +xillybus_read_36678 xillybus_read 3 36678 NULL
110104 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
110105 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
110106 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
110107 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
110108 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
110109 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 2-3-4-5 36796 NULL
110110 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
110111 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
110112 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
110113 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
110114 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
110115 +cm_write_36858 cm_write 3 36858 NULL
110116 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
110117 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
110118 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
110119 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
110120 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
110121 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
110122 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
110123 +audio_set_endpoint_req_36918 audio_set_endpoint_req 0 36918 NULL
110124 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
110125 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
110126 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
110127 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
110128 +setxattr_37006 setxattr 4 37006 NULL
110129 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
110130 +command_file_read_37038 command_file_read 3 37038 NULL
110131 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
110132 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
110133 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
110134 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
110135 +parse_command_37079 parse_command 2 37079 NULL
110136 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
110137 +tun_get_user_37094 tun_get_user 5 37094 NULL
110138 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
110139 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
110140 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
110141 +msg_word_37164 msg_word 0 37164 NULL
110142 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
110143 +can_set_xattr_37182 can_set_xattr 4 37182 NULL
110144 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
110145 +sysfs_add_file_37200 sysfs_add_file 0 37200 NULL
110146 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
110147 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
110148 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
110149 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
110150 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
110151 +__do_replace_37227 __do_replace 5 37227 NULL
110152 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
110153 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
110154 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
110155 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
110156 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
110157 +ocfs2_calc_extend_credits_37310 ocfs2_calc_extend_credits 0 37310 NULL
110158 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
110159 +send_msg_37323 send_msg 4 37323 NULL
110160 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
110161 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
110162 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
110163 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
110164 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
110165 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
110166 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
110167 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
110168 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 7-9-0 37433 NULL
110169 +fru_alloc_37442 fru_alloc 1 37442 NULL
110170 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
110171 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
110172 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
110173 +get_est_timing_37484 get_est_timing 0 37484 NULL
110174 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
110175 +__hfsplus_setxattr_37499 __hfsplus_setxattr 4 37499 NULL
110176 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
110177 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
110178 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
110179 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
110180 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
110181 +hdr_size_37536 hdr_size 0 37536 NULL
110182 +extent_map_end_37550 extent_map_end 0 37550 NULL
110183 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
110184 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
110185 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
110186 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
110187 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
110188 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
110189 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
110190 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
110191 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
110192 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
110193 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
110194 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
110195 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
110196 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
110197 +page_chain_free_37697 page_chain_free 0 37697 NULL
110198 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
110199 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
110200 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
110201 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
110202 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
110203 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
110204 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
110205 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
110206 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
110207 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
110208 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
110209 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
110210 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
110211 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
110212 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
110213 +set_registers_37883 set_registers 4 37883 NULL
110214 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
110215 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
110216 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
110217 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
110218 +write_file_bool_37957 write_file_bool 3 37957 NULL
110219 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
110220 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
110221 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
110222 +vfs_readv_38011 vfs_readv 3 38011 NULL
110223 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
110224 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
110225 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
110226 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
110227 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
110228 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
110229 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
110230 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
110231 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
110232 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
110233 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
110234 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
110235 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
110236 +ep0_read_38095 ep0_read 3 38095 NULL
110237 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
110238 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
110239 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
110240 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
110241 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
110242 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
110243 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
110244 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
110245 +cdev_add_38176 cdev_add 2-3 38176 NULL
110246 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
110247 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
110248 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
110249 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
110250 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
110251 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
110252 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
110253 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
110254 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
110255 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
110256 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
110257 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
110258 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
110259 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
110260 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
110261 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
110262 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
110263 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
110264 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
110265 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
110266 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
110267 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
110268 +dev_names_read_38509 dev_names_read 3 38509 NULL
110269 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
110270 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
110271 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
110272 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
110273 +kuc_len_38557 kuc_len 0-1 38557 NULL
110274 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
110275 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
110276 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
110277 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
110278 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
110279 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
110280 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
110281 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
110282 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
110283 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
110284 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
110285 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
110286 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
110287 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
110288 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
110289 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
110290 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
110291 +udf_readpages_38761 udf_readpages 4 38761 NULL
110292 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
110293 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
110294 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
110295 +slab_order_38794 slab_order 0 38794 NULL
110296 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
110297 +err_decode_38804 err_decode 2 38804 NULL
110298 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
110299 +direct_entry_38836 direct_entry 3 38836 NULL
110300 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
110301 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
110302 +interfaces_38859 interfaces 2 38859 NULL
110303 +pci_msix_table_size_38867 pci_msix_table_size 0 38867 NULL
110304 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
110305 +f2fs_xattr_set_acl_38895 f2fs_xattr_set_acl 4 38895 NULL
110306 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
110307 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
110308 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
110309 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
110310 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
110311 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
110312 +get_nodes_39012 get_nodes 3 39012 NULL
110313 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
110314 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
110315 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
110316 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
110317 +ReadHFC_39104 ReadHFC 0 39104 NULL
110318 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
110319 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
110320 +ea_foreach_39133 ea_foreach 0 39133 NULL
110321 +generic_permission_39150 generic_permission 0 39150 NULL
110322 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
110323 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
110324 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
110325 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
110326 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
110327 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
110328 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
110329 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
110330 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
110331 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
110332 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
110333 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
110334 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
110335 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
110336 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
110337 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
110338 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
110339 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
110340 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
110341 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
110342 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
110343 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
110344 +__send_to_port_39386 __send_to_port 3 39386 NULL
110345 +user_power_read_39414 user_power_read 3 39414 NULL
110346 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
110347 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
110348 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
110349 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
110350 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
110351 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
110352 +int_proc_write_39542 int_proc_write 3 39542 NULL
110353 +mdc_unpack_capa_39553 mdc_unpack_capa 0 39553 NULL
110354 +pp_write_39554 pp_write 3 39554 NULL
110355 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
110356 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
110357 +ext_depth_39607 ext_depth 0 39607 NULL
110358 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
110359 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
110360 +sdio_readb_39618 sdio_readb 0 39618 NULL
110361 +set_dev_class_39645 set_dev_class 4 39645 NULL
110362 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
110363 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
110364 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
110365 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
110366 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
110367 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
110368 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
110369 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
110370 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
110371 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
110372 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
110373 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
110374 +pkt_add_39897 pkt_add 3 39897 NULL
110375 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
110376 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
110377 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
110378 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
110379 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
110380 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
110381 +__spi_async_39932 __spi_async 0 39932 NULL
110382 +__get_order_39935 __get_order 0 39935 NULL
110383 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
110384 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
110385 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
110386 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
110387 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
110388 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
110389 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
110390 +server_name2svname_39998 server_name2svname 4 39998 NULL
110391 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
110392 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
110393 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
110394 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
110395 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
110396 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
110397 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
110398 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
110399 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
110400 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
110401 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
110402 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
110403 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
110404 +pt_write_40159 pt_write 3 40159 NULL
110405 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
110406 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
110407 +allocate_probes_40204 allocate_probes 1 40204 NULL
110408 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
110409 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
110410 +osst_read_40237 osst_read 3 40237 NULL
110411 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
110412 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
110413 +ptlrpc_queue_wait_40252 ptlrpc_queue_wait 0 40252 NULL
110414 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
110415 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
110416 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
110417 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
110418 +SyS_bind_40303 SyS_bind 3 40303 NULL
110419 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
110420 +mmio_read_40348 mmio_read 4 40348 NULL
110421 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
110422 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
110423 +get_chars_40373 get_chars 3 40373 NULL
110424 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
110425 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
110426 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
110427 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
110428 +SyS_writev_40467 SyS_writev 3 40467 NULL
110429 +SyS_select_40473 SyS_select 1 40473 NULL
110430 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
110431 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
110432 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
110433 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
110434 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
110435 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
110436 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
110437 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
110438 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
110439 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
110440 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
110441 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
110442 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
110443 +fops_read_40672 fops_read 3 40672 NULL
110444 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
110445 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
110446 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
110447 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
110448 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
110449 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
110450 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
110451 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
110452 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
110453 +card_send_command_40757 card_send_command 3 40757 NULL
110454 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
110455 +pg_write_40766 pg_write 3 40766 NULL
110456 +show_list_40775 show_list 3-0 40775 NULL
110457 +kfifo_out_copy_r_40784 kfifo_out_copy_r 3-0 40784 NULL
110458 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
110459 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
110460 +add_action_40811 add_action 4 40811 NULL
110461 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
110462 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
110463 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
110464 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
110465 +read_file_queue_40895 read_file_queue 3 40895 NULL
110466 +waiters_read_40902 waiters_read 3 40902 NULL
110467 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
110468 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
110469 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
110470 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
110471 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
110472 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
110473 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
110474 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
110475 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
110476 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
110477 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
110478 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
110479 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
110480 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
110481 +calculate_order_41061 calculate_order 0 41061 NULL
110482 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
110483 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
110484 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
110485 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
110486 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
110487 +dma_attach_41094 dma_attach 5-6 41094 NULL
110488 +provide_user_output_41105 provide_user_output 3 41105 NULL
110489 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
110490 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
110491 +ocfs2_extend_trans_41116 ocfs2_extend_trans 2 41116 NULL
110492 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
110493 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
110494 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
110495 +dgap_driver_kzmalloc_41189 dgap_driver_kzmalloc 1 41189 NULL
110496 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
110497 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
110498 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
110499 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
110500 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
110501 +erst_read_41260 erst_read 0 41260 NULL
110502 +alloc_context_41283 alloc_context 1 41283 NULL
110503 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
110504 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
110505 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
110506 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
110507 +kmp_init_41373 kmp_init 2 41373 NULL
110508 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
110509 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
110510 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
110511 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
110512 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
110513 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
110514 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
110515 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
110516 +se_io_cb_41461 se_io_cb 3 41461 NULL
110517 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
110518 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
110519 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
110520 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
110521 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
110522 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
110523 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
110524 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
110525 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
110526 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
110527 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
110528 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
110529 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
110530 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
110531 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
110532 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
110533 +vga_io_r_41609 vga_io_r 0 41609 NULL
110534 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
110535 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
110536 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
110537 +a2mp_send_41615 a2mp_send 4 41615 NULL
110538 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
110539 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
110540 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
110541 +get_std_timing_41654 get_std_timing 0 41654 NULL
110542 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
110543 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
110544 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
110545 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
110546 +fillonedir_41746 fillonedir 3 41746 NULL
110547 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
110548 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
110549 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
110550 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
110551 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
110552 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
110553 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
110554 +pci_map_single_41869 pci_map_single 0 41869 NULL
110555 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
110556 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
110557 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
110558 +nfsd_getxattr_41934 nfsd_getxattr 0 41934 NULL
110559 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
110560 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
110561 +read_gssp_41947 read_gssp 3 41947 NULL
110562 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
110563 +portnames_read_41958 portnames_read 3 41958 NULL
110564 +dst_mtu_41969 dst_mtu 0 41969 NULL
110565 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
110566 +pool_allocate_42012 pool_allocate 3 42012 NULL
110567 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
110568 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
110569 +create_dir_42025 create_dir 0 42025 NULL
110570 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
110571 +__btrfs_drop_extents_42032 __btrfs_drop_extents 5 42032 NULL
110572 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
110573 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
110574 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
110575 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
110576 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
110577 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
110578 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
110579 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
110580 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
110581 +obd_get_info_42156 obd_get_info 0 42156 NULL
110582 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
110583 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
110584 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
110585 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
110586 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
110587 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
110588 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
110589 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
110590 +find_last_bit_42260 find_last_bit 0 42260 NULL
110591 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
110592 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
110593 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
110594 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
110595 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
110596 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
110597 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
110598 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
110599 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
110600 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
110601 +tipc_send_42374 tipc_send 3 42374 NULL
110602 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
110603 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
110604 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
110605 +krng_get_random_42420 krng_get_random 3 42420 NULL
110606 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
110607 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
110608 +alloc_request_42448 alloc_request 0 42448 NULL
110609 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
110610 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
110611 +kuc_free_42455 kuc_free 2 42455 NULL
110612 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
110613 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
110614 +bypass_write_42498 bypass_write 3 42498 NULL
110615 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
110616 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
110617 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
110618 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
110619 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
110620 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
110621 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
110622 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
110623 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
110624 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
110625 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
110626 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
110627 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
110628 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
110629 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
110630 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
110631 +vb2_read_42703 vb2_read 3 42703 NULL
110632 +read_status_42722 read_status 0 42722 NULL
110633 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
110634 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
110635 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
110636 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
110637 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
110638 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
110639 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
110640 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
110641 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
110642 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
110643 +ptlrpc_request_bufs_pack_42793 ptlrpc_request_bufs_pack 0 42793 NULL
110644 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
110645 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
110646 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
110647 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
110648 +set_arg_42824 set_arg 3 42824 NULL
110649 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
110650 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
110651 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
110652 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
110653 +hd_end_request_42904 hd_end_request 2 42904 NULL
110654 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
110655 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL nohasharray
110656 +mdc_unpack_acl_42941 mdc_unpack_acl 0 42941 &sctp_getsockopt_maxburst_42941
110657 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
110658 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
110659 +read_file_node_stat_42964 read_file_node_stat 3 42964 NULL
110660 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
110661 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
110662 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
110663 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
110664 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
110665 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
110666 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
110667 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
110668 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
110669 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
110670 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
110671 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
110672 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
110673 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
110674 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
110675 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
110676 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
110677 +uio_write_43202 uio_write 3 43202 NULL
110678 +iso_callback_43208 iso_callback 3 43208 NULL
110679 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
110680 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
110681 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
110682 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
110683 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
110684 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
110685 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
110686 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
110687 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
110688 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
110689 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
110690 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
110691 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
110692 +xenfb_write_43412 xenfb_write 3 43412 NULL
110693 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
110694 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
110695 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
110696 +usb_string_43443 usb_string 0 43443 NULL nohasharray
110697 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
110698 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
110699 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
110700 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
110701 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
110702 +do_readlink_43518 do_readlink 2 43518 NULL
110703 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
110704 +read_events_43534 read_events 3 43534 NULL
110705 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
110706 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
110707 +request_resource_43548 request_resource 0 43548 NULL
110708 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
110709 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
110710 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
110711 +proc_read_43614 proc_read 3 43614 NULL
110712 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
110713 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
110714 +random_write_43656 random_write 3 43656 NULL
110715 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
110716 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
110717 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
110718 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
110719 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
110720 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
110721 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
110722 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
110723 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
110724 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
110725 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
110726 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
110727 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
110728 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
110729 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
110730 +read_flush_43851 read_flush 3 43851 NULL
110731 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
110732 +SendString_43928 SendString 3 43928 NULL
110733 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
110734 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
110735 +nla_reserve_43984 nla_reserve 3 43984 NULL
110736 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
110737 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
110738 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
110739 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
110740 +emit_flags_44006 emit_flags 4-3 44006 NULL
110741 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
110742 +fru_strlen_44046 fru_strlen 0 44046 NULL
110743 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
110744 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
110745 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 NULL
110746 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
110747 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
110748 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
110749 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
110750 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
110751 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
110752 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
110753 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
110754 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
110755 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
110756 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
110757 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
110758 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
110759 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
110760 +device_create_file_44285 device_create_file 0 44285 NULL
110761 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
110762 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
110763 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
110764 +rs_init_44327 rs_init 1 44327 NULL
110765 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
110766 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
110767 +alloc_requests_44372 alloc_requests 0 44372 NULL
110768 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
110769 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
110770 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
110771 +strlcpy_44400 strlcpy 3 44400 NULL
110772 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
110773 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
110774 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
110775 +iwl_dbgfs_bf_params_write_44450 iwl_dbgfs_bf_params_write 3 44450 NULL
110776 +write_file_debug_44476 write_file_debug 3 44476 NULL
110777 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
110778 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
110779 +bio_advance_44496 bio_advance 2 44496 NULL
110780 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
110781 +ac_register_board_44504 ac_register_board 3 44504 NULL
110782 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
110783 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
110784 +spidev_write_44510 spidev_write 3 44510 NULL
110785 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
110786 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
110787 +comm_write_44537 comm_write 3 44537 NULL
110788 +xfs_log_calc_unit_res_44540 xfs_log_calc_unit_res 0-2 44540 NULL
110789 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
110790 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
110791 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
110792 +mpi_resize_44674 mpi_resize 2 44674 NULL
110793 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
110794 +ts_read_44687 ts_read 3 44687 NULL
110795 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
110796 +__ocfs2_rotate_tree_left_44705 __ocfs2_rotate_tree_left 3 44705 NULL
110797 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
110798 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
110799 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
110800 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
110801 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
110802 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
110803 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
110804 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
110805 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
110806 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
110807 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
110808 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
110809 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
110810 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
110811 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
110812 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
110813 +sisusb_write_44834 sisusb_write 3 44834 NULL
110814 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
110815 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
110816 +copydesc_user_44855 copydesc_user 3 44855 NULL
110817 +set_advertising_44870 set_advertising 4 44870 NULL
110818 +init_rs_44873 init_rs 1 44873 NULL
110819 +skb_availroom_44883 skb_availroom 0 44883 NULL
110820 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
110821 +do_tty_write_44896 do_tty_write 5 44896 NULL
110822 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
110823 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
110824 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
110825 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
110826 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
110827 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
110828 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
110829 +sel_write_user_45060 sel_write_user 3 45060 NULL
110830 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
110831 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
110832 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
110833 +usbdev_read_45114 usbdev_read 3 45114 NULL
110834 +send_to_tty_45141 send_to_tty 3 45141 NULL
110835 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
110836 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
110837 +device_write_45156 device_write 3 45156 NULL nohasharray
110838 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
110839 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
110840 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
110841 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
110842 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
110843 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
110844 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
110845 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
110846 +event_enable_write_45238 event_enable_write 3 45238 NULL
110847 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
110848 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
110849 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
110850 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
110851 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
110852 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
110853 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
110854 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
110855 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
110856 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
110857 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
110858 +__node_remap_45458 __node_remap 4 45458 NULL
110859 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
110860 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
110861 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
110862 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
110863 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
110864 +copy_macs_45534 copy_macs 4 45534 NULL
110865 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
110866 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
110867 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
110868 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
110869 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
110870 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
110871 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
110872 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
110873 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
110874 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
110875 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
110876 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
110877 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
110878 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
110879 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
110880 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL nohasharray
110881 +task_cgroup_path_45734 task_cgroup_path 3 45734 &snd_cs46xx_io_read_45734
110882 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
110883 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
110884 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
110885 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
110886 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
110887 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
110888 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
110889 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
110890 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
110891 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
110892 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
110893 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
110894 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
110895 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
110896 +isdn_write_45863 isdn_write 3 45863 NULL
110897 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
110898 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
110899 +ima_eventdigest_init_common_45889 ima_eventdigest_init_common 2 45889 NULL
110900 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
110901 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
110902 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
110903 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
110904 +alloc_mr_45935 alloc_mr 1 45935 NULL
110905 +copy_to_45969 copy_to 3 45969 NULL
110906 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
110907 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
110908 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
110909 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
110910 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
110911 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
110912 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
110913 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
110914 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
110915 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
110916 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
110917 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
110918 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
110919 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
110920 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
110921 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
110922 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
110923 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
110924 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
110925 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
110926 +fq_resize_46195 fq_resize 2 46195 NULL
110927 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
110928 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
110929 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
110930 +dsp_write_46218 dsp_write 2 46218 NULL
110931 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
110932 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
110933 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
110934 +ReadReg_46277 ReadReg 0 46277 NULL
110935 +sptlrpc_req_get_ctx_46303 sptlrpc_req_get_ctx 0 46303 NULL
110936 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
110937 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
110938 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
110939 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
110940 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
110941 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
110942 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
110943 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
110944 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
110945 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
110946 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
110947 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
110948 +filldir64_46469 filldir64 3 46469 NULL
110949 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
110950 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
110951 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
110952 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
110953 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
110954 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
110955 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
110956 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
110957 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
110958 +il3945_stats_flag_46606 il3945_stats_flag 3-0 46606 NULL
110959 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
110960 +__kfifo_out_r_46623 __kfifo_out_r 3-0 46623 NULL
110961 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
110962 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
110963 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
110964 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
110965 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
110966 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
110967 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
110968 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
110969 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
110970 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
110971 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
110972 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
110973 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
110974 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
110975 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
110976 +readreg_46845 readreg 0 46845 NULL
110977 +spi_async_46857 spi_async 0 46857 NULL
110978 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
110979 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
110980 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
110981 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
110982 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
110983 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
110984 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
110985 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
110986 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
110987 +fb_write_46924 fb_write 3 46924 NULL
110988 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
110989 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
110990 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
110991 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
110992 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
110993 +strlcat_46985 strlcat 3 46985 NULL
110994 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
110995 +sel_write_bool_46996 sel_write_bool 3 46996 NULL nohasharray
110996 +gfs2_xattr_system_set_46996 gfs2_xattr_system_set 4 46996 &sel_write_bool_46996
110997 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
110998 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
110999 +fs_path_len_47060 fs_path_len 0 47060 NULL
111000 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
111001 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
111002 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
111003 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
111004 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
111005 +mousedev_read_47123 mousedev_read 3 47123 NULL
111006 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
111007 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
111008 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
111009 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
111010 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
111011 +can_set_system_xattr_47182 can_set_system_xattr 4 47182 NULL
111012 +options_write_47243 options_write 3 47243 NULL
111013 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
111014 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
111015 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
111016 +vsnprintf_47291 vsnprintf 0 47291 NULL
111017 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
111018 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
111019 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
111020 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
111021 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
111022 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
111023 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
111024 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
111025 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
111026 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
111027 +nametbl_list_47391 nametbl_list 2 47391 NULL
111028 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
111029 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
111030 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
111031 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
111032 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
111033 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
111034 +posix_acl_from_disk_47445 posix_acl_from_disk 2 47445 NULL
111035 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
111036 +newpart_47485 newpart 6-4 47485 NULL
111037 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
111038 +core_sys_select_47494 core_sys_select 1 47494 NULL
111039 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
111040 +unlink_simple_47506 unlink_simple 3 47506 NULL
111041 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
111042 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
111043 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
111044 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
111045 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
111046 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
111047 +read_ldt_47570 read_ldt 2 47570 NULL
111048 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
111049 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
111050 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
111051 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
111052 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
111053 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
111054 +get_size_47644 get_size 1-2 47644 NULL
111055 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
111056 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
111057 +save_microcode_47717 save_microcode 3 47717 NULL
111058 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
111059 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
111060 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
111061 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
111062 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
111063 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
111064 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
111065 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
111066 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
111067 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
111068 +lov_packmd_47810 lov_packmd 0 47810 NULL
111069 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
111070 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
111071 +vhci_read_47878 vhci_read 3 47878 NULL
111072 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
111073 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
111074 +comedi_write_47926 comedi_write 3 47926 NULL
111075 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
111076 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
111077 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
111078 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
111079 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
111080 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
111081 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
111082 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
111083 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
111084 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
111085 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
111086 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
111087 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
111088 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
111089 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
111090 +disc_write_48070 disc_write 3 48070 NULL
111091 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
111092 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
111093 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
111094 +set_discoverable_48141 set_discoverable 4 48141 NULL
111095 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
111096 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
111097 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
111098 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
111099 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
111100 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
111101 +brcmf_sdio_chip_cm3_exitdl_48192 brcmf_sdio_chip_cm3_exitdl 4 48192 NULL
111102 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
111103 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
111104 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
111105 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
111106 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
111107 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
111108 +read_file_recv_48232 read_file_recv 3 48232 NULL
111109 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
111110 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
111111 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
111112 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
111113 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
111114 +trace_options_write_48275 trace_options_write 3 48275 NULL
111115 +send_set_info_48288 send_set_info 7 48288 NULL
111116 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
111117 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
111118 +hash_setkey_48310 hash_setkey 3 48310 NULL
111119 +audio_set_intf_req_48319 audio_set_intf_req 0 48319 NULL
111120 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
111121 +skb_add_data_48363 skb_add_data 3 48363 NULL
111122 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
111123 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
111124 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
111125 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
111126 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
111127 +print_filtered_48442 print_filtered 2-0 48442 NULL
111128 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
111129 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
111130 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
111131 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
111132 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
111133 +send_control_msg_48498 send_control_msg 6 48498 NULL
111134 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
111135 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
111136 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
111137 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
111138 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
111139 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
111140 +llog_data_len_48607 llog_data_len 1 48607 NULL
111141 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
111142 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
111143 +mtd_read_48655 mtd_read 0 48655 NULL
111144 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
111145 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
111146 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
111147 +altera_drscan_48698 altera_drscan 2 48698 NULL
111148 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
111149 +recv_msg_48709 recv_msg 4 48709 NULL
111150 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
111151 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
111152 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
111153 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
111154 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
111155 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
111156 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
111157 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
111158 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
111159 +azx_get_position_48841 azx_get_position 0 48841 NULL
111160 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
111161 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
111162 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
111163 +sptlrpc_cli_alloc_reqbuf_48855 sptlrpc_cli_alloc_reqbuf 0 48855 NULL
111164 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
111165 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
111166 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
111167 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
111168 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
111169 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
111170 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
111171 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
111172 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
111173 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
111174 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
111175 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
111176 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
111177 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
111178 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
111179 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
111180 +aic_inb_49023 aic_inb 0 49023 NULL
111181 +transient_status_49027 transient_status 4 49027 NULL
111182 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
111183 +aic7xxx_rem_scb_from_disc_list_49041 aic7xxx_rem_scb_from_disc_list 0 49041 NULL
111184 +scsi_register_49094 scsi_register 2 49094 NULL
111185 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
111186 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
111187 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
111188 +pt_read_49136 pt_read 3 49136 NULL
111189 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
111190 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
111191 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
111192 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
111193 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
111194 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
111195 +print_queue_49191 print_queue 4-0 49191 NULL
111196 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
111197 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
111198 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
111199 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
111200 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
111201 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
111202 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
111203 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
111204 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
111205 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
111206 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
111207 +uio_read_49300 uio_read 3 49300 NULL
111208 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
111209 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
111210 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
111211 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
111212 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
111213 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
111214 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
111215 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
111216 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
111217 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
111218 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
111219 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
111220 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
111221 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
111222 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
111223 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
111224 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
111225 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
111226 +smk_write_access_49561 smk_write_access 3 49561 NULL
111227 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
111228 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
111229 +ptlrpc_request_pack_49581 ptlrpc_request_pack 0 49581 NULL
111230 +readfifo_49583 readfifo 1 49583 NULL
111231 +tap_write_49595 tap_write 3 49595 NULL
111232 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
111233 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
111234 +heap_init_49617 heap_init 2 49617 NULL
111235 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
111236 +port_fops_read_49626 port_fops_read 3 49626 NULL
111237 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
111238 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
111239 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
111240 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
111241 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
111242 +write_pool_49718 write_pool 3 49718 NULL
111243 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
111244 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
111245 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
111246 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
111247 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
111248 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
111249 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
111250 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
111251 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
111252 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
111253 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
111254 +add_uuid_49831 add_uuid 4 49831 NULL
111255 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
111256 +twl4030_write_49846 twl4030_write 2 49846 NULL
111257 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
111258 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
111259 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
111260 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
111261 +ceph_get_caps_49890 ceph_get_caps 0 49890 NULL
111262 +osc_brw_49896 osc_brw 4 49896 NULL
111263 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
111264 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
111265 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
111266 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
111267 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
111268 +isdn_read_50021 isdn_read 3 50021 NULL
111269 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
111270 +ioread8_50049 ioread8 0 50049 NULL
111271 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
111272 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
111273 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
111274 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
111275 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
111276 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
111277 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
111278 +read_file_slot_50111 read_file_slot 3 50111 NULL
111279 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
111280 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
111281 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
111282 +copy_items_50140 copy_items 6 50140 NULL
111283 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
111284 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
111285 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
111286 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
111287 +odev_update_50169 odev_update 2 50169 NULL
111288 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
111289 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
111290 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
111291 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
111292 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
111293 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
111294 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
111295 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
111296 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
111297 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
111298 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
111299 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
111300 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
111301 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
111302 +do_launder_page_50329 do_launder_page 0 50329 NULL
111303 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
111304 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
111305 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
111306 +tpm_read_50344 tpm_read 3 50344 NULL
111307 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
111308 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
111309 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
111310 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
111311 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
111312 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
111313 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
111314 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
111315 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
111316 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
111317 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
111318 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
111319 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
111320 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
111321 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
111322 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
111323 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
111324 +fat_readpages_50582 fat_readpages 4 50582 NULL
111325 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
111326 +xillybus_write_50605 xillybus_write 3 50605 NULL
111327 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
111328 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
111329 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
111330 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
111331 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
111332 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
111333 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
111334 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
111335 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
111336 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
111337 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
111338 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
111339 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
111340 +tpm_write_50798 tpm_write 3 50798 NULL
111341 +write_flush_50803 write_flush 3 50803 NULL
111342 +dvb_play_50814 dvb_play 3 50814 NULL
111343 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
111344 +SetArea_50835 SetArea 4 50835 NULL
111345 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
111346 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
111347 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
111348 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
111349 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
111350 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
111351 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
111352 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
111353 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
111354 +show_device_status_50947 show_device_status 0 50947 NULL
111355 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
111356 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
111357 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
111358 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
111359 +iwl_statistics_flag_50981 iwl_statistics_flag 3-0 50981 NULL
111360 +timeout_write_50991 timeout_write 3 50991 NULL
111361 +proc_write_51003 proc_write 3 51003 NULL
111362 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
111363 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
111364 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
111365 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
111366 +dump_midi_51040 dump_midi 3 51040 NULL
111367 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
111368 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
111369 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
111370 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
111371 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
111372 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
111373 +ti_recv_51110 ti_recv 3 51110 NULL
111374 +uasp_prepare_r_request_51124 uasp_prepare_r_request 0 51124 NULL
111375 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
111376 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
111377 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
111378 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
111379 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
111380 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
111381 +drm_property_create_51239 drm_property_create 4 51239 NULL
111382 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
111383 +st_read_51251 st_read 3 51251 NULL
111384 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
111385 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
111386 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
111387 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
111388 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
111389 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
111390 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
111391 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
111392 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
111393 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
111394 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
111395 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
111396 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
111397 +ceph_sync_read_51410 ceph_sync_read 3-0 51410 NULL
111398 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
111399 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
111400 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
111401 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
111402 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
111403 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
111404 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
111405 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
111406 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
111407 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
111408 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
111409 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
111410 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
111411 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
111412 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
111413 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
111414 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
111415 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
111416 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
111417 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
111418 +sel_write_access_51704 sel_write_access 3 51704 NULL
111419 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
111420 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
111421 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
111422 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
111423 +cm4040_read_51732 cm4040_read 3 51732 NULL
111424 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
111425 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
111426 +if_write_51756 if_write 3 51756 NULL
111427 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
111428 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
111429 +ioread32_51847 ioread32 0 51847 NULL nohasharray
111430 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
111431 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
111432 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
111433 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
111434 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
111435 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
111436 +user_read_51881 user_read 3 51881 NULL
111437 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
111438 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
111439 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
111440 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
111441 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
111442 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
111443 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
111444 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
111445 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
111446 +get_zone_51981 get_zone 0-1 51981 NULL
111447 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
111448 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
111449 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
111450 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
111451 +rdmalt_52022 rdmalt 0 52022 NULL
111452 +override_release_52032 override_release 2 52032 NULL
111453 +end_port_52042 end_port 0 52042 NULL
111454 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
111455 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
111456 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
111457 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
111458 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
111459 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
111460 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
111461 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
111462 +retry_count_read_52129 retry_count_read 3 52129 NULL
111463 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
111464 +sub_alloc_52140 sub_alloc 0 52140 NULL
111465 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
111466 +htable_size_52148 htable_size 0-1 52148 NULL
111467 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
111468 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
111469 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
111470 +print_prefix_52176 print_prefix 0 52176 NULL
111471 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
111472 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
111473 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
111474 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 3 52243 &fuse_request_alloc_52243
111475 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
111476 +shrink_slab_52261 shrink_slab 2 52261 NULL
111477 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
111478 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
111479 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
111480 +read_file_reset_52310 read_file_reset 3 52310 NULL
111481 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
111482 +hwflags_read_52318 hwflags_read 3 52318 NULL
111483 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
111484 +hur_len_52339 hur_len 0 52339 NULL
111485 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
111486 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
111487 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
111488 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
111489 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
111490 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
111491 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
111492 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
111493 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
111494 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
111495 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
111496 +delay_status_52431 delay_status 5 52431 NULL
111497 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
111498 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
111499 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
111500 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
111501 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
111502 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
111503 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
111504 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
111505 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
111506 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
111507 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
111508 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
111509 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
111510 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
111511 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
111512 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
111513 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
111514 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
111515 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
111516 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
111517 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
111518 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
111519 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
111520 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
111521 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
111522 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
111523 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
111524 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
111525 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
111526 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
111527 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
111528 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
111529 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
111530 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
111531 +ext2_xattr_set_acl_52857 ext2_xattr_set_acl 4 52857 NULL
111532 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
111533 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
111534 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
111535 +twlreg_write_52880 twlreg_write 3 52880 NULL
111536 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
111537 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
111538 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
111539 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
111540 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
111541 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
111542 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
111543 +send_packet_52960 send_packet 4 52960 NULL
111544 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
111545 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
111546 +num_node_state_52989 num_node_state 0 52989 NULL
111547 +uasp_alloc_stream_res_53015 uasp_alloc_stream_res 0 53015 NULL
111548 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
111549 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
111550 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
111551 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
111552 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
111553 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
111554 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
111555 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
111556 +verity_status_53120 verity_status 5 53120 NULL
111557 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
111558 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
111559 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
111560 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
111561 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
111562 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
111563 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
111564 +hfsplus_xattr_set_posix_acl_53249 hfsplus_xattr_set_posix_acl 4 53249 NULL
111565 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
111566 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
111567 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
111568 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
111569 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
111570 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
111571 +vm_mmap_53339 vm_mmap 0 53339 NULL
111572 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
111573 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
111574 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
111575 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
111576 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
111577 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
111578 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
111579 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL
111580 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
111581 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
111582 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
111583 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
111584 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
111585 +ocfs2_xattr_set_acl_53508 ocfs2_xattr_set_acl 4 53508 NULL
111586 +check_acl_53512 check_acl 0 53512 NULL
111587 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
111588 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
111589 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
111590 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
111591 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
111592 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
111593 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
111594 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
111595 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
111596 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
111597 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
111598 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
111599 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
111600 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
111601 +bio_integrity_split_53714 bio_integrity_split 3 53714 NULL
111602 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
111603 +wdm_write_53735 wdm_write 3 53735 NULL
111604 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
111605 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
111606 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
111607 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
111608 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
111609 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
111610 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
111611 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
111612 +setup_data_read_53822 setup_data_read 3 53822 NULL
111613 +pms_read_53873 pms_read 3 53873 NULL
111614 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
111615 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
111616 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
111617 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
111618 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
111619 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
111620 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
111621 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
111622 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
111623 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
111624 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
111625 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
111626 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
111627 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
111628 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
111629 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
111630 +_malloc_54077 _malloc 1 54077 NULL
111631 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
111632 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
111633 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
111634 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
111635 +strn_len_54122 strn_len 0 54122 NULL
111636 +isku_receive_54130 isku_receive 4 54130 NULL
111637 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
111638 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
111639 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
111640 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
111641 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
111642 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
111643 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
111644 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
111645 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
111646 +reada_add_block_54247 reada_add_block 2 54247 NULL
111647 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
111648 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
111649 +audio_write_54261 audio_write 4 54261 NULL nohasharray
111650 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
111651 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
111652 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
111653 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
111654 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
111655 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
111656 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
111657 +sprintf_54306 sprintf 0 54306 NULL
111658 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
111659 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
111660 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
111661 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
111662 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
111663 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
111664 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
111665 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
111666 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
111667 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
111668 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
111669 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
111670 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
111671 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
111672 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
111673 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
111674 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
111675 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
111676 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
111677 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
111678 +viacam_read_54526 viacam_read 3 54526 NULL
111679 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
111680 +setsockopt_54539 setsockopt 5 54539 NULL
111681 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
111682 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
111683 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
111684 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
111685 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
111686 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
111687 +port_fops_write_54627 port_fops_write 3 54627 NULL
111688 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
111689 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
111690 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
111691 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
111692 +bus_add_device_54665 bus_add_device 0 54665 NULL
111693 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
111694 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
111695 +evm_read_key_54674 evm_read_key 3 54674 NULL
111696 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
111697 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
111698 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
111699 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
111700 +kzalloc_54740 kzalloc 1 54740 NULL
111701 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
111702 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
111703 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
111704 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
111705 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
111706 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
111707 +nfsd_write_54809 nfsd_write 6 54809 NULL
111708 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
111709 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
111710 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
111711 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
111712 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
111713 +write_rio_54837 write_rio 3 54837 NULL
111714 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
111715 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
111716 +ll_layout_conf_54841 ll_layout_conf 0 54841 NULL
111717 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
111718 +printer_read_54851 printer_read 3 54851 NULL
111719 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
111720 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
111721 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
111722 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
111723 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
111724 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
111725 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
111726 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
111727 +add_port_54941 add_port 2 54941 NULL
111728 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
111729 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
111730 +c4_add_card_54968 c4_add_card 3 54968 NULL
111731 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
111732 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
111733 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
111734 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
111735 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
111736 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
111737 +read_dma_55086 read_dma 3 55086 NULL
111738 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
111739 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
111740 +filldir_55137 filldir 3 55137 NULL
111741 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
111742 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
111743 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
111744 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
111745 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
111746 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
111747 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
111748 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
111749 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
111750 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
111751 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
111752 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
111753 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
111754 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
111755 +persistent_ram_new_55286 persistent_ram_new 2-1 55286 NULL
111756 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
111757 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
111758 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
111759 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
111760 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
111761 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
111762 +vme_user_read_55338 vme_user_read 3 55338 NULL
111763 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
111764 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
111765 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
111766 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
111767 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
111768 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
111769 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
111770 +sysfs_sd_setattr_55437 sysfs_sd_setattr 0 55437 NULL
111771 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
111772 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
111773 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
111774 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
111775 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
111776 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
111777 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
111778 +ea_get_55522 ea_get 3-0 55522 NULL
111779 +buffer_size_55534 buffer_size 0 55534 NULL
111780 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
111781 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
111782 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
111783 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
111784 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
111785 +add_partition_55588 add_partition 2 55588 NULL
111786 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
111787 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL nohasharray
111788 +config_buf_55602 config_buf 0 55602 &SyS_keyctl_55602
111789 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
111790 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
111791 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
111792 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
111793 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
111794 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
111795 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
111796 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
111797 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
111798 +get_info_55681 get_info 3 55681 NULL
111799 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
111800 +echo_big_lmm_get_55690 echo_big_lmm_get 0 55690 NULL
111801 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
111802 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
111803 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
111804 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
111805 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
111806 +set_local_name_55757 set_local_name 4 55757 NULL
111807 +strlen_55778 strlen 0 55778 NULL
111808 +set_spte_55783 set_spte 4-5 55783 NULL
111809 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
111810 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
111811 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
111812 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
111813 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
111814 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
111815 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
111816 +hsc_write_55875 hsc_write 3 55875 NULL
111817 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
111818 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
111819 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
111820 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
111821 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
111822 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
111823 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
111824 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
111825 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
111826 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
111827 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
111828 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
111829 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
111830 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
111831 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
111832 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
111833 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
111834 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
111835 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
111836 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
111837 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
111838 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
111839 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
111840 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
111841 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
111842 +fd_copyin_56247 fd_copyin 3 56247 NULL
111843 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
111844 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
111845 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
111846 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
111847 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
111848 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
111849 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
111850 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
111851 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
111852 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
111853 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
111854 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
111855 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
111856 +dev_read_56369 dev_read 3 56369 NULL
111857 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
111858 +write_gssp_56404 write_gssp 3 56404 NULL
111859 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
111860 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
111861 +store_msg_56417 store_msg 3 56417 NULL
111862 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
111863 +fl_create_56435 fl_create 5 56435 NULL
111864 +gnttab_map_56439 gnttab_map 2 56439 NULL
111865 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
111866 +set_connectable_56458 set_connectable 4 56458 NULL
111867 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
111868 +putused_user_56467 putused_user 3 56467 NULL
111869 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
111870 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
111871 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
111872 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
111873 +init_map_ip_56508 init_map_ip 5 56508 NULL
111874 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
111875 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
111876 +ip_options_get_56538 ip_options_get 4 56538 NULL
111877 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
111878 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
111879 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
111880 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
111881 +event_filter_write_56609 event_filter_write 3 56609 NULL
111882 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
111883 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
111884 +gather_array_56641 gather_array 3 56641 NULL
111885 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
111886 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
111887 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
111888 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
111889 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
111890 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
111891 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
111892 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
111893 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
111894 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
111895 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
111896 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
111897 +do_syslog_56807 do_syslog 3 56807 NULL
111898 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
111899 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
111900 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
111901 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
111902 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
111903 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
111904 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
111905 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
111906 +hfsplus_setxattr_56902 hfsplus_setxattr 4 56902 NULL
111907 +strcspn_56913 strcspn 0 56913 NULL
111908 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
111909 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
111910 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
111911 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
111912 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
111913 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
111914 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
111915 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
111916 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
111917 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
111918 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
111919 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
111920 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
111921 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
111922 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
111923 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
111924 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
111925 +altera_get_note_57099 altera_get_note 6 57099 NULL
111926 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
111927 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
111928 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
111929 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
111930 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
111931 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
111932 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
111933 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
111934 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
111935 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
111936 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
111937 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
111938 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
111939 +dma_fifo_alloc_57236 dma_fifo_alloc 5-3-2 57236 NULL
111940 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
111941 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
111942 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
111943 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
111944 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
111945 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
111946 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
111947 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
111948 +write_file_regval_57313 write_file_regval 3 57313 NULL
111949 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
111950 +usblp_read_57342 usblp_read 3 57342 NULL
111951 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
111952 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
111953 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
111954 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
111955 +read_file_blob_57406 read_file_blob 3 57406 NULL
111956 +enclosure_register_57412 enclosure_register 3 57412 NULL
111957 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
111958 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
111959 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
111960 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
111961 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
111962 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
111963 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
111964 +skb_headlen_57501 skb_headlen 0 57501 NULL
111965 +copy_in_user_57502 copy_in_user 3 57502 NULL
111966 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
111967 +init_tag_map_57515 init_tag_map 3 57515 NULL
111968 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
111969 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
111970 +cmm_read_57520 cmm_read 3 57520 NULL
111971 +inode_permission_57531 inode_permission 0 57531 NULL
111972 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
111973 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
111974 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
111975 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
111976 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
111977 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
111978 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
111979 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
111980 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
111981 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
111982 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
111983 +mem_read_57631 mem_read 3 57631 NULL
111984 +r3964_write_57662 r3964_write 4 57662 NULL
111985 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
111986 +__lgwrite_57669 __lgwrite 4 57669 NULL
111987 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
111988 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
111989 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
111990 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
111991 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
111992 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
111993 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
111994 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
111995 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
111996 +ld2_57794 ld2 0 57794 NULL
111997 +ivtv_read_57796 ivtv_read 3 57796 NULL
111998 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
111999 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
112000 +flash_read_57843 flash_read 3 57843 NULL
112001 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
112002 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
112003 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
112004 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
112005 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
112006 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
112007 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
112008 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
112009 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
112010 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
112011 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
112012 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
112013 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
112014 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
112015 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
112016 +mce_async_out_58056 mce_async_out 3 58056 NULL
112017 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
112018 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
112019 +cm4040_write_58079 cm4040_write 3 58079 NULL
112020 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
112021 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
112022 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
112023 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
112024 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
112025 +read_file_debug_58256 read_file_debug 3 58256 NULL
112026 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
112027 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
112028 +profile_load_58267 profile_load 3 58267 NULL
112029 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
112030 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
112031 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
112032 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
112033 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
112034 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
112035 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
112036 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
112037 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
112038 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
112039 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
112040 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
112041 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
112042 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
112043 +capabilities_read_58457 capabilities_read 3 58457 NULL
112044 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
112045 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
112046 +nv_rd08_58472 nv_rd08 0 58472 NULL
112047 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
112048 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
112049 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
112050 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
112051 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
112052 +ldlm_srv_pool_shrink_58554 ldlm_srv_pool_shrink 0 58554 NULL
112053 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
112054 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
112055 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
112056 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
112057 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
112058 +xip_file_read_58592 xip_file_read 3 58592 NULL
112059 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
112060 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
112061 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
112062 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
112063 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
112064 +find_zero_58685 find_zero 0-1 58685 NULL
112065 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
112066 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
112067 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
112068 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
112069 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
112070 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
112071 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
112072 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
112073 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
112074 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
112075 +ep_read_58813 ep_read 3 58813 NULL
112076 +command_write_58841 command_write 3 58841 NULL
112077 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
112078 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
112079 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
112080 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
112081 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
112082 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
112083 +sptlrpc_import_sec_adapt_58948 sptlrpc_import_sec_adapt 0 58948 NULL
112084 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
112085 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
112086 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
112087 +init_list_set_59005 init_list_set 3 59005 NULL
112088 +ep_write_59008 ep_write 3 59008 NULL
112089 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
112090 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
112091 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
112092 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
112093 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
112094 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
112095 +sysfs_link_sibling_59078 sysfs_link_sibling 0 59078 NULL
112096 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
112097 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL
112098 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
112099 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
112100 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
112101 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
112102 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
112103 +md_getxattr_59161 md_getxattr 0 59161 NULL
112104 +ksize_59176 ksize 0 59176 NULL
112105 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
112106 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
112107 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
112108 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
112109 +dt3155_read_59226 dt3155_read 3 59226 NULL
112110 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
112111 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
112112 +nla_len_59258 nla_len 0 59258 NULL
112113 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
112114 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
112115 +fd_copyout_59323 fd_copyout 3 59323 NULL
112116 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
112117 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
112118 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
112119 +__map_request_59350 __map_request 0 59350 NULL
112120 +f2fs_fallocate_59377 f2fs_fallocate 3-4 59377 NULL
112121 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
112122 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
112123 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
112124 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
112125 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
112126 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
112127 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
112128 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
112129 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
112130 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
112131 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
112132 +tunables_write_59563 tunables_write 3 59563 NULL
112133 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
112134 +write_pbl_59583 write_pbl 4 59583 NULL
112135 +memdup_user_59590 memdup_user 2 59590 NULL
112136 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
112137 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
112138 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
112139 +mtrr_write_59622 mtrr_write 3 59622 NULL
112140 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
112141 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
112142 +hidraw_read_59650 hidraw_read 3 59650 NULL
112143 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
112144 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
112145 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
112146 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
112147 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
112148 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
112149 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
112150 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
112151 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
112152 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
112153 +strnlen_59746 strnlen 0 59746 NULL
112154 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
112155 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
112156 +venus_remove_59781 venus_remove 4 59781 NULL
112157 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
112158 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
112159 +ipw_write_59807 ipw_write 3 59807 NULL
112160 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
112161 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
112162 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
112163 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
112164 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
112165 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
112166 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
112167 +ocfs2_extend_rotate_transaction_59894 ocfs2_extend_rotate_transaction 2-3 59894 NULL
112168 +aic7xxx_abort_waiting_scb_59932 aic7xxx_abort_waiting_scb 0 59932 NULL
112169 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
112170 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
112171 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
112172 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
112173 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
112174 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
112175 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
112176 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
112177 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
112178 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
112179 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
112180 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
112181 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
112182 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
112183 +vcs_size_60050 vcs_size 0 60050 NULL
112184 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
112185 +compat_writev_60063 compat_writev 3 60063 NULL
112186 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
112187 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
112188 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
112189 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
112190 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
112191 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
112192 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
112193 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
112194 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
112195 +init_state_60165 init_state 2 60165 NULL
112196 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
112197 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
112198 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
112199 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
112200 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
112201 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
112202 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
112203 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
112204 +printer_write_60276 printer_write 3 60276 NULL
112205 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
112206 +getDataLength_60301 getDataLength 0 60301 NULL
112207 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
112208 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
112209 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
112210 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
112211 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
112212 +driver_names_read_60399 driver_names_read 3 60399 NULL
112213 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
112214 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
112215 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
112216 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
112217 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
112218 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
112219 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
112220 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
112221 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
112222 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
112223 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
112224 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
112225 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
112226 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
112227 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
112228 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
112229 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
112230 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
112231 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
112232 +raid_status_60755 raid_status 5 60755 NULL
112233 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
112234 +opticon_write_60775 opticon_write 4 60775 NULL
112235 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
112236 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
112237 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
112238 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
112239 +generic_writepages_60871 generic_writepages 0 60871 NULL
112240 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
112241 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
112242 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
112243 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
112244 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
112245 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
112246 +pti_char_write_60960 pti_char_write 3 60960 NULL
112247 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
112248 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
112249 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
112250 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
112251 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
112252 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
112253 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
112254 +symtab_init_61050 symtab_init 2 61050 NULL
112255 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
112256 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
112257 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
112258 +get_derived_key_61100 get_derived_key 4 61100 NULL
112259 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-1-2-3-4 61104 NULL
112260 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
112261 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
112262 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
112263 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
112264 +brcmf_sdio_chip_cr4_exitdl_61143 brcmf_sdio_chip_cr4_exitdl 4 61143 NULL
112265 +pair_device_61175 pair_device 4 61175 NULL nohasharray
112266 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
112267 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
112268 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
112269 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
112270 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
112271 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
112272 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
112273 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
112274 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
112275 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
112276 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
112277 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
112278 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
112279 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
112280 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
112281 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
112282 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
112283 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
112284 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
112285 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
112286 +system_enable_write_61396 system_enable_write 3 61396 NULL
112287 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
112288 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
112289 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
112290 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
112291 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
112292 +erst_errno_61526 erst_errno 0 61526 NULL
112293 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
112294 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
112295 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
112296 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
112297 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
112298 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
112299 +seq_open_private_61589 seq_open_private 3 61589 NULL
112300 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
112301 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
112302 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
112303 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
112304 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
112305 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
112306 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL
112307 +resize_stripes_61650 resize_stripes 2 61650 NULL
112308 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
112309 +insert_one_name_61668 insert_one_name 7 61668 NULL
112310 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
112311 +lock_loop_61681 lock_loop 1 61681 NULL
112312 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
112313 +filter_read_61692 filter_read 3 61692 NULL
112314 +iov_length_61716 iov_length 0 61716 NULL
112315 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
112316 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
112317 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
112318 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
112319 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
112320 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
112321 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
112322 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
112323 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
112324 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
112325 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
112326 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
112327 +get_fw_name_61874 get_fw_name 3 61874 NULL
112328 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
112329 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
112330 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
112331 +clear_refs_write_61904 clear_refs_write 3 61904 NULL nohasharray
112332 +import_sec_check_expire_61904 import_sec_check_expire 0 61904 &clear_refs_write_61904
112333 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
112334 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
112335 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
112336 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
112337 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
112338 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
112339 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
112340 +fix_read_error_61965 fix_read_error 4 61965 NULL
112341 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
112342 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
112343 +cow_file_range_61979 cow_file_range 3 61979 NULL
112344 +dequeue_event_62000 dequeue_event 3 62000 NULL
112345 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
112346 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
112347 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
112348 +SYSC_select_62024 SYSC_select 1 62024 NULL
112349 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
112350 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
112351 +do_pselect_62061 do_pselect 1 62061 NULL
112352 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
112353 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
112354 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
112355 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
112356 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
112357 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
112358 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
112359 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
112360 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
112361 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
112362 +video_usercopy_62151 video_usercopy 2 62151 NULL
112363 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
112364 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
112365 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
112366 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
112367 +btrfs_xattr_acl_set_62203 btrfs_xattr_acl_set 4 62203 NULL
112368 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
112369 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
112370 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
112371 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
112372 +get_random_int_62279 get_random_int 0 62279 NULL
112373 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
112374 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
112375 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
112376 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
112377 +ocfs2_xattr_buckets_per_cluster_62330 ocfs2_xattr_buckets_per_cluster 0 62330 NULL
112378 +subseq_list_62332 subseq_list 3-0 62332 NULL
112379 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
112380 +flash_write_62354 flash_write 3 62354 NULL
112381 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
112382 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
112383 +altera_irscan_62396 altera_irscan 2 62396 NULL
112384 +set_ssp_62411 set_ssp 4 62411 NULL
112385 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
112386 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
112387 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
112388 +debugfs_read_62535 debugfs_read 3 62535 NULL
112389 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
112390 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
112391 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
112392 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
112393 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
112394 +get_subdir_62581 get_subdir 3 62581 NULL
112395 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
112396 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
112397 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
112398 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
112399 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
112400 +ocfs2_wait_for_mask_interruptible_62675 ocfs2_wait_for_mask_interruptible 0 62675 NULL
112401 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
112402 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
112403 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
112404 +rdm_62719 rdm 0 62719 NULL
112405 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
112406 +key_replays_read_62746 key_replays_read 3 62746 NULL
112407 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
112408 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
112409 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
112410 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
112411 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
112412 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
112413 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
112414 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
112415 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
112416 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
112417 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
112418 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
112419 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
112420 +aoechr_write_62883 aoechr_write 3 62883 NULL
112421 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
112422 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
112423 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
112424 +getdqbuf_62908 getdqbuf 1 62908 NULL
112425 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
112426 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
112427 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
112428 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
112429 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
112430 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
112431 +unlink1_63059 unlink1 3 63059 NULL
112432 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
112433 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
112434 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
112435 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
112436 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
112437 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
112438 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
112439 +vme_master_read_63221 vme_master_read 0 63221 NULL
112440 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
112441 +ptp_read_63251 ptp_read 4 63251 NULL
112442 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
112443 +raid5_resize_63306 raid5_resize 2 63306 NULL
112444 +proc_info_read_63344 proc_info_read 3 63344 NULL
112445 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
112446 +idmouse_read_63374 idmouse_read 3 63374 NULL
112447 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
112448 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
112449 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
112450 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
112451 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
112452 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
112453 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
112454 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
112455 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
112456 +read_kcore_63488 read_kcore 3 63488 NULL
112457 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
112458 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
112459 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
112460 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
112461 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
112462 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
112463 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
112464 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
112465 +write_debug_level_63613 write_debug_level 3 63613 NULL
112466 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
112467 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
112468 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
112469 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
112470 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
112471 +vbi_read_63673 vbi_read 3 63673 NULL
112472 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
112473 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
112474 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
112475 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
112476 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
112477 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
112478 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
112479 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
112480 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
112481 +prepare_copy_63826 prepare_copy 2 63826 NULL
112482 +sel_write_load_63830 sel_write_load 3 63830 NULL
112483 +ll_readlink_63836 ll_readlink 3 63836 NULL
112484 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
112485 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
112486 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
112487 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
112488 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
112489 +__team_options_register_63941 __team_options_register 3 63941 NULL
112490 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
112491 +sysfs_add_one_63969 sysfs_add_one 0 63969 NULL
112492 +set_bredr_63975 set_bredr 4 63975 NULL
112493 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
112494 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
112495 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
112496 +hfsplus_security_setxattr_64009 hfsplus_security_setxattr 4 64009 NULL
112497 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
112498 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
112499 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
112500 +get_u8_64076 get_u8 0 64076 NULL
112501 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
112502 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
112503 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
112504 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
112505 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
112506 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
112507 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
112508 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
112509 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
112510 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
112511 +init_bch_64130 init_bch 1-2 64130 NULL
112512 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
112513 +read_div_64147 read_div 0 64147 NULL
112514 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
112515 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
112516 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
112517 +read_pulse_64227 read_pulse 0-3 64227 NULL
112518 +ea_len_64229 ea_len 0 64229 NULL
112519 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
112520 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
112521 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
112522 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
112523 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
112524 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
112525 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
112526 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
112527 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
112528 +ts_write_64336 ts_write 3 64336 NULL
112529 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
112530 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
112531 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
112532 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
112533 +reg_create_64372 reg_create 5 64372 NULL
112534 +ilo_write_64378 ilo_write 3 64378 NULL
112535 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
112536 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
112537 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
112538 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
112539 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
112540 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
112541 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
112542 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
112543 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
112544 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
112545 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
112546 +single_open_size_64483 single_open_size 4 64483 NULL
112547 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
112548 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
112549 +remove_uuid_64505 remove_uuid 4 64505 NULL
112550 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
112551 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
112552 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
112553 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
112554 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
112555 +SyS_bind_64544 SyS_bind 3 64544 NULL
112556 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
112557 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
112558 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
112559 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
112560 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
112561 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
112562 +do_erase_64574 do_erase 4 64574 NULL
112563 +fanotify_write_64623 fanotify_write 3 64623 NULL
112564 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
112565 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
112566 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
112567 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
112568 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
112569 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
112570 +sec_bulk_write_64691 sec_bulk_write 2-3 64691 NULL
112571 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
112572 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
112573 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
112574 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
112575 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
112576 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
112577 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
112578 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
112579 +message_for_md_64777 message_for_md 5 64777 NULL
112580 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
112581 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
112582 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
112583 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
112584 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
112585 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
112586 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
112587 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
112588 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
112589 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
112590 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
112591 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
112592 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
112593 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
112594 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
112595 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
112596 +insert_dent_65034 insert_dent 7 65034 NULL
112597 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
112598 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
112599 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
112600 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
112601 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
112602 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
112603 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
112604 +uasp_alloc_cmd_65097 uasp_alloc_cmd 0 65097 NULL
112605 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
112606 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
112607 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
112608 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
112609 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
112610 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
112611 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
112612 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
112613 +get_var_len_65304 get_var_len 0 65304 NULL
112614 +unpack_array_65318 unpack_array 0 65318 NULL
112615 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
112616 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
112617 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
112618 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
112619 +SyS_writev_65372 SyS_writev 3 65372 NULL
112620 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
112621 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
112622 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
112623 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
112624 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
112625 +device_add_groups_65423 device_add_groups 0 65423 NULL
112626 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
112627 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
112628 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
112629 +clear_user_65470 clear_user 2 65470 NULL
112630 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
112631 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
112632 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
112633 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
112634 new file mode 100644
112635 index 0000000..94aa56d
112636 --- /dev/null
112637 +++ b/tools/gcc/size_overflow_plugin.c
112638 @@ -0,0 +1,4040 @@
112639 +/*
112640 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
112641 + * Licensed under the GPL v2, or (at your option) v3
112642 + *
112643 + * Homepage:
112644 + * http://www.grsecurity.net/~ephox/overflow_plugin/
112645 + *
112646 + * Documentation:
112647 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
112648 + *
112649 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
112650 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
112651 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
112652 + *
112653 + * Usage:
112654 + * $ gcc -I`gcc -print-file-name=plugin`/include/c-family -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -ggdb -Wall -W -o size_overflow_plugin.so size_overflow_plugin.c
112655 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
112656 + */
112657 +
112658 +#include "gcc-common.h"
112659 +
112660 +int plugin_is_GPL_compatible;
112661 +
112662 +static struct plugin_info size_overflow_plugin_info = {
112663 + .version = "20140128",
112664 + .help = "no-size-overflow\tturn off size overflow checking\n",
112665 +};
112666 +
112667 +#define BEFORE_STMT true
112668 +#define AFTER_STMT false
112669 +#define CREATE_NEW_VAR NULL_TREE
112670 +#define CODES_LIMIT 32
112671 +#define MAX_PARAM 31
112672 +#define VEC_LEN 128
112673 +#define MY_STMT GF_PLF_1
112674 +#define NO_CAST_CHECK GF_PLF_2
112675 +#define RET_CHECK NULL_TREE
112676 +#define CANNOT_FIND_ARG 32
112677 +#define WRONG_NODE 32
112678 +#define NOT_INTENTIONAL_ASM NULL
112679 +#define MIN_CHECK true
112680 +#define MAX_CHECK false
112681 +
112682 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
112683 +#define YES_ASM_STR "# size_overflow MARK_YES "
112684 +#define OK_ASM_STR "# size_overflow "
112685 +
112686 +struct size_overflow_hash {
112687 + const struct size_overflow_hash * const next;
112688 + const char * const name;
112689 + const unsigned int param;
112690 +};
112691 +
112692 +#include "size_overflow_hash.h"
112693 +
112694 +enum mark {
112695 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
112696 +};
112697 +
112698 +static unsigned int call_count;
112699 +
112700 +struct visited {
112701 + struct visited *next;
112702 + const_tree fndecl;
112703 + unsigned int num;
112704 + const_tree rhs;
112705 +};
112706 +
112707 +struct next_cgraph_node {
112708 + struct next_cgraph_node *next;
112709 + struct cgraph_node *current_function;
112710 + tree callee_fndecl;
112711 + unsigned int num;
112712 +};
112713 +
112714 +struct interesting_node {
112715 + struct interesting_node *next;
112716 + gimple first_stmt;
112717 + const_tree fndecl;
112718 + tree node;
112719 +#if BUILDING_GCC_VERSION <= 4007
112720 + VEC(tree, gc) *last_nodes;
112721 +#else
112722 + vec<tree, va_gc> *last_nodes;
112723 +#endif
112724 + unsigned int num;
112725 + enum mark intentional_attr_decl;
112726 + enum mark intentional_attr_cur_fndecl;
112727 + gimple intentional_mark_from_gimple;
112728 +};
112729 +
112730 +static tree report_size_overflow_decl;
112731 +static const_tree const_char_ptr_type_node;
112732 +
112733 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs);
112734 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
112735 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
112736 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
112737 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
112738 +
112739 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
112740 +static tree get_size_overflow_type(gimple stmt, const_tree node);
112741 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
112742 +
112743 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
112744 +{
112745 + unsigned int arg_count;
112746 + enum tree_code code = TREE_CODE(*node);
112747 +
112748 + switch (code) {
112749 + case FUNCTION_DECL:
112750 + arg_count = type_num_arguments(TREE_TYPE(*node));
112751 + break;
112752 + case FUNCTION_TYPE:
112753 + case METHOD_TYPE:
112754 + arg_count = type_num_arguments(*node);
112755 + break;
112756 + default:
112757 + *no_add_attrs = true;
112758 + error("%s: %qE attribute only applies to functions", __func__, name);
112759 + return NULL_TREE;
112760 + }
112761 +
112762 + for (; args; args = TREE_CHAIN(args)) {
112763 + tree position = TREE_VALUE(args);
112764 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
112765 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
112766 + *no_add_attrs = true;
112767 + }
112768 + }
112769 + return NULL_TREE;
112770 +}
112771 +
112772 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
112773 +{
112774 + unsigned int arg_count;
112775 + enum tree_code code = TREE_CODE(*node);
112776 +
112777 + switch (code) {
112778 + case FUNCTION_DECL:
112779 + arg_count = type_num_arguments(TREE_TYPE(*node));
112780 + break;
112781 + case FUNCTION_TYPE:
112782 + case METHOD_TYPE:
112783 + arg_count = type_num_arguments(*node);
112784 + break;
112785 + case FIELD_DECL:
112786 + return NULL_TREE;
112787 + default:
112788 + *no_add_attrs = true;
112789 + error("%qE attribute only applies to functions", name);
112790 + return NULL_TREE;
112791 + }
112792 +
112793 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
112794 + return NULL_TREE;
112795 +
112796 + for (; args; args = TREE_CHAIN(args)) {
112797 + tree position = TREE_VALUE(args);
112798 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
112799 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
112800 + *no_add_attrs = true;
112801 + }
112802 + }
112803 + return NULL_TREE;
112804 +}
112805 +
112806 +static struct attribute_spec size_overflow_attr = {
112807 + .name = "size_overflow",
112808 + .min_length = 1,
112809 + .max_length = -1,
112810 + .decl_required = true,
112811 + .type_required = false,
112812 + .function_type_required = false,
112813 + .handler = handle_size_overflow_attribute,
112814 +#if BUILDING_GCC_VERSION >= 4007
112815 + .affects_type_identity = false
112816 +#endif
112817 +};
112818 +
112819 +static struct attribute_spec intentional_overflow_attr = {
112820 + .name = "intentional_overflow",
112821 + .min_length = 1,
112822 + .max_length = -1,
112823 + .decl_required = true,
112824 + .type_required = false,
112825 + .function_type_required = false,
112826 + .handler = handle_intentional_overflow_attribute,
112827 +#if BUILDING_GCC_VERSION >= 4007
112828 + .affects_type_identity = false
112829 +#endif
112830 +};
112831 +
112832 +static void register_attributes(void __unused *event_data, void __unused *data)
112833 +{
112834 + register_attribute(&size_overflow_attr);
112835 + register_attribute(&intentional_overflow_attr);
112836 +}
112837 +
112838 +static bool is_bool(const_tree node)
112839 +{
112840 + const_tree type;
112841 +
112842 + if (node == NULL_TREE)
112843 + return false;
112844 +
112845 + type = TREE_TYPE(node);
112846 + if (!INTEGRAL_TYPE_P(type))
112847 + return false;
112848 + if (TREE_CODE(type) == BOOLEAN_TYPE)
112849 + return true;
112850 + if (TYPE_PRECISION(type) == 1)
112851 + return true;
112852 + return false;
112853 +}
112854 +
112855 +static bool skip_types(const_tree var)
112856 +{
112857 + tree type;
112858 + enum tree_code code;
112859 +
112860 + if (is_gimple_constant(var))
112861 + return true;
112862 +
112863 + switch (TREE_CODE(var)) {
112864 + case ADDR_EXPR:
112865 +#if BUILDING_GCC_VERSION >= 4006
112866 + case MEM_REF:
112867 +#endif
112868 + case ARRAY_REF:
112869 + case BIT_FIELD_REF:
112870 + case INDIRECT_REF:
112871 + case TARGET_MEM_REF:
112872 + case COMPONENT_REF:
112873 + case VAR_DECL:
112874 + case VIEW_CONVERT_EXPR:
112875 + return true;
112876 + default:
112877 + break;
112878 + }
112879 +
112880 + code = TREE_CODE(var);
112881 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
112882 +
112883 + type = TREE_TYPE(var);
112884 + switch (TREE_CODE(type)) {
112885 + case INTEGER_TYPE:
112886 + case ENUMERAL_TYPE:
112887 + return false;
112888 + case BOOLEAN_TYPE:
112889 + return is_bool(var);
112890 + default:
112891 + return true;
112892 + }
112893 +}
112894 +
112895 +static inline gimple get_def_stmt(const_tree node)
112896 +{
112897 + gcc_assert(node != NULL_TREE);
112898 +
112899 + if (skip_types(node))
112900 + return NULL;
112901 +
112902 + if (TREE_CODE(node) != SSA_NAME)
112903 + return NULL;
112904 + return SSA_NAME_DEF_STMT(node);
112905 +}
112906 +
112907 +static unsigned char get_tree_code(const_tree type)
112908 +{
112909 + switch (TREE_CODE(type)) {
112910 + case ARRAY_TYPE:
112911 + return 0;
112912 + case BOOLEAN_TYPE:
112913 + return 1;
112914 + case ENUMERAL_TYPE:
112915 + return 2;
112916 + case FUNCTION_TYPE:
112917 + return 3;
112918 + case INTEGER_TYPE:
112919 + return 4;
112920 + case POINTER_TYPE:
112921 + return 5;
112922 + case RECORD_TYPE:
112923 + return 6;
112924 + case UNION_TYPE:
112925 + return 7;
112926 + case VOID_TYPE:
112927 + return 8;
112928 + case REAL_TYPE:
112929 + return 9;
112930 + case VECTOR_TYPE:
112931 + return 10;
112932 + case REFERENCE_TYPE:
112933 + return 11;
112934 + case OFFSET_TYPE:
112935 + return 12;
112936 + case COMPLEX_TYPE:
112937 + return 13;
112938 + default:
112939 + debug_tree((tree)type);
112940 + gcc_unreachable();
112941 + }
112942 +}
112943 +
112944 +struct function_hash {
112945 + size_t tree_codes_len;
112946 + unsigned char tree_codes[CODES_LIMIT];
112947 + const_tree fndecl;
112948 + unsigned int hash;
112949 +};
112950 +
112951 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
112952 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
112953 +{
112954 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
112955 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
112956 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
112957 +
112958 + unsigned int m = 0x57559429;
112959 + unsigned int n = 0x5052acdb;
112960 + const unsigned int *key4 = (const unsigned int *)key;
112961 + unsigned int h = len;
112962 + unsigned int k = len + seed + n;
112963 + unsigned long long p;
112964 +
112965 + while (len >= 8) {
112966 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
112967 + len -= 8;
112968 + }
112969 + if (len >= 4) {
112970 + cwmixb(key4[0]) key4 += 1;
112971 + len -= 4;
112972 + }
112973 + if (len)
112974 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
112975 + cwmixb(h ^ (k + n));
112976 + return k ^ h;
112977 +
112978 +#undef cwfold
112979 +#undef cwmixa
112980 +#undef cwmixb
112981 +}
112982 +
112983 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
112984 +{
112985 + unsigned int fn, codes, seed = 0;
112986 +
112987 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
112988 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
112989 +
112990 + fn_hash_data->hash = fn ^ codes;
112991 +}
112992 +
112993 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
112994 +{
112995 + gcc_assert(type != NULL_TREE);
112996 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
112997 +
112998 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
112999 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
113000 + fn_hash_data->tree_codes_len++;
113001 + type = TREE_TYPE(type);
113002 + }
113003 +}
113004 +
113005 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
113006 +{
113007 + const_tree result;
113008 +
113009 + gcc_assert(node != NULL_TREE);
113010 +
113011 + if (DECL_P(node)) {
113012 + result = DECL_RESULT(node);
113013 + if (result != NULL_TREE)
113014 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
113015 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
113016 + }
113017 +
113018 + gcc_assert(TYPE_P(node));
113019 +
113020 + if (TREE_CODE(node) == FUNCTION_TYPE)
113021 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
113022 +
113023 + return set_node_codes(node, fn_hash_data);
113024 +}
113025 +
113026 +static void set_function_codes(struct function_hash *fn_hash_data)
113027 +{
113028 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
113029 + enum tree_code code = TREE_CODE(type);
113030 +
113031 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
113032 +
113033 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
113034 +
113035 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
113036 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
113037 +}
113038 +
113039 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
113040 +{
113041 + const struct size_overflow_hash *entry;
113042 + struct function_hash fn_hash_data;
113043 + const char *func_name;
113044 +
113045 + // skip builtins __builtin_constant_p
113046 + if (DECL_BUILT_IN(fndecl))
113047 + return NULL;
113048 +
113049 + fn_hash_data.fndecl = fndecl;
113050 + fn_hash_data.tree_codes_len = 0;
113051 +
113052 + set_function_codes(&fn_hash_data);
113053 + gcc_assert(fn_hash_data.tree_codes_len != 0);
113054 +
113055 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
113056 + set_hash(func_name, &fn_hash_data);
113057 +
113058 + entry = size_overflow_hash[fn_hash_data.hash];
113059 +
113060 + while (entry) {
113061 + if (!strcmp(entry->name, func_name))
113062 + return entry;
113063 + entry = entry->next;
113064 + }
113065 + return NULL;
113066 +}
113067 +
113068 +static void print_missing_msg(const_tree func, unsigned int argnum)
113069 +{
113070 + location_t loc;
113071 + const char *curfunc;
113072 + struct function_hash fn_hash_data;
113073 +
113074 + fn_hash_data.fndecl = DECL_ORIGIN(func);
113075 + fn_hash_data.tree_codes_len = 0;
113076 +
113077 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
113078 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
113079 +
113080 + set_function_codes(&fn_hash_data);
113081 + set_hash(curfunc, &fn_hash_data);
113082 +
113083 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
113084 +}
113085 +
113086 +static unsigned int find_arg_number_tree(const_tree arg, const_tree func)
113087 +{
113088 + tree var;
113089 + unsigned int argnum = 1;
113090 +
113091 + if (TREE_CODE(arg) == SSA_NAME)
113092 + arg = SSA_NAME_VAR(arg);
113093 +
113094 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
113095 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
113096 + continue;
113097 + if (!skip_types(var))
113098 + return argnum;
113099 + }
113100 +
113101 + return CANNOT_FIND_ARG;
113102 +}
113103 +
113104 +static tree create_new_var(tree type)
113105 +{
113106 + tree new_var = create_tmp_var(type, "cicus");
113107 +
113108 + add_referenced_var(new_var);
113109 + return new_var;
113110 +}
113111 +
113112 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
113113 +{
113114 + gimple assign;
113115 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113116 + tree type = TREE_TYPE(rhs1);
113117 + tree lhs = create_new_var(type);
113118 +
113119 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
113120 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
113121 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113122 +
113123 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113124 + update_stmt(assign);
113125 + gimple_set_plf(assign, MY_STMT, true);
113126 + return assign;
113127 +}
113128 +
113129 +static tree cast_a_tree(tree type, tree var)
113130 +{
113131 + gcc_assert(type != NULL_TREE);
113132 + gcc_assert(var != NULL_TREE);
113133 + gcc_assert(fold_convertible_p(type, var));
113134 +
113135 + return fold_convert(type, var);
113136 +}
113137 +
113138 +static tree get_lhs(const_gimple stmt)
113139 +{
113140 + switch (gimple_code(stmt)) {
113141 + case GIMPLE_ASSIGN:
113142 + case GIMPLE_CALL:
113143 + return gimple_get_lhs(stmt);
113144 + case GIMPLE_PHI:
113145 + return gimple_phi_result(stmt);
113146 + default:
113147 + return NULL_TREE;
113148 + }
113149 +}
113150 +
113151 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
113152 +{
113153 + const_gimple def_stmt = get_def_stmt(rhs);
113154 +
113155 + if (force)
113156 + return false;
113157 +
113158 + if (is_gimple_constant(rhs))
113159 + return false;
113160 +
113161 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
113162 + return false;
113163 +
113164 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
113165 + return false;
113166 +
113167 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
113168 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
113169 + return false;
113170 +
113171 + return true;
113172 +}
113173 +
113174 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
113175 +{
113176 + gimple assign, def_stmt;
113177 +
113178 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
113179 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
113180 + gcc_unreachable();
113181 +
113182 + def_stmt = get_def_stmt(rhs);
113183 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && gimple_plf(def_stmt, MY_STMT))
113184 + return def_stmt;
113185 +
113186 + if (lhs == CREATE_NEW_VAR)
113187 + lhs = create_new_var(dst_type);
113188 +
113189 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
113190 +
113191 + if (!gsi_end_p(*gsi)) {
113192 + location_t loc = gimple_location(gsi_stmt(*gsi));
113193 + gimple_set_location(assign, loc);
113194 + }
113195 +
113196 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113197 +
113198 + if (before)
113199 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
113200 + else
113201 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
113202 + update_stmt(assign);
113203 + return assign;
113204 +}
113205 +
113206 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
113207 +{
113208 + gimple_stmt_iterator gsi;
113209 + tree lhs;
113210 + gimple new_stmt;
113211 +
113212 + if (rhs == NULL_TREE)
113213 + return NULL_TREE;
113214 +
113215 + gsi = gsi_for_stmt(stmt);
113216 + new_stmt = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
113217 + gimple_set_plf(new_stmt, MY_STMT, true);
113218 +
113219 + lhs = get_lhs(new_stmt);
113220 + gcc_assert(lhs != NULL_TREE);
113221 + return lhs;
113222 +}
113223 +
113224 +static tree cast_to_TI_type(gimple stmt, tree node)
113225 +{
113226 + gimple_stmt_iterator gsi;
113227 + gimple cast_stmt;
113228 + tree type = TREE_TYPE(node);
113229 +
113230 + if (types_compatible_p(type, intTI_type_node))
113231 + return node;
113232 +
113233 + gsi = gsi_for_stmt(stmt);
113234 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113235 + gimple_set_plf(cast_stmt, MY_STMT, true);
113236 + return gimple_assign_lhs(cast_stmt);
113237 +}
113238 +
113239 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
113240 +{
113241 + tree lhs, new_lhs;
113242 + gimple_stmt_iterator gsi;
113243 +
113244 + if (rhs1 == NULL_TREE) {
113245 + debug_gimple_stmt(oldstmt);
113246 + error("%s: rhs1 is NULL_TREE", __func__);
113247 + gcc_unreachable();
113248 + }
113249 +
113250 + switch (gimple_code(oldstmt)) {
113251 + case GIMPLE_ASM:
113252 + lhs = rhs1;
113253 + break;
113254 + case GIMPLE_CALL:
113255 + case GIMPLE_ASSIGN:
113256 + lhs = gimple_get_lhs(oldstmt);
113257 + break;
113258 + default:
113259 + debug_gimple_stmt(oldstmt);
113260 + gcc_unreachable();
113261 + }
113262 +
113263 + gsi = gsi_for_stmt(oldstmt);
113264 + pointer_set_insert(visited, oldstmt);
113265 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
113266 + basic_block next_bb, cur_bb;
113267 + const_edge e;
113268 +
113269 + gcc_assert(before == false);
113270 + gcc_assert(stmt_can_throw_internal(oldstmt));
113271 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
113272 + gcc_assert(!gsi_end_p(gsi));
113273 +
113274 + cur_bb = gimple_bb(oldstmt);
113275 + next_bb = cur_bb->next_bb;
113276 + e = find_edge(cur_bb, next_bb);
113277 + gcc_assert(e != NULL);
113278 + gcc_assert(e->flags & EDGE_FALLTHRU);
113279 +
113280 + gsi = gsi_after_labels(next_bb);
113281 + gcc_assert(!gsi_end_p(gsi));
113282 +
113283 + before = true;
113284 + oldstmt = gsi_stmt(gsi);
113285 + }
113286 +
113287 + new_lhs = cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
113288 + return new_lhs;
113289 +}
113290 +
113291 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
113292 +{
113293 + gimple stmt;
113294 + gimple_stmt_iterator gsi;
113295 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
113296 +
113297 + if (gimple_plf(oldstmt, MY_STMT))
113298 + return lhs;
113299 +
113300 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
113301 + rhs1 = gimple_assign_rhs1(oldstmt);
113302 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
113303 + }
113304 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
113305 + rhs2 = gimple_assign_rhs2(oldstmt);
113306 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
113307 + }
113308 +
113309 + stmt = gimple_copy(oldstmt);
113310 + gimple_set_location(stmt, gimple_location(oldstmt));
113311 + gimple_set_plf(stmt, MY_STMT, true);
113312 +
113313 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
113314 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
113315 +
113316 + size_overflow_type = get_size_overflow_type(oldstmt, node);
113317 +
113318 + new_var = create_new_var(size_overflow_type);
113319 + new_var = make_ssa_name(new_var, stmt);
113320 + gimple_assign_set_lhs(stmt, new_var);
113321 +
113322 + if (rhs1 != NULL_TREE)
113323 + gimple_assign_set_rhs1(stmt, rhs1);
113324 +
113325 + if (rhs2 != NULL_TREE)
113326 + gimple_assign_set_rhs2(stmt, rhs2);
113327 +#if BUILDING_GCC_VERSION >= 4006
113328 + if (rhs3 != NULL_TREE)
113329 + gimple_assign_set_rhs3(stmt, rhs3);
113330 +#endif
113331 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
113332 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
113333 +
113334 + gsi = gsi_for_stmt(oldstmt);
113335 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
113336 + update_stmt(stmt);
113337 + pointer_set_insert(visited, oldstmt);
113338 + return gimple_assign_lhs(stmt);
113339 +}
113340 +
113341 +static tree cast_parm_decl(tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
113342 +{
113343 + gimple assign;
113344 + gimple_stmt_iterator gsi;
113345 + basic_block first_bb;
113346 +
113347 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
113348 +
113349 + if (bb->index == 0) {
113350 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
113351 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
113352 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
113353 + bb = first_bb;
113354 + }
113355 +
113356 + gsi = gsi_after_labels(bb);
113357 + assign = build_cast_stmt(size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
113358 + gimple_set_plf(assign, MY_STMT, true);
113359 +
113360 + return gimple_assign_lhs(assign);
113361 +}
113362 +
113363 +static tree use_phi_ssa_name(tree ssa_name_var, tree new_arg)
113364 +{
113365 + gimple_stmt_iterator gsi;
113366 + gimple assign, def_stmt = get_def_stmt(new_arg);
113367 +
113368 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
113369 + gsi = gsi_after_labels(gimple_bb(def_stmt));
113370 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
113371 + } else {
113372 + gsi = gsi_for_stmt(def_stmt);
113373 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
113374 + }
113375 +
113376 + gimple_set_plf(assign, MY_STMT, true);
113377 + return gimple_assign_lhs(assign);
113378 +}
113379 +
113380 +static tree cast_visited_phi_arg(tree ssa_name_var, tree arg, tree size_overflow_type)
113381 +{
113382 + basic_block bb;
113383 + gimple_stmt_iterator gsi;
113384 + const_gimple def_stmt;
113385 + gimple assign;
113386 +
113387 + def_stmt = get_def_stmt(arg);
113388 + bb = gimple_bb(def_stmt);
113389 + gcc_assert(bb->index != 0);
113390 + gsi = gsi_after_labels(bb);
113391 +
113392 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
113393 + gimple_set_plf(assign, MY_STMT, true);
113394 + return gimple_assign_lhs(assign);
113395 +}
113396 +
113397 +static tree create_new_phi_arg(tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
113398 +{
113399 + tree size_overflow_type;
113400 + tree arg;
113401 + const_gimple def_stmt;
113402 +
113403 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
113404 + return new_arg;
113405 +
113406 + arg = gimple_phi_arg_def(oldstmt, i);
113407 + def_stmt = get_def_stmt(arg);
113408 + gcc_assert(def_stmt != NULL);
113409 + size_overflow_type = get_size_overflow_type(oldstmt, arg);
113410 +
113411 + switch (gimple_code(def_stmt)) {
113412 + case GIMPLE_PHI:
113413 + return cast_visited_phi_arg(ssa_name_var, arg, size_overflow_type);
113414 + case GIMPLE_NOP: {
113415 + basic_block bb;
113416 +
113417 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
113418 + return cast_parm_decl(ssa_name_var, arg, size_overflow_type, bb);
113419 + }
113420 + case GIMPLE_ASM: {
113421 + gimple_stmt_iterator gsi;
113422 + gimple assign, stmt = get_def_stmt(arg);
113423 +
113424 + gsi = gsi_for_stmt(stmt);
113425 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
113426 + gimple_set_plf(assign, MY_STMT, true);
113427 + return gimple_assign_lhs(assign);
113428 + }
113429 + default:
113430 + gcc_assert(new_arg != NULL_TREE);
113431 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
113432 + return use_phi_ssa_name(ssa_name_var, new_arg);
113433 + }
113434 +}
113435 +
113436 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
113437 +{
113438 + basic_block bb;
113439 + gimple phi;
113440 + gimple_seq seq;
113441 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
113442 +
113443 + bb = gsi_bb(gsi);
113444 +
113445 + if (result == NULL_TREE) {
113446 + tree old_result = gimple_phi_result(oldstmt);
113447 + tree size_overflow_type = get_size_overflow_type(oldstmt, old_result);
113448 +
113449 + result = create_new_var(size_overflow_type);
113450 + }
113451 +
113452 + phi = create_phi_node(result, bb);
113453 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
113454 + seq = phi_nodes(bb);
113455 + gsi = gsi_last(seq);
113456 + gsi_remove(&gsi, false);
113457 +
113458 + gsi = gsi_for_stmt(oldstmt);
113459 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
113460 + gimple_set_bb(phi, bb);
113461 + gimple_set_plf(phi, MY_STMT, true);
113462 + return phi;
113463 +}
113464 +
113465 +#if BUILDING_GCC_VERSION <= 4007
113466 +static tree create_new_phi_node(VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
113467 +#else
113468 +static tree create_new_phi_node(vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
113469 +#endif
113470 +{
113471 + gimple new_phi;
113472 + unsigned int i;
113473 + tree arg, result;
113474 + location_t loc = gimple_location(oldstmt);
113475 +
113476 +#if BUILDING_GCC_VERSION <= 4007
113477 + gcc_assert(!VEC_empty(tree, *args));
113478 +#else
113479 + gcc_assert(!args->is_empty());
113480 +#endif
113481 +
113482 + new_phi = overflow_create_phi_node(oldstmt, ssa_name_var);
113483 + result = gimple_phi_result(new_phi);
113484 + ssa_name_var = SSA_NAME_VAR(result);
113485 +
113486 +#if BUILDING_GCC_VERSION <= 4007
113487 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
113488 +#else
113489 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
113490 +#endif
113491 + arg = create_new_phi_arg(ssa_name_var, arg, oldstmt, i);
113492 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
113493 + }
113494 +
113495 +#if BUILDING_GCC_VERSION <= 4007
113496 + VEC_free(tree, heap, *args);
113497 +#else
113498 + vec_free(args);
113499 +#endif
113500 + update_stmt(new_phi);
113501 + return result;
113502 +}
113503 +
113504 +static tree handle_phi(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree orig_result)
113505 +{
113506 + tree ssa_name_var = NULL_TREE;
113507 +#if BUILDING_GCC_VERSION <= 4007
113508 + VEC(tree, heap) *args = NULL;
113509 +#else
113510 + vec<tree, va_heap, vl_embed> *args = NULL;
113511 +#endif
113512 + gimple oldstmt = get_def_stmt(orig_result);
113513 + unsigned int i, len = gimple_phi_num_args(oldstmt);
113514 +
113515 + pointer_set_insert(visited, oldstmt);
113516 + for (i = 0; i < len; i++) {
113517 + tree arg, new_arg;
113518 +
113519 + arg = gimple_phi_arg_def(oldstmt, i);
113520 + new_arg = expand(visited, caller_node, arg);
113521 +
113522 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
113523 + ssa_name_var = SSA_NAME_VAR(new_arg);
113524 +
113525 + if (is_gimple_constant(arg)) {
113526 + tree size_overflow_type = get_size_overflow_type(oldstmt, arg);
113527 +
113528 + new_arg = cast_a_tree(size_overflow_type, arg);
113529 + }
113530 +
113531 +#if BUILDING_GCC_VERSION <= 4007
113532 + VEC_safe_push(tree, heap, args, new_arg);
113533 +#else
113534 + vec_safe_push(args, new_arg);
113535 +#endif
113536 + }
113537 +
113538 +#if BUILDING_GCC_VERSION <= 4007
113539 + return create_new_phi_node(&args, ssa_name_var, oldstmt);
113540 +#else
113541 + return create_new_phi_node(args, ssa_name_var, oldstmt);
113542 +#endif
113543 +}
113544 +
113545 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
113546 +{
113547 + gimple assign;
113548 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113549 + tree origtype = TREE_TYPE(orig_rhs);
113550 +
113551 + gcc_assert(is_gimple_assign(stmt));
113552 +
113553 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113554 + gimple_set_plf(assign, MY_STMT, true);
113555 + return gimple_assign_lhs(assign);
113556 +}
113557 +
113558 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
113559 +{
113560 + const_tree rhs1, lhs, rhs1_type, lhs_type;
113561 + enum machine_mode lhs_mode, rhs_mode;
113562 + gimple def_stmt = get_def_stmt(no_const_rhs);
113563 +
113564 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113565 + return false;
113566 +
113567 + rhs1 = gimple_assign_rhs1(def_stmt);
113568 + lhs = gimple_assign_lhs(def_stmt);
113569 + rhs1_type = TREE_TYPE(rhs1);
113570 + lhs_type = TREE_TYPE(lhs);
113571 + rhs_mode = TYPE_MODE(rhs1_type);
113572 + lhs_mode = TYPE_MODE(lhs_type);
113573 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
113574 + return false;
113575 +
113576 + return true;
113577 +}
113578 +
113579 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
113580 +{
113581 + tree rhs1 = gimple_assign_rhs1(stmt);
113582 + tree lhs = gimple_assign_lhs(stmt);
113583 + const_tree rhs1_type = TREE_TYPE(rhs1);
113584 + const_tree lhs_type = TREE_TYPE(lhs);
113585 +
113586 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
113587 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113588 +
113589 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
113590 +}
113591 +
113592 +static bool no_uses(tree node)
113593 +{
113594 + imm_use_iterator imm_iter;
113595 + use_operand_p use_p;
113596 +
113597 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113598 + const_gimple use_stmt = USE_STMT(use_p);
113599 +
113600 + if (use_stmt == NULL)
113601 + return true;
113602 + if (is_gimple_debug(use_stmt))
113603 + continue;
113604 + return false;
113605 + }
113606 + return true;
113607 +}
113608 +
113609 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
113610 +static bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
113611 +{
113612 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
113613 + gimple def_stmt = get_def_stmt(lhs);
113614 +
113615 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113616 + return false;
113617 +
113618 + rhs1 = gimple_assign_rhs1(def_stmt);
113619 + rhs_type = TREE_TYPE(rhs1);
113620 + lhs_type = TREE_TYPE(lhs);
113621 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
113622 + return false;
113623 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
113624 + return false;
113625 +
113626 + def_stmt = get_def_stmt(rhs1);
113627 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
113628 + return false;
113629 +
113630 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
113631 + return false;
113632 +
113633 + rhs1 = gimple_assign_rhs1(def_stmt);
113634 + rhs2 = gimple_assign_rhs2(def_stmt);
113635 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113636 + return false;
113637 +
113638 + if (is_gimple_constant(rhs2))
113639 + not_const_rhs = rhs1;
113640 + else
113641 + not_const_rhs = rhs2;
113642 +
113643 + return no_uses(not_const_rhs);
113644 +}
113645 +
113646 +static bool skip_lhs_cast_check(const_gimple stmt)
113647 +{
113648 + const_tree rhs = gimple_assign_rhs1(stmt);
113649 + const_gimple def_stmt = get_def_stmt(rhs);
113650 +
113651 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
113652 + if (gimple_code(def_stmt) == GIMPLE_ASM)
113653 + return true;
113654 +
113655 + if (is_const_plus_unsigned_signed_truncation(rhs))
113656 + return true;
113657 +
113658 + return false;
113659 +}
113660 +
113661 +static tree create_cast_overflow_check(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
113662 +{
113663 + bool cast_lhs, cast_rhs;
113664 + tree lhs = gimple_assign_lhs(stmt);
113665 + tree rhs = gimple_assign_rhs1(stmt);
113666 + const_tree lhs_type = TREE_TYPE(lhs);
113667 + const_tree rhs_type = TREE_TYPE(rhs);
113668 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
113669 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
113670 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
113671 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
113672 +
113673 + static bool check_lhs[3][4] = {
113674 + // ss su us uu
113675 + { false, true, true, false }, // lhs > rhs
113676 + { false, false, false, false }, // lhs = rhs
113677 + { true, true, true, true }, // lhs < rhs
113678 + };
113679 +
113680 + static bool check_rhs[3][4] = {
113681 + // ss su us uu
113682 + { true, false, true, true }, // lhs > rhs
113683 + { true, false, true, true }, // lhs = rhs
113684 + { true, false, true, true }, // lhs < rhs
113685 + };
113686 +
113687 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
113688 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
113689 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113690 +
113691 + if (lhs_size > rhs_size) {
113692 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113693 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113694 + } else if (lhs_size == rhs_size) {
113695 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113696 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113697 + } else {
113698 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113699 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113700 + }
113701 +
113702 + if (!cast_lhs && !cast_rhs)
113703 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113704 +
113705 + if (cast_lhs && !skip_lhs_cast_check(stmt))
113706 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
113707 +
113708 + if (cast_rhs)
113709 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
113710 +
113711 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113712 +}
113713 +
113714 +static tree handle_unary_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
113715 +{
113716 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
113717 +
113718 + if (gimple_plf(stmt, MY_STMT))
113719 + return lhs;
113720 +
113721 + rhs1 = gimple_assign_rhs1(stmt);
113722 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
113723 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113724 +
113725 + new_rhs1 = expand(visited, caller_node, rhs1);
113726 +
113727 + if (new_rhs1 == NULL_TREE)
113728 + return create_cast_assign(visited, stmt);
113729 +
113730 + if (gimple_plf(stmt, NO_CAST_CHECK))
113731 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113732 +
113733 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
113734 + tree size_overflow_type = get_size_overflow_type(stmt, rhs1);
113735 +
113736 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
113737 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
113738 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113739 + }
113740 +
113741 + if (!gimple_assign_cast_p(stmt))
113742 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113743 +
113744 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
113745 +}
113746 +
113747 +static tree handle_unary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
113748 +{
113749 + tree rhs1, lhs = gimple_assign_lhs(stmt);
113750 + gimple def_stmt = get_def_stmt(lhs);
113751 +
113752 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
113753 + rhs1 = gimple_assign_rhs1(def_stmt);
113754 +
113755 + if (is_gimple_constant(rhs1))
113756 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
113757 +
113758 + switch (TREE_CODE(rhs1)) {
113759 + case SSA_NAME:
113760 + return handle_unary_rhs(visited, caller_node, def_stmt);
113761 + case ARRAY_REF:
113762 + case BIT_FIELD_REF:
113763 + case ADDR_EXPR:
113764 + case COMPONENT_REF:
113765 + case INDIRECT_REF:
113766 +#if BUILDING_GCC_VERSION >= 4006
113767 + case MEM_REF:
113768 +#endif
113769 + case TARGET_MEM_REF:
113770 + case VIEW_CONVERT_EXPR:
113771 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
113772 + case PARM_DECL:
113773 + case VAR_DECL:
113774 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113775 +
113776 + default:
113777 + debug_gimple_stmt(def_stmt);
113778 + debug_tree(rhs1);
113779 + gcc_unreachable();
113780 + }
113781 +}
113782 +
113783 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
113784 +{
113785 + gimple cond_stmt;
113786 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
113787 +
113788 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
113789 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
113790 + update_stmt(cond_stmt);
113791 +}
113792 +
113793 +static tree create_string_param(tree string)
113794 +{
113795 + tree i_type, a_type;
113796 + const int length = TREE_STRING_LENGTH(string);
113797 +
113798 + gcc_assert(length > 0);
113799 +
113800 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
113801 + a_type = build_array_type(char_type_node, i_type);
113802 +
113803 + TREE_TYPE(string) = a_type;
113804 + TREE_CONSTANT(string) = 1;
113805 + TREE_READONLY(string) = 1;
113806 +
113807 + return build1(ADDR_EXPR, ptr_type_node, string);
113808 +}
113809 +
113810 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
113811 +{
113812 + gimple func_stmt;
113813 + const_gimple def_stmt;
113814 + const_tree loc_line;
113815 + tree loc_file, ssa_name, current_func;
113816 + expanded_location xloc;
113817 + char *ssa_name_buf;
113818 + int len;
113819 + struct cgraph_edge *edge;
113820 + struct cgraph_node *callee_node;
113821 + int frequency;
113822 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
113823 +
113824 + def_stmt = get_def_stmt(arg);
113825 + xloc = expand_location(gimple_location(def_stmt));
113826 +
113827 + if (!gimple_has_location(def_stmt)) {
113828 + xloc = expand_location(gimple_location(stmt));
113829 + if (!gimple_has_location(stmt))
113830 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
113831 + }
113832 +
113833 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
113834 +
113835 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
113836 + loc_file = create_string_param(loc_file);
113837 +
113838 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
113839 + current_func = create_string_param(current_func);
113840 +
113841 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
113842 + call_count++;
113843 + 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);
113844 + gcc_assert(len > 0);
113845 + ssa_name = build_string(len + 1, ssa_name_buf);
113846 + free(ssa_name_buf);
113847 + ssa_name = create_string_param(ssa_name);
113848 +
113849 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
113850 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
113851 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
113852 +
113853 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
113854 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
113855 +
113856 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
113857 + gcc_assert(edge != NULL);
113858 +}
113859 +
113860 +static void __unused print_the_code_insertions(const_gimple stmt)
113861 +{
113862 + location_t loc = gimple_location(stmt);
113863 +
113864 + inform(loc, "Integer size_overflow check applied here.");
113865 +}
113866 +
113867 +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)
113868 +{
113869 + basic_block cond_bb, join_bb, bb_true;
113870 + edge e;
113871 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113872 +
113873 + cond_bb = gimple_bb(stmt);
113874 + if (before)
113875 + gsi_prev(&gsi);
113876 + if (gsi_end_p(gsi))
113877 + e = split_block_after_labels(cond_bb);
113878 + else
113879 + e = split_block(cond_bb, gsi_stmt(gsi));
113880 + cond_bb = e->src;
113881 + join_bb = e->dest;
113882 + e->flags = EDGE_FALSE_VALUE;
113883 + e->probability = REG_BR_PROB_BASE;
113884 +
113885 + bb_true = create_empty_bb(cond_bb);
113886 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
113887 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
113888 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
113889 +
113890 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
113891 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
113892 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
113893 +
113894 + if (current_loops != NULL) {
113895 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
113896 + add_bb_to_loop(bb_true, cond_bb->loop_father);
113897 + }
113898 +
113899 + insert_cond(cond_bb, arg, cond_code, type_value);
113900 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
113901 +
113902 +// print_the_code_insertions(stmt);
113903 +}
113904 +
113905 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
113906 +{
113907 + const_tree rhs_type = TREE_TYPE(rhs);
113908 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
113909 +
113910 + gcc_assert(rhs_type != NULL_TREE);
113911 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
113912 + return;
113913 +
113914 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
113915 +
113916 + if (is_const_plus_unsigned_signed_truncation(rhs))
113917 + return;
113918 +
113919 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
113920 + // typemax (-1) < typemin (0)
113921 + if (TREE_OVERFLOW(type_max))
113922 + return;
113923 +
113924 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
113925 +
113926 + cast_rhs_type = TREE_TYPE(cast_rhs);
113927 + type_max_type = TREE_TYPE(type_max);
113928 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
113929 +
113930 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
113931 +
113932 + // special case: get_size_overflow_type(), 32, u64->s
113933 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
113934 + return;
113935 +
113936 + type_min_type = TREE_TYPE(type_min);
113937 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
113938 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
113939 +}
113940 +
113941 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
113942 +{
113943 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
113944 + return false;
113945 + if (!is_gimple_constant(rhs))
113946 + return false;
113947 + return true;
113948 +}
113949 +
113950 +static tree get_def_stmt_rhs(const_tree var)
113951 +{
113952 + tree rhs1, def_stmt_rhs1;
113953 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
113954 +
113955 + def_stmt = get_def_stmt(var);
113956 + if (!gimple_assign_cast_p(def_stmt))
113957 + return NULL_TREE;
113958 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
113959 +
113960 + rhs1 = gimple_assign_rhs1(def_stmt);
113961 + rhs1_def_stmt = get_def_stmt(rhs1);
113962 + if (!gimple_assign_cast_p(rhs1_def_stmt))
113963 + return rhs1;
113964 +
113965 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113966 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
113967 +
113968 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
113969 + case GIMPLE_CALL:
113970 + case GIMPLE_NOP:
113971 + case GIMPLE_ASM:
113972 + case GIMPLE_PHI:
113973 + return def_stmt_rhs1;
113974 + case GIMPLE_ASSIGN:
113975 + return rhs1;
113976 + default:
113977 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
113978 + gcc_unreachable();
113979 + }
113980 +}
113981 +
113982 +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)
113983 +{
113984 + tree new_rhs, orig_rhs;
113985 + void (*gimple_assign_set_rhs)(gimple, tree);
113986 + tree rhs1 = gimple_assign_rhs1(stmt);
113987 + tree rhs2 = gimple_assign_rhs2(stmt);
113988 + tree lhs = gimple_assign_lhs(stmt);
113989 +
113990 + if (!check_overflow)
113991 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113992 +
113993 + if (change_rhs == NULL_TREE)
113994 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113995 +
113996 + if (new_rhs2 == NULL_TREE) {
113997 + orig_rhs = rhs1;
113998 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
113999 + } else {
114000 + orig_rhs = rhs2;
114001 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
114002 + }
114003 +
114004 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
114005 +
114006 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
114007 + gimple_assign_set_rhs(stmt, new_rhs);
114008 + update_stmt(stmt);
114009 +
114010 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114011 +}
114012 +
114013 +static bool is_subtraction_special(const_gimple stmt)
114014 +{
114015 + gimple rhs1_def_stmt, rhs2_def_stmt;
114016 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
114017 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
114018 + const_tree rhs1 = gimple_assign_rhs1(stmt);
114019 + const_tree rhs2 = gimple_assign_rhs2(stmt);
114020 +
114021 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
114022 + return false;
114023 +
114024 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
114025 +
114026 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
114027 + return false;
114028 +
114029 + rhs1_def_stmt = get_def_stmt(rhs1);
114030 + rhs2_def_stmt = get_def_stmt(rhs2);
114031 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
114032 + return false;
114033 +
114034 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
114035 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
114036 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
114037 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
114038 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
114039 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
114040 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
114041 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
114042 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
114043 + return false;
114044 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
114045 + return false;
114046 +
114047 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
114048 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
114049 + return true;
114050 +}
114051 +
114052 +static tree handle_integer_truncation(struct pointer_set_t *visited, struct cgraph_node *caller_node, const_tree lhs)
114053 +{
114054 + tree new_rhs1, new_rhs2;
114055 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
114056 + gimple assign, stmt = get_def_stmt(lhs);
114057 + tree rhs1 = gimple_assign_rhs1(stmt);
114058 + tree rhs2 = gimple_assign_rhs2(stmt);
114059 +
114060 + if (!is_subtraction_special(stmt))
114061 + return NULL_TREE;
114062 +
114063 + new_rhs1 = expand(visited, caller_node, rhs1);
114064 + new_rhs2 = expand(visited, caller_node, rhs2);
114065 +
114066 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
114067 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
114068 +
114069 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
114070 + return NULL_TREE;
114071 +
114072 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
114073 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
114074 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
114075 + }
114076 +
114077 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
114078 + new_lhs = gimple_assign_lhs(assign);
114079 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
114080 +
114081 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114082 +}
114083 +
114084 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
114085 +{
114086 + const_gimple def_stmt;
114087 +
114088 + if (TREE_CODE(rhs) != SSA_NAME)
114089 + return false;
114090 +
114091 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
114092 + return false;
114093 +
114094 + def_stmt = get_def_stmt(rhs);
114095 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
114096 + return false;
114097 +
114098 + return true;
114099 +}
114100 +
114101 +static tree handle_binary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114102 +{
114103 + tree rhs1, rhs2, new_lhs;
114104 + gimple def_stmt = get_def_stmt(lhs);
114105 + tree new_rhs1 = NULL_TREE;
114106 + tree new_rhs2 = NULL_TREE;
114107 +
114108 + rhs1 = gimple_assign_rhs1(def_stmt);
114109 + rhs2 = gimple_assign_rhs2(def_stmt);
114110 +
114111 + /* no DImode/TImode division in the 32/64 bit kernel */
114112 + switch (gimple_assign_rhs_code(def_stmt)) {
114113 + case RDIV_EXPR:
114114 + case TRUNC_DIV_EXPR:
114115 + case CEIL_DIV_EXPR:
114116 + case FLOOR_DIV_EXPR:
114117 + case ROUND_DIV_EXPR:
114118 + case TRUNC_MOD_EXPR:
114119 + case CEIL_MOD_EXPR:
114120 + case FLOOR_MOD_EXPR:
114121 + case ROUND_MOD_EXPR:
114122 + case EXACT_DIV_EXPR:
114123 + case POINTER_PLUS_EXPR:
114124 + case BIT_AND_EXPR:
114125 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114126 + default:
114127 + break;
114128 + }
114129 +
114130 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
114131 + if (new_lhs != NULL_TREE)
114132 + return new_lhs;
114133 +
114134 + if (TREE_CODE(rhs1) == SSA_NAME)
114135 + new_rhs1 = expand(visited, caller_node, rhs1);
114136 + if (TREE_CODE(rhs2) == SSA_NAME)
114137 + new_rhs2 = expand(visited, caller_node, rhs2);
114138 +
114139 + if (is_a_neg_overflow(def_stmt, rhs2))
114140 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
114141 + if (is_a_neg_overflow(def_stmt, rhs1))
114142 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
114143 +
114144 +
114145 + if (is_a_constant_overflow(def_stmt, rhs2))
114146 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
114147 + if (is_a_constant_overflow(def_stmt, rhs1))
114148 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
114149 +
114150 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114151 +}
114152 +
114153 +#if BUILDING_GCC_VERSION >= 4006
114154 +static tree get_new_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
114155 +{
114156 + if (is_gimple_constant(rhs))
114157 + return cast_a_tree(size_overflow_type, rhs);
114158 + if (TREE_CODE(rhs) != SSA_NAME)
114159 + return NULL_TREE;
114160 + return expand(visited, caller_node, rhs);
114161 +}
114162 +
114163 +static tree handle_ternary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114164 +{
114165 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
114166 + gimple def_stmt = get_def_stmt(lhs);
114167 +
114168 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
114169 +
114170 + rhs1 = gimple_assign_rhs1(def_stmt);
114171 + rhs2 = gimple_assign_rhs2(def_stmt);
114172 + rhs3 = gimple_assign_rhs3(def_stmt);
114173 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
114174 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
114175 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
114176 +
114177 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
114178 +}
114179 +#endif
114180 +
114181 +static tree get_size_overflow_type(gimple stmt, const_tree node)
114182 +{
114183 + const_tree type;
114184 + tree new_type;
114185 +
114186 + gcc_assert(node != NULL_TREE);
114187 +
114188 + type = TREE_TYPE(node);
114189 +
114190 + if (gimple_plf(stmt, MY_STMT))
114191 + return TREE_TYPE(node);
114192 +
114193 + switch (TYPE_MODE(type)) {
114194 + case QImode:
114195 + new_type = intHI_type_node;
114196 + break;
114197 + case HImode:
114198 + new_type = intSI_type_node;
114199 + break;
114200 + case SImode:
114201 + new_type = intDI_type_node;
114202 + break;
114203 + case DImode:
114204 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114205 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114206 + else
114207 + new_type = intTI_type_node;
114208 + break;
114209 + case TImode:
114210 + gcc_assert(!TYPE_UNSIGNED(type));
114211 + new_type = intTI_type_node;
114212 + break;
114213 + default:
114214 + debug_tree((tree)node);
114215 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
114216 + gcc_unreachable();
114217 + }
114218 +
114219 + if (TYPE_QUALS(type) != 0)
114220 + return build_qualified_type(new_type, TYPE_QUALS(type));
114221 + return new_type;
114222 +}
114223 +
114224 +static tree expand_visited(gimple def_stmt)
114225 +{
114226 + const_gimple next_stmt;
114227 + gimple_stmt_iterator gsi;
114228 + enum gimple_code code = gimple_code(def_stmt);
114229 +
114230 + if (code == GIMPLE_ASM)
114231 + return NULL_TREE;
114232 +
114233 + gsi = gsi_for_stmt(def_stmt);
114234 + gsi_next(&gsi);
114235 +
114236 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
114237 + return NULL_TREE;
114238 + gcc_assert(!gsi_end_p(gsi));
114239 + next_stmt = gsi_stmt(gsi);
114240 +
114241 + if (gimple_code(def_stmt) == GIMPLE_PHI && !gimple_plf((gimple)next_stmt, MY_STMT))
114242 + return NULL_TREE;
114243 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
114244 +
114245 + return get_lhs(next_stmt);
114246 +}
114247 +
114248 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114249 +{
114250 + gimple def_stmt;
114251 +
114252 + def_stmt = get_def_stmt(lhs);
114253 +
114254 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
114255 + return NULL_TREE;
114256 +
114257 + if (gimple_plf(def_stmt, MY_STMT))
114258 + return lhs;
114259 +
114260 + if (pointer_set_contains(visited, def_stmt))
114261 + return expand_visited(def_stmt);
114262 +
114263 + switch (gimple_code(def_stmt)) {
114264 + case GIMPLE_PHI:
114265 + return handle_phi(visited, caller_node, lhs);
114266 + case GIMPLE_CALL:
114267 + case GIMPLE_ASM:
114268 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114269 + case GIMPLE_ASSIGN:
114270 + switch (gimple_num_ops(def_stmt)) {
114271 + case 2:
114272 + return handle_unary_ops(visited, caller_node, def_stmt);
114273 + case 3:
114274 + return handle_binary_ops(visited, caller_node, lhs);
114275 +#if BUILDING_GCC_VERSION >= 4006
114276 + case 4:
114277 + return handle_ternary_ops(visited, caller_node, lhs);
114278 +#endif
114279 + }
114280 + default:
114281 + debug_gimple_stmt(def_stmt);
114282 + error("%s: unknown gimple code", __func__);
114283 + gcc_unreachable();
114284 + }
114285 +}
114286 +
114287 +static tree cast_to_orig_type(gimple stmt, const_tree orig_node, tree new_node)
114288 +{
114289 + const_gimple assign;
114290 + tree orig_type = TREE_TYPE(orig_node);
114291 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114292 +
114293 + assign = build_cast_stmt(orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114294 + return gimple_assign_lhs(assign);
114295 +}
114296 +
114297 +static void change_orig_node(struct interesting_node *cur_node, tree new_node)
114298 +{
114299 + void (*set_rhs)(gimple, tree);
114300 + gimple stmt = cur_node->first_stmt;
114301 + const_tree orig_node = cur_node->node;
114302 +
114303 + switch (gimple_code(stmt)) {
114304 + case GIMPLE_RETURN:
114305 + gimple_return_set_retval(stmt, cast_to_orig_type(stmt, orig_node, new_node));
114306 + break;
114307 + case GIMPLE_CALL:
114308 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(stmt, orig_node, new_node));
114309 + break;
114310 + case GIMPLE_ASSIGN:
114311 + switch (cur_node->num) {
114312 + case 1:
114313 + set_rhs = &gimple_assign_set_rhs1;
114314 + break;
114315 + case 2:
114316 + set_rhs = &gimple_assign_set_rhs2;
114317 + break;
114318 +#if BUILDING_GCC_VERSION >= 4006
114319 + case 3:
114320 + set_rhs = &gimple_assign_set_rhs3;
114321 + break;
114322 +#endif
114323 + default:
114324 + gcc_unreachable();
114325 + }
114326 +
114327 + set_rhs(stmt, cast_to_orig_type(stmt, orig_node, new_node));
114328 + break;
114329 + default:
114330 + debug_gimple_stmt(stmt);
114331 + gcc_unreachable();
114332 + }
114333 +
114334 + update_stmt(stmt);
114335 +}
114336 +
114337 +static unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
114338 +{
114339 + const struct size_overflow_hash *hash;
114340 + unsigned int new_argnum;
114341 + tree arg;
114342 + const_tree origarg;
114343 +
114344 + if (argnum == 0)
114345 + return argnum;
114346 +
114347 + hash = get_function_hash(fndecl);
114348 + if (hash && hash->param & (1U << argnum))
114349 + return argnum;
114350 +
114351 + if (DECL_EXTERNAL(fndecl))
114352 + return argnum;
114353 +
114354 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
114355 + argnum--;
114356 + while (origarg && argnum) {
114357 + origarg = TREE_CHAIN(origarg);
114358 + argnum--;
114359 + }
114360 + gcc_assert(argnum == 0);
114361 + gcc_assert(origarg != NULL_TREE);
114362 +
114363 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
114364 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
114365 + return new_argnum;
114366 +
114367 + return CANNOT_FIND_ARG;
114368 +}
114369 +
114370 +// Don't want to duplicate entries in next_cgraph_node
114371 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
114372 +{
114373 + const_tree new_callee_fndecl;
114374 + struct next_cgraph_node *cur_node;
114375 +
114376 + if (fndecl == RET_CHECK)
114377 + new_callee_fndecl = NODE_DECL(node);
114378 + else
114379 + new_callee_fndecl = fndecl;
114380 +
114381 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
114382 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
114383 + continue;
114384 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
114385 + continue;
114386 + if (num == cur_node->num)
114387 + return true;
114388 + }
114389 + return false;
114390 +}
114391 +
114392 +/* Add a next_cgraph_node into the list for handle_function().
114393 + * handle_function() iterates over all the next cgraph nodes and
114394 + * starts the overflow check insertion process.
114395 + */
114396 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
114397 +{
114398 + struct next_cgraph_node *new_node;
114399 +
114400 + if (is_in_next_cgraph_node(head, node, fndecl, num))
114401 + return head;
114402 +
114403 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
114404 + new_node->current_function = node;
114405 + new_node->next = NULL;
114406 + new_node->num = num;
114407 + if (fndecl == RET_CHECK)
114408 + new_node->callee_fndecl = NODE_DECL(node);
114409 + else
114410 + new_node->callee_fndecl = fndecl;
114411 +
114412 + if (!head)
114413 + return new_node;
114414 +
114415 + new_node->next = head;
114416 + return new_node;
114417 +}
114418 +
114419 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
114420 +{
114421 + struct cgraph_edge *e;
114422 +
114423 + if (num == 0)
114424 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
114425 +
114426 + for (e = node->callers; e; e = e->next_caller) {
114427 + tree fndecl = gimple_call_fndecl(e->call_stmt);
114428 +
114429 + gcc_assert(fndecl != NULL_TREE);
114430 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
114431 + }
114432 +
114433 + return head;
114434 +}
114435 +
114436 +static bool is_a_return_check(const_tree node)
114437 +{
114438 + if (TREE_CODE(node) == FUNCTION_DECL)
114439 + return true;
114440 +
114441 + gcc_assert(TREE_CODE(node) == PARM_DECL);
114442 + return false;
114443 +}
114444 +
114445 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
114446 +{
114447 + const struct size_overflow_hash *hash;
114448 +
114449 + hash = get_function_hash(fndecl);
114450 + if (hash && (hash->param & (1U << num)))
114451 + return true;
114452 + return false;
114453 +}
114454 +
114455 +struct missing_functions {
114456 + struct missing_functions *next;
114457 + const_tree node;
114458 + tree fndecl;
114459 +};
114460 +
114461 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
114462 +{
114463 + struct missing_functions *new_function;
114464 +
114465 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
114466 + new_function->node = node;
114467 + new_function->next = NULL;
114468 +
114469 + if (TREE_CODE(node) == FUNCTION_DECL)
114470 + new_function->fndecl = node;
114471 + else
114472 + new_function->fndecl = current_function_decl;
114473 + gcc_assert(new_function->fndecl);
114474 +
114475 + if (!missing_fn_head)
114476 + return new_function;
114477 +
114478 + new_function->next = missing_fn_head;
114479 + return new_function;
114480 +}
114481 +
114482 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
114483 + * If the function is missing everywhere then print the missing message into stderr.
114484 + */
114485 +static bool is_missing_function(const_tree orig_fndecl, unsigned int num)
114486 +{
114487 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
114488 +#if BUILDING_GCC_VERSION >= 4008
114489 + case BUILT_IN_BSWAP16:
114490 +#endif
114491 + case BUILT_IN_BSWAP32:
114492 + case BUILT_IN_BSWAP64:
114493 + case BUILT_IN_EXPECT:
114494 + case BUILT_IN_MEMCMP:
114495 + return false;
114496 + default:
114497 + break;
114498 + }
114499 +
114500 + // skip test.c
114501 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
114502 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
114503 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
114504 + }
114505 +
114506 + if (is_in_hash_table(orig_fndecl, num))
114507 + return false;
114508 +
114509 + print_missing_msg(orig_fndecl, num);
114510 + return true;
114511 +}
114512 +
114513 +// Get the argnum of a function decl, if node is a return then the argnum is 0
114514 +static unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
114515 +{
114516 + if (is_a_return_check(node))
114517 + return 0;
114518 + else
114519 + return find_arg_number_tree(node, orig_fndecl);
114520 +}
114521 +
114522 +/* If the function is missing from the hash table and it is a static function
114523 + * then create a next_cgraph_node from it for handle_function()
114524 + */
114525 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
114526 +{
114527 + unsigned int num;
114528 + const_tree orig_fndecl;
114529 + struct cgraph_node *next_node = NULL;
114530 +
114531 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
114532 +
114533 + num = get_function_num(missing_fn_head->node, orig_fndecl);
114534 + if (num == CANNOT_FIND_ARG)
114535 + return cnodes;
114536 +
114537 + if (!is_missing_function(orig_fndecl, num))
114538 + return cnodes;
114539 +
114540 + next_node = cgraph_get_node(missing_fn_head->fndecl);
114541 + if (next_node && next_node->local.local)
114542 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
114543 + return cnodes;
114544 +}
114545 +
114546 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
114547 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
114548 + */
114549 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
114550 +{
114551 + unsigned int i;
114552 + tree node;
114553 + struct missing_functions *cur, *missing_fn_head = NULL;
114554 +
114555 +#if BUILDING_GCC_VERSION <= 4007
114556 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
114557 +#else
114558 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
114559 +#endif
114560 + switch (TREE_CODE(node)) {
114561 + case PARM_DECL:
114562 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
114563 + break;
114564 + case FUNCTION_DECL:
114565 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
114566 + break;
114567 + default:
114568 + break;
114569 + }
114570 + }
114571 +
114572 + while (missing_fn_head) {
114573 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
114574 +
114575 + cur = missing_fn_head->next;
114576 + free(missing_fn_head);
114577 + missing_fn_head = cur;
114578 + }
114579 +
114580 + return cnodes;
114581 +}
114582 +
114583 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
114584 +{
114585 + gimple phi = get_def_stmt(result);
114586 + unsigned int i, n = gimple_phi_num_args(phi);
114587 +
114588 + pointer_set_insert(visited, phi);
114589 + for (i = 0; i < n; i++) {
114590 + const_tree arg = gimple_phi_arg_def(phi, i);
114591 +
114592 + set_conditions(visited, interesting_conditions, arg);
114593 + }
114594 +}
114595 +
114596 +enum conditions {
114597 + FROM_CONST, NOT_UNARY, CAST
114598 +};
114599 +
114600 +// Search for constants, cast assignments and binary/ternary assignments
114601 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
114602 +{
114603 + gimple def_stmt = get_def_stmt(lhs);
114604 +
114605 + if (is_gimple_constant(lhs)) {
114606 + interesting_conditions[FROM_CONST] = true;
114607 + return;
114608 + }
114609 +
114610 + if (!def_stmt)
114611 + return;
114612 +
114613 + if (pointer_set_contains(visited, def_stmt))
114614 + return;
114615 +
114616 + switch (gimple_code(def_stmt)) {
114617 + case GIMPLE_NOP:
114618 + case GIMPLE_CALL:
114619 + case GIMPLE_ASM:
114620 + return;
114621 + case GIMPLE_PHI:
114622 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
114623 + case GIMPLE_ASSIGN:
114624 + if (gimple_num_ops(def_stmt) == 2) {
114625 + const_tree rhs = gimple_assign_rhs1(def_stmt);
114626 +
114627 + if (gimple_assign_cast_p(def_stmt))
114628 + interesting_conditions[CAST] = true;
114629 +
114630 + return set_conditions(visited, interesting_conditions, rhs);
114631 + } else {
114632 + interesting_conditions[NOT_UNARY] = true;
114633 + return;
114634 + }
114635 + default:
114636 + debug_gimple_stmt(def_stmt);
114637 + gcc_unreachable();
114638 + }
114639 +}
114640 +
114641 +// determine whether duplication will be necessary or not.
114642 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
114643 +{
114644 + struct pointer_set_t *visited;
114645 +
114646 + if (gimple_assign_cast_p(cur_node->first_stmt))
114647 + interesting_conditions[CAST] = true;
114648 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
114649 + interesting_conditions[NOT_UNARY] = true;
114650 +
114651 + visited = pointer_set_create();
114652 + set_conditions(visited, interesting_conditions, cur_node->node);
114653 + pointer_set_destroy(visited);
114654 +}
114655 +
114656 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
114657 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
114658 +{
114659 + gimple assign;
114660 + gimple_stmt_iterator gsi;
114661 +
114662 + // already removed
114663 + if (gimple_bb(asm_stmt) == NULL)
114664 + return;
114665 + gsi = gsi_for_stmt(asm_stmt);
114666 +
114667 + assign = gimple_build_assign(lhs, rhs);
114668 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
114669 + SSA_NAME_DEF_STMT(lhs) = assign;
114670 +
114671 + gsi_remove(&gsi, true);
114672 +}
114673 +
114674 +// Get the field decl of a component ref for intentional_overflow checking
114675 +static const_tree search_field_decl(const_tree comp_ref)
114676 +{
114677 + const_tree field = NULL_TREE;
114678 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
114679 +
114680 + for (i = 0; i < len; i++) {
114681 + field = TREE_OPERAND(comp_ref, i);
114682 + if (TREE_CODE(field) == FIELD_DECL)
114683 + break;
114684 + }
114685 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
114686 + return field;
114687 +}
114688 +
114689 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
114690 + * stmt is a return otherwise it is the callee function.
114691 + */
114692 +static const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
114693 +{
114694 + const_tree fndecl;
114695 +
114696 + if (argnum == 0)
114697 + fndecl = current_function_decl;
114698 + else
114699 + fndecl = gimple_call_fndecl(stmt);
114700 +
114701 + if (fndecl == NULL_TREE)
114702 + return NULL_TREE;
114703 +
114704 + return DECL_ORIGIN(fndecl);
114705 +}
114706 +
114707 +/* Get the param of the intentional_overflow attribute.
114708 + * * 0: MARK_NOT_INTENTIONAL
114709 + * * 1..MAX_PARAM: MARK_YES
114710 + * * -1: MARK_TURN_OFF
114711 + */
114712 +static tree get_attribute_param(const_tree decl)
114713 +{
114714 + const_tree attr;
114715 +
114716 + if (decl == NULL_TREE)
114717 + return NULL_TREE;
114718 +
114719 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
114720 + if (!attr || !TREE_VALUE(attr))
114721 + return NULL_TREE;
114722 +
114723 + return TREE_VALUE(attr);
114724 +}
114725 +
114726 +// MARK_TURN_OFF
114727 +static bool is_turn_off_intentional_attr(const_tree decl)
114728 +{
114729 + const_tree param_head;
114730 +
114731 + param_head = get_attribute_param(decl);
114732 + if (param_head == NULL_TREE)
114733 + return false;
114734 +
114735 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
114736 + return true;
114737 + return false;
114738 +}
114739 +
114740 +// MARK_NOT_INTENTIONAL
114741 +static bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
114742 +{
114743 + const_tree param_head;
114744 +
114745 + if (argnum == 0)
114746 + return false;
114747 +
114748 + param_head = get_attribute_param(decl);
114749 + if (param_head == NULL_TREE)
114750 + return false;
114751 +
114752 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
114753 + return true;
114754 + return false;
114755 +}
114756 +
114757 +// MARK_YES
114758 +static bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
114759 +{
114760 + tree param, param_head;
114761 +
114762 + if (argnum == 0)
114763 + return false;
114764 +
114765 + param_head = get_attribute_param(decl);
114766 + for (param = param_head; param; param = TREE_CHAIN(param))
114767 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
114768 + return true;
114769 + return false;
114770 +}
114771 +
114772 +static const char *get_asm_string(const_gimple stmt)
114773 +{
114774 + if (!stmt)
114775 + return NULL;
114776 + if (gimple_code(stmt) != GIMPLE_ASM)
114777 + return NULL;
114778 +
114779 + return gimple_asm_string(stmt);
114780 +}
114781 +
114782 +static bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
114783 +{
114784 + const char *str;
114785 +
114786 + str = get_asm_string(stmt);
114787 + if (!str)
114788 + return false;
114789 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
114790 +}
114791 +
114792 +static bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
114793 +{
114794 + const char *str;
114795 +
114796 + str = get_asm_string(stmt);
114797 + if (!str)
114798 + return false;
114799 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
114800 +}
114801 +
114802 +static bool is_size_overflow_asm(const_gimple stmt)
114803 +{
114804 + const char *str;
114805 +
114806 + str = get_asm_string(stmt);
114807 + if (!str)
114808 + return false;
114809 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
114810 +}
114811 +
114812 +static void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
114813 +{
114814 + location_t loc;
114815 +
114816 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
114817 + return;
114818 +
114819 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
114820 + return;
114821 +
114822 + loc = DECL_SOURCE_LOCATION(decl);
114823 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
114824 +}
114825 +
114826 +/* Get the type of the intentional_overflow attribute of a node
114827 + * * MARK_TURN_OFF
114828 + * * MARK_YES
114829 + * * MARK_NO
114830 + * * MARK_NOT_INTENTIONAL
114831 + */
114832 +static enum mark get_intentional_attr_type(const_tree node)
114833 +{
114834 + const_tree cur_decl;
114835 +
114836 + if (node == NULL_TREE)
114837 + return MARK_NO;
114838 +
114839 + switch (TREE_CODE(node)) {
114840 + case COMPONENT_REF:
114841 + cur_decl = search_field_decl(node);
114842 + if (is_turn_off_intentional_attr(cur_decl))
114843 + return MARK_TURN_OFF;
114844 + if (is_end_intentional_intentional_attr(cur_decl, 1))
114845 + return MARK_YES;
114846 + break;
114847 + case PARM_DECL: {
114848 + unsigned int argnum;
114849 +
114850 + cur_decl = DECL_ORIGIN(current_function_decl);
114851 + argnum = find_arg_number_tree(node, cur_decl);
114852 + if (argnum == CANNOT_FIND_ARG)
114853 + return MARK_NO;
114854 + if (is_yes_intentional_attr(cur_decl, argnum))
114855 + return MARK_YES;
114856 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
114857 + return MARK_NOT_INTENTIONAL;
114858 + break;
114859 + }
114860 + case FUNCTION_DECL:
114861 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
114862 + return MARK_TURN_OFF;
114863 + break;
114864 + default:
114865 + break;
114866 + }
114867 + return MARK_NO;
114868 +}
114869 +
114870 +// Search for the intentional_overflow attribute on the last nodes
114871 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
114872 +{
114873 + unsigned int i;
114874 + tree last_node;
114875 + enum mark mark = MARK_NO;
114876 +
114877 +#if BUILDING_GCC_VERSION <= 4007
114878 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
114879 +#else
114880 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
114881 +#endif
114882 + mark = get_intentional_attr_type(last_node);
114883 + if (mark != MARK_NO)
114884 + break;
114885 + }
114886 + return mark;
114887 +}
114888 +
114889 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
114890 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
114891 + */
114892 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
114893 +{
114894 + if (!cur_node->intentional_mark_from_gimple)
114895 + return false;
114896 +
114897 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
114898 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
114899 + else
114900 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
114901 +
114902 + // skip param decls
114903 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
114904 + return true;
114905 + return true;
114906 +}
114907 +
114908 +/* Search intentional_overflow attribute on caller and on callee too.
114909 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
114910 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
114911 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
114912 +*/
114913 +static void check_intentional_attribute_ipa(struct interesting_node *cur_node)
114914 +{
114915 + const_tree fndecl;
114916 +
114917 + if (is_intentional_attribute_from_gimple(cur_node))
114918 + return;
114919 +
114920 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
114921 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
114922 + return;
114923 + }
114924 +
114925 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
114926 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
114927 + return;
114928 + }
114929 +
114930 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
114931 + return;
114932 +
114933 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
114934 + if (is_turn_off_intentional_attr(fndecl)) {
114935 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
114936 + return;
114937 + }
114938 +
114939 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
114940 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
114941 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
114942 + cur_node->intentional_attr_decl = MARK_YES;
114943 +
114944 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
114945 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
114946 +}
114947 +
114948 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
114949 +static bool skip_asm(const_tree arg)
114950 +{
114951 + gimple def_stmt = get_def_stmt(arg);
114952 +
114953 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
114954 + return false;
114955 +
114956 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
114957 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
114958 +}
114959 +
114960 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
114961 +{
114962 + gimple phi = get_def_stmt(result);
114963 + unsigned int i, n = gimple_phi_num_args(phi);
114964 +
114965 + pointer_set_insert(visited, phi);
114966 + for (i = 0; i < n; i++) {
114967 + tree arg = gimple_phi_arg_def(phi, i);
114968 +
114969 + walk_use_def(visited, cur_node, arg);
114970 + }
114971 +}
114972 +
114973 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
114974 +{
114975 + gimple def_stmt = get_def_stmt(lhs);
114976 + tree rhs1, rhs2;
114977 +
114978 + rhs1 = gimple_assign_rhs1(def_stmt);
114979 + rhs2 = gimple_assign_rhs2(def_stmt);
114980 +
114981 + walk_use_def(visited, cur_node, rhs1);
114982 + walk_use_def(visited, cur_node, rhs2);
114983 +}
114984 +
114985 +static void insert_last_node(struct interesting_node *cur_node, tree node)
114986 +{
114987 + unsigned int i;
114988 + tree element;
114989 + enum tree_code code;
114990 +
114991 + gcc_assert(node != NULL_TREE);
114992 +
114993 + if (is_gimple_constant(node))
114994 + return;
114995 +
114996 + code = TREE_CODE(node);
114997 + if (code == VAR_DECL) {
114998 + node = DECL_ORIGIN(node);
114999 + code = TREE_CODE(node);
115000 + }
115001 +
115002 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
115003 + return;
115004 +
115005 +#if BUILDING_GCC_VERSION <= 4007
115006 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
115007 +#else
115008 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
115009 +#endif
115010 + if (operand_equal_p(node, element, 0))
115011 + return;
115012 + }
115013 +
115014 +#if BUILDING_GCC_VERSION <= 4007
115015 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
115016 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
115017 +#else
115018 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
115019 + vec_safe_push(cur_node->last_nodes, node);
115020 +#endif
115021 +}
115022 +
115023 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
115024 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
115025 +{
115026 + if (!is_size_overflow_asm(stmt))
115027 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115028 +}
115029 +
115030 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
115031 + * and component refs (for checking the intentional_overflow attribute).
115032 + */
115033 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115034 +{
115035 + const_gimple def_stmt;
115036 +
115037 + if (TREE_CODE(lhs) != SSA_NAME) {
115038 + insert_last_node(cur_node, lhs);
115039 + return;
115040 + }
115041 +
115042 + def_stmt = get_def_stmt(lhs);
115043 + if (!def_stmt)
115044 + return;
115045 +
115046 + if (pointer_set_insert(visited, def_stmt))
115047 + return;
115048 +
115049 + switch (gimple_code(def_stmt)) {
115050 + case GIMPLE_NOP:
115051 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115052 + case GIMPLE_ASM:
115053 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
115054 + case GIMPLE_CALL: {
115055 + tree fndecl = gimple_call_fndecl(def_stmt);
115056 +
115057 + if (fndecl == NULL_TREE)
115058 + return;
115059 + insert_last_node(cur_node, fndecl);
115060 + return;
115061 + }
115062 + case GIMPLE_PHI:
115063 + return walk_use_def_phi(visited, cur_node, lhs);
115064 + case GIMPLE_ASSIGN:
115065 + switch (gimple_num_ops(def_stmt)) {
115066 + case 2:
115067 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
115068 + case 3:
115069 + return walk_use_def_binary(visited, cur_node, lhs);
115070 + }
115071 + default:
115072 + debug_gimple_stmt((gimple)def_stmt);
115073 + error("%s: unknown gimple code", __func__);
115074 + gcc_unreachable();
115075 + }
115076 +}
115077 +
115078 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
115079 +static void set_last_nodes(struct interesting_node *cur_node)
115080 +{
115081 + struct pointer_set_t *visited;
115082 +
115083 + visited = pointer_set_create();
115084 + walk_use_def(visited, cur_node, cur_node->node);
115085 + pointer_set_destroy(visited);
115086 +}
115087 +
115088 +enum precond {
115089 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
115090 +};
115091 +
115092 +/* 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.
115093 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
115094 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
115095 + * 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.
115096 + */
115097 +static enum precond check_preconditions(struct interesting_node *cur_node)
115098 +{
115099 + bool interesting_conditions[3] = {false, false, false};
115100 +
115101 + set_last_nodes(cur_node);
115102 +
115103 + check_intentional_attribute_ipa(cur_node);
115104 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
115105 + return NO_ATTRIBUTE_SEARCH;
115106 +
115107 + search_interesting_conditions(cur_node, interesting_conditions);
115108 +
115109 + // error code
115110 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
115111 + return NO_ATTRIBUTE_SEARCH;
115112 +
115113 + // unnecessary overflow check
115114 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
115115 + return NO_CHECK_INSERT;
115116 +
115117 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
115118 + return NO_CHECK_INSERT;
115119 +
115120 + return NONE;
115121 +}
115122 +
115123 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
115124 + * 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
115125 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
115126 + */
115127 +static struct next_cgraph_node *handle_interesting_stmt(struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
115128 +{
115129 + enum precond ret;
115130 + struct pointer_set_t *visited;
115131 + tree new_node, orig_node = cur_node->node;
115132 +
115133 + ret = check_preconditions(cur_node);
115134 + if (ret == NO_ATTRIBUTE_SEARCH)
115135 + return cnodes;
115136 +
115137 + cnodes = search_overflow_attribute(cnodes, cur_node);
115138 +
115139 + if (ret == NO_CHECK_INSERT)
115140 + return cnodes;
115141 +
115142 + visited = pointer_set_create();
115143 + new_node = expand(visited, caller_node, orig_node);
115144 + pointer_set_destroy(visited);
115145 +
115146 + if (new_node == NULL_TREE)
115147 + return cnodes;
115148 +
115149 + change_orig_node(cur_node, new_node);
115150 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
115151 +
115152 + return cnodes;
115153 +}
115154 +
115155 +// Check visited interesting nodes.
115156 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
115157 +{
115158 + struct interesting_node *cur;
115159 +
115160 + for (cur = head; cur; cur = cur->next) {
115161 + if (!operand_equal_p(node, cur->node, 0))
115162 + continue;
115163 + if (num != cur->num)
115164 + continue;
115165 + if (first_stmt == cur->first_stmt)
115166 + return true;
115167 + }
115168 + return false;
115169 +}
115170 +
115171 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
115172 + 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
115173 + 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
115174 + the intentional_overflow attribute check. They are collected by set_last_nodes().
115175 + num: arg count of a call stmt or 0 when it is a ret
115176 + node: the recursion starts from here, it is a call arg or a return value
115177 + 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.
115178 + intentional_attr_decl: intentional_overflow attribute of the callee function
115179 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
115180 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
115181 + */
115182 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
115183 +{
115184 + struct interesting_node *new_node;
115185 + tree fndecl;
115186 + enum gimple_code code;
115187 +
115188 + gcc_assert(node != NULL_TREE);
115189 + code = gimple_code(first_stmt);
115190 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
115191 +
115192 + if (num == CANNOT_FIND_ARG)
115193 + return head;
115194 +
115195 + if (skip_types(node))
115196 + return head;
115197 +
115198 + if (skip_asm(node))
115199 + return head;
115200 +
115201 + if (is_gimple_call(first_stmt))
115202 + fndecl = gimple_call_fndecl(first_stmt);
115203 + else
115204 + fndecl = current_function_decl;
115205 +
115206 + if (fndecl == NULL_TREE)
115207 + return head;
115208 +
115209 + if (is_in_interesting_node(head, first_stmt, node, num))
115210 + return head;
115211 +
115212 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
115213 +
115214 + new_node->next = NULL;
115215 + new_node->first_stmt = first_stmt;
115216 +#if BUILDING_GCC_VERSION <= 4007
115217 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
115218 +#else
115219 + vec_alloc(new_node->last_nodes, VEC_LEN);
115220 +#endif
115221 + new_node->num = num;
115222 + new_node->node = node;
115223 + new_node->fndecl = fndecl;
115224 + new_node->intentional_attr_decl = MARK_NO;
115225 + new_node->intentional_attr_cur_fndecl = MARK_NO;
115226 + new_node->intentional_mark_from_gimple = asm_stmt;
115227 +
115228 + if (!head)
115229 + return new_node;
115230 +
115231 + new_node->next = head;
115232 + return new_node;
115233 +}
115234 +
115235 +/* 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).
115236 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
115237 + */
115238 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115239 +{
115240 + struct next_cgraph_node *cur_node;
115241 + tree ret = gimple_return_retval(stmt);
115242 +
115243 + if (ret == NULL_TREE)
115244 + return head;
115245 +
115246 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115247 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
115248 + continue;
115249 + if (cur_node->num == 0)
115250 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
115251 + }
115252 +
115253 + return head;
115254 +}
115255 +
115256 +/* 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).
115257 + * If the call stmt is in the next cgraph node list then it's an interesting call.
115258 + */
115259 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115260 +{
115261 + unsigned int argnum;
115262 + tree arg;
115263 + const_tree fndecl;
115264 + struct next_cgraph_node *cur_node;
115265 +
115266 + fndecl = gimple_call_fndecl(stmt);
115267 + if (fndecl == NULL_TREE)
115268 + return head;
115269 +
115270 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115271 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
115272 + continue;
115273 + argnum = get_correct_arg_count(cur_node->num, fndecl);
115274 + gcc_assert(argnum != CANNOT_FIND_ARG);
115275 + if (argnum == 0)
115276 + continue;
115277 +
115278 + arg = gimple_call_arg(stmt, argnum - 1);
115279 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
115280 + }
115281 +
115282 + return head;
115283 +}
115284 +
115285 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
115286 +{
115287 + if (!operand_equal_p(orig_node, node, 0))
115288 + return WRONG_NODE;
115289 + if (skip_types(node))
115290 + return WRONG_NODE;
115291 + return ret_count;
115292 +}
115293 +
115294 +// Get the index of the rhs node in an assignment
115295 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
115296 +{
115297 + const_tree rhs1, rhs2;
115298 + unsigned int ret;
115299 +
115300 + gcc_assert(stmt);
115301 + gcc_assert(is_gimple_assign(stmt));
115302 +
115303 + rhs1 = gimple_assign_rhs1(stmt);
115304 + gcc_assert(rhs1 != NULL_TREE);
115305 +
115306 + switch (gimple_num_ops(stmt)) {
115307 + case 2:
115308 + return check_ops(node, rhs1, 1);
115309 + case 3:
115310 + ret = check_ops(node, rhs1, 1);
115311 + if (ret != WRONG_NODE)
115312 + return ret;
115313 +
115314 + rhs2 = gimple_assign_rhs2(stmt);
115315 + gcc_assert(rhs2 != NULL_TREE);
115316 + return check_ops(node, rhs2, 2);
115317 + default:
115318 + gcc_unreachable();
115319 + }
115320 +}
115321 +
115322 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
115323 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
115324 +{
115325 + unsigned int i;
115326 +
115327 + if (gimple_call_fndecl(stmt) == NULL_TREE)
115328 + return CANNOT_FIND_ARG;
115329 +
115330 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
115331 + tree node;
115332 +
115333 + node = gimple_call_arg(stmt, i);
115334 + if (!operand_equal_p(arg, node, 0))
115335 + continue;
115336 + if (!skip_types(node))
115337 + return i + 1;
115338 + }
115339 +
115340 + return CANNOT_FIND_ARG;
115341 +}
115342 +
115343 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
115344 + * any of return, call or assignment stmts (because of inlining).
115345 + */
115346 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
115347 +{
115348 + use_operand_p use_p;
115349 + imm_use_iterator imm_iter;
115350 + unsigned int argnum;
115351 +
115352 + gcc_assert(TREE_CODE(node) == SSA_NAME);
115353 +
115354 + if (pointer_set_insert(visited, node))
115355 + return head;
115356 +
115357 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115358 + gimple stmt = USE_STMT(use_p);
115359 +
115360 + if (stmt == NULL)
115361 + return head;
115362 + if (is_gimple_debug(stmt))
115363 + continue;
115364 +
115365 + switch (gimple_code(stmt)) {
115366 + case GIMPLE_CALL:
115367 + argnum = find_arg_number_gimple(node, stmt);
115368 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115369 + break;
115370 + case GIMPLE_RETURN:
115371 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
115372 + break;
115373 + case GIMPLE_ASSIGN:
115374 + argnum = get_assign_ops_count(stmt, node);
115375 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115376 + break;
115377 + case GIMPLE_PHI: {
115378 + tree result = gimple_phi_result(stmt);
115379 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
115380 + break;
115381 + }
115382 + case GIMPLE_ASM:
115383 + if (gimple_asm_noutputs(stmt) != 0)
115384 + break;
115385 + if (!is_size_overflow_asm(stmt))
115386 + break;
115387 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
115388 + break;
115389 + case GIMPLE_COND:
115390 + case GIMPLE_SWITCH:
115391 + break;
115392 + default:
115393 + debug_gimple_stmt(stmt);
115394 + gcc_unreachable();
115395 + break;
115396 + }
115397 + }
115398 + return head;
115399 +}
115400 +
115401 +static void remove_size_overflow_asm(gimple stmt)
115402 +{
115403 + gimple_stmt_iterator gsi;
115404 + tree input, output;
115405 +
115406 + if (!is_size_overflow_asm(stmt))
115407 + return;
115408 +
115409 + if (gimple_asm_noutputs(stmt) == 0) {
115410 + gsi = gsi_for_stmt(stmt);
115411 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
115412 + gsi_remove(&gsi, true);
115413 + return;
115414 + }
115415 +
115416 + input = gimple_asm_input_op(stmt, 0);
115417 + output = gimple_asm_output_op(stmt, 0);
115418 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
115419 +}
115420 +
115421 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
115422 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
115423 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
115424 + */
115425 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
115426 +{
115427 + const_tree output;
115428 + struct pointer_set_t *visited;
115429 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
115430 +
115431 + if (!is_size_overflow_asm(stmt))
115432 + return head;
115433 +
115434 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
115435 + intentional_asm = stmt;
115436 +
115437 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
115438 +
115439 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
115440 + return head;
115441 +
115442 + if (gimple_asm_noutputs(stmt) == 0) {
115443 + const_tree input;
115444 +
115445 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
115446 + return head;
115447 +
115448 + input = gimple_asm_input_op(stmt, 0);
115449 + remove_size_overflow_asm(stmt);
115450 + if (is_gimple_constant(TREE_VALUE(input)))
115451 + return head;
115452 + visited = pointer_set_create();
115453 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
115454 + pointer_set_destroy(visited);
115455 + return head;
115456 + }
115457 +
115458 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
115459 + remove_size_overflow_asm(stmt);
115460 +
115461 + visited = pointer_set_create();
115462 + output = gimple_asm_output_op(stmt, 0);
115463 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
115464 + pointer_set_destroy(visited);
115465 + return head;
115466 +}
115467 +
115468 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
115469 + * or a call stmt or a return stmt and store them in the interesting_node list
115470 + */
115471 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
115472 +{
115473 + basic_block bb;
115474 + struct interesting_node *head = NULL;
115475 +
115476 + FOR_ALL_BB_FN(bb, cfun) {
115477 + gimple_stmt_iterator gsi;
115478 +
115479 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
115480 + enum gimple_code code;
115481 + gimple stmt = gsi_stmt(gsi);
115482 +
115483 + code = gimple_code(stmt);
115484 +
115485 + if (code == GIMPLE_ASM)
115486 + head = handle_stmt_by_size_overflow_asm(stmt, head);
115487 +
115488 + if (!next_node)
115489 + continue;
115490 + if (code == GIMPLE_CALL)
115491 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
115492 + if (code == GIMPLE_RETURN)
115493 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
115494 + }
115495 + }
115496 + return head;
115497 +}
115498 +
115499 +static void set_current_function_decl(tree fndecl)
115500 +{
115501 + gcc_assert(fndecl != NULL_TREE);
115502 +
115503 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
115504 + calculate_dominance_info(CDI_DOMINATORS);
115505 + current_function_decl = fndecl;
115506 +}
115507 +
115508 +static void unset_current_function_decl(void)
115509 +{
115510 + free_dominance_info(CDI_DOMINATORS);
115511 + pop_cfun();
115512 + current_function_decl = NULL_TREE;
115513 +}
115514 +
115515 +static void free_interesting_node(struct interesting_node *head)
115516 +{
115517 + struct interesting_node *cur;
115518 +
115519 + while (head) {
115520 + cur = head->next;
115521 +#if BUILDING_GCC_VERSION <= 4007
115522 + VEC_free(tree, gc, head->last_nodes);
115523 +#else
115524 + vec_free(head->last_nodes);
115525 +#endif
115526 + free(head);
115527 + head = cur;
115528 + }
115529 +}
115530 +
115531 +static struct visited *insert_visited_function(struct visited *head, struct interesting_node *cur_node)
115532 +{
115533 + struct visited *new_visited;
115534 +
115535 + new_visited = (struct visited *)xmalloc(sizeof(*new_visited));
115536 + new_visited->fndecl = cur_node->fndecl;
115537 + new_visited->num = cur_node->num;
115538 + new_visited->rhs = cur_node->node;
115539 + new_visited->next = NULL;
115540 +
115541 + if (!head)
115542 + return new_visited;
115543 +
115544 + new_visited->next = head;
115545 + return new_visited;
115546 +}
115547 +
115548 +/* 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
115549 + * it is a visited function.
115550 + */
115551 +static bool is_visited_function(struct visited *head, struct interesting_node *cur_node)
115552 +{
115553 + struct visited *cur;
115554 +
115555 + if (!head)
115556 + return false;
115557 +
115558 + for (cur = head; cur; cur = cur->next) {
115559 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
115560 + continue;
115561 + if (cur_node->num != cur->num)
115562 + continue;
115563 + if (cur_node->node == cur->rhs)
115564 + return true;
115565 + }
115566 + return false;
115567 +}
115568 +
115569 +static void free_next_cgraph_node(struct next_cgraph_node *head)
115570 +{
115571 + struct next_cgraph_node *cur;
115572 +
115573 + while (head) {
115574 + cur = head->next;
115575 + free(head);
115576 + head = cur;
115577 + }
115578 +}
115579 +
115580 +static void remove_all_size_overflow_asm(void)
115581 +{
115582 + basic_block bb;
115583 +
115584 + FOR_ALL_BB_FN(bb, cfun) {
115585 + gimple_stmt_iterator si;
115586 +
115587 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
115588 + remove_size_overflow_asm(gsi_stmt(si));
115589 + }
115590 +}
115591 +
115592 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
115593 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
115594 + * the newly collected interesting functions (they are interesting if there is control flow between
115595 + * the interesting stmts and them).
115596 + */
115597 +static struct visited *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited *visited)
115598 +{
115599 + struct interesting_node *head, *cur_node;
115600 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
115601 +
115602 + set_current_function_decl(NODE_DECL(node));
115603 + call_count = 0;
115604 +
115605 + head = collect_interesting_stmts(next_node);
115606 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115607 + if (is_visited_function(visited, cur_node))
115608 + continue;
115609 + cnodes_head = handle_interesting_stmt(cnodes_head, cur_node, node);
115610 + visited = insert_visited_function(visited, cur_node);
115611 + }
115612 +
115613 + free_interesting_node(head);
115614 + remove_all_size_overflow_asm();
115615 + unset_current_function_decl();
115616 +
115617 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
115618 + visited = handle_function(cur_cnodes->current_function, cur_cnodes, visited);
115619 +
115620 + free_next_cgraph_node(cnodes_head);
115621 + return visited;
115622 +}
115623 +
115624 +static void free_visited(struct visited *head)
115625 +{
115626 + struct visited *cur;
115627 +
115628 + while (head) {
115629 + cur = head->next;
115630 + free(head);
115631 + head = cur;
115632 + }
115633 +}
115634 +
115635 +// erase the local flag
115636 +static void set_plf_false(void)
115637 +{
115638 + basic_block bb;
115639 +
115640 + FOR_ALL_BB_FN(bb, cfun) {
115641 + gimple_stmt_iterator si;
115642 +
115643 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
115644 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
115645 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
115646 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
115647 + }
115648 +}
115649 +
115650 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
115651 +static unsigned int search_function(void)
115652 +{
115653 + struct cgraph_node *node;
115654 + struct visited *visited = NULL;
115655 +
115656 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
115657 + set_current_function_decl(NODE_DECL(node));
115658 + set_plf_false();
115659 + unset_current_function_decl();
115660 + }
115661 +
115662 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
115663 + gcc_assert(cgraph_function_flags_ready);
115664 +#if BUILDING_GCC_VERSION <= 4007
115665 + gcc_assert(node->reachable);
115666 +#endif
115667 +
115668 + visited = handle_function(node, NULL, visited);
115669 + }
115670 +
115671 + free_visited(visited);
115672 + return 0;
115673 +}
115674 +
115675 +#if BUILDING_GCC_VERSION >= 4009
115676 +static const struct pass_data ipa_pass_data = {
115677 +#else
115678 +static struct ipa_opt_pass_d ipa_pass = {
115679 + .pass = {
115680 +#endif
115681 + .type = SIMPLE_IPA_PASS,
115682 + .name = "size_overflow",
115683 +#if BUILDING_GCC_VERSION >= 4008
115684 + .optinfo_flags = OPTGROUP_NONE,
115685 +#endif
115686 +#if BUILDING_GCC_VERSION >= 4009
115687 + .has_gate = false,
115688 + .has_execute = true,
115689 +#else
115690 + .gate = NULL,
115691 + .execute = search_function,
115692 + .sub = NULL,
115693 + .next = NULL,
115694 + .static_pass_number = 0,
115695 +#endif
115696 + .tv_id = TV_NONE,
115697 + .properties_required = 0,
115698 + .properties_provided = 0,
115699 + .properties_destroyed = 0,
115700 + .todo_flags_start = 0,
115701 + .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,
115702 +#if BUILDING_GCC_VERSION < 4009
115703 + },
115704 + .generate_summary = NULL,
115705 + .write_summary = NULL,
115706 + .read_summary = NULL,
115707 +#if BUILDING_GCC_VERSION >= 4006
115708 + .write_optimization_summary = NULL,
115709 + .read_optimization_summary = NULL,
115710 +#endif
115711 + .stmt_fixup = NULL,
115712 + .function_transform_todo_flags_start = 0,
115713 + .function_transform = NULL,
115714 + .variable_transform = NULL,
115715 +#endif
115716 +};
115717 +
115718 +#if BUILDING_GCC_VERSION >= 4009
115719 +namespace {
115720 +class ipa_pass : public ipa_opt_pass_d {
115721 +public:
115722 + ipa_pass() : ipa_opt_pass_d(ipa_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
115723 + unsigned int execute() { return search_function(); }
115724 +};
115725 +}
115726 +#endif
115727 +
115728 +static struct opt_pass *make_ipa_pass(void)
115729 +{
115730 +#if BUILDING_GCC_VERSION >= 4009
115731 + return new ipa_pass();
115732 +#else
115733 + return &ipa_pass.pass;
115734 +#endif
115735 +}
115736 +
115737 +// data for the size_overflow asm stmt
115738 +struct asm_data {
115739 + gimple def_stmt;
115740 + tree input;
115741 + tree output;
115742 +};
115743 +
115744 +#if BUILDING_GCC_VERSION <= 4007
115745 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
115746 +#else
115747 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
115748 +#endif
115749 +{
115750 + tree list;
115751 +#if BUILDING_GCC_VERSION <= 4007
115752 + VEC(tree, gc) *vec_list = NULL;
115753 +#else
115754 + vec<tree, va_gc> *vec_list = NULL;
115755 +#endif
115756 +
115757 + list = build_tree_list(NULL_TREE, string);
115758 + list = chainon(NULL_TREE, build_tree_list(list, io));
115759 +#if BUILDING_GCC_VERSION <= 4007
115760 + VEC_safe_push(tree, gc, vec_list, list);
115761 +#else
115762 + vec_safe_push(vec_list, list);
115763 +#endif
115764 + return vec_list;
115765 +}
115766 +
115767 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
115768 +{
115769 + gimple asm_stmt;
115770 + gimple_stmt_iterator gsi;
115771 +#if BUILDING_GCC_VERSION <= 4007
115772 + VEC(tree, gc) *input, *output = NULL;
115773 +#else
115774 + vec<tree, va_gc> *input, *output = NULL;
115775 +#endif
115776 +
115777 + input = create_asm_io_list(str_input, asm_data->input);
115778 +
115779 + if (asm_data->output)
115780 + output = create_asm_io_list(str_output, asm_data->output);
115781 +
115782 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
115783 + gsi = gsi_for_stmt(asm_data->def_stmt);
115784 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
115785 +
115786 + if (asm_data->output)
115787 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
115788 +}
115789 +
115790 +static void replace_call_lhs(const struct asm_data *asm_data)
115791 +{
115792 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
115793 + update_stmt(asm_data->def_stmt);
115794 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
115795 +}
115796 +
115797 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
115798 +{
115799 + enum mark cur_fndecl_attr;
115800 + gimple phi = get_def_stmt(result);
115801 + unsigned int i, n = gimple_phi_num_args(phi);
115802 +
115803 + pointer_set_insert(visited, phi);
115804 + for (i = 0; i < n; i++) {
115805 + tree arg = gimple_phi_arg_def(phi, i);
115806 +
115807 + cur_fndecl_attr = search_intentional(visited, arg);
115808 + if (cur_fndecl_attr != MARK_NO)
115809 + return cur_fndecl_attr;
115810 + }
115811 + return MARK_NO;
115812 +}
115813 +
115814 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
115815 +{
115816 + enum mark cur_fndecl_attr;
115817 + const_tree rhs1, rhs2;
115818 + gimple def_stmt = get_def_stmt(lhs);
115819 +
115820 + rhs1 = gimple_assign_rhs1(def_stmt);
115821 + rhs2 = gimple_assign_rhs2(def_stmt);
115822 +
115823 + cur_fndecl_attr = search_intentional(visited, rhs1);
115824 + if (cur_fndecl_attr != MARK_NO)
115825 + return cur_fndecl_attr;
115826 + return search_intentional(visited, rhs2);
115827 +}
115828 +
115829 +// Look up the intentional_overflow attribute on the caller and the callee functions.
115830 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
115831 +{
115832 + const_gimple def_stmt;
115833 +
115834 + if (TREE_CODE(lhs) != SSA_NAME)
115835 + return get_intentional_attr_type(lhs);
115836 +
115837 + def_stmt = get_def_stmt(lhs);
115838 + if (!def_stmt)
115839 + return MARK_NO;
115840 +
115841 + if (pointer_set_contains(visited, def_stmt))
115842 + return MARK_NO;
115843 +
115844 + switch (gimple_code(def_stmt)) {
115845 + case GIMPLE_NOP:
115846 + return search_intentional(visited, SSA_NAME_VAR(lhs));
115847 + case GIMPLE_ASM:
115848 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
115849 + return MARK_TURN_OFF;
115850 + return MARK_NO;
115851 + case GIMPLE_CALL:
115852 + return MARK_NO;
115853 + case GIMPLE_PHI:
115854 + return search_intentional_phi(visited, lhs);
115855 + case GIMPLE_ASSIGN:
115856 + switch (gimple_num_ops(def_stmt)) {
115857 + case 2:
115858 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
115859 + case 3:
115860 + return search_intentional_binary(visited, lhs);
115861 + }
115862 + case GIMPLE_RETURN:
115863 + return MARK_NO;
115864 + default:
115865 + debug_gimple_stmt((gimple)def_stmt);
115866 + error("%s: unknown gimple code", __func__);
115867 + gcc_unreachable();
115868 + }
115869 +}
115870 +
115871 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
115872 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
115873 +{
115874 + const_tree fndecl;
115875 + struct pointer_set_t *visited;
115876 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
115877 +
115878 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
115879 + if (is_end_intentional_intentional_attr(fndecl, argnum))
115880 + decl_attr = MARK_NOT_INTENTIONAL;
115881 + else if (is_yes_intentional_attr(fndecl, argnum))
115882 + decl_attr = MARK_YES;
115883 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
115884 + return MARK_TURN_OFF;
115885 + }
115886 +
115887 + visited = pointer_set_create();
115888 + cur_fndecl_attr = search_intentional(visited, arg);
115889 + pointer_set_destroy(visited);
115890 +
115891 + switch (cur_fndecl_attr) {
115892 + case MARK_NO:
115893 + case MARK_TURN_OFF:
115894 + return cur_fndecl_attr;
115895 + default:
115896 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
115897 + return MARK_YES;
115898 + }
115899 +}
115900 +
115901 +static void check_missing_size_overflow_attribute(tree var)
115902 +{
115903 + tree orig_fndecl;
115904 + unsigned int num;
115905 +
115906 + if (is_a_return_check(var))
115907 + orig_fndecl = DECL_ORIGIN(var);
115908 + else
115909 + orig_fndecl = DECL_ORIGIN(current_function_decl);
115910 +
115911 + num = get_function_num(var, orig_fndecl);
115912 + if (num == CANNOT_FIND_ARG)
115913 + return;
115914 +
115915 + is_missing_function(orig_fndecl, num);
115916 +}
115917 +
115918 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
115919 +{
115920 + gimple phi = get_def_stmt(result);
115921 + unsigned int i, n = gimple_phi_num_args(phi);
115922 +
115923 + pointer_set_insert(visited, phi);
115924 + for (i = 0; i < n; i++) {
115925 + tree arg = gimple_phi_arg_def(phi, i);
115926 +
115927 + search_size_overflow_attribute(visited, arg);
115928 + }
115929 +}
115930 +
115931 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
115932 +{
115933 + const_gimple def_stmt = get_def_stmt(lhs);
115934 + tree rhs1, rhs2;
115935 +
115936 + rhs1 = gimple_assign_rhs1(def_stmt);
115937 + rhs2 = gimple_assign_rhs2(def_stmt);
115938 +
115939 + search_size_overflow_attribute(visited, rhs1);
115940 + search_size_overflow_attribute(visited, rhs2);
115941 +}
115942 +
115943 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
115944 +{
115945 + const_gimple def_stmt;
115946 +
115947 + if (TREE_CODE(lhs) == PARM_DECL) {
115948 + check_missing_size_overflow_attribute(lhs);
115949 + return;
115950 + }
115951 +
115952 + def_stmt = get_def_stmt(lhs);
115953 + if (!def_stmt)
115954 + return;
115955 +
115956 + if (pointer_set_insert(visited, def_stmt))
115957 + return;
115958 +
115959 + switch (gimple_code(def_stmt)) {
115960 + case GIMPLE_NOP:
115961 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
115962 + case GIMPLE_ASM:
115963 + return;
115964 + case GIMPLE_CALL: {
115965 + tree fndecl = gimple_call_fndecl(def_stmt);
115966 +
115967 + if (fndecl == NULL_TREE)
115968 + return;
115969 + check_missing_size_overflow_attribute(fndecl);
115970 + return;
115971 + }
115972 + case GIMPLE_PHI:
115973 + return search_size_overflow_attribute_phi(visited, lhs);
115974 + case GIMPLE_ASSIGN:
115975 + switch (gimple_num_ops(def_stmt)) {
115976 + case 2:
115977 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
115978 + case 3:
115979 + return search_size_overflow_attribute_binary(visited, lhs);
115980 + }
115981 + default:
115982 + debug_gimple_stmt((gimple)def_stmt);
115983 + error("%s: unknown gimple code", __func__);
115984 + gcc_unreachable();
115985 + }
115986 +}
115987 +
115988 +// Search missing entries in the hash table (invoked from the gimple pass)
115989 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
115990 +{
115991 + tree fndecl = NULL_TREE;
115992 + tree lhs;
115993 + struct pointer_set_t *visited;
115994 +
115995 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
115996 + return;
115997 +
115998 + if (num == 0) {
115999 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
116000 + lhs = gimple_return_retval(stmt);
116001 + } else {
116002 + gcc_assert(is_gimple_call(stmt));
116003 + lhs = gimple_call_arg(stmt, num - 1);
116004 + fndecl = gimple_call_fndecl(stmt);
116005 + }
116006 +
116007 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
116008 + return;
116009 +
116010 + visited = pointer_set_create();
116011 + search_size_overflow_attribute(visited, lhs);
116012 + pointer_set_destroy(visited);
116013 +}
116014 +
116015 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
116016 +{
116017 + gimple_stmt_iterator gsi;
116018 + gimple assign;
116019 +
116020 + assign = gimple_build_assign(asm_data->input, asm_data->output);
116021 + gsi = gsi_for_stmt(stmt);
116022 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
116023 + asm_data->def_stmt = assign;
116024 +
116025 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
116026 + asm_data->output = make_ssa_name(asm_data->output, stmt);
116027 + if (gimple_code(stmt) == GIMPLE_RETURN)
116028 + gimple_return_set_retval(stmt, asm_data->output);
116029 + else
116030 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
116031 + update_stmt(stmt);
116032 +}
116033 +
116034 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
116035 +{
116036 + const char *fn_name;
116037 + char *asm_comment;
116038 + unsigned int len;
116039 +
116040 + if (argnum == 0)
116041 + fn_name = DECL_NAME_POINTER(current_function_decl);
116042 + else
116043 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
116044 +
116045 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
116046 + gcc_assert(len > 0);
116047 +
116048 + return asm_comment;
116049 +}
116050 +
116051 +static const char *convert_mark_to_str(enum mark mark)
116052 +{
116053 + switch (mark) {
116054 + case MARK_NO:
116055 + return OK_ASM_STR;
116056 + case MARK_YES:
116057 + case MARK_NOT_INTENTIONAL:
116058 + return YES_ASM_STR;
116059 + case MARK_TURN_OFF:
116060 + return TURN_OFF_ASM_STR;
116061 + }
116062 +
116063 + gcc_unreachable();
116064 +}
116065 +
116066 +/* Create the input of the size_overflow asm stmt.
116067 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
116068 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
116069 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
116070 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
116071 + */
116072 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
116073 +{
116074 + if (!asm_data->def_stmt) {
116075 + asm_data->input = NULL_TREE;
116076 + return;
116077 + }
116078 +
116079 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
116080 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
116081 +
116082 + switch (gimple_code(asm_data->def_stmt)) {
116083 + case GIMPLE_ASSIGN:
116084 + case GIMPLE_CALL:
116085 + replace_call_lhs(asm_data);
116086 + break;
116087 + case GIMPLE_PHI:
116088 + create_output_from_phi(stmt, argnum, asm_data);
116089 + break;
116090 + case GIMPLE_NOP: {
116091 + enum mark mark;
116092 + const char *mark_str;
116093 + char *asm_comment;
116094 +
116095 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
116096 +
116097 + asm_data->input = asm_data->output;
116098 + asm_data->output = NULL;
116099 + asm_data->def_stmt = stmt;
116100 +
116101 + mark_str = convert_mark_to_str(mark);
116102 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
116103 +
116104 + create_asm_stmt(asm_comment, build_string(2, "rm"), NULL, asm_data);
116105 + free(asm_comment);
116106 + asm_data->input = NULL_TREE;
116107 + break;
116108 + }
116109 + case GIMPLE_ASM:
116110 + if (is_size_overflow_asm(asm_data->def_stmt)) {
116111 + asm_data->input = NULL_TREE;
116112 + break;
116113 + }
116114 + default:
116115 + debug_gimple_stmt(asm_data->def_stmt);
116116 + gcc_unreachable();
116117 + }
116118 +}
116119 +
116120 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
116121 + * is of the right kind create the appropriate size_overflow asm stmts:
116122 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
116123 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
116124 + */
116125 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
116126 +{
116127 + struct asm_data asm_data;
116128 + const char *mark_str;
116129 + char *asm_comment;
116130 + enum mark mark;
116131 +
116132 + if (is_gimple_constant(output_node))
116133 + return;
116134 +
116135 + asm_data.output = output_node;
116136 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
116137 + if (mark != MARK_TURN_OFF)
116138 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
116139 +
116140 + asm_data.def_stmt = get_def_stmt(asm_data.output);
116141 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
116142 + return;
116143 +
116144 + create_asm_input(stmt, argnum, &asm_data);
116145 + if (asm_data.input == NULL_TREE)
116146 + return;
116147 +
116148 + mark_str = convert_mark_to_str(mark);
116149 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
116150 + create_asm_stmt(asm_comment, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
116151 + free(asm_comment);
116152 +}
116153 +
116154 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
116155 +static bool create_mark_asm(gimple stmt, enum mark mark)
116156 +{
116157 + struct asm_data asm_data;
116158 + const char *asm_str;
116159 +
116160 + switch (mark) {
116161 + case MARK_TURN_OFF:
116162 + asm_str = TURN_OFF_ASM_STR;
116163 + break;
116164 + case MARK_NOT_INTENTIONAL:
116165 + case MARK_YES:
116166 + asm_str = YES_ASM_STR;
116167 + break;
116168 + default:
116169 + gcc_unreachable();
116170 + }
116171 +
116172 + asm_data.def_stmt = stmt;
116173 + asm_data.output = gimple_call_lhs(stmt);
116174 +
116175 + if (asm_data.output == NULL_TREE) {
116176 + asm_data.input = gimple_call_arg(stmt, 0);
116177 + if (is_gimple_constant(asm_data.input))
116178 + return false;
116179 + asm_data.output = NULL;
116180 + create_asm_stmt(asm_str, build_string(2, "rm"), NULL, &asm_data);
116181 + return true;
116182 + }
116183 +
116184 + create_asm_input(stmt, 0, &asm_data);
116185 + gcc_assert(asm_data.input != NULL_TREE);
116186 +
116187 + create_asm_stmt(asm_str, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
116188 + return true;
116189 +}
116190 +
116191 +static bool is_from_cast(const_tree node)
116192 +{
116193 + gimple def_stmt = get_def_stmt(node);
116194 +
116195 + if (!def_stmt)
116196 + return false;
116197 +
116198 + if (gimple_assign_cast_p(def_stmt))
116199 + return true;
116200 +
116201 + return false;
116202 +}
116203 +
116204 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
116205 +static bool skip_ptr_minus(gimple stmt)
116206 +{
116207 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
116208 +
116209 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116210 + return false;
116211 +
116212 + rhs1 = gimple_assign_rhs1(stmt);
116213 + if (!is_from_cast(rhs1))
116214 + return false;
116215 +
116216 + rhs2 = gimple_assign_rhs2(stmt);
116217 + if (!is_from_cast(rhs2))
116218 + return false;
116219 +
116220 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
116221 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
116222 +
116223 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
116224 + return false;
116225 +
116226 + create_mark_asm(stmt, MARK_YES);
116227 + return true;
116228 +}
116229 +
116230 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
116231 +{
116232 + gimple def_stmt;
116233 +
116234 + def_stmt = get_def_stmt(lhs);
116235 + if (!def_stmt)
116236 + return;
116237 +
116238 + if (pointer_set_insert(visited, def_stmt))
116239 + return;
116240 +
116241 + switch (gimple_code(def_stmt)) {
116242 + case GIMPLE_NOP:
116243 + case GIMPLE_ASM:
116244 + case GIMPLE_CALL:
116245 + break;
116246 + case GIMPLE_PHI: {
116247 + unsigned int i, n = gimple_phi_num_args(def_stmt);
116248 +
116249 + pointer_set_insert(visited, def_stmt);
116250 +
116251 + for (i = 0; i < n; i++) {
116252 + tree arg = gimple_phi_arg_def(def_stmt, i);
116253 +
116254 + walk_use_def_ptr(visited, arg);
116255 + }
116256 + }
116257 + case GIMPLE_ASSIGN:
116258 + switch (gimple_num_ops(def_stmt)) {
116259 + case 2:
116260 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
116261 + return;
116262 + case 3:
116263 + if (skip_ptr_minus(def_stmt))
116264 + return;
116265 +
116266 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
116267 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
116268 + return;
116269 + default:
116270 + return;
116271 + }
116272 + default:
116273 + debug_gimple_stmt((gimple)def_stmt);
116274 + error("%s: unknown gimple code", __func__);
116275 + gcc_unreachable();
116276 + }
116277 +}
116278 +
116279 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
116280 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
116281 +{
116282 + struct pointer_set_t *visited;
116283 +
116284 + visited = pointer_set_create();
116285 + walk_use_def_ptr(visited, arg);
116286 + pointer_set_destroy(visited);
116287 +}
116288 +
116289 +// Determine the return value and insert the asm stmt to mark the return stmt.
116290 +static void insert_asm_ret(gimple stmt)
116291 +{
116292 + tree ret;
116293 +
116294 + ret = gimple_return_retval(stmt);
116295 + create_size_overflow_asm(stmt, ret, 0);
116296 +}
116297 +
116298 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
116299 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
116300 +{
116301 + tree arg;
116302 + unsigned int argnum;
116303 +
116304 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
116305 + gcc_assert(argnum != 0);
116306 + if (argnum == CANNOT_FIND_ARG)
116307 + return;
116308 +
116309 + arg = gimple_call_arg(stmt, argnum - 1);
116310 + gcc_assert(arg != NULL_TREE);
116311 +
116312 + // skip all ptr - ptr expressions
116313 + insert_mark_not_intentional_asm_at_ptr(arg);
116314 +
116315 + create_size_overflow_asm(stmt, arg, argnum);
116316 +}
116317 +
116318 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
116319 +static void set_argnum_attribute(const_tree attr, bool *argnums)
116320 +{
116321 + unsigned int argnum;
116322 + tree attr_value;
116323 +
116324 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
116325 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
116326 + argnums[argnum] = true;
116327 + }
116328 +}
116329 +
116330 +// If a function arg or the return value is in the hash table then set its index in the array.
116331 +static void set_argnum_hash(tree fndecl, bool *argnums)
116332 +{
116333 + unsigned int num;
116334 + const struct size_overflow_hash *hash;
116335 +
116336 + hash = get_function_hash(DECL_ORIGIN(fndecl));
116337 + if (!hash)
116338 + return;
116339 +
116340 + for (num = 0; num <= MAX_PARAM; num++) {
116341 + if (!(hash->param & (1U << num)))
116342 + continue;
116343 +
116344 + argnums[num] = true;
116345 + }
116346 +}
116347 +
116348 +static bool is_all_the_argnums_empty(bool *argnums)
116349 +{
116350 + unsigned int i;
116351 +
116352 + for (i = 0; i <= MAX_PARAM; i++)
116353 + if (argnums[i])
116354 + return false;
116355 + return true;
116356 +}
116357 +
116358 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
116359 +static void search_interesting_args(tree fndecl, bool *argnums)
116360 +{
116361 + const_tree attr;
116362 +
116363 + set_argnum_hash(fndecl, argnums);
116364 + if (!is_all_the_argnums_empty(argnums))
116365 + return;
116366 +
116367 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
116368 + if (attr && TREE_VALUE(attr))
116369 + set_argnum_attribute(attr, argnums);
116370 +}
116371 +
116372 +/*
116373 + * Look up the intentional_overflow attribute that turns off ipa based duplication
116374 + * on the callee function.
116375 + */
116376 +static bool is_mark_turn_off_attribute(gimple stmt)
116377 +{
116378 + enum mark mark;
116379 + const_tree fndecl = gimple_call_fndecl(stmt);
116380 +
116381 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
116382 + if (mark == MARK_TURN_OFF)
116383 + return true;
116384 + return false;
116385 +}
116386 +
116387 +// 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
116388 +static void handle_interesting_function(gimple stmt)
116389 +{
116390 + unsigned int argnum;
116391 + tree fndecl;
116392 + bool orig_argnums[MAX_PARAM + 1] = {false};
116393 +
116394 + if (gimple_call_num_args(stmt) == 0)
116395 + return;
116396 + fndecl = gimple_call_fndecl(stmt);
116397 + if (fndecl == NULL_TREE)
116398 + return;
116399 + fndecl = DECL_ORIGIN(fndecl);
116400 +
116401 + if (is_mark_turn_off_attribute(stmt)) {
116402 + create_mark_asm(stmt, MARK_TURN_OFF);
116403 + return;
116404 + }
116405 +
116406 + search_interesting_args(fndecl, orig_argnums);
116407 +
116408 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
116409 + if (orig_argnums[argnum])
116410 + insert_asm_arg(stmt, argnum);
116411 +}
116412 +
116413 +// 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
116414 +static void handle_interesting_ret(gimple stmt)
116415 +{
116416 + bool orig_argnums[MAX_PARAM + 1] = {false};
116417 +
116418 + search_interesting_args(current_function_decl, orig_argnums);
116419 +
116420 + if (orig_argnums[0])
116421 + insert_asm_ret(stmt);
116422 +}
116423 +
116424 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
116425 +static unsigned int search_interesting_functions(void)
116426 +{
116427 + basic_block bb;
116428 +
116429 + FOR_ALL_BB_FN(bb, cfun) {
116430 + gimple_stmt_iterator gsi;
116431 +
116432 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116433 + gimple stmt = gsi_stmt(gsi);
116434 +
116435 + if (is_size_overflow_asm(stmt))
116436 + continue;
116437 +
116438 + if (is_gimple_call(stmt))
116439 + handle_interesting_function(stmt);
116440 + else if (gimple_code(stmt) == GIMPLE_RETURN)
116441 + handle_interesting_ret(stmt);
116442 + }
116443 + }
116444 + return 0;
116445 +}
116446 +
116447 +/*
116448 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
116449 + * this pass inserts asm stmts to mark the interesting args
116450 + * that the ipa pass will detect and insert the size overflow checks for.
116451 + */
116452 +#if BUILDING_GCC_VERSION >= 4009
116453 +static const struct pass_data insert_size_overflow_asm_pass_data = {
116454 +#else
116455 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
116456 + .pass = {
116457 +#endif
116458 + .type = GIMPLE_PASS,
116459 + .name = "insert_size_overflow_asm",
116460 +#if BUILDING_GCC_VERSION >= 4008
116461 + .optinfo_flags = OPTGROUP_NONE,
116462 +#endif
116463 +#if BUILDING_GCC_VERSION >= 4009
116464 + .has_gate = false,
116465 + .has_execute = true,
116466 +#else
116467 + .gate = NULL,
116468 + .execute = search_interesting_functions,
116469 + .sub = NULL,
116470 + .next = NULL,
116471 + .static_pass_number = 0,
116472 +#endif
116473 + .tv_id = TV_NONE,
116474 + .properties_required = PROP_cfg,
116475 + .properties_provided = 0,
116476 + .properties_destroyed = 0,
116477 + .todo_flags_start = 0,
116478 + .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
116479 +#if BUILDING_GCC_VERSION < 4009
116480 + }
116481 +#endif
116482 +};
116483 +
116484 +#if BUILDING_GCC_VERSION >= 4009
116485 +namespace {
116486 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
116487 +public:
116488 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
116489 + unsigned int execute() { return search_interesting_functions(); }
116490 +};
116491 +}
116492 +#endif
116493 +
116494 +static struct opt_pass *make_insert_size_overflow_asm_pass(void)
116495 +{
116496 +#if BUILDING_GCC_VERSION >= 4009
116497 + return new insert_size_overflow_asm_pass();
116498 +#else
116499 + return &insert_size_overflow_asm_pass.pass;
116500 +#endif
116501 +}
116502 +
116503 +// Create the noreturn report_size_overflow() function decl.
116504 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
116505 +{
116506 + tree fntype;
116507 +
116508 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
116509 +
116510 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
116511 + fntype = build_function_type_list(void_type_node,
116512 + const_char_ptr_type_node,
116513 + unsigned_type_node,
116514 + const_char_ptr_type_node,
116515 + const_char_ptr_type_node,
116516 + NULL_TREE);
116517 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
116518 +
116519 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
116520 + TREE_PUBLIC(report_size_overflow_decl) = 1;
116521 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
116522 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
116523 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
116524 +}
116525 +
116526 +static unsigned int dump_functions(void)
116527 +{
116528 + struct cgraph_node *node;
116529 +
116530 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116531 + basic_block bb;
116532 +
116533 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
116534 + current_function_decl = NODE_DECL(node);
116535 +
116536 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
116537 +
116538 + FOR_ALL_BB_FN(bb, cfun) {
116539 + gimple_stmt_iterator si;
116540 +
116541 + fprintf(stderr, "<bb %u>:\n", bb->index);
116542 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
116543 + debug_gimple_stmt(gsi_stmt(si));
116544 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116545 + debug_gimple_stmt(gsi_stmt(si));
116546 + fprintf(stderr, "\n");
116547 + }
116548 +
116549 + fprintf(stderr, "-------------------------------------------------------------------------\n");
116550 +
116551 + pop_cfun();
116552 + current_function_decl = NULL_TREE;
116553 + }
116554 +
116555 + fprintf(stderr, "###############################################################################\n");
116556 +
116557 + return 0;
116558 +}
116559 +
116560 +#if BUILDING_GCC_VERSION >= 4009
116561 +static const struct pass_data dump_pass_data = {
116562 +#else
116563 +static struct ipa_opt_pass_d dump_pass = {
116564 + .pass = {
116565 +#endif
116566 + .type = SIMPLE_IPA_PASS,
116567 + .name = "dump",
116568 +#if BUILDING_GCC_VERSION >= 4008
116569 + .optinfo_flags = OPTGROUP_NONE,
116570 +#endif
116571 +#if BUILDING_GCC_VERSION >= 4009
116572 + .has_gate = false,
116573 + .has_execute = true,
116574 +#else
116575 + .gate = NULL,
116576 + .execute = dump_functions,
116577 + .sub = NULL,
116578 + .next = NULL,
116579 + .static_pass_number = 0,
116580 +#endif
116581 + .tv_id = TV_NONE,
116582 + .properties_required = 0,
116583 + .properties_provided = 0,
116584 + .properties_destroyed = 0,
116585 + .todo_flags_start = 0,
116586 + .todo_flags_finish = 0,
116587 +#if BUILDING_GCC_VERSION < 4009
116588 + },
116589 + .generate_summary = NULL,
116590 + .write_summary = NULL,
116591 + .read_summary = NULL,
116592 +#if BUILDING_GCC_VERSION >= 4006
116593 + .write_optimization_summary = NULL,
116594 + .read_optimization_summary = NULL,
116595 +#endif
116596 + .stmt_fixup = NULL,
116597 + .function_transform_todo_flags_start = 0,
116598 + .function_transform = NULL,
116599 + .variable_transform = NULL,
116600 +#endif
116601 +};
116602 +
116603 +#if BUILDING_GCC_VERSION >= 4009
116604 +namespace {
116605 +class dump_pass : public ipa_opt_pass_d {
116606 +public:
116607 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
116608 + unsigned int execute() { return dump_functions(); }
116609 +};
116610 +}
116611 +#endif
116612 +
116613 +static struct opt_pass *make_dump_pass(void)
116614 +{
116615 +#if BUILDING_GCC_VERSION >= 4009
116616 + return new dump_pass();
116617 +#else
116618 + return &dump_pass.pass;
116619 +#endif
116620 +}
116621 +
116622 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
116623 +{
116624 + int i;
116625 + const char * const plugin_name = plugin_info->base_name;
116626 + const int argc = plugin_info->argc;
116627 + const struct plugin_argument * const argv = plugin_info->argv;
116628 + bool enable = true;
116629 + struct register_pass_info insert_size_overflow_asm_pass_info;
116630 + struct register_pass_info __unused dump_before_pass_info;
116631 + struct register_pass_info __unused dump_after_pass_info;
116632 + struct register_pass_info ipa_pass_info;
116633 +
116634 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
116635 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
116636 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
116637 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
116638 +
116639 + dump_before_pass_info.pass = make_dump_pass();
116640 + dump_before_pass_info.reference_pass_name = "increase_alignment";
116641 + dump_before_pass_info.ref_pass_instance_number = 1;
116642 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116643 +
116644 + ipa_pass_info.pass = make_ipa_pass();
116645 + ipa_pass_info.reference_pass_name = "increase_alignment";
116646 + ipa_pass_info.ref_pass_instance_number = 1;
116647 + ipa_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116648 +
116649 + dump_after_pass_info.pass = make_dump_pass();
116650 + dump_after_pass_info.reference_pass_name = "increase_alignment";
116651 + dump_after_pass_info.ref_pass_instance_number = 1;
116652 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116653 +
116654 + if (!plugin_default_version_check(version, &gcc_version)) {
116655 + error(G_("incompatible gcc/plugin versions"));
116656 + return 1;
116657 + }
116658 +
116659 + for (i = 0; i < argc; ++i) {
116660 + if (!strcmp(argv[i].key, "no-size-overflow")) {
116661 + enable = false;
116662 + continue;
116663 + }
116664 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
116665 + }
116666 +
116667 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
116668 + if (enable) {
116669 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
116670 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
116671 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
116672 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);
116673 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
116674 + }
116675 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
116676 +
116677 + return 0;
116678 +}
116679 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
116680 new file mode 100644
116681 index 0000000..a4f816a
116682 --- /dev/null
116683 +++ b/tools/gcc/stackleak_plugin.c
116684 @@ -0,0 +1,341 @@
116685 +/*
116686 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
116687 + * Licensed under the GPL v2
116688 + *
116689 + * Note: the choice of the license means that the compilation process is
116690 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
116691 + * but for the kernel it doesn't matter since it doesn't link against
116692 + * any of the gcc libraries
116693 + *
116694 + * gcc plugin to help implement various PaX features
116695 + *
116696 + * - track lowest stack pointer
116697 + *
116698 + * TODO:
116699 + * - initialize all local variables
116700 + *
116701 + * BUGS:
116702 + * - none known
116703 + */
116704 +
116705 +#include "gcc-common.h"
116706 +
116707 +int plugin_is_GPL_compatible;
116708 +
116709 +static int track_frame_size = -1;
116710 +static const char track_function[] = "pax_track_stack";
116711 +static const char check_function[] = "pax_check_alloca";
116712 +static bool init_locals;
116713 +
116714 +static struct plugin_info stackleak_plugin_info = {
116715 + .version = "201401260140",
116716 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
116717 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
116718 +};
116719 +
116720 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
116721 +{
116722 + gimple check_alloca;
116723 + tree fntype, fndecl, alloca_size;
116724 +
116725 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
116726 + fndecl = build_fn_decl(check_function, fntype);
116727 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
116728 +
116729 + // insert call to void pax_check_alloca(unsigned long size)
116730 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
116731 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
116732 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
116733 +}
116734 +
116735 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
116736 +{
116737 + gimple track_stack;
116738 + tree fntype, fndecl;
116739 +
116740 + fntype = build_function_type_list(void_type_node, NULL_TREE);
116741 + fndecl = build_fn_decl(track_function, fntype);
116742 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
116743 +
116744 + // insert call to void pax_track_stack(void)
116745 + track_stack = gimple_build_call(fndecl, 0);
116746 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
116747 +}
116748 +
116749 +static bool is_alloca(gimple stmt)
116750 +{
116751 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
116752 + return true;
116753 +
116754 +#if BUILDING_GCC_VERSION >= 4007
116755 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
116756 + return true;
116757 +#endif
116758 +
116759 + return false;
116760 +}
116761 +
116762 +static unsigned int execute_stackleak_tree_instrument(void)
116763 +{
116764 + basic_block bb, entry_bb;
116765 + bool prologue_instrumented = false, is_leaf = true;
116766 +
116767 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
116768 +
116769 + // 1. loop through BBs and GIMPLE statements
116770 + FOR_EACH_BB_FN(bb, cfun) {
116771 + gimple_stmt_iterator gsi;
116772 +
116773 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116774 + gimple stmt;
116775 +
116776 + stmt = gsi_stmt(gsi);
116777 +
116778 + if (is_gimple_call(stmt))
116779 + is_leaf = false;
116780 +
116781 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
116782 + if (!is_alloca(stmt))
116783 + continue;
116784 +
116785 + // 2. insert stack overflow check before each __builtin_alloca call
116786 + stackleak_check_alloca(&gsi);
116787 +
116788 + // 3. insert track call after each __builtin_alloca call
116789 + stackleak_add_instrumentation(&gsi);
116790 + if (bb == entry_bb)
116791 + prologue_instrumented = true;
116792 + }
116793 + }
116794 +
116795 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
116796 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
116797 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
116798 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
116799 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
116800 + return 0;
116801 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
116802 + return 0;
116803 +
116804 + // 4. insert track call at the beginning
116805 + if (!prologue_instrumented) {
116806 + gimple_stmt_iterator gsi;
116807 +
116808 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
116809 + if (dom_info_available_p(CDI_DOMINATORS))
116810 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
116811 + gsi = gsi_start_bb(bb);
116812 + stackleak_add_instrumentation(&gsi);
116813 + }
116814 +
116815 + return 0;
116816 +}
116817 +
116818 +static unsigned int execute_stackleak_final(void)
116819 +{
116820 + rtx insn, next;
116821 +
116822 + if (cfun->calls_alloca)
116823 + return 0;
116824 +
116825 + // keep calls only if function frame is big enough
116826 + if (get_frame_size() >= track_frame_size)
116827 + return 0;
116828 +
116829 + // 1. find pax_track_stack calls
116830 + for (insn = get_insns(); insn; insn = next) {
116831 + // 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))
116832 + rtx body;
116833 +
116834 + next = NEXT_INSN(insn);
116835 + if (!CALL_P(insn))
116836 + continue;
116837 + body = PATTERN(insn);
116838 + if (GET_CODE(body) != CALL)
116839 + continue;
116840 + body = XEXP(body, 0);
116841 + if (GET_CODE(body) != MEM)
116842 + continue;
116843 + body = XEXP(body, 0);
116844 + if (GET_CODE(body) != SYMBOL_REF)
116845 + continue;
116846 + if (strcmp(XSTR(body, 0), track_function))
116847 + continue;
116848 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
116849 + // 2. delete call
116850 + delete_insn_and_edges(insn);
116851 +#if BUILDING_GCC_VERSION >= 4007
116852 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
116853 + insn = next;
116854 + next = NEXT_INSN(insn);
116855 + delete_insn_and_edges(insn);
116856 + }
116857 +#endif
116858 + }
116859 +
116860 +// print_simple_rtl(stderr, get_insns());
116861 +// print_rtl(stderr, get_insns());
116862 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
116863 +
116864 + return 0;
116865 +}
116866 +
116867 +static bool gate_stackleak_track_stack(void)
116868 +{
116869 + return track_frame_size >= 0;
116870 +}
116871 +
116872 +#if BUILDING_GCC_VERSION >= 4009
116873 +static const struct pass_data stackleak_tree_instrument_pass_data = {
116874 +#else
116875 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
116876 + .pass = {
116877 +#endif
116878 + .type = GIMPLE_PASS,
116879 + .name = "stackleak_tree_instrument",
116880 +#if BUILDING_GCC_VERSION >= 4008
116881 + .optinfo_flags = OPTGROUP_NONE,
116882 +#endif
116883 +#if BUILDING_GCC_VERSION >= 4009
116884 + .has_gate = true,
116885 + .has_execute = true,
116886 +#else
116887 + .gate = gate_stackleak_track_stack,
116888 + .execute = execute_stackleak_tree_instrument,
116889 + .sub = NULL,
116890 + .next = NULL,
116891 + .static_pass_number = 0,
116892 +#endif
116893 + .tv_id = TV_NONE,
116894 + .properties_required = PROP_gimple_leh | PROP_cfg,
116895 + .properties_provided = 0,
116896 + .properties_destroyed = 0,
116897 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
116898 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
116899 +#if BUILDING_GCC_VERSION < 4009
116900 + }
116901 +#endif
116902 +};
116903 +
116904 +#if BUILDING_GCC_VERSION >= 4009
116905 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
116906 +#else
116907 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
116908 + .pass = {
116909 +#endif
116910 + .type = RTL_PASS,
116911 + .name = "stackleak_final",
116912 +#if BUILDING_GCC_VERSION >= 4008
116913 + .optinfo_flags = OPTGROUP_NONE,
116914 +#endif
116915 +#if BUILDING_GCC_VERSION >= 4009
116916 + .has_gate = true,
116917 + .has_execute = true,
116918 +#else
116919 + .gate = gate_stackleak_track_stack,
116920 + .execute = execute_stackleak_final,
116921 + .sub = NULL,
116922 + .next = NULL,
116923 + .static_pass_number = 0,
116924 +#endif
116925 + .tv_id = TV_NONE,
116926 + .properties_required = 0,
116927 + .properties_provided = 0,
116928 + .properties_destroyed = 0,
116929 + .todo_flags_start = 0,
116930 + .todo_flags_finish = TODO_dump_func
116931 +#if BUILDING_GCC_VERSION < 4009
116932 + }
116933 +#endif
116934 +};
116935 +
116936 +#if BUILDING_GCC_VERSION >= 4009
116937 +namespace {
116938 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
116939 +public:
116940 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
116941 + bool gate() { return gate_stackleak_track_stack(); }
116942 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
116943 +};
116944 +
116945 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
116946 +public:
116947 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
116948 + bool gate() { return gate_stackleak_track_stack(); }
116949 + unsigned int execute() { return execute_stackleak_final(); }
116950 +};
116951 +}
116952 +#endif
116953 +
116954 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
116955 +{
116956 +#if BUILDING_GCC_VERSION >= 4009
116957 + return new stackleak_tree_instrument_pass();
116958 +#else
116959 + return &stackleak_tree_instrument_pass.pass;
116960 +#endif
116961 +}
116962 +
116963 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
116964 +{
116965 +#if BUILDING_GCC_VERSION >= 4009
116966 + return new stackleak_final_rtl_opt_pass();
116967 +#else
116968 + return &stackleak_final_rtl_opt_pass.pass;
116969 +#endif
116970 +}
116971 +
116972 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
116973 +{
116974 + const char * const plugin_name = plugin_info->base_name;
116975 + const int argc = plugin_info->argc;
116976 + const struct plugin_argument * const argv = plugin_info->argv;
116977 + int i;
116978 + struct register_pass_info stackleak_tree_instrument_pass_info;
116979 + struct register_pass_info stackleak_final_pass_info;
116980 +
116981 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
116982 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
116983 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
116984 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
116985 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116986 +
116987 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
116988 + stackleak_final_pass_info.reference_pass_name = "final";
116989 + stackleak_final_pass_info.ref_pass_instance_number = 1;
116990 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116991 +
116992 + if (!plugin_default_version_check(version, &gcc_version)) {
116993 + error(G_("incompatible gcc/plugin versions"));
116994 + return 1;
116995 + }
116996 +
116997 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
116998 +
116999 + for (i = 0; i < argc; ++i) {
117000 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
117001 + if (!argv[i].value) {
117002 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117003 + continue;
117004 + }
117005 + track_frame_size = atoi(argv[i].value);
117006 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
117007 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
117008 + continue;
117009 + }
117010 + if (!strcmp(argv[i].key, "initialize-locals")) {
117011 + if (argv[i].value) {
117012 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
117013 + continue;
117014 + }
117015 + init_locals = true;
117016 + continue;
117017 + }
117018 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117019 + }
117020 +
117021 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
117022 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
117023 +
117024 + return 0;
117025 +}
117026 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
117027 new file mode 100644
117028 index 0000000..796569a
117029 --- /dev/null
117030 +++ b/tools/gcc/structleak_plugin.c
117031 @@ -0,0 +1,273 @@
117032 +/*
117033 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
117034 + * Licensed under the GPL v2
117035 + *
117036 + * Note: the choice of the license means that the compilation process is
117037 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
117038 + * but for the kernel it doesn't matter since it doesn't link against
117039 + * any of the gcc libraries
117040 + *
117041 + * gcc plugin to forcibly initialize certain local variables that could
117042 + * otherwise leak kernel stack to userland if they aren't properly initialized
117043 + * by later code
117044 + *
117045 + * Homepage: http://pax.grsecurity.net/
117046 + *
117047 + * Usage:
117048 + * $ # for 4.5/4.6/C based 4.7
117049 + * $ 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
117050 + * $ # for C++ based 4.7/4.8+
117051 + * $ 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
117052 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
117053 + *
117054 + * TODO: eliminate redundant initializers
117055 + * increase type coverage
117056 + */
117057 +
117058 +#include "gcc-common.h"
117059 +
117060 +// unused C type flag in all versions 4.5-4.9
117061 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
117062 +
117063 +int plugin_is_GPL_compatible;
117064 +
117065 +static struct plugin_info structleak_plugin_info = {
117066 + .version = "201401260140",
117067 + .help = "disable\tdo not activate plugin\n",
117068 +};
117069 +
117070 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
117071 +{
117072 + *no_add_attrs = true;
117073 +
117074 + // check for types? for now accept everything linux has to offer
117075 + if (TREE_CODE(*node) != FIELD_DECL)
117076 + return NULL_TREE;
117077 +
117078 + *no_add_attrs = false;
117079 + return NULL_TREE;
117080 +}
117081 +
117082 +static struct attribute_spec user_attr = {
117083 + .name = "user",
117084 + .min_length = 0,
117085 + .max_length = 0,
117086 + .decl_required = false,
117087 + .type_required = false,
117088 + .function_type_required = false,
117089 + .handler = handle_user_attribute,
117090 +#if BUILDING_GCC_VERSION >= 4007
117091 + .affects_type_identity = true
117092 +#endif
117093 +};
117094 +
117095 +static void register_attributes(void *event_data, void *data)
117096 +{
117097 + register_attribute(&user_attr);
117098 +// register_attribute(&force_attr);
117099 +}
117100 +
117101 +static tree get_field_type(tree field)
117102 +{
117103 + return strip_array_types(TREE_TYPE(field));
117104 +}
117105 +
117106 +static bool is_userspace_type(tree type)
117107 +{
117108 + tree field;
117109 +
117110 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
117111 + tree fieldtype = get_field_type(field);
117112 + enum tree_code code = TREE_CODE(fieldtype);
117113 +
117114 + if (code == RECORD_TYPE || code == UNION_TYPE)
117115 + if (is_userspace_type(fieldtype))
117116 + return true;
117117 +
117118 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
117119 + return true;
117120 + }
117121 + return false;
117122 +}
117123 +
117124 +static void finish_type(void *event_data, void *data)
117125 +{
117126 + tree type = (tree)event_data;
117127 +
117128 + if (TYPE_USERSPACE(type))
117129 + return;
117130 +
117131 + if (is_userspace_type(type))
117132 + TYPE_USERSPACE(type) = 1;
117133 +}
117134 +
117135 +static void initialize(tree var)
117136 +{
117137 + basic_block bb;
117138 + gimple_stmt_iterator gsi;
117139 + tree initializer;
117140 + gimple init_stmt;
117141 +
117142 + // this is the original entry bb before the forced split
117143 + // TODO: check further BBs in case more splits occured before us
117144 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
117145 +
117146 + // first check if the variable is already initialized, warn otherwise
117147 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117148 + gimple stmt = gsi_stmt(gsi);
117149 + tree rhs1;
117150 +
117151 + // we're looking for an assignment of a single rhs...
117152 + if (!gimple_assign_single_p(stmt))
117153 + continue;
117154 + rhs1 = gimple_assign_rhs1(stmt);
117155 +#if BUILDING_GCC_VERSION >= 4007
117156 + // ... of a non-clobbering expression...
117157 + if (TREE_CLOBBER_P(rhs1))
117158 + continue;
117159 +#endif
117160 + // ... to our variable...
117161 + if (gimple_get_lhs(stmt) != var)
117162 + continue;
117163 + // if it's an initializer then we're good
117164 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
117165 + return;
117166 + }
117167 +
117168 + // these aren't the 0days you're looking for
117169 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
117170 +
117171 + // build the initializer expression
117172 + initializer = build_constructor(TREE_TYPE(var), NULL);
117173 +
117174 + // build the initializer stmt
117175 + init_stmt = gimple_build_assign(var, initializer);
117176 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
117177 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
117178 + update_stmt(init_stmt);
117179 +}
117180 +
117181 +static unsigned int handle_function(void)
117182 +{
117183 + basic_block bb;
117184 + unsigned int ret = 0;
117185 + tree var;
117186 + unsigned int i;
117187 +
117188 + // split the first bb where we can put the forced initializers
117189 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
117190 + if (dom_info_available_p(CDI_DOMINATORS))
117191 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
117192 +
117193 + // enumarate all local variables and forcibly initialize our targets
117194 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
117195 + tree type = TREE_TYPE(var);
117196 +
117197 + gcc_assert(DECL_P(var));
117198 + if (!auto_var_in_fn_p(var, current_function_decl))
117199 + continue;
117200 +
117201 + // only care about structure types
117202 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
117203 + continue;
117204 +
117205 + // if the type is of interest, examine the variable
117206 + if (TYPE_USERSPACE(type))
117207 + initialize(var);
117208 + }
117209 +
117210 + return ret;
117211 +}
117212 +
117213 +#if BUILDING_GCC_VERSION >= 4009
117214 +static const struct pass_data structleak_pass_data = {
117215 +#else
117216 +static struct gimple_opt_pass structleak_pass = {
117217 + .pass = {
117218 +#endif
117219 + .type = GIMPLE_PASS,
117220 + .name = "structleak",
117221 +#if BUILDING_GCC_VERSION >= 4008
117222 + .optinfo_flags = OPTGROUP_NONE,
117223 +#endif
117224 +#if BUILDING_GCC_VERSION >= 4009
117225 + .has_gate = false,
117226 + .has_execute = true,
117227 +#else
117228 + .gate = NULL,
117229 + .execute = handle_function,
117230 + .sub = NULL,
117231 + .next = NULL,
117232 + .static_pass_number = 0,
117233 +#endif
117234 + .tv_id = TV_NONE,
117235 + .properties_required = PROP_cfg,
117236 + .properties_provided = 0,
117237 + .properties_destroyed = 0,
117238 + .todo_flags_start = 0,
117239 + .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
117240 +#if BUILDING_GCC_VERSION < 4009
117241 + }
117242 +#endif
117243 +};
117244 +
117245 +#if BUILDING_GCC_VERSION >= 4009
117246 +namespace {
117247 +class structleak_pass : public gimple_opt_pass {
117248 +public:
117249 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
117250 + unsigned int execute() { return handle_function(); }
117251 +};
117252 +}
117253 +#endif
117254 +
117255 +static struct opt_pass *make_structleak_pass(void)
117256 +{
117257 +#if BUILDING_GCC_VERSION >= 4009
117258 + return new structleak_pass();
117259 +#else
117260 + return &structleak_pass.pass;
117261 +#endif
117262 +}
117263 +
117264 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117265 +{
117266 + int i;
117267 + const char * const plugin_name = plugin_info->base_name;
117268 + const int argc = plugin_info->argc;
117269 + const struct plugin_argument * const argv = plugin_info->argv;
117270 + bool enable = true;
117271 + struct register_pass_info structleak_pass_info;
117272 +
117273 + structleak_pass_info.pass = make_structleak_pass();
117274 + structleak_pass_info.reference_pass_name = "ssa";
117275 + structleak_pass_info.ref_pass_instance_number = 1;
117276 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117277 +
117278 + if (!plugin_default_version_check(version, &gcc_version)) {
117279 + error(G_("incompatible gcc/plugin versions"));
117280 + return 1;
117281 + }
117282 +
117283 + if (strcmp(lang_hooks.name, "GNU C")) {
117284 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
117285 + enable = false;
117286 + }
117287 +
117288 + for (i = 0; i < argc; ++i) {
117289 + if (!strcmp(argv[i].key, "disable")) {
117290 + enable = false;
117291 + continue;
117292 + }
117293 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117294 + }
117295 +
117296 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
117297 + if (enable) {
117298 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
117299 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
117300 + }
117301 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
117302 +
117303 + return 0;
117304 +}
117305 diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
117306 index 3dba0a4..97175dc 100644
117307 --- a/tools/lib/lk/Makefile
117308 +++ b/tools/lib/lk/Makefile
117309 @@ -13,7 +13,7 @@ LIB_OBJS += $(OUTPUT)debugfs.o
117310
117311 LIBFILE = liblk.a
117312
117313 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
117314 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
117315 EXTLIBS = -lelf -lpthread -lrt -lm
117316 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
117317 ALL_LDFLAGS = $(LDFLAGS)
117318 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
117319 index 6789d78..4afd019e 100644
117320 --- a/tools/perf/util/include/asm/alternative-asm.h
117321 +++ b/tools/perf/util/include/asm/alternative-asm.h
117322 @@ -5,4 +5,7 @@
117323
117324 #define altinstruction_entry #
117325
117326 + .macro pax_force_retaddr rip=0, reload=0
117327 + .endm
117328 +
117329 #endif
117330 diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h
117331 index b003ad7..c0a02f8 100644
117332 --- a/tools/perf/util/include/linux/compiler.h
117333 +++ b/tools/perf/util/include/linux/compiler.h
117334 @@ -27,4 +27,12 @@
117335 # define __weak __attribute__((weak))
117336 #endif
117337
117338 +#ifndef __size_overflow
117339 +# define __size_overflow(...)
117340 +#endif
117341 +
117342 +#ifndef __intentional_overflow
117343 +# define __intentional_overflow(...)
117344 +#endif
117345 +
117346 #endif
117347 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
117348 index 4f588bc..d3cfc5c 100644
117349 --- a/virt/kvm/kvm_main.c
117350 +++ b/virt/kvm/kvm_main.c
117351 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
117352
117353 static cpumask_var_t cpus_hardware_enabled;
117354 static int kvm_usage_count = 0;
117355 -static atomic_t hardware_enable_failed;
117356 +static atomic_unchecked_t hardware_enable_failed;
117357
117358 struct kmem_cache *kvm_vcpu_cache;
117359 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
117360
117361 -static __read_mostly struct preempt_ops kvm_preempt_ops;
117362 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
117363 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
117364 +static struct preempt_ops kvm_preempt_ops = {
117365 + .sched_in = kvm_sched_in,
117366 + .sched_out = kvm_sched_out,
117367 +};
117368
117369 struct dentry *kvm_debugfs_dir;
117370
117371 @@ -751,7 +756,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
117372 /* We can read the guest memory with __xxx_user() later on. */
117373 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
117374 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
117375 - !access_ok(VERIFY_WRITE,
117376 + !__access_ok(VERIFY_WRITE,
117377 (void __user *)(unsigned long)mem->userspace_addr,
117378 mem->memory_size)))
117379 goto out;
117380 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
117381
117382 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
117383 {
117384 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
117385 + int r;
117386 + unsigned long addr;
117387
117388 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
117389 + addr = gfn_to_hva(kvm, gfn);
117390 + if (kvm_is_error_hva(addr))
117391 + return -EFAULT;
117392 + r = __clear_user((void __user *)addr + offset, len);
117393 + if (r)
117394 + return -EFAULT;
117395 + mark_page_dirty(kvm, gfn);
117396 + return 0;
117397 }
117398 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
117399
117400 @@ -1872,7 +1885,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
117401 return 0;
117402 }
117403
117404 -static struct file_operations kvm_vcpu_fops = {
117405 +static file_operations_no_const kvm_vcpu_fops __read_only = {
117406 .release = kvm_vcpu_release,
117407 .unlocked_ioctl = kvm_vcpu_ioctl,
117408 #ifdef CONFIG_COMPAT
117409 @@ -2532,7 +2545,7 @@ out:
117410 }
117411 #endif
117412
117413 -static struct file_operations kvm_vm_fops = {
117414 +static file_operations_no_const kvm_vm_fops __read_only = {
117415 .release = kvm_vm_release,
117416 .unlocked_ioctl = kvm_vm_ioctl,
117417 #ifdef CONFIG_COMPAT
117418 @@ -2632,7 +2645,7 @@ out:
117419 return r;
117420 }
117421
117422 -static struct file_operations kvm_chardev_ops = {
117423 +static file_operations_no_const kvm_chardev_ops __read_only = {
117424 .unlocked_ioctl = kvm_dev_ioctl,
117425 .compat_ioctl = kvm_dev_ioctl,
117426 .llseek = noop_llseek,
117427 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
117428
117429 if (r) {
117430 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
117431 - atomic_inc(&hardware_enable_failed);
117432 + atomic_inc_unchecked(&hardware_enable_failed);
117433 printk(KERN_INFO "kvm: enabling virtualization on "
117434 "CPU%d failed\n", cpu);
117435 }
117436 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
117437
117438 kvm_usage_count++;
117439 if (kvm_usage_count == 1) {
117440 - atomic_set(&hardware_enable_failed, 0);
117441 + atomic_set_unchecked(&hardware_enable_failed, 0);
117442 on_each_cpu(hardware_enable_nolock, NULL, 1);
117443
117444 - if (atomic_read(&hardware_enable_failed)) {
117445 + if (atomic_read_unchecked(&hardware_enable_failed)) {
117446 hardware_disable_all_nolock();
117447 r = -EBUSY;
117448 }
117449 @@ -3148,7 +3161,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
117450 kvm_arch_vcpu_put(vcpu);
117451 }
117452
117453 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117454 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117455 struct module *module)
117456 {
117457 int r;
117458 @@ -3195,7 +3208,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117459 if (!vcpu_align)
117460 vcpu_align = __alignof__(struct kvm_vcpu);
117461 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
117462 - 0, NULL);
117463 + SLAB_USERCOPY, NULL);
117464 if (!kvm_vcpu_cache) {
117465 r = -ENOMEM;
117466 goto out_free_3;
117467 @@ -3205,9 +3218,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117468 if (r)
117469 goto out_free;
117470
117471 + pax_open_kernel();
117472 kvm_chardev_ops.owner = module;
117473 kvm_vm_fops.owner = module;
117474 kvm_vcpu_fops.owner = module;
117475 + pax_close_kernel();
117476
117477 r = misc_register(&kvm_dev);
117478 if (r) {
117479 @@ -3217,9 +3232,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117480
117481 register_syscore_ops(&kvm_syscore_ops);
117482
117483 - kvm_preempt_ops.sched_in = kvm_sched_in;
117484 - kvm_preempt_ops.sched_out = kvm_sched_out;
117485 -
117486 r = kvm_init_debug();
117487 if (r) {
117488 printk(KERN_ERR "kvm: create debugfs files failed\n");